001 #include "MuonGeoModel/MuonDetectorTool.h"
002 #include "MuonGeoModel/MuonDetectorFactory001.h"
003 #include "MuonReadoutGeometry/MuonDetectorManager.h"
004
005 #include "GeoModelSvc/IGeoModelSvc.h"
006 #include "GeoModelSvc/GeoModelExperiment.h"
007 #include "GeoModelSvc/StoredMaterialManager.h"
008 #include "GeoModelKernel/GeoPhysVol.h"
009 #include "GeoModelKernel/GeoPerfUtils.h"
010 #include "GaudiKernel/IService.h"
011 #include "GaudiKernel/ISvcLocator.h"
012 #include "GaudiKernel/MsgStream.h"
013 #include "GaudiKernel/Bootstrap.h"
014 #include "StoreGate/StoreGateSvc.h"
015
016 #include "RDBAccessSvc/IRDBAccessSvc.h"
017 #include "RDBAccessSvc/IRDBRecord.h"
018 #include "RDBAccessSvc/IRDBRecordset.h"
019
020 #include "AthenaPoolUtilities/CondAttrListCollection.h"
021 #include "GaudiKernel/IToolSvc.h"
022 #include "GaudiKernel/IIncidentSvc.h"
023
024 #include <fstream>
025 #include "CLIDSvc/tools/ClassID_traits.h"
026 #include "SGTools/DataProxy.h"
027
028 using namespace MuonGM;
029
030
031
032
033 MuonDetectorTool::MuonDetectorTool( const std::string& type, const std::string& name, const IInterface* parent )
034 : GeoModelTool( type, name, parent ),
035 m_layout("P03"),
036
037
038
039 m_accessCondDb(0),
040 m_asciiCondData(0),
041
042 m_includeCutouts(0),
043 m_includeCutoutsBog(0),
044 m_includeCtbBis(0),
045 m_stationSelection(0),
046 m_controlAlines(111111),
047 m_altAsztFile(""),
048 m_cachingFlag(1),
049 m_fillCache_initTime(0),
050 m_enableFineClashFixing(0),
051 m_condDataTool("MuonAlignmentDbTool/MGM_AlignmentDbTool"),
052 m_manager(0)
053 {
054 declareInterface<IGeoModelTool>(this);
055 MsgStream log(msgSvc(), "MGM::MuonDetectorTool::MuonDetectorTool");
056
057 declareProperty("LayoutName", m_layout );
058
059
060
061 declareProperty("UseConditionDb", m_accessCondDb);
062 declareProperty("UseAsciiConditionData", m_asciiCondData);
063 declareProperty("BuildFromNova",m_nova);
064 declareProperty("IncludeCutouts",m_includeCutouts);
065 declareProperty("IncludeCutoutsBog",m_includeCutoutsBog);
066 declareProperty("IncludeCtbBis",m_includeCtbBis);
067
068 declareProperty("StationSelection", m_stationSelection = 0);
069 declareProperty("SelectedStations", m_selectedStations);
070 declareProperty("SelectedStJzz", m_selectedStEta);
071 declareProperty("SelectedStJff", m_selectedStPhi);
072 declareProperty("ControlAlines", m_controlAlines = 111111);
073 declareProperty("AlternateASZTFile", m_altAsztFile);
074
075
076 declareProperty("FillCacheInitTime", m_fillCache_initTime = 0);
077 declareProperty("EnableFineClashFixing", m_enableFineClashFixing = 0);
078 declareProperty("TheMuonAlignmentTool", m_condDataTool, "a Tool to read from the condDB and save in StoreGate" );
079
080
081
082
083
084 declareProperty("ForceSwitchOnOff_BUILDINERTMATERIALS", m_switchOnOff_BUILDINERTMATERIALS = 0);
085 declareProperty("ForceSwitchOnOff_MINIMALGEO", m_switchOnOff_MINIMALGEO = 0);
086 declareProperty("ForceSwitchOnOff_BUILDENDCAP", m_switchOnOff_BUILDENDCAP = 0);
087 declareProperty("ForceSwitchOnOff_BUILDCALOSADDLE", m_switchOnOff_BUILDCALOSADDLE = 0);
088 declareProperty("ForceSwitchOnOff_BUILDBARRELTOROID", m_switchOnOff_BUILDBARRELTOROID = 0);
089 declareProperty("ForceSwitchOnOff_BUILDENDCAPTOROID", m_switchOnOff_BUILDENDCAPTOROID = 0);
090 declareProperty("ForceSwitchOnOff_BUILDFEET", m_switchOnOff_BUILDFEET = 0);
091 declareProperty("ForceSwitchOnOff_BUILDDISKSHIELD", m_switchOnOff_BUILDDISKSHIELD = 0);
092 declareProperty("ForceSwitchOnOff_BUILDTOROIDSHIELD", m_switchOnOff_BUILDTOROIDSHIELD = 0);
093 declareProperty("ForceSwitchOnOff_BUILDFORWARDSHIELD", m_switchOnOff_BUILDFORWARDSHIELD = 0);
094
095 }
096
097
098
099
100 MuonDetectorTool::~MuonDetectorTool()
101 {
102
103
104 if ( 0 != m_detector ) {
105 delete m_detector;
106 m_detector = 0;
107 }
108 }
109
110 StatusCode
111 MuonDetectorTool::initialize()
112 {
113
114
115 msg(MSG::INFO)<<"Initializing ..."<<endreq;
116
117 StatusCode sc = m_condDataTool.retrieve();
118 if ( sc.isFailure() )
119 {
120
121 msg(MSG::ERROR) << "Could not retrieve MuonAlignmentDbTool" << endreq;
122 }
123 else
124 {
125
126 msg(MSG::INFO)<<"MuonAlignmentDbTool retrieved with statusCode = "<<sc<<" pointer = "<<m_condDataTool<<endreq;
127 }
128
129
130 ServiceHandle<IIncidentSvc> incidentSvc("IncidentSvc", name());
131 sc = incidentSvc.retrieve();
132 if (sc.isFailure()) {
133
134 msg(MSG::ERROR) << "IncidentSvc not found" << endreq;
135 return StatusCode::FAILURE;
136 }
137
138
139
140 incidentSvc->addListener(this, "StoreCleared");
141
142 return sc;
143 }
144
145 void MuonDetectorTool::handle(const Incident& inc)
146 {
147
148
149 if (inc.type()=="StoreCleared" && m_fillCache_initTime ==0 && m_manager!=0)
150 {
151
152
153
154 ATH_MSG_DEBUG ("Clearing cache at end of event after EventStore is cleared");
155 m_manager->clearCache();
156 }
157 }
158
159
160
161
162
163 StatusCode
164 MuonDetectorTool::create( StoreGateSvc* detStore )
165 {
166
167 std::ofstream geoModelStats("MuonGeoModelStatistics_MuonDetectorTool");
168 int mem = GeoPerfUtils::getMem();
169 int cpu = int(GeoPerfUtils::getCpu()/100.);
170 geoModelStats <<"At MuonDetectorTool::create entry point: \t SZ= " <<mem << " Kb \t Time = " << cpu << " seconds " << std::endl;
171
172 int umem = GeoPerfUtils::getMem();
173 int ucpu = int(GeoPerfUtils::getCpu()/100.);
174 geoModelStats <<"At MuonDetectorTool::resetting to 0: \t SZ= " <<umem-mem << " Kb \t Time = " << ucpu-cpu << " seconds " << std::endl;
175 mem = umem;
176 cpu = ucpu;
177
178
179
180
181 if (msgLvl(MSG::VERBOSE))
182 msg(MSG::VERBOSE)<<" Show properties (user sett.s or default): LayoutName "<<m_layout
183 <<endreq
184 <<" Show properties (user sett.s or default): IncludeCutouts "<<m_includeCutouts
185 <<endreq
186 <<" Show properties (user sett.s or default): IncludeCutoutsBog "<<m_includeCutoutsBog
187 <<endreq
188 <<" Show properties (user sett.s or default): IncludeCtbBis "<<m_includeCtbBis
189 <<endreq;
190
191
192 IGeoModelSvc *geoModel;
193 service ("GeoModelSvc",geoModel);
194
195 std::string AtlasVersion = geoModel->atlasVersion();
196 std::string MuonVersion = geoModel->muonVersionOverride();
197
198 msg(MSG::INFO)<<"create MuonDetectorTool - package version = "<<PACKAGE_VERSION<<endreq;
199 msg(MSG::INFO)<<"(from GeoModelSvc) AtlasVersion = <"<< AtlasVersion<<"> MuonVersion = <"<<MuonVersion<<">"<<endreq;
200
201
202
203
204 std::string detectorKey = MuonVersion.empty() ? AtlasVersion : MuonVersion;
205 std::string detectorNode = MuonVersion.empty() ? "ATLAS" : "MuonSpectrometer";
206 msg(MSG::INFO)<<"Keys for Muon Switches are (key) " << detectorKey << " (node) " << detectorNode << endreq;
207
208 std::map<std::string,std::string>* altAsciiDBMap=0;
209 if ( MuonVersion == "CUSTOM" )
210 msg( MSG::WARNING )<< "Detector Information coming from a custom configuration !!" << endreq;
211 else
212 {
213 msg( MSG::DEBUG )<< "Detector Information coming from the database (job options IGNORED)" << endreq;
214 IRDBAccessSvc *accessSvc;
215 service("RDBAccessSvc",accessSvc);
216 const IRDBRecordset *switchSet = accessSvc->getRecordset("MuonSwitches", detectorKey, detectorNode);
217 if ((*switchSet).size()==0) return StatusCode::FAILURE;
218 const IRDBRecord *switches = (*switchSet)[0];
219
220 m_layout = switches->getString("LAYOUTNAME");
221
222
223 if (MuonVersion == "") {
224 MuonVersion = accessSvc->getChildTag("MuonSpectrometer",detectorKey,detectorNode);
225 msg(MSG::INFO)<<"(from GeoModelSvc) in AtlasVersion = <"<< AtlasVersion<<"> default MuonVersion is <"
226 <<MuonVersion<<">"<<endreq;
227 }
228
229 msg(MSG::DEBUG)<<" m_altAsztFile: "<<m_altAsztFile<<endreq;
230
231 if (m_altAsztFile != "") {
232 altAsciiDBMap=new std::map<std::string,std::string>;
233 altAsciiDBMap->insert(std::make_pair("ASZT",m_altAsztFile));
234 }
235 }
236
237
238
239
240
241 DataHandle<GeoModelExperiment> theExpt;
242 if (StatusCode::SUCCESS != detStore->retrieve( theExpt, "ATLAS" ))
243 {
244 msg(MSG::ERROR)
245 << "Could not find GeoModelExperiment ATLAS"
246 << endreq;
247 return (StatusCode::FAILURE);
248 }
249
250 msg(MSG::INFO)<<"Properties have been set as follows: "<<endreq
251 <<" LayoutName "<< m_layout.substr(0,1)<<endreq
252 <<" IncludeCutouts "<< m_includeCutouts<<endreq
253 <<" IncludeCutoutsBog "<< m_includeCutoutsBog<<endreq
254 <<" IncludeCtbBis "<< m_includeCtbBis<<endreq
255 <<" ControlAlines "<< m_controlAlines<<endreq;
256
257 if ( m_stationSelection == 1) {
258 if ( (m_selectedStations.size()+ m_selectedStEta.size()+ m_selectedStPhi.size()) < 1){
259 msg(MSG::ERROR) << " **** Badly set Option "<< endreq
260 << " **** SelectedStations size =" << m_selectedStations.size()<<endreq
261 << " **** SelectedStJzz size =" << m_selectedStations.size()<<endreq
262 << " **** SelectedStJff size =" << m_selectedStations.size()<<endreq
263 << " **** while StationSelection = 1"<< endreq;
264 return( StatusCode::FAILURE );
265 }
266 for (unsigned int i=0; i<m_selectedStations.size() ; i++){
267 msg(MSG::INFO) << " Selected stations " << m_selectedStations[i] << endreq;
268 }
269
270 if ( m_selectedStEta.size() > 0 )
271 {
272 for (unsigned int i=0; i<m_selectedStEta.size() ; i++)
273 msg(MSG::INFO) << " Selected Jzz locations " << m_selectedStEta[i] << endreq;
274 }
275 if ( m_selectedStPhi.size() > 0 )
276 {
277 for (unsigned int i=0; i<m_selectedStPhi.size() ; i++)
278 msg(MSG::INFO) << " Selected Jff locations " << m_selectedStPhi[i] << endreq;
279 }
280 }
281
282
283
284
285
286 DataHandle<StoredMaterialManager> theMaterialManager;
287 if (StatusCode::SUCCESS != detStore->retrieve(theMaterialManager, "MATERIALS")) {
288 msg(MSG::ERROR)
289 << "Could not find Material Manager MATERIALS"
290 << endreq;
291 return (StatusCode::FAILURE);
292 }
293
294
295 umem = GeoPerfUtils::getMem();
296 ucpu = int(GeoPerfUtils::getCpu()/100.);
297 geoModelStats <<"At MuonDetectorTool::material mgr done \t SZ= " <<umem << " Kb \t Time = " << ucpu << " seconds ---- \t DeltaM = "<<umem-mem<<" \t Delta T ="<<ucpu - cpu << std::endl;
298 mem = umem;
299 cpu = ucpu;
300
301
302 StatusCode result = StatusCode::SUCCESS;
303
304 if ( 0 == m_detector ) {
305 IRDBAccessSvc* access = 0;
306 service("RDBAccessSvc",access);
307
308 MuonDetectorFactory001 theFactory(detStore);
309
310 theFactory.setDBAtlasVersion(AtlasVersion);
311 theFactory.setDBMuonVersion(MuonVersion);
312 theFactory.setDBkey( detectorKey );
313 theFactory.setDBnode(detectorNode);
314
315 theFactory.setLayout(m_layout);
316
317
318
319 theFactory.setCutoutsFlag(m_includeCutouts);
320 theFactory.setCutoutsBogFlag(m_includeCutoutsBog);
321 theFactory.setCtbBisFlag(m_includeCtbBis);
322 theFactory.setControlAlines(m_controlAlines);
323 theFactory.setCachingFlag(m_cachingFlag);
324 theFactory.setCacheFillingFlag(m_fillCache_initTime);
325 theFactory.setFineClashFixingFlag(m_enableFineClashFixing);
326 if ( m_stationSelection == 1 ) theFactory.setSelection(m_selectedStations, m_selectedStEta, m_selectedStPhi);
327
328 theFactory.setSwitchOnOff(m_switchOnOff_BUILDINERTMATERIALS ,
329 m_switchOnOff_MINIMALGEO ,
330 m_switchOnOff_BUILDENDCAP ,
331 m_switchOnOff_BUILDCALOSADDLE ,
332 m_switchOnOff_BUILDBARRELTOROID ,
333 m_switchOnOff_BUILDENDCAPTOROID ,
334 m_switchOnOff_BUILDFEET ,
335 m_switchOnOff_BUILDDISKSHIELD ,
336 m_switchOnOff_BUILDTOROIDSHIELD ,
337 m_switchOnOff_BUILDFORWARDSHIELD );
338
339
340
341 theFactory.setRDBAccess(access);
342
343 theFactory.setAltAsciiDBMap(altAsciiDBMap);
344
345
346 try {
347
348
349
350
351 GeoPhysVol *world=&*theExpt->getPhysVol();
352 theFactory.create(world);
353
354 } catch (std::bad_alloc) {
355 msg(MSG::FATAL)<< "Could not create new MuonDetectorNode!" << endreq;
356 return StatusCode::FAILURE;
357 }
358
359 umem = GeoPerfUtils::getMem();
360 ucpu = int(GeoPerfUtils::getCpu()/100.);
361 geoModelStats <<"At MuonDetectorTool::factory created \t SZ= " <<umem << " Kb \t Time = " << ucpu << " seconds ---- \t DeltaM = "<<umem-mem<<" \t Delta T ="<<ucpu - cpu << std::endl;
362 mem = umem;
363 cpu = ucpu;
364
365
366
367 m_manager = theFactory.getDetectorManager();
368
369 m_manager->initABlineContainers();
370
371 ALineMapContainer * amap = m_manager->ALineContainer();
372 BLineMapContainer * bmap = m_manager->BLineContainer();
373 msg(MSG::INFO)<<"A/BLineMapContainers are @ <"<<(uintptr_t)amap<<"> annd <"<<(uintptr_t)bmap<<">"<<endreq;
374
375 if ((detStore->record(amap,"MDT_A_LINE_CORR")).isFailure()) return StatusCode::FAILURE;
376 if ((detStore->record(bmap,"MDT_B_LINE_CORR")).isFailure()) return StatusCode::FAILURE;
377
378 if (m_fillCache_initTime) m_manager->fillCache();
379
380
381 umem = GeoPerfUtils::getMem();
382 ucpu = int(GeoPerfUtils::getCpu()/100.);
383 geoModelStats <<"At MuonDetectorTool::trk cache done \t SZ= " <<umem << " Kb \t Time = " << ucpu << " seconds ---- \t DeltaM = "<<umem-mem<<" \t Delta T ="<<ucpu - cpu << std::endl;
384 mem = umem;
385 cpu = ucpu;
386
387
388 result = detStore->record(theFactory.getDetectorManager(),theFactory.getDetectorManager()->getName());
389 if (result != StatusCode::SUCCESS) return result;
390
391
392
393
394
395 StatusCode scridh = detStore->record(theFactory.getDetectorManager()->mdtIdHelper(), "MDTIDHELPER");
396 if (scridh != StatusCode::SUCCESS) msg(MSG::ERROR)
397 << "Could not record MDTIDHELPER" << endreq;
398 scridh = detStore->record(theFactory.getDetectorManager()->rpcIdHelper(), "RPCIDHELPER");
399 if (scridh != StatusCode::SUCCESS) msg(MSG::ERROR)
400 << "Could not record RPCIDHELPER" << endreq;
401 scridh = detStore->record(theFactory.getDetectorManager()->tgcIdHelper(), "TGCIDHELPER");
402 if (scridh != StatusCode::SUCCESS) msg(MSG::ERROR)
403 << "Could not record TGCIDHELPER" << endreq;
404 scridh = detStore->record(theFactory.getDetectorManager()->cscIdHelper(), "CSCIDHELPER");
405 if (scridh != StatusCode::SUCCESS) msg(MSG::ERROR)
406 << "Could not record CSCIDHELPER" << endreq;
407
408 theExpt->addManager(theFactory.getDetectorManager());
409
410
411
412
413
414
415
416
417 if (altAsciiDBMap)
418 {
419 delete altAsciiDBMap;
420 altAsciiDBMap = 0;
421 }
422 }
423
424 umem = GeoPerfUtils::getMem();
425 ucpu = int(GeoPerfUtils::getCpu()/100.);
426 geoModelStats <<"At MuonDetectorTool::everything done \t SZ= " <<umem << " Kb \t Time = " << ucpu << " seconds ---- \t DeltaM = "<<umem-mem<<" \t Delta T ="<<ucpu - cpu << std::endl;
427 geoModelStats.close();
428
429 return result;
430 }
431
432 StatusCode
433 MuonDetectorTool::clear(StoreGateSvc* detStore)
434 {
435 SG::DataProxy* _proxy = detStore->proxy(ClassID_traits<MuonGM::MuonDetectorManager>::ID(),m_manager->getName());
436 if(_proxy) {
437 _proxy->reset();
438 m_manager = 0;
439 }
440 return StatusCode::SUCCESS;
441 }
442
443 StatusCode
444 MuonDetectorTool::registerCallback( StoreGateSvc* detStore)
445 {
446
447
448
449 if (m_accessCondDb == 0)
450 {
451 msg(MSG::INFO)<<"No data will be read from the condition DB"<<endreq;
452 if (m_asciiCondData == 0) return StatusCode::FAILURE;
453 }
454
455
456
457
458
459
460
461
462
463 std::vector<std::string> folderNames = m_condDataTool->abLineFolderNames();
464 std::vector<std::string> foundFolderNames;
465 msg(MSG::INFO)<<"Register call-back against "<<folderNames.size()<<" folders listed below "<<endreq;
466 int ic=0;
467 bool aFolderFound = false;
468 for (std::vector<std::string>::const_iterator ifld =folderNames.begin(); ifld!=folderNames.end(); ++ifld )
469 {
470 ++ic;
471 msg(MSG::INFO)<<" Folder n. "<<ic<<" <"<<(*ifld)<<">";
472 if (detStore->contains<CondAttrListCollection>(*ifld)) {
473 aFolderFound=true;
474 foundFolderNames.push_back(*ifld);
475 msg(MSG::INFO)<<" found in the DetStore"<<endreq;
476 }
477 else
478 msg(MSG::INFO)<<" NOT found in the DetStore"<<endreq;
479 }
480 if (!aFolderFound)
481 {
482 msg(MSG::INFO)<<"CondAttrListCollection not found in the DetectorStore"<<endreq
483 <<"Unable to register callback on CondAttrListCollection for any folder in the list "<<endreq
484 <<"This is OK unless you expect to read alignment and deformations from COOL "<<endreq;
485 if (m_asciiCondData!=0)
486 {
487 int dummyint;
488 std::list<std::string> dummylist;
489 this->align(dummyint,dummylist);
490 if (m_accessCondDb==0) return StatusCode::FAILURE;
491 }
492 else return StatusCode::FAILURE;
493 }
494
495
496 for (std::vector<std::string>::const_iterator ifld=foundFolderNames.begin(); ifld!=foundFolderNames.end(); ++ifld)
497 {
498 const DataHandle<CondAttrListCollection> parlineData;
499 StatusCode sc = detStore->regFcn(&IGeoModelTool::align,
500 dynamic_cast<IGeoModelTool *>(this),
501 parlineData,
502 *ifld);
503 if (sc.isFailure())
504 {
505 msg(MSG::WARNING)<<"Unable to register call-back to MuonDetectorTool::align() against folder <"<<*ifld<<">"
506 <<" This is OK unless you expect to read alignment and deformations from COOL "<<endreq;
507 }
508 else msg(MSG::INFO)<<"Call-back to MuonDetectorTool::align() against folder "<<*ifld<<" registered "<<endreq;
509 }
510
511 return StatusCode::SUCCESS;
512 }
513
514 StatusCode MuonDetectorTool::align(IOVSVC_CALLBACK_ARGS_P(I,keys))
515 {
516
517 msg(MSG::INFO)<<"In MuonDetectorTool::align"<<endreq;
518 if (m_accessCondDb == 0)
519 {
520 msg(MSG::INFO)<<"Access to the cond DB not enabled by MuonGeoModel specific job-options (UseConditionDb=0)"<<endreq;
521 if (m_asciiCondData==0) return StatusCode::SUCCESS;
522 }
523 if (m_asciiCondData==0) msg(MSG::INFO)<<"Access to the cond DB enabled by MuonGeoModel specific job-options (UseConditionDb=1)"<<endreq;
524
525 msg(MSG::DEBUG)<<"ToolHandle in align - "<<m_condDataTool<<endreq;
526 IMuonAlignmentDbTool* pAliTool = &*m_condDataTool;
527
528 msg(MSG::DEBUG)<<"pointer to the concrete tool in align - "<<pAliTool<<endreq;
529
530 StatusCode sc = m_condDataTool->loadParameters(I, keys);
531 if (sc.isRecoverable())
532 {
533 msg(MSG::WARNING)
534 <<"Recoverable error while loading the Alignment and Deformation parameters"<<endreq
535 <<"part of alignment data requested might be missing"<<endreq;
536 }
537 else if (sc.isFailure())
538 {
539 msg(MSG::ERROR)<<"Unable to load the Alignment and Deformation parameters"<<endreq;
540 return sc;
541 }
542 msg(MSG::INFO)<<"Alignment and Deformation parameters loaded and stored in the DetectorStore"<<endreq;
543
544
545 sc = m_manager->updateAlignment(m_condDataTool->ALineContainer());
546 if (sc.isFailure()) msg(MSG::ERROR)<<"Unable to updateAlignment"<<endreq;
547 else msg(MSG::DEBUG)<<"updateAlignment DONE"<<endreq;
548
549
550 sc = m_manager->updateDeformations(m_condDataTool->BLineContainer());
551
552 if (sc.isFailure()) msg(MSG::ERROR)<<"Unable to updateDeformations"<<endreq;
553 else msg(MSG::DEBUG)<<"updateDeformations DONE"<<endreq;
554
555 return sc;
556 }
| Due to the LXR bug, the updates fail sometimes to remove references to deleted files. The Saturday's full rebuilds fix these problems |
|
This page was automatically generated by the
LXR engine.
|
|