[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.12 - (view) (download)

1 : giraudpf 1.1 #include "AsapPilotImpl.hh"
2 :    
3 :     #include "Pilot.h"
4 : giraudpf 1.11 #include "Element.hh"
5 : giraudpf 1.1 #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 "SurveySensor.hh"
12 :     #include "Handle.hh"
13 :     #include "AsapIOV.hh"
14 :     #include "AsapResultHeader.hh"
15 :     #include "AsapCorrection.hh"
16 :     #include "AsapSensorSummary.hh"
17 :     #include "AsapSensorMeasurement.hh"
18 :     #include "AsapSensorResidual.hh"
19 :     #include "AsapConfSection.hh"
20 :     #include "ScopedLock.hh"
21 : giraudpf 1.6 #include "LogStream.hh"
22 : giraudpf 1.1 #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 : giraudpf 1.7 int irow = config["configelementvar"].getRow(id);
119 :     if (irow == -1)
120 :     throw AsapServerException(Form("Invalid element id %s", id));
121 :     config["configelementvar"].setInt("activate", irow, (activate ? 1 : 0));
122 : giraudpf 1.1 } catch (AsapException e) {
123 :     throw AsapServerException(e.what());
124 :     }
125 :     }
126 :    
127 :     void AsapPilotImpl::setOpticallineConfiguration(const char* id, CORBA::Boolean activate, CORBA::Boolean absolute) {
128 :     // Synchronize this method
129 :     ScopedLock lock;
130 :    
131 :     try {
132 :     AsapConfiguration& config = *(this->m_p->getConfiguration());
133 : giraudpf 1.7
134 : giraudpf 1.1 string section = "configoptlinevar";
135 : giraudpf 1.7 section += string(id,0,3); // hack
136 :     int irow = config[section].getRow(id);
137 :     if (irow == -1)
138 :     throw AsapServerException(Form("Invalid sensor id %s", id));
139 :     config[section].setInt("activate", irow, (activate ? 1 : 0));
140 :     config[section].setInt("absolute", irow, (absolute ? 1 : 0));
141 : giraudpf 1.1 } catch (AsapException e) {
142 :     throw AsapServerException(e.what());
143 :     }
144 :     }
145 :    
146 :     void AsapPilotImpl::setAmdb(const char* amdbfile) {
147 :     // Synchronize this method
148 :     ScopedLock lock;
149 :    
150 :     try {
151 :     AsapConfiguration& config = *(this->m_p->getConfiguration());
152 :     config.setAmdb("amdb", amdbfile);
153 : giraudpf 1.8 //config.setAmdb("amdb_nom", amdbfile);
154 : giraudpf 1.1 } catch (AsapException e) {
155 :     throw AsapServerException(e.what());
156 :     }
157 :     }
158 :    
159 :     void AsapPilotImpl::setSensorOffset(const char* id, CORBA::Double x, CORBA::Double y, CORBA::Double mag, CORBA::Double tz,
160 :     CORBA::Double err_x, CORBA::Double err_y, CORBA::Double err_mag, CORBA::Double err_tz) {
161 :     // Synchronize this method
162 :     ScopedLock lock;
163 :    
164 :     try {
165 :     AsapConfiguration& config = *(this->m_p->getConfiguration());
166 :     AsapConfSection& sensor_offset = config["sensor_offset"];
167 : giraudpf 1.7 int irow = sensor_offset.getRow(id);
168 :     if (irow == -1) {
169 :     irow = sensor_offset.getInt("nrow");
170 :     sensor_offset.setString("name", irow, id);
171 :     sensor_offset.setRowName(irow, id);
172 :     sensor_offset.setInt("nrow", irow+1);
173 :     }
174 :     sensor_offset.setFloat("x", irow, x);
175 :     sensor_offset.setFloat("y", irow, y);
176 :     sensor_offset.setFloat("mag", irow, mag);
177 :     sensor_offset.setFloat("tz", irow, tz);
178 :     sensor_offset.setFloat("sx", irow, err_x);
179 :     sensor_offset.setFloat("sy", irow, err_y);
180 :     sensor_offset.setFloat("smag", irow, err_mag);
181 :     sensor_offset.setFloat("stz", irow, err_tz);
182 : giraudpf 1.1 } catch (AsapException e) {
183 :     throw AsapServerException(e.what());
184 :     }
185 :     }
186 :    
187 :     void AsapPilotImpl::setConditions(const Conditions& cond) {
188 :     // Synchronize this method
189 :     ScopedLock lock;
190 :    
191 :     try {
192 : giraudpf 1.3 log(DEBUG).printf("setConditions_old %lld %lld %lld %s\n",
193 : giraudpf 1.4 (long long)cond.since, (long long)cond.till,
194 : giraudpf 1.5 (long long)cond.iov_id, (const char*)cond.tag);
195 : giraudpf 1.1 // create a new Conditions object to send to Pilot
196 :     Handle< ::Conditions > asap_cond = new ::Conditions();
197 :     asap_cond -> setSince(UTCTime(cond.since));
198 :     asap_cond -> setTill(UTCTime(cond.till));
199 :     asap_cond -> setIovId(cond.iov_id);
200 :     asap_cond -> setTag ((const char*)cond.tag);
201 :    
202 :     PortableServer::POA_var poa = this->_default_POA();
203 :    
204 :     TTree* ictree = NULL;
205 :     PortableServer::ServantBase_var servantIcTree;
206 :     if(!CORBA::is_nil(cond.icaras_tree))
207 :     {
208 :     servantIcTree = poa->reference_to_servant(cond.icaras_tree);
209 :     RootTreeImpl *rootIcTree = dynamic_cast<RootTreeImpl*>(servantIcTree.in());
210 :     ictree = rootIcTree->getTree();
211 :     }
212 :     asap_cond -> setIcarasData(new CdbTree(ictree));
213 :    
214 :     TTree* temptree = NULL;
215 :     PortableServer::ServantBase_var servantTempTree;
216 :     if(!CORBA::is_nil(cond.temp_tree))
217 :     {
218 :     servantTempTree = poa->reference_to_servant(cond.temp_tree);
219 :     RootTreeImpl *rootTempTree = dynamic_cast<RootTreeImpl*>(servantTempTree.in());
220 :     temptree = rootTempTree->getTree();
221 :     }
222 :     asap_cond->setTemperatureData(new CdbTree(temptree));
223 :    
224 :     // send the conditions to Pilot
225 :     this->m_p->setConditions(asap_cond);
226 :     } catch (AsapException e) {
227 :     throw AsapServerException(e.what());
228 :     }
229 :     }
230 :    
231 :     void AsapPilotImpl::getOutputData(IOVList_out outIOVs)
232 :     {
233 :     // Synchronize this method
234 :     ScopedLock lock;
235 :    
236 :     try {
237 :     Handle<CdbAsap> outputs = m_p->getOutputHandler();
238 :     //printOutput(outputs);
239 :     unsigned nIov = outputs->getEntries();
240 :     outIOVs = new IOVList();
241 :     outIOVs->length(nIov);
242 :     for(unsigned i = 0; i < nIov; i++)
243 :     {
244 :     convertIOV(*outputs->getIOV(i), outIOVs[i]);
245 :     }
246 :     } catch (AsapException e) {
247 :     throw AsapServerException(e.what());
248 :     }
249 :     }
250 :    
251 :     void AsapPilotImpl::writeOutputData (const char* rootfilename) {
252 :     // Synchronize this method
253 :     ScopedLock lock;
254 :    
255 :     try {
256 : giraudpf 1.3 log(DEBUG).printf("AsapPilotImpl::writeOutputData\n");
257 : giraudpf 1.1 Handle<CdbAsap> out = m_p->getOutputHandler();
258 :     TTree* outtree = out -> getCurrentTree ();
259 :     TFile* fout = TFile::Open(rootfilename, "RECREATE");
260 :     if (!fout) {
261 : giraudpf 1.3 log(ERR).printf("writeOutputData: cannot open output file %s\n",
262 : giraudpf 1.1 rootfilename);
263 :     return;
264 :     }
265 :     outtree->CloneTree()->Write();
266 :     fout->Close ();
267 :     } catch (AsapException e) {
268 :     throw AsapServerException(e.what());
269 :     }
270 :     }
271 :    
272 :     void AsapPilotImpl::clearOutputData () {
273 :     // Synchronize this method
274 :     ScopedLock lock;
275 :    
276 :     try {
277 : giraudpf 1.3 log(DEBUG).printf("AsapPilotImpl::clearOutputData\n");
278 : giraudpf 1.1 m_p->setOutputHandler(new CdbAsap());
279 :     } catch (AsapException e) {
280 :     throw AsapServerException(e.what());
281 :     }
282 :     }
283 :    
284 : giraudpf 1.9 CORBA::Boolean AsapPilotImpl::reco(const FitParameters& thefit)
285 : giraudpf 1.1 {
286 :     // Synchronize this method
287 :     ScopedLock lock;
288 :    
289 :     try {
290 : giraudpf 1.3 log(INFO).printf("reco: running ASAP reconstruction on IOV %lld, tag %s, since %s, till %s\n",
291 :     this->m_p->getConditions()->getIovId(),
292 :     this->m_p->getConditions()->getTag().Data(),
293 :     UTCTime(this->m_p->getConditions()->getSince()).getString().c_str(),
294 :     UTCTime(this->m_p->getConditions()->getTill()).getString().c_str());
295 : giraudpf 1.1
296 :     // Set the output data container
297 :     Handle<CdbAsap> local_out = new CdbAsap ();
298 :     this->m_p->setOutputHandler (local_out);
299 : giraudpf 1.9 return this->m_p->reco(thefit.iterations);
300 : giraudpf 1.1 } catch (AsapException e) {
301 :     throw AsapServerException(e.what());
302 :     }
303 :     }
304 :    
305 :     void AsapPilotImpl::printOutput (Handle<CdbAsap> out)
306 :     {
307 :     try {
308 :     int ncorr = out -> getEntries ();
309 :     for (int icorr = 0; icorr < ncorr; icorr ++)
310 :     {
311 :     cout << "***" << endl
312 :     << "*** IOV number " << icorr << endl
313 :     << "***" << endl;
314 :     const AsapIOV* iov = out->getIOV(icorr);
315 :     const AsapResultHeader *h = iov -> getResultHeader(0);
316 :     int ncorr = h -> getNCorrections ();
317 :    
318 :     cout << "since = " << UTCTime(iov -> getSinceT ()).getString () << endl
319 :     << "till = " << UTCTime(iov -> getTillT ()).getString () << endl
320 :     << "Chi2 = " << h -> getChi2Norm () << endl
321 :     << "NCorrections = " << ncorr << endl;
322 :    
323 :     for (int i=0; i<ncorr; i++)
324 :     {
325 :     const AsapCorrection* c = h -> getCorrection (i);
326 :     cout << "---------------------------------------" << endl
327 :     << "Chamber = " << c -> getAsapID () << endl
328 :     << "s = " << c -> getS () << endl
329 :     << "z = " << c -> getZ () << endl
330 :     << "t = " << c -> getT () << endl
331 :     << "thetaS = " << c -> getThetaS () << endl
332 :     << "thetaZ = " << c -> getThetaZ () << endl
333 :     << "thetaT = " << c -> getThetaT () << endl;
334 :     }
335 :     }
336 :     } catch (AsapException e) {
337 :     throw AsapServerException(e.what());
338 :     }
339 :     }
340 :    
341 :     void AsapPilotImpl::convertIOV(const AsapIOV& asapIOV, AlignIOV& corbaIOV)
342 :     {
343 :     try {
344 :     corbaIOV.iov_id = asapIOV.getIovId();
345 :     corbaIOV.since = asapIOV.getSinceT();
346 :     corbaIOV.till = asapIOV.getTillT();
347 :    
348 :     assert(asapIOV.getNResultHeaders() == 1);
349 :     const AsapResultHeader& asapResult = *asapIOV.getResultHeader(0);
350 :     corbaIOV.results.length(1);
351 :     convertResult(asapResult, corbaIOV.results[0]);
352 :    
353 :     int nCorr = asapResult.getNCorrections();
354 :     corbaIOV.corrections.length(nCorr);
355 :     for(int i = 0; i < nCorr; i++)
356 :     {
357 :     convertCorrection(*asapResult.getCorrection(i), corbaIOV.corrections[i]);
358 :     }
359 :     int nSensorSummary = asapResult.getNSensorSummary();
360 :     corbaIOV.sensorsummary.length(nSensorSummary);
361 :     for(int i = 0; i < nSensorSummary; i++)
362 :     {
363 :     convertSensorSummary(*asapResult.getSensorSummary(i), corbaIOV.sensorsummary[i]);
364 :     }
365 :     int nSensorResidual = asapResult.getNSensorResiduals();
366 :     corbaIOV.sensorresidual.length(nSensorResidual);
367 :     for(int i = 0; i < nSensorResidual; i++)
368 :     {
369 :     convertSensorResidual(*asapResult.getSensorResidual(i), corbaIOV.sensorresidual[i]);
370 :     }
371 :     } catch (AsapException e) {
372 :     throw AsapServerException(e.what());
373 :     }
374 :     }
375 :    
376 :     void AsapPilotImpl::convertResult(const AsapResultHeader& asapResult, AlignResult& corbaResult)
377 :     {
378 :     try {
379 :     corbaResult.chi2 = asapResult.getChi2();
380 :     corbaResult.chi2norm = asapResult.getChi2Norm();
381 :     corbaResult.nDOF = asapResult.getNDOF();
382 :    
383 :     corbaResult.icarasSince = asapResult.getSinceT();
384 :     corbaResult.icarasTill = asapResult.getTillT();
385 :    
386 :     corbaResult.cycleStart = asapResult.getCycleStart();
387 :     corbaResult.cycleEnd = asapResult.getCycleEnd();
388 :    
389 :     corbaResult.nIteration = asapResult.getNIteration();
390 :     corbaResult.nMaxIteration = asapResult.getNMaxIteration();
391 :     corbaResult.exitReason = asapResult.getExitReason();
392 :     } catch (AsapException e) {
393 :     throw AsapServerException(e.what());
394 :     }
395 :     }
396 :    
397 :     void AsapPilotImpl::convertCorrection(const AsapCorrection& asapCorr, AlignCorrection& corbaCorr)
398 :     {
399 :     try {
400 :     corbaCorr.asap_id = asapCorr.getAsapID();
401 :     corbaCorr.asap_type = asapCorr.getAsapType();
402 :    
403 :     corbaCorr.amdb_typ = asapCorr.getAmdbTyp();
404 :     corbaCorr.amdb_jff = asapCorr.getAmdbJff();
405 :     corbaCorr.amdb_jzz = asapCorr.getAmdbJzz();
406 :     corbaCorr.amdb_job = asapCorr.getAmdbJob();
407 :    
408 :     corbaCorr.s = asapCorr.getS();
409 :     corbaCorr.z = asapCorr.getZ();
410 :     corbaCorr.t = asapCorr.getT();
411 :     corbaCorr.thetas = asapCorr.getThetaS();
412 :     corbaCorr.thetaz = asapCorr.getThetaZ();
413 :     corbaCorr.thetat = asapCorr.getThetaT();
414 : giraudpf 1.2
415 :    
416 : giraudpf 1.12 corbaCorr.eg = asapCorr.getEG();
417 :     corbaCorr.tw = asapCorr.getTW();
418 :     corbaCorr.sp = asapCorr.getSP();
419 :     corbaCorr.sn = asapCorr.getSN();
420 :     corbaCorr.bp = asapCorr.getBP();
421 :     corbaCorr.bn = asapCorr.getBN();
422 :     corbaCorr.bz = asapCorr.getBZ();
423 :     corbaCorr.ep = asapCorr.getEP();
424 :     corbaCorr.en = asapCorr.getEN();
425 :     corbaCorr.tr = asapCorr.getTR();
426 :     corbaCorr.pg = asapCorr.getPG();
427 :    
428 : giraudpf 1.1
429 :     corbaCorr.xatlas = asapCorr.getXAtlas();
430 :     corbaCorr.yatlas = asapCorr.getYAtlas();
431 :     } catch (AsapException e) {
432 :     throw AsapServerException(e.what());
433 :     }
434 :     }
435 :    
436 :     void AsapPilotImpl::convertSensorSummary(const AsapSensorSummary& asapSensorSummary,
437 :     AlignSensorSummary& corbaSensorSummary)
438 :     {
439 :     try {
440 :     corbaSensorSummary.sensorType = asapSensorSummary.getSensorType();
441 :     corbaSensorSummary.nSensorTotal = asapSensorSummary.getNSensorsTotal();
442 :     corbaSensorSummary.nSensorFailure = asapSensorSummary.getNSensorsFailure();
443 :     } catch (AsapException e) {
444 :     throw AsapServerException(e.what());
445 :     }
446 :     }
447 :     void AsapPilotImpl::convertSensorResidual(const AsapSensorResidual& asapSensorResidual,
448 :     AlignSensorResidual& corbaSensorResidual)
449 :     {
450 :     try {
451 :     corbaSensorResidual.channelName = asapSensorResidual.getChannelName();
452 :     corbaSensorResidual.type = asapSensorResidual.getType();
453 :     corbaSensorResidual.nmeas = asapSensorResidual.getNMeas();
454 :     corbaSensorResidual.distCL = asapSensorResidual.getDistCL();
455 :     corbaSensorResidual.distLM = asapSensorResidual.getDistLM();
456 :    
457 :     int nMeas = asapSensorResidual.getNMeas();
458 :     corbaSensorResidual.meas.length(nMeas);
459 :     for(int i = 0; i < nMeas; i++)
460 :     {
461 :     convertSensorMeasurement(asapSensorResidual.at(i), corbaSensorResidual.meas[i]);
462 :     }
463 :     } catch (AsapException e) {
464 :     throw AsapServerException(e.what());
465 :     }
466 :     }
467 :     void AsapPilotImpl::convertSensorMeasurement(const AsapSensorMeasurement& asapSensorMeasurement,
468 :     AlignSensorMeasurement& corbaSensorMeasurement)
469 :     {
470 :     try {
471 :     corbaSensorMeasurement.id = asapSensorMeasurement.id();
472 :     corbaSensorMeasurement.meas = asapSensorMeasurement.meas();
473 :     corbaSensorMeasurement.model = asapSensorMeasurement.model();
474 :     corbaSensorMeasurement.error = asapSensorMeasurement.error();
475 :     corbaSensorMeasurement.measraw = asapSensorMeasurement.measraw();
476 :     corbaSensorMeasurement.measrawerror = asapSensorMeasurement.measrawerror();
477 :     corbaSensorMeasurement.measrawnpoints = asapSensorMeasurement.measrawnpoints();
478 :     } catch (AsapException e) {
479 :     throw AsapServerException(e.what());
480 :     }
481 :     }
482 :    
483 :     }
484 :     }
485 :     }
486 :     }
487 :    

CERN Central CVS service
ViewVC Help
Powered by ViewVC 1.0.9