[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.3 - (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 :     cond.since, cond.till, cond.iov_id, (const char*)cond.tag);
182 : giraudpf 1.1 // create a new Conditions object to send to Pilot
183 :     Handle< ::Conditions > asap_cond = new ::Conditions();
184 :     asap_cond -> setSince(UTCTime(cond.since));
185 :     asap_cond -> setTill(UTCTime(cond.till));
186 :     asap_cond -> setIovId(cond.iov_id);
187 :     asap_cond -> setTag ((const char*)cond.tag);
188 :    
189 :     PortableServer::POA_var poa = this->_default_POA();
190 :    
191 :     TTree* ictree = NULL;
192 :     PortableServer::ServantBase_var servantIcTree;
193 :     if(!CORBA::is_nil(cond.icaras_tree))
194 :     {
195 :     servantIcTree = poa->reference_to_servant(cond.icaras_tree);
196 :     RootTreeImpl *rootIcTree = dynamic_cast<RootTreeImpl*>(servantIcTree.in());
197 :     ictree = rootIcTree->getTree();
198 :     }
199 :     asap_cond -> setIcarasData(new CdbTree(ictree));
200 :    
201 :     TTree* temptree = NULL;
202 :     PortableServer::ServantBase_var servantTempTree;
203 :     if(!CORBA::is_nil(cond.temp_tree))
204 :     {
205 :     servantTempTree = poa->reference_to_servant(cond.temp_tree);
206 :     RootTreeImpl *rootTempTree = dynamic_cast<RootTreeImpl*>(servantTempTree.in());
207 :     temptree = rootTempTree->getTree();
208 :     }
209 :     asap_cond->setTemperatureData(new CdbTree(temptree));
210 :    
211 :     // send the conditions to Pilot
212 :     this->m_p->setConditions(asap_cond);
213 :     } catch (AsapException e) {
214 :     throw AsapServerException(e.what());
215 :     }
216 :     }
217 :    
218 :     void AsapPilotImpl::getOutputData(IOVList_out outIOVs)
219 :     {
220 :     // Synchronize this method
221 :     ScopedLock lock;
222 :    
223 :     try {
224 :     Handle<CdbAsap> outputs = m_p->getOutputHandler();
225 :     //printOutput(outputs);
226 :     unsigned nIov = outputs->getEntries();
227 :     outIOVs = new IOVList();
228 :     outIOVs->length(nIov);
229 :     for(unsigned i = 0; i < nIov; i++)
230 :     {
231 :     convertIOV(*outputs->getIOV(i), outIOVs[i]);
232 :     }
233 :     } catch (AsapException e) {
234 :     throw AsapServerException(e.what());
235 :     }
236 :     }
237 :    
238 :     void AsapPilotImpl::writeOutputData (const char* rootfilename) {
239 :     // Synchronize this method
240 :     ScopedLock lock;
241 :    
242 :     try {
243 : giraudpf 1.3 log(DEBUG).printf("AsapPilotImpl::writeOutputData\n");
244 : giraudpf 1.1 Handle<CdbAsap> out = m_p->getOutputHandler();
245 :     TTree* outtree = out -> getCurrentTree ();
246 :     TFile* fout = TFile::Open(rootfilename, "RECREATE");
247 :     if (!fout) {
248 : giraudpf 1.3 log(ERR).printf("writeOutputData: cannot open output file %s\n",
249 : giraudpf 1.1 rootfilename);
250 :     return;
251 :     }
252 :     outtree->CloneTree()->Write();
253 :     fout->Close ();
254 :     } catch (AsapException e) {
255 :     throw AsapServerException(e.what());
256 :     }
257 :     }
258 :    
259 :     void AsapPilotImpl::clearOutputData () {
260 :     // Synchronize this method
261 :     ScopedLock lock;
262 :    
263 :     try {
264 : giraudpf 1.3 log(DEBUG).printf("AsapPilotImpl::clearOutputData\n");
265 : giraudpf 1.1 m_p->setOutputHandler(new CdbAsap());
266 :     } catch (AsapException e) {
267 :     throw AsapServerException(e.what());
268 :     }
269 :     }
270 :    
271 :     void AsapPilotImpl::reco(const FitParameters& thefit)
272 :     {
273 :     // Synchronize this method
274 :     ScopedLock lock;
275 :    
276 :     try {
277 : giraudpf 1.3 log(INFO).printf("reco: running ASAP reconstruction on IOV %lld, tag %s, since %s, till %s\n",
278 :     this->m_p->getConditions()->getIovId(),
279 :     this->m_p->getConditions()->getTag().Data(),
280 :     UTCTime(this->m_p->getConditions()->getSince()).getString().c_str(),
281 :     UTCTime(this->m_p->getConditions()->getTill()).getString().c_str());
282 : giraudpf 1.1
283 :     // Set the output data container
284 :     Handle<CdbAsap> local_out = new CdbAsap ();
285 :     this->m_p->setOutputHandler (local_out);
286 :     this->m_p->reco(thefit.iterations);
287 :     } catch (AsapException e) {
288 :     throw AsapServerException(e.what());
289 :     }
290 :     }
291 :    
292 :     void AsapPilotImpl::printOutput (Handle<CdbAsap> out)
293 :     {
294 :     try {
295 :     int ncorr = out -> getEntries ();
296 :     for (int icorr = 0; icorr < ncorr; icorr ++)
297 :     {
298 :     cout << "***" << endl
299 :     << "*** IOV number " << icorr << endl
300 :     << "***" << endl;
301 :     const AsapIOV* iov = out->getIOV(icorr);
302 :     const AsapResultHeader *h = iov -> getResultHeader(0);
303 :     int ncorr = h -> getNCorrections ();
304 :    
305 :     cout << "since = " << UTCTime(iov -> getSinceT ()).getString () << endl
306 :     << "till = " << UTCTime(iov -> getTillT ()).getString () << endl
307 :     << "Chi2 = " << h -> getChi2Norm () << endl
308 :     << "NCorrections = " << ncorr << endl;
309 :    
310 :     for (int i=0; i<ncorr; i++)
311 :     {
312 :     const AsapCorrection* c = h -> getCorrection (i);
313 :     cout << "---------------------------------------" << endl
314 :     << "Chamber = " << c -> getAsapID () << endl
315 :     << "s = " << c -> getS () << endl
316 :     << "z = " << c -> getZ () << endl
317 :     << "t = " << c -> getT () << endl
318 :     << "thetaS = " << c -> getThetaS () << endl
319 :     << "thetaZ = " << c -> getThetaZ () << endl
320 :     << "thetaT = " << c -> getThetaT () << endl;
321 :     }
322 :     }
323 :     } catch (AsapException e) {
324 :     throw AsapServerException(e.what());
325 :     }
326 :     }
327 :    
328 :     void AsapPilotImpl::convertIOV(const AsapIOV& asapIOV, AlignIOV& corbaIOV)
329 :     {
330 :     try {
331 :     corbaIOV.iov_id = asapIOV.getIovId();
332 :     corbaIOV.since = asapIOV.getSinceT();
333 :     corbaIOV.till = asapIOV.getTillT();
334 :    
335 :     assert(asapIOV.getNResultHeaders() == 1);
336 :     const AsapResultHeader& asapResult = *asapIOV.getResultHeader(0);
337 :     corbaIOV.results.length(1);
338 :     convertResult(asapResult, corbaIOV.results[0]);
339 :    
340 :     int nCorr = asapResult.getNCorrections();
341 :     corbaIOV.corrections.length(nCorr);
342 :     for(int i = 0; i < nCorr; i++)
343 :     {
344 :     convertCorrection(*asapResult.getCorrection(i), corbaIOV.corrections[i]);
345 :     }
346 :     int nSensorSummary = asapResult.getNSensorSummary();
347 :     corbaIOV.sensorsummary.length(nSensorSummary);
348 :     for(int i = 0; i < nSensorSummary; i++)
349 :     {
350 :     convertSensorSummary(*asapResult.getSensorSummary(i), corbaIOV.sensorsummary[i]);
351 :     }
352 :     int nSensorResidual = asapResult.getNSensorResiduals();
353 :     corbaIOV.sensorresidual.length(nSensorResidual);
354 :     for(int i = 0; i < nSensorResidual; i++)
355 :     {
356 :     convertSensorResidual(*asapResult.getSensorResidual(i), corbaIOV.sensorresidual[i]);
357 :     }
358 :     } catch (AsapException e) {
359 :     throw AsapServerException(e.what());
360 :     }
361 :     }
362 :    
363 :     void AsapPilotImpl::convertResult(const AsapResultHeader& asapResult, AlignResult& corbaResult)
364 :     {
365 :     try {
366 :     corbaResult.chi2 = asapResult.getChi2();
367 :     corbaResult.chi2norm = asapResult.getChi2Norm();
368 :     corbaResult.nDOF = asapResult.getNDOF();
369 :    
370 :     corbaResult.icarasSince = asapResult.getSinceT();
371 :     corbaResult.icarasTill = asapResult.getTillT();
372 :    
373 :     corbaResult.cycleStart = asapResult.getCycleStart();
374 :     corbaResult.cycleEnd = asapResult.getCycleEnd();
375 :    
376 :     corbaResult.nIteration = asapResult.getNIteration();
377 :     corbaResult.nMaxIteration = asapResult.getNMaxIteration();
378 :     corbaResult.exitReason = asapResult.getExitReason();
379 :     } catch (AsapException e) {
380 :     throw AsapServerException(e.what());
381 :     }
382 :     }
383 :    
384 :     void AsapPilotImpl::convertCorrection(const AsapCorrection& asapCorr, AlignCorrection& corbaCorr)
385 :     {
386 :     try {
387 :     corbaCorr.asap_id = asapCorr.getAsapID();
388 :     corbaCorr.asap_type = asapCorr.getAsapType();
389 :    
390 :     corbaCorr.amdb_typ = asapCorr.getAmdbTyp();
391 :     corbaCorr.amdb_jff = asapCorr.getAmdbJff();
392 :     corbaCorr.amdb_jzz = asapCorr.getAmdbJzz();
393 :     corbaCorr.amdb_job = asapCorr.getAmdbJob();
394 :    
395 :     corbaCorr.s = asapCorr.getS();
396 :     corbaCorr.z = asapCorr.getZ();
397 :     corbaCorr.t = asapCorr.getT();
398 :     corbaCorr.thetas = asapCorr.getThetaS();
399 :     corbaCorr.thetaz = asapCorr.getThetaZ();
400 :     corbaCorr.thetat = asapCorr.getThetaT();
401 : giraudpf 1.2
402 :    
403 :     corbaCorr.temp = asapCorr.getTEMP();
404 :     corbaCorr.tortion = asapCorr.getTORTION();
405 :     corbaCorr.sagro = asapCorr.getSAGRO();
406 :     corbaCorr.saghv = asapCorr.getSAGHV();
407 : giraudpf 1.1 corbaCorr.saglbv = asapCorr.getSAGLBV();
408 :     corbaCorr.saglbh = asapCorr.getSAGLBH();
409 : giraudpf 1.2 corbaCorr.dero = asapCorr.getDERO();
410 :     corbaCorr.dehv = asapCorr.getDEHV();
411 :     corbaCorr.dwac = asapCorr.getDWAC();
412 :     corbaCorr.dwro = asapCorr.getDWRO();
413 :     corbaCorr.dwhv = asapCorr.getDWHV();
414 :    
415 :     // corbaCorr.torw = asapCorr.getTORW();
416 :     // corbaCorr.sagro = asapCorr.getSAGRO();
417 :     // corbaCorr.saghv = asapCorr.getSAGHV();
418 :     // corbaCorr.dwro = asapCorr.getDWRO();
419 :     // corbaCorr.dwhv = asapCorr.getDWHV();
420 :     // corbaCorr.saglbv = asapCorr.getSAGLBV();
421 :     // corbaCorr.saglbh = asapCorr.getSAGLBH();
422 :     // corbaCorr.dwac = asapCorr.getDWAC();
423 :     // corbaCorr.temp = asapCorr.getTEMP();
424 : giraudpf 1.1
425 :     corbaCorr.xatlas = asapCorr.getXAtlas();
426 :     corbaCorr.yatlas = asapCorr.getYAtlas();
427 :     } catch (AsapException e) {
428 :     throw AsapServerException(e.what());
429 :     }
430 :     }
431 :    
432 :     void AsapPilotImpl::convertSensorSummary(const AsapSensorSummary& asapSensorSummary,
433 :     AlignSensorSummary& corbaSensorSummary)
434 :     {
435 :     try {
436 :     corbaSensorSummary.sensorType = asapSensorSummary.getSensorType();
437 :     corbaSensorSummary.nSensorTotal = asapSensorSummary.getNSensorsTotal();
438 :     corbaSensorSummary.nSensorFailure = asapSensorSummary.getNSensorsFailure();
439 :     } catch (AsapException e) {
440 :     throw AsapServerException(e.what());
441 :     }
442 :     }
443 :     void AsapPilotImpl::convertSensorResidual(const AsapSensorResidual& asapSensorResidual,
444 :     AlignSensorResidual& corbaSensorResidual)
445 :     {
446 :     try {
447 :     corbaSensorResidual.channelName = asapSensorResidual.getChannelName();
448 :     corbaSensorResidual.type = asapSensorResidual.getType();
449 :     corbaSensorResidual.nmeas = asapSensorResidual.getNMeas();
450 :     corbaSensorResidual.distCL = asapSensorResidual.getDistCL();
451 :     corbaSensorResidual.distLM = asapSensorResidual.getDistLM();
452 :    
453 :     int nMeas = asapSensorResidual.getNMeas();
454 :     corbaSensorResidual.meas.length(nMeas);
455 :     for(int i = 0; i < nMeas; i++)
456 :     {
457 :     convertSensorMeasurement(asapSensorResidual.at(i), corbaSensorResidual.meas[i]);
458 :     }
459 :     } catch (AsapException e) {
460 :     throw AsapServerException(e.what());
461 :     }
462 :     }
463 :     void AsapPilotImpl::convertSensorMeasurement(const AsapSensorMeasurement& asapSensorMeasurement,
464 :     AlignSensorMeasurement& corbaSensorMeasurement)
465 :     {
466 :     try {
467 :     corbaSensorMeasurement.id = asapSensorMeasurement.id();
468 :     corbaSensorMeasurement.meas = asapSensorMeasurement.meas();
469 :     corbaSensorMeasurement.model = asapSensorMeasurement.model();
470 :     corbaSensorMeasurement.error = asapSensorMeasurement.error();
471 :     corbaSensorMeasurement.measraw = asapSensorMeasurement.measraw();
472 :     corbaSensorMeasurement.measrawerror = asapSensorMeasurement.measrawerror();
473 :     corbaSensorMeasurement.measrawnpoints = asapSensorMeasurement.measrawnpoints();
474 :     } catch (AsapException e) {
475 :     throw AsapServerException(e.what());
476 :     }
477 :     }
478 :    
479 :     }
480 :     }
481 :     }
482 :     }
483 :    

CERN Central CVS service
ViewVC Help
Powered by ViewVC 1.0.9