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

CERN Central CVS service
ViewVC Help
Powered by ViewVC 1.0.9