[atlas] / groups / Asap / pilotcorba / AsapPilotImpl.cc Repository:
ViewVC logotype

Annotation of /groups/Asap/pilotcorba/AsapPilotImpl.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.7 - (view) (download)

1 : giraudpf 1.1 #include "AsapPilotImpl.hh"
2 :    
3 :     #include "Pilot.h"
4 :     #include "Element.h"
5 :     #include "UTCTime.hh"
6 :     #include "CdbTree.h"
7 :     #include "RootTreeImpl.h"
8 :     #include "RootTree.hh"
9 :     #include "DbTreeCorba.hh"
10 :     #include "AsapException.hh"
11 :     #include "Rasnik.h"
12 :     #include "SurveySensor.hh"
13 :     #include "Handle.hh"
14 :     #include "AsapIOV.hh"
15 :     #include "AsapResultHeader.hh"
16 :     #include "AsapCorrection.hh"
17 :     #include "AsapSensorSummary.hh"
18 :     #include "AsapSensorMeasurement.hh"
19 :     #include "AsapSensorResidual.hh"
20 :     #include "AsapConfSection.hh"
21 :     #include "ScopedLock.hh"
22 : giraudpf 1.6 #include "LogStream.hh"
23 : giraudpf 1.1 #include "TFile.h"
24 :    
25 :     #include <sstream>
26 :     #include <memory>
27 : giraudpf 1.3 #include <cassert>
28 : giraudpf 1.1
29 :     #include <string.h>
30 :    
31 :     using namespace std;
32 : giraudpf 1.3 using namespace asap;
33 : giraudpf 1.1
34 :     namespace asap
35 :     {
36 :     namespace pilot
37 :     {
38 :     namespace facade
39 :     {
40 :     namespace corba
41 :     {
42 :    
43 :     using namespace asap::jdbtree::facade::corba;
44 :     using namespace asap::servers::corba;
45 :    
46 :     AsapPilotFactoryImpl* AsapPilotFactoryImpl::pilotFactory = NULL;
47 :    
48 :    
49 : giraudpf 1.3 asap::Log AsapPilotFactoryImpl::log("AsapPilotFactoryImpl");
50 :     asap::Log AsapPilotImpl::log("AsapPilotImpl");
51 :    
52 : giraudpf 1.1
53 :     AsapPilotFactoryImpl::AsapPilotFactoryImpl()
54 :     {
55 :     }
56 :    
57 :     AsapPilotFactoryImpl::~AsapPilotFactoryImpl()
58 :     {
59 : giraudpf 1.3 log(DEBUG).printf("AsapPilotFactory deleted\n");
60 : giraudpf 1.1 }
61 :    
62 :     AsapPilot_ptr AsapPilotFactoryImpl::createPilot(const char* fname)
63 :     {
64 :     // Synchronize this method
65 :     ScopedLock lock;
66 :    
67 :     try {
68 : giraudpf 1.3 log(DEBUG).printf("Creating pilot ... \n");
69 : giraudpf 1.1 Pilot* p = new Pilot(fname);
70 :    
71 :     AsapPilotImpl *pilotImpl = new AsapPilotImpl(p);
72 :     PortableServer::ServantBase_var servant = pilotImpl;
73 :     AsapPilot_var pilot = pilotImpl->_this();
74 : giraudpf 1.3 log(DEBUG).printf("End of Pilot Creation...send back a Corba reference\n");
75 : giraudpf 1.1 return pilot._retn();
76 :     } catch (AsapException e) {
77 :     throw AsapServerException(e.what());
78 :     }
79 :     }
80 :    
81 :     AsapPilotFactoryImpl* AsapPilotFactoryImpl::getInstance()
82 :     {
83 :     if(!pilotFactory)
84 :     {
85 :     pilotFactory = new AsapPilotFactoryImpl;
86 :     }
87 :     return pilotFactory;
88 :     }
89 :    
90 :     AsapPilotImpl::AsapPilotImpl(Pilot* pilot) : m_p(pilot)
91 :     {
92 :     }
93 :    
94 :     AsapPilotImpl::~AsapPilotImpl()
95 :     {
96 : giraudpf 1.3 log(DEBUG).printf("AsapPilot deleted\n");
97 : giraudpf 1.1 }
98 :    
99 :     void AsapPilotImpl::destroy()
100 :     {
101 :     try {
102 : giraudpf 1.3 log(DEBUG).printf("Destroying Pilot Corba Proxy on Server : \n");
103 : giraudpf 1.1
104 :     // get the poa
105 :     PortableServer::POA_var poa = this->_default_POA();
106 :     PortableServer::ObjectId_var oid = poa->servant_to_id(this);
107 :     poa->deactivate_object(oid.in());
108 :     } catch (AsapException e) {
109 :     throw AsapServerException(e.what());
110 :     }
111 :     }
112 :    
113 :     void AsapPilotImpl::setElementConfiguration(const char* id, CORBA::Boolean activate) {
114 :     // Synchronize this method
115 :     ScopedLock lock;
116 :    
117 :     try {
118 :     AsapConfiguration& config = *(this->m_p->getConfiguration());
119 : giraudpf 1.7 int irow = config["configelementvar"].getRow(id);
120 :     if (irow == -1)
121 :     throw AsapServerException(Form("Invalid element id %s", id));
122 :     config["configelementvar"].setInt("activate", irow, (activate ? 1 : 0));
123 : giraudpf 1.1 } catch (AsapException e) {
124 :     throw AsapServerException(e.what());
125 :     }
126 :     }
127 :    
128 :     void AsapPilotImpl::setOpticallineConfiguration(const char* id, CORBA::Boolean activate, CORBA::Boolean absolute) {
129 :     // Synchronize this method
130 :     ScopedLock lock;
131 :    
132 :     try {
133 :     AsapConfiguration& config = *(this->m_p->getConfiguration());
134 : giraudpf 1.7
135 : giraudpf 1.1 string section = "configoptlinevar";
136 : giraudpf 1.7 section += string(id,0,3); // hack
137 :     int irow = config[section].getRow(id);
138 :     if (irow == -1)
139 :     throw AsapServerException(Form("Invalid sensor id %s", id));
140 :     config[section].setInt("activate", irow, (activate ? 1 : 0));
141 :     config[section].setInt("absolute", irow, (absolute ? 1 : 0));
142 : giraudpf 1.1 } catch (AsapException e) {
143 :     throw AsapServerException(e.what());
144 :     }
145 :     }
146 :    
147 :     void AsapPilotImpl::setAmdb(const char* amdbfile) {
148 :     // Synchronize this method
149 :     ScopedLock lock;
150 :    
151 :     try {
152 :     AsapConfiguration& config = *(this->m_p->getConfiguration());
153 :     config.setAmdb("amdb", amdbfile);
154 :     config.setAmdb("amdb_nom", amdbfile);
155 :     } catch (AsapException e) {
156 :     throw AsapServerException(e.what());
157 :     }
158 :     }
159 :    
160 :     void AsapPilotImpl::setSensorOffset(const char* id, CORBA::Double x, CORBA::Double y, CORBA::Double mag, CORBA::Double tz,
161 :     CORBA::Double err_x, CORBA::Double err_y, CORBA::Double err_mag, CORBA::Double err_tz) {
162 :     // Synchronize this method
163 :     ScopedLock lock;
164 :    
165 :     try {
166 :     AsapConfiguration& config = *(this->m_p->getConfiguration());
167 :     AsapConfSection& sensor_offset = config["sensor_offset"];
168 : giraudpf 1.7 int irow = sensor_offset.getRow(id);
169 :     if (irow == -1) {
170 :     irow = sensor_offset.getInt("nrow");
171 :     sensor_offset.setString("name", irow, id);
172 :     sensor_offset.setRowName(irow, id);
173 :     sensor_offset.setInt("nrow", irow+1);
174 :     }
175 :     sensor_offset.setFloat("x", irow, x);
176 :     sensor_offset.setFloat("y", irow, y);
177 :     sensor_offset.setFloat("mag", irow, mag);
178 :     sensor_offset.setFloat("tz", irow, tz);
179 :     sensor_offset.setFloat("sx", irow, err_x);
180 :     sensor_offset.setFloat("sy", irow, err_y);
181 :     sensor_offset.setFloat("smag", irow, err_mag);
182 :     sensor_offset.setFloat("stz", irow, err_tz);
183 : giraudpf 1.1 } catch (AsapException e) {
184 :     throw AsapServerException(e.what());
185 :     }
186 :     }
187 :    
188 :     void AsapPilotImpl::setConditions(const Conditions& cond) {
189 :     // Synchronize this method
190 :     ScopedLock lock;
191 :    
192 :     try {
193 : giraudpf 1.3 log(DEBUG).printf("setConditions_old %lld %lld %lld %s\n",
194 : giraudpf 1.4 (long long)cond.since, (long long)cond.till,
195 : giraudpf 1.5 (long long)cond.iov_id, (const char*)cond.tag);
196 : giraudpf 1.1 // create a new Conditions object to send to Pilot
197 :     Handle< ::Conditions > asap_cond = new ::Conditions();
198 :     asap_cond -> setSince(UTCTime(cond.since));
199 :     asap_cond -> setTill(UTCTime(cond.till));
200 :     asap_cond -> setIovId(cond.iov_id);
201 :     asap_cond -> setTag ((const char*)cond.tag);
202 :    
203 :     PortableServer::POA_var poa = this->_default_POA();
204 :    
205 :     TTree* ictree = NULL;
206 :     PortableServer::ServantBase_var servantIcTree;
207 :     if(!CORBA::is_nil(cond.icaras_tree))
208 :     {
209 :     servantIcTree = poa->reference_to_servant(cond.icaras_tree);
210 :     RootTreeImpl *rootIcTree = dynamic_cast<RootTreeImpl*>(servantIcTree.in());
211 :     ictree = rootIcTree->getTree();
212 :     }
213 :     asap_cond -> setIcarasData(new CdbTree(ictree));
214 :    
215 :     TTree* temptree = NULL;
216 :     PortableServer::ServantBase_var servantTempTree;
217 :     if(!CORBA::is_nil(cond.temp_tree))
218 :     {
219 :     servantTempTree = poa->reference_to_servant(cond.temp_tree);
220 :     RootTreeImpl *rootTempTree = dynamic_cast<RootTreeImpl*>(servantTempTree.in());
221 :     temptree = rootTempTree->getTree();
222 :     }
223 :     asap_cond->setTemperatureData(new CdbTree(temptree));
224 :    
225 :     // send the conditions to Pilot
226 :     this->m_p->setConditions(asap_cond);
227 :     } catch (AsapException e) {
228 :     throw AsapServerException(e.what());
229 :     }
230 :     }
231 :    
232 :     void AsapPilotImpl::getOutputData(IOVList_out outIOVs)
233 :     {
234 :     // Synchronize this method
235 :     ScopedLock lock;
236 :    
237 :     try {
238 :     Handle<CdbAsap> outputs = m_p->getOutputHandler();
239 :     //printOutput(outputs);
240 :     unsigned nIov = outputs->getEntries();
241 :     outIOVs = new IOVList();
242 :     outIOVs->length(nIov);
243 :     for(unsigned i = 0; i < nIov; i++)
244 :     {
245 :     convertIOV(*outputs->getIOV(i), outIOVs[i]);
246 :     }
247 :     } catch (AsapException e) {
248 :     throw AsapServerException(e.what());
249 :     }
250 :     }
251 :    
252 :     void AsapPilotImpl::writeOutputData (const char* rootfilename) {
253 :     // Synchronize this method
254 :     ScopedLock lock;
255 :    
256 :     try {
257 : giraudpf 1.3 log(DEBUG).printf("AsapPilotImpl::writeOutputData\n");
258 : giraudpf 1.1 Handle<CdbAsap> out = m_p->getOutputHandler();
259 :     TTree* outtree = out -> getCurrentTree ();
260 :     TFile* fout = TFile::Open(rootfilename, "RECREATE");
261 :     if (!fout) {
262 : giraudpf 1.3 log(ERR).printf("writeOutputData: cannot open output file %s\n",
263 : giraudpf 1.1 rootfilename);
264 :     return;
265 :     }
266 :     outtree->CloneTree()->Write();
267 :     fout->Close ();
268 :     } catch (AsapException e) {
269 :     throw AsapServerException(e.what());
270 :     }
271 :     }
272 :    
273 :     void AsapPilotImpl::clearOutputData () {
274 :     // Synchronize this method
275 :     ScopedLock lock;
276 :    
277 :     try {
278 : giraudpf 1.3 log(DEBUG).printf("AsapPilotImpl::clearOutputData\n");
279 : giraudpf 1.1 m_p->setOutputHandler(new CdbAsap());
280 :     } catch (AsapException e) {
281 :     throw AsapServerException(e.what());
282 :     }
283 :     }
284 :    
285 :     void AsapPilotImpl::reco(const FitParameters& thefit)
286 :     {
287 :     // Synchronize this method
288 :     ScopedLock lock;
289 :    
290 :     try {
291 : giraudpf 1.3 log(INFO).printf("reco: running ASAP reconstruction on IOV %lld, tag %s, since %s, till %s\n",
292 :     this->m_p->getConditions()->getIovId(),
293 :     this->m_p->getConditions()->getTag().Data(),
294 :     UTCTime(this->m_p->getConditions()->getSince()).getString().c_str(),
295 :     UTCTime(this->m_p->getConditions()->getTill()).getString().c_str());
296 : giraudpf 1.1
297 :     // Set the output data container
298 :     Handle<CdbAsap> local_out = new CdbAsap ();
299 :     this->m_p->setOutputHandler (local_out);
300 :     this->m_p->reco(thefit.iterations);
301 :     } catch (AsapException e) {
302 :     throw AsapServerException(e.what());
303 :     }
304 :     }
305 :    
306 :     void AsapPilotImpl::printOutput (Handle<CdbAsap> out)
307 :     {
308 :     try {
309 :     int ncorr = out -> getEntries ();
310 :     for (int icorr = 0; icorr < ncorr; icorr ++)
311 :     {
312 :     cout << "***" << endl
313 :     << "*** IOV number " << icorr << endl
314 :     << "***" << endl;
315 :     const AsapIOV* iov = out->getIOV(icorr);
316 :     const AsapResultHeader *h = iov -> getResultHeader(0);
317 :     int ncorr = h -> getNCorrections ();
318 :    
319 :     cout << "since = " << UTCTime(iov -> getSinceT ()).getString () << endl
320 :     << "till = " << UTCTime(iov -> getTillT ()).getString () << endl
321 :     << "Chi2 = " << h -> getChi2Norm () << endl
322 :     << "NCorrections = " << ncorr << endl;
323 :    
324 :     for (int i=0; i<ncorr; i++)
325 :     {
326 :     const AsapCorrection* c = h -> getCorrection (i);
327 :     cout << "---------------------------------------" << endl
328 :     << "Chamber = " << c -> getAsapID () << endl
329 :     << "s = " << c -> getS () << endl
330 :     << "z = " << c -> getZ () << endl
331 :     << "t = " << c -> getT () << endl
332 :     << "thetaS = " << c -> getThetaS () << endl
333 :     << "thetaZ = " << c -> getThetaZ () << endl
334 :     << "thetaT = " << c -> getThetaT () << endl;
335 :     }
336 :     }
337 :     } catch (AsapException e) {
338 :     throw AsapServerException(e.what());
339 :     }
340 :     }
341 :    
342 :     void AsapPilotImpl::convertIOV(const AsapIOV& asapIOV, AlignIOV& corbaIOV)
343 :     {
344 :     try {
345 :     corbaIOV.iov_id = asapIOV.getIovId();
346 :     corbaIOV.since = asapIOV.getSinceT();
347 :     corbaIOV.till = asapIOV.getTillT();
348 :    
349 :     assert(asapIOV.getNResultHeaders() == 1);
350 :     const AsapResultHeader& asapResult = *asapIOV.getResultHeader(0);
351 :     corbaIOV.results.length(1);
352 :     convertResult(asapResult, corbaIOV.results[0]);
353 :    
354 :     int nCorr = asapResult.getNCorrections();
355 :     corbaIOV.corrections.length(nCorr);
356 :     for(int i = 0; i < nCorr; i++)
357 :     {
358 :     convertCorrection(*asapResult.getCorrection(i), corbaIOV.corrections[i]);
359 :     }
360 :     int nSensorSummary = asapResult.getNSensorSummary();
361 :     corbaIOV.sensorsummary.length(nSensorSummary);
362 :     for(int i = 0; i < nSensorSummary; i++)
363 :     {
364 :     convertSensorSummary(*asapResult.getSensorSummary(i), corbaIOV.sensorsummary[i]);
365 :     }
366 :     int nSensorResidual = asapResult.getNSensorResiduals();
367 :     corbaIOV.sensorresidual.length(nSensorResidual);
368 :     for(int i = 0; i < nSensorResidual; i++)
369 :     {
370 :     convertSensorResidual(*asapResult.getSensorResidual(i), corbaIOV.sensorresidual[i]);
371 :     }
372 :     } catch (AsapException e) {
373 :     throw AsapServerException(e.what());
374 :     }
375 :     }
376 :    
377 :     void AsapPilotImpl::convertResult(const AsapResultHeader& asapResult, AlignResult& corbaResult)
378 :     {
379 :     try {
380 :     corbaResult.chi2 = asapResult.getChi2();
381 :     corbaResult.chi2norm = asapResult.getChi2Norm();
382 :     corbaResult.nDOF = asapResult.getNDOF();
383 :    
384 :     corbaResult.icarasSince = asapResult.getSinceT();
385 :     corbaResult.icarasTill = asapResult.getTillT();
386 :    
387 :     corbaResult.cycleStart = asapResult.getCycleStart();
388 :     corbaResult.cycleEnd = asapResult.getCycleEnd();
389 :    
390 :     corbaResult.nIteration = asapResult.getNIteration();
391 :     corbaResult.nMaxIteration = asapResult.getNMaxIteration();
392 :     corbaResult.exitReason = asapResult.getExitReason();
393 :     } catch (AsapException e) {
394 :     throw AsapServerException(e.what());
395 :     }
396 :     }
397 :    
398 :     void AsapPilotImpl::convertCorrection(const AsapCorrection& asapCorr, AlignCorrection& corbaCorr)
399 :     {
400 :     try {
401 :     corbaCorr.asap_id = asapCorr.getAsapID();
402 :     corbaCorr.asap_type = asapCorr.getAsapType();
403 :    
404 :     corbaCorr.amdb_typ = asapCorr.getAmdbTyp();
405 :     corbaCorr.amdb_jff = asapCorr.getAmdbJff();
406 :     corbaCorr.amdb_jzz = asapCorr.getAmdbJzz();
407 :     corbaCorr.amdb_job = asapCorr.getAmdbJob();
408 :    
409 :     corbaCorr.s = asapCorr.getS();
410 :     corbaCorr.z = asapCorr.getZ();
411 :     corbaCorr.t = asapCorr.getT();
412 :     corbaCorr.thetas = asapCorr.getThetaS();
413 :     corbaCorr.thetaz = asapCorr.getThetaZ();
414 :     corbaCorr.thetat = asapCorr.getThetaT();
415 : giraudpf 1.2
416 :    
417 :     corbaCorr.temp = asapCorr.getTEMP();
418 :     corbaCorr.tortion = asapCorr.getTORTION();
419 :     corbaCorr.sagro = asapCorr.getSAGRO();
420 :     corbaCorr.saghv = asapCorr.getSAGHV();
421 : giraudpf 1.1 corbaCorr.saglbv = asapCorr.getSAGLBV();
422 :     corbaCorr.saglbh = asapCorr.getSAGLBH();
423 : giraudpf 1.2 corbaCorr.dero = asapCorr.getDERO();
424 :     corbaCorr.dehv = asapCorr.getDEHV();
425 :     corbaCorr.dwac = asapCorr.getDWAC();
426 :     corbaCorr.dwro = asapCorr.getDWRO();
427 :     corbaCorr.dwhv = asapCorr.getDWHV();
428 :    
429 :     // corbaCorr.torw = asapCorr.getTORW();
430 :     // corbaCorr.sagro = asapCorr.getSAGRO();
431 :     // corbaCorr.saghv = asapCorr.getSAGHV();
432 :     // corbaCorr.dwro = asapCorr.getDWRO();
433 :     // corbaCorr.dwhv = asapCorr.getDWHV();
434 :     // corbaCorr.saglbv = asapCorr.getSAGLBV();
435 :     // corbaCorr.saglbh = asapCorr.getSAGLBH();
436 :     // corbaCorr.dwac = asapCorr.getDWAC();
437 :     // corbaCorr.temp = asapCorr.getTEMP();
438 : giraudpf 1.1
439 :     corbaCorr.xatlas = asapCorr.getXAtlas();
440 :     corbaCorr.yatlas = asapCorr.getYAtlas();
441 :     } catch (AsapException e) {
442 :     throw AsapServerException(e.what());
443 :     }
444 :     }
445 :    
446 :     void AsapPilotImpl::convertSensorSummary(const AsapSensorSummary& asapSensorSummary,
447 :     AlignSensorSummary& corbaSensorSummary)
448 :     {
449 :     try {
450 :     corbaSensorSummary.sensorType = asapSensorSummary.getSensorType();
451 :     corbaSensorSummary.nSensorTotal = asapSensorSummary.getNSensorsTotal();
452 :     corbaSensorSummary.nSensorFailure = asapSensorSummary.getNSensorsFailure();
453 :     } catch (AsapException e) {
454 :     throw AsapServerException(e.what());
455 :     }
456 :     }
457 :     void AsapPilotImpl::convertSensorResidual(const AsapSensorResidual& asapSensorResidual,
458 :     AlignSensorResidual& corbaSensorResidual)
459 :     {
460 :     try {
461 :     corbaSensorResidual.channelName = asapSensorResidual.getChannelName();
462 :     corbaSensorResidual.type = asapSensorResidual.getType();
463 :     corbaSensorResidual.nmeas = asapSensorResidual.getNMeas();
464 :     corbaSensorResidual.distCL = asapSensorResidual.getDistCL();
465 :     corbaSensorResidual.distLM = asapSensorResidual.getDistLM();
466 :    
467 :     int nMeas = asapSensorResidual.getNMeas();
468 :     corbaSensorResidual.meas.length(nMeas);
469 :     for(int i = 0; i < nMeas; i++)
470 :     {
471 :     convertSensorMeasurement(asapSensorResidual.at(i), corbaSensorResidual.meas[i]);
472 :     }
473 :     } catch (AsapException e) {
474 :     throw AsapServerException(e.what());
475 :     }
476 :     }
477 :     void AsapPilotImpl::convertSensorMeasurement(const AsapSensorMeasurement& asapSensorMeasurement,
478 :     AlignSensorMeasurement& corbaSensorMeasurement)
479 :     {
480 :     try {
481 :     corbaSensorMeasurement.id = asapSensorMeasurement.id();
482 :     corbaSensorMeasurement.meas = asapSensorMeasurement.meas();
483 :     corbaSensorMeasurement.model = asapSensorMeasurement.model();
484 :     corbaSensorMeasurement.error = asapSensorMeasurement.error();
485 :     corbaSensorMeasurement.measraw = asapSensorMeasurement.measraw();
486 :     corbaSensorMeasurement.measrawerror = asapSensorMeasurement.measrawerror();
487 :     corbaSensorMeasurement.measrawnpoints = asapSensorMeasurement.measrawnpoints();
488 :     } catch (AsapException e) {
489 :     throw AsapServerException(e.what());
490 :     }
491 :     }
492 :    
493 :     }
494 :     }
495 :     }
496 :     }
497 :    

CERN Central CVS service
ViewVC Help
Powered by ViewVC 1.0.9