ATLAS Offline Software
RDBMaterialManager.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "RDBMaterialManager.h"
8 
9 #include "GeoModelKernel/GeoMaterial.h"
10 #include "GeoModelKernel/Units.h"
11 
12 #include "StoreGate/DataHandle.h"
13 
17 
19 #include "GaudiKernel/IMessageSvc.h"
20 #include "GaudiKernel/ISvcLocator.h"
21 #include "GaudiKernel/MsgStream.h"
22 #include "GaudiKernel/SystemOfUnits.h"
24 
25 #include <algorithm>
26 #include <iostream>
27 #include <stdexcept>
28 
29 
30 //---------------------------Help find elements in the list-----------------------//
31 class NameEquals { //
32 public: //
33  NameEquals(const std::string & name):m_name(name){} //
34  bool operator() (const GeoElement *e) const {return m_name==e->getName();} //
35 private: //
36  std::string m_name; //
37 }; //
38 //--------------------------------------------------------------------------------//
39 
40 //---------------------------Help find elements in the list-----------------------//
41 class NumberEquals { //
42 public: //
43  NumberEquals(unsigned int number):m_number(number){} //
44  bool operator() (const GeoElement *e) const {return m_number==e->getZ();} //
45 private: //
46  unsigned int m_number; //
47 }; //
48 //--------------------------------------------------------------------------------//
49 
50 int CheckElement(std::string &name)
51 {
52  if(name.find("::",0) == std::string::npos) {
53  return 1;
54  }
55  else {
56  return 0;
57  }
58 }
59 
60 int printElement ( GeoElement* &p_element)
61 {
62  std::string name = p_element->getName();
63  std::string symbol = p_element->getSymbol();
64  double a = p_element->getA();
65  double z = p_element->getZ();
66 
67  std::cout << " ***** CheckElement(): Print the Element: " << name << "\n";
68  std::cout << " ***** The Element: name, symbol, A, Z \n" ;
69  std::cout << " ***** "<<name <<" "<<symbol <<" "<< a * (Gaudi::Units::mole / GeoModelKernelUnits::gram) <<" "<< z <<" " << std::endl;
70 
71  return 1;
72 }
73 
74 int printElement ( const GeoElement* &p_element)
75 {
76  std::string name = p_element->getName();
77  std::string symbol = p_element->getSymbol();
78  double a = p_element->getA();
79  double z = p_element->getZ();
80 
81  std::cout << " ***** PrintElement(): Print the Element: " << name << "\n";
82  std::cout << " ***** The Element: name, symbol, A, Z \n";
83  std::cout << " ***** "<<name <<" "<<symbol <<" "<< a * (Gaudi::Units::mole / GeoModelKernelUnits::gram) <<" "<< z <<" " << std::endl;
84 
85  return 1;
86 }
87 
88 int printMaterial ( GeoMaterial* &p_material)
89 {
90  std::string name = p_material->getName();
91  double density = p_material->getDensity() * (Gaudi::Units::cm3 / GeoModelKernelUnits::gram);
92 
93  std::cout << " ***** PrintMaterial(): Print the Material: " << name << "\n";
94  std::cout << " ***** The Material: name, density \n" ;
95  std::cout << " ***** "<< name <<" "<<density <<" " << std::endl;
96 
97  return 1;
98 }
99 
100 int printFullMaterial ( GeoMaterial* &p_material)
101 {
102  std::string name = p_material->getName();
103  double density = p_material->getDensity() * (Gaudi::Units::cm3 / GeoModelKernelUnits::gram);
104 
105  std::cout << " ***** PrintFullMaterial(): Print the Material: " << name << "\n";
106  std::cout << " ***** The Material: name, density\n" ;
107  std::cout << " ***** "<< name <<" "<<density <<" " << std::endl;
108 
109  p_material->lock();
110  int element_number = p_material->getNumElements();
111 
112 
113  if ( element_number == 0){
114  std::cout << " ***** No Elements now in this printMaterial( ) " << std::endl;
115  return 1;
116  }
117  else {
118  element_number = p_material->getNumElements();
119 
120  for(int i =0; i< element_number;i ++)
121  {
122  const GeoElement* tmp_element = p_material->getElement(i);
123  double element_fraction = p_material->getFraction(i);
124 
125  std::cout<<" ***** ***** Number: " << i << " Fraction: " << element_fraction<< std::endl;
126  printElement( tmp_element);
127  }
128  }
129  return 1;
130 }
131 
132 
133 
134 RDBMaterialManager::RDBMaterialManager(ISvcLocator* pSvcLocator)
135 {
136  if(!readMaterialsFromDB(pSvcLocator).isSuccess()) {
137  throw std::runtime_error("RDBMaterialManager failed to read Geometry DB");
138  }
139 }
140 
142 {
143  MsgStream log(Athena::getMessageSvc(), "GeoModelSvc::RDBMaterialManager");
144 
145  SmartIF<IGeoModelSvc> iGeoModel{pSvcLocator->service("GeoModelSvc")};
146  ATH_CHECK( iGeoModel.isValid() );
147 
148  SmartIF<IRDBAccessSvc> iAccessSvc{pSvcLocator->service("RDBAccessSvc")};
149  ATH_CHECK( iAccessSvc.isValid() );
150 
151  auto warn = [&](const std::string & msg){
152  if (log.level()<=MSG::WARNING){
153  log << MSG::WARNING <<msg << endmsg;
154  }
155  };
156  auto debug = [&](const std::string & msg){
157  if (log.level()<=MSG::DEBUG){
158  log << MSG::DEBUG <<msg << endmsg;
159  }
160  };
161  const bool loadDefaults = iGeoModel->geoConfig() != GeoModel::GEO_RUN4;
162  auto defaulted = [=](const IRDBRecordset_ptr pRecordset) -> bool{
163  return (loadDefaults and pRecordset->size() == 0);
164  };
165  // Do not load defaults for RUN4
166  if (loadDefaults) debug("Will load material defaults if not present");
167 
168  // --- Standard materials, elements
169  DecodeVersionKey keyAtlas(iGeoModel, "ATLAS");
170  m_elements = iAccessSvc->getRecordsetPtr("Elements",keyAtlas.tag(),keyAtlas.node());
171  if(defaulted(m_elements)) {
172  warn("Getting Elements with default tag");
173  m_elements = iAccessSvc->getRecordsetPtr("Elements","Materials-00","Materials");
174  }
175  m_stdmatcomponents = iAccessSvc->getRecordsetPtr("StdMatComponents",keyAtlas.tag(),keyAtlas.node());
176  if(defaulted(m_stdmatcomponents)) {
177  warn("Getting StdMatComponents with default tag");
178  m_stdmatcomponents = iAccessSvc->getRecordsetPtr("StdMatComponents","Materials-00","Materials");
179  }
180  m_stdmaterials = iAccessSvc->getRecordsetPtr("StdMaterials",keyAtlas.tag(),keyAtlas.node());
181  if(defaulted(m_stdmaterials)) {
182  warn("Getting StdMaterials with default tag");
183  m_stdmaterials = iAccessSvc->getRecordsetPtr("StdMaterials","Materials-00","Materials");
184  }
185 
186  // --- Pixel materials
187  DecodeVersionKey keyPixel(iGeoModel, "Pixel");
188  m_pixmatcomponents = iAccessSvc->getRecordsetPtr("PixMatComponents",keyPixel.tag(),keyPixel.node());
189  if(defaulted(m_pixmatcomponents)) {
190  warn("Getting PixMatComponents with default tag");
191  m_pixmatcomponents = iAccessSvc->getRecordsetPtr("PixMatComponents","PixMatComponents-00");
192  }
193  m_pixmaterials = iAccessSvc->getRecordsetPtr("PixMaterials",keyPixel.tag(),keyPixel.node());
194  if(defaulted(m_pixmaterials)) {
195  warn("Getting PixMaterials with default tag");
196  m_pixmaterials = iAccessSvc->getRecordsetPtr("PixMaterials","PixMaterials-00");
197  }
198 
199  // --- Pixel materials for TB
200  //for test beam materials we just issue debug level messages. Perhaps this load can be fully omitted?
201  m_pixtbmatcomponents = iAccessSvc->getRecordsetPtr("PixelTBMatComponents",keyPixel.tag(),keyPixel.node());
202  if(defaulted( m_pixtbmatcomponents)) {
203  debug("Getting PixTBMatComponents with default tag" );
204  m_pixtbmatcomponents = iAccessSvc->getRecordsetPtr("PixMatComponents","PixMatComponents-00");
205  }
206  m_pixtbmaterials = iAccessSvc->getRecordsetPtr("PixelTBMaterials",keyPixel.tag(),keyPixel.node());
207  if(defaulted(m_pixtbmaterials)) {
208  debug("Getting PixTBMaterials with default tag");
209  m_pixtbmaterials = iAccessSvc->getRecordsetPtr("PixMaterials","PixMaterials-00");
210  }
211 
212  // --- SCT materials
213  DecodeVersionKey keySCT(iGeoModel, "SCT");
214  m_sctmatcomponents = iAccessSvc->getRecordsetPtr("SCTMatComponents",keySCT.tag(),keySCT.node());
215  if(defaulted(m_sctmatcomponents)) {
216  warn("Getting SCTMatComponents with default tag");
217  m_sctmatcomponents = iAccessSvc->getRecordsetPtr("SCTMatComponents","SCTMatComponents-00");
218  }
219 
220  m_sctmaterials = iAccessSvc->getRecordsetPtr("SCTMaterials",keySCT.tag(),keySCT.node());
221  if(defaulted(m_sctmaterials)) {
222  warn("Getting SCTMaterials with default tag");
223  m_sctmaterials = iAccessSvc->getRecordsetPtr("SCTMaterials","SCTMaterials-00");
224  }
225 
226  // --- TRT materials
227  DecodeVersionKey keyTRT(iGeoModel, "TRT");
228  m_trtmatcomponents = iAccessSvc->getRecordsetPtr("TrtMatComponents",keyTRT.tag(),keyTRT.node());
229  if(defaulted(m_trtmatcomponents)) {
230  warn("Getting TrtMatComponents with default tag");
231  m_trtmatcomponents = iAccessSvc->getRecordsetPtr("TrtMatComponents","TrtMatComponents-00");
232  }
233  m_trtmaterials = iAccessSvc->getRecordsetPtr("TrtMaterials",keyTRT.tag(),keyTRT.node());
234  if(defaulted(m_trtmaterials)) {
235  warn("Getting TrtMaterials with default tag");
236  m_trtmaterials = iAccessSvc->getRecordsetPtr("TrtMaterials","TrtMaterials-00");
237  }
238 
239  // --- InDet common materials
240  DecodeVersionKey keyInDet(iGeoModel, "InnerDetector");
241  m_indetmatcomponents = iAccessSvc->getRecordsetPtr("InDetMatComponents",keyInDet.tag(),keyInDet.node());
242  if(defaulted(m_indetmatcomponents)) {
243  debug("Getting InDetMatComponents with default tag");
244  m_indetmatcomponents = iAccessSvc->getRecordsetPtr("InDetMatComponents","InDetMatComponents-00");
245  }
246 
247  m_indetmaterials = iAccessSvc->getRecordsetPtr("InDetMaterials",keyInDet.tag(),keyInDet.node());
248  if(defaulted(m_indetmaterials)) {
249  debug("Getting InDetMaterials with default tag");
250  m_indetmaterials = iAccessSvc->getRecordsetPtr("InDetMaterials","InDetMaterials-00");
251  }
252 
253  // --- LAr materials
254  DecodeVersionKey keyLAr(iGeoModel, "LAr");
255  m_larmatcomponents = iAccessSvc->getRecordsetPtr("LArMatComponents",keyLAr.tag(),keyLAr.node());
256  if(defaulted(m_larmatcomponents)) {
257  warn("Getting LArMatComponents with default tag");
258  m_larmatcomponents = iAccessSvc->getRecordsetPtr("LArMatComponents","LArMatComponents-00");
259  }
260  m_larmaterials = iAccessSvc->getRecordsetPtr("LArMaterials",keyLAr.tag(),keyLAr.node());
261  if(defaulted(m_larmaterials)) {
262  warn("Getting LArMaterials with default tag");
263  m_larmaterials = iAccessSvc->getRecordsetPtr("LArMaterials","LArMaterials-00");
264  }
265 
266  // --- Tile materials
267  DecodeVersionKey keyTile(iGeoModel, "TileCal");
268  m_tilematcomponents = iAccessSvc->getRecordsetPtr("TileMatComponents",keyTile.tag(),keyTile.node());
269  if (defaulted(m_tilematcomponents)) {
270  warn("Getting TileMatComponents with default tag" );
271  m_tilematcomponents = iAccessSvc->getRecordsetPtr("TileMatComponents","TileMatComponents-00");
272  }
273  m_tilematerials = iAccessSvc->getRecordsetPtr("TileMaterials",keyTile.tag(),keyTile.node());
274  if(defaulted(m_tilematerials)) {
275  warn("Getting TileMaterials with default tag");
276  m_tilematerials = iAccessSvc->getRecordsetPtr("TileMaterials","TileMaterials-00");
277  }
278 
279  // --- Muon
280  DecodeVersionKey keyMuon(iGeoModel, "MuonSpectrometer");
281  m_muomatcomponents = iAccessSvc->getRecordsetPtr("MUOMatComponents",keyMuon.tag(),keyMuon.node());
282  if(defaulted(m_muomatcomponents)) {
283  warn("Getting MUOMatComponents with default tag");
284  m_muomatcomponents = iAccessSvc->getRecordsetPtr("MUOMatComponents","MUOMatComponents-00");
285  }
286  m_muomaterials = iAccessSvc->getRecordsetPtr("MUOMaterials",keyMuon.tag(),keyMuon.node());
287  if(defaulted(m_muomaterials)) {
288  warn("Getting MUOMaterials with default tag" );
289  m_muomaterials = iAccessSvc->getRecordsetPtr("MUOMaterials","MUOMaterials-00");
290  }
291  m_shieldmatcomponents = iAccessSvc->getRecordsetPtr("ShieldMatComponents",keyMuon.tag(),keyMuon.node());
292  if(defaulted(m_shieldmatcomponents)) {
293  warn("Getting ShieldMatComponents with default tag");
294  m_shieldmatcomponents = iAccessSvc->getRecordsetPtr("ShieldMatComponents","ShieldMatComponents-00");
295  }
296  m_shieldmaterials = iAccessSvc->getRecordsetPtr("ShieldMaterials",keyMuon.tag(),keyMuon.node());
297  if(defaulted(m_shieldmaterials)) {
298  warn("Getting ShieldMaterials with default tag");
299  m_shieldmaterials = iAccessSvc->getRecordsetPtr("ShieldMaterials","ShieldMaterials-00");
300  }
301  m_toromatcomponents = iAccessSvc->getRecordsetPtr("ToroMatComponents",keyMuon.tag(),keyMuon.node());
302  if(defaulted(m_toromatcomponents)) {
303  warn("Getting ToroMatComponents with default tag");
304  m_toromatcomponents = iAccessSvc->getRecordsetPtr("ToroMatComponents","ToroMatComponents-00");
305  }
306  m_toromaterials = iAccessSvc->getRecordsetPtr("ToroMaterials",keyMuon.tag(),keyMuon.node());
307  if(defaulted(m_toromaterials)) {
308  warn("Getting ToroMaterials with default tag");
309  m_toromaterials = iAccessSvc->getRecordsetPtr("ToroMaterials","ToroMaterials-00");
310  }
311  return StatusCode::SUCCESS;
312 }
313 
314 // Destructor:
316 
317 GeoMaterial* RDBMaterialManager::searchMaterialMap(const std::string & name) const
318 {
319  MsgStream log(Athena::getMessageSvc(), "GeoModelSvc::RDBMaterialManager");
320 
321  MaterialMap::const_iterator m = m_materialMap.find(std::string(name));
322 
323  if (m!=m_materialMap.end()) {
324  if(log.level()==MSG::VERBOSE)
325  log << MSG::VERBOSE << " ***** in searchMaterialMap(): search sucess " << endmsg;
326  return (*m).second;
327  }
328 
329  if(log.level()==MSG::VERBOSE)
330  log << MSG::VERBOSE << " ***** in searchMaterialMap(): search fail " << endmsg;
331 
332  return nullptr;
333 
334 }
335 
336 
337 GeoElement *RDBMaterialManager::searchElementVector(const std::string & name) const
338 {
339  MsgStream log(Athena::getMessageSvc(), "GeoModelSvc::RDBMaterialManager");
340 
341  NameEquals matchByName(name);
342  GeoEleVec::const_iterator e=std::find_if(m_elementVector.begin(), m_elementVector.end(),matchByName);
343 
344  if (e!=m_elementVector.end()) {
345  if(log.level()==MSG::VERBOSE)
346  log << MSG::VERBOSE << " ***** in searchElementVector() search succes " << endmsg;
347  return *e;
348  }
349  else {
350  if(log.level()==MSG::VERBOSE)
351  log << MSG::VERBOSE << " ***** in searchElementVector() search fail " << endmsg;
352  return nullptr;
353  }
354 }
355 
356 
357 GeoElement *RDBMaterialManager::searchElementVector(const unsigned int atomicNumber) const
358 {
359  MsgStream log(Athena::getMessageSvc(), "GeoModelSvc::RDBMaterialManager");
360 
361  NumberEquals matchByNumber(atomicNumber);
362  GeoEleVec::const_iterator e=std::find_if(m_elementVector.begin(), m_elementVector.end(), matchByNumber);
363 
364  if (e!=m_elementVector.end()) {
365  if(log.level()==MSG::VERBOSE)
366  log << MSG::VERBOSE << " ***** in searchElementVector(atomicNumber) search succes " << endmsg;
367  return *e;
368  }
369 
370  if(log.level()==MSG::VERBOSE)
371  log << MSG::VERBOSE << " ***** in searchElementVector(atomicNumber) search succes " << endmsg;
372  return nullptr;
373 
374 }
375 
376 const GeoMaterial* RDBMaterialManager:: getMaterial(const std::string &name) {
377 
378  unsigned int ind{0}, com_ind{0};
379 
380  std::string material_name;
381  std::string tmp_name;
382  long material_id{0};
383  double material_density{0.};
384 
385 
386  std::string component_name{};
387  double component_fraction{0.};
388  int component_id{0};
389 
390  std::string detector;
391  std::string tmp_det;
392  std::string data_id;
393 
394 
395  std::string matcomponents_table;
396 
397  [[maybe_unused]] static const bool specialMaterialsDone = [this]() {
399  return true;
400  }();
401 
402  GeoMaterial* pmaterial;
403 
404  const GeoElement* p_com_element;
405 
406  IRDBRecordset_ptr tmp_materials;
407  IRDBRecordset_ptr tmp_matcomponents;
408 
409  MsgStream log(Athena::getMessageSvc(), "GeoModelSvc::RDBMaterialManager");
410  if(log.level()<=MSG::DEBUG)
411  log << MSG::DEBUG << " ***** getMaterial( ): " << name << endmsg;
412 
413  pmaterial = nullptr;
414  pmaterial = searchMaterialMap( name);
415  if (pmaterial!= nullptr)
416  return pmaterial;
417 
418  if(name.starts_with("std"))
419  {
420  detector = "std";
421  tmp_materials = m_stdmaterials;
422  tmp_matcomponents = m_stdmatcomponents;
423  data_id = "STDMATERIALS_DATA_ID";
424  }
425  else if(name.starts_with("trt"))
426  {
427  detector = "trt";
428  tmp_materials = m_trtmaterials;
429  tmp_matcomponents = m_trtmatcomponents;
430  data_id = "TRTMATERIALS_DATA_ID";
431  }
432  else if(name.starts_with("LAr"))
433  {
434  detector = "LAr";
435  tmp_materials = m_larmaterials;
436  tmp_matcomponents = m_larmatcomponents;
437  data_id = "LARMATERIALS_DATA_ID";
438  }
439  else if(name.starts_with("muo"))
440  {
441  detector = "muo";
442  tmp_materials = m_muomaterials;
443  tmp_matcomponents = m_muomatcomponents;
444  data_id = "MUOMATERIALS_DATA_ID";
445  }
446  else if(name.starts_with("pixtb"))
447  {
448  detector = "pixtb";
449  tmp_materials = m_pixtbmaterials;
450  tmp_matcomponents = m_pixtbmatcomponents;
451  data_id = "PIXELTBMATERIALS_DATA_ID";
452  }
453  else if(name.starts_with("pix"))
454  {
455  detector = "pix";
456  tmp_materials = m_pixmaterials;
457  tmp_matcomponents = m_pixmatcomponents;
458  data_id = "PIXMATERIALS_DATA_ID";
459  }
460  else if(name.starts_with("sct"))
461  {
462  detector = "sct";
463  tmp_materials = m_sctmaterials;
464  tmp_matcomponents = m_sctmatcomponents;
465  data_id = "SCTMATERIALS_DATA_ID";
466  }
467  else if(name.starts_with("indet"))
468  {
469  detector = "indet";
470  tmp_materials = m_indetmaterials;
471  tmp_matcomponents = m_indetmatcomponents;
472  data_id = "INDETMATERIALS_DATA_ID";
473  }
474  else if(name.starts_with("shield"))
475  {
476  detector = "shield";
477  tmp_materials = m_shieldmaterials;
478  tmp_matcomponents = m_shieldmatcomponents;
479  data_id = "SHIELDMATERIALS_DATA_ID";
480  }
481  else if(name.starts_with("tile"))
482  {
483  detector = "tile";
484  tmp_materials = m_tilematerials;
485  tmp_matcomponents = m_tilematcomponents;
486  data_id = "TILEMATERIALS_DATA_ID";
487  }
488  else if(name.starts_with("toro"))
489  {
490  detector = "toro";
491  tmp_materials = m_toromaterials;
492  tmp_matcomponents = m_toromatcomponents;
493  data_id = "TOROMATERIALS_DATA_ID";
494  }
495  else {return 0 ;}
496 
497  for( ind = 0; ind < tmp_materials->size(); ind++)
498  {
499  const IRDBRecord* rec = (*tmp_materials)[ind];
500  tmp_name = detector+"::"+rec->getString("NAME");
501 
502  if( name == tmp_name){
503  material_name =detector+"::"+rec->getString("NAME");
504  material_id = rec->getLong(data_id);
505  material_density = rec->getDouble("DENSITY");
506 
507  if(log.level()<=MSG::DEBUG)
508  log << MSG::DEBUG << " ***** Material: name id density: " << material_name <<" " << material_id <<" "<< material_density << endmsg;
509  break;
510  }
511  }
512 
513  if (ind == tmp_materials->size())
514  return nullptr;
515 
516  pmaterial = new GeoMaterial( material_name,material_density * (GeoModelKernelUnits::gram / Gaudi::Units::cm3));
517 
518  bool firstComponent = true;
519  bool hasSubMaterial = false;
520  bool calculateFraction = false;
521  double totalFraction = 0.;
522  std::vector <const GeoElement*> elementComponents;
523  std::vector <double> elementFractions;
524 
525  for( com_ind = 0; com_ind <tmp_matcomponents->size(); com_ind++)
526  {
527  const IRDBRecord* com_rec = (*tmp_matcomponents)[com_ind];
528 
529  component_id = com_rec->getLong("MATERIAL_ID");
530  if( component_id == material_id)
531  {
532  component_name = com_rec->getString("COMPNAME");
533  component_fraction = com_rec->getDouble("FRACTION");
534 
535  if(firstComponent)
536  {
537  firstComponent = false;
538  if(component_fraction>=1.)
539  calculateFraction = true;
540  }
541 
542  if( CheckElement( component_name) == 1)
543  {
544  p_com_element = getElement(component_name);
545 
546  if(calculateFraction)
547  {
548  totalFraction += component_fraction*p_com_element->getA();
549  elementComponents.push_back(p_com_element);
550  elementFractions.push_back(component_fraction);
551  }
552  else
553  pmaterial->add( p_com_element, component_fraction);
554 
555  }
556  else{
557  hasSubMaterial = true;
558  const GeoMaterial* p_com_material = getMaterial(component_name);
559  pmaterial->add(p_com_material, component_fraction);
560 
561  }
562  }
563  }
564 
565  if(calculateFraction && hasSubMaterial && elementComponents.size()>0)
566  std::cerr << material_name << " description should be changed. Please indicate the exact fraction for elements\n";
567 
568  if(calculateFraction && !elementComponents.empty()) {
569  double inv_totalFraction = 1. / totalFraction;
570  for(unsigned i=0; i<elementComponents.size(); i++)
571  pmaterial->add(elementComponents[i],elementFractions[i]*elementComponents[i]->getA() * inv_totalFraction);
572  }
573 
574  // a table to keep the memory allocation, and easy for delete
575  addMaterial(detector,pmaterial);
576 
577  return pmaterial;
578 }
579 
580 
581 const GeoElement *RDBMaterialManager::getElement(const std::string & name) {
582 
583  unsigned int ind;
584 
585  std::string element_name;
586  std::string element_symbol;
587  std::string tmp_name;
588 
589  double element_a;
590  double element_z;
591 
592  GeoElement *pelement;
593 
594  pelement = nullptr;
595  pelement = searchElementVector( name);
596  if (pelement != nullptr)
597  return pelement;
598 
599  MsgStream log(Athena::getMessageSvc(), "GeoModelSvc::RDBMaterialManager");
600  if(log.level()==MSG::VERBOSE)
601  log << MSG::VERBOSE << " ***** getElement(): " << name <<endmsg;
602 
603  for(ind = 0; ind < m_elements->size(); ind++)
604  {
605  const IRDBRecord* rec = (*m_elements)[ind];
606 
607  tmp_name = rec->getString("NAME");
608 
609  if( name == tmp_name)
610  {
611  element_name = rec->getString("NAME");
612  element_symbol = rec->getString("SYMBOL");
613  element_a = rec->getDouble("A");
614  element_z = rec->getDouble("Z");
615 
616  pelement = new GeoElement( element_name , element_symbol ,element_z , element_a *(GeoModelKernelUnits::gram/Gaudi::Units::mole));
617 
618  // a table to keep the memory allocation, and easy for delete
619  m_elementVector.push_back( pelement);
620 
621  break;
622  }
623  }
624  if (ind == m_elements->size()) return nullptr;
625 
626  return pelement;
627 
628 }
629 
630 
631 const GeoElement *RDBMaterialManager::getElement(unsigned int atomicNumber) {
632 
633  unsigned int ind;
634 
635  std::string element_name;
636  std::string element_symbol;
637 
638  double element_a;
639  double element_z;
640 
641  GeoElement* pelement(0);
642 
643  MsgStream log(Athena::getMessageSvc(), "GeoModelSvc::RDBMaterialManager");
644  if(log.level()==MSG::VERBOSE)
645  log << MSG::VERBOSE << " ***** const getElement(atomicNumber) const : " << atomicNumber <<endmsg;
646 
647  for(ind = 0; ind < m_elements->size(); ind++)
648  {
649  const IRDBRecord* rec = (*m_elements)[ind];
650 
651  if(atomicNumber == rec->getDouble("A"))
652  {
653  element_name = rec->getString("NAME");
654  element_symbol = rec->getString("SYMBOL");
655  element_a = rec->getDouble("A");
656  element_z = rec->getDouble("Z");
657 
658  pelement = new GeoElement( element_name , element_symbol ,element_z , element_a *(GeoModelKernelUnits::gram/Gaudi::Units::mole));
659 
660  // a table to keep the memory allocation, and easy for delete
661  m_elementVector.push_back( pelement);
662 
663  break;
664  }
665  }
666  if (ind == m_elements->size()) return nullptr;
667 
668  return pelement;
669 }
670 
671 void RDBMaterialManager::addMaterial(const std::string & /*space*/, GeoMaterial *material) {
672 
673  MsgStream log(Athena::getMessageSvc(), "GeoModelSvc::RDBMaterialManager");
674  if(log.level()==MSG::VERBOSE)
675  log << MSG::VERBOSE << " ***** RDBMaterialManager::addMaterial() "<<endmsg;
676 
677  std::string key = std::string(material->getName());
678  // Check whether we already have materials with the same space::name defined
679  if(m_materialMap.find(key)!=m_materialMap.end())
680  log << MSG::WARNING << " Attempt to redefine material " << key << "!. The existing instance is kept. Please choose another name for new material" << endmsg;
681  else {
682  material->lock();
683  m_materialMap[key]=material;
684  }
685 }
686 
688 {
689  return m_materialMap.begin();
690 }
691 
693 {
694  return m_materialMap.end();
695 }
696 
698 {
699  return m_materialMap.size();
700 }
701 
702 std::ostream & RDBMaterialManager::printAll(std::ostream & o) const
703 {
704  o << "============Material Manager Element List========================\n";
705  for (GeoElement* elt : m_elementVector){
706  o << elt->getSymbol() << '\t' << elt->getZ() << '\t' << elt->getA() * (Gaudi::Units::mole / GeoModelKernelUnits::gram) << '\t' << elt->getName() << "\n";
707  }
708 
709  for (const auto& p : m_materialMap){
710  o << "Material: " << p.first << " Density " << p.second->getDensity() * (Gaudi::Units::cm3 / GeoModelKernelUnits::gram) << "\n";
711  for (size_t i = 0; i< p.second->getNumElements();i++) {
712  o <<" ***** ***** "<< int (p.second->getFraction(i)*100) << "% \t" << p.second->getElement(i)->getName() << std::endl;
713  }
714  }
715 
716  return o;
717 }
718 
720 {
721  // Create special materials
722  GeoElement* ethElement = new GeoElement("Ether","ET",500.0,0.0);
723  m_elementVector.push_back(ethElement);
724  GeoMaterial* ether = new GeoMaterial("special::Ether",0.0);
725  ether->add(ethElement,1.);
726  addMaterial("special",ether);
727  // "Alternative" assembly material
728  GeoMaterial* hu = new GeoMaterial("special::HyperUranium",0.0);
729  hu->add(ethElement,1.);
730  addMaterial("special",hu);
731 }
RDBMaterialManager.h
RDBMaterialManager::m_indetmatcomponents
IRDBRecordset_ptr m_indetmatcomponents
Definition: RDBMaterialManager.h:86
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
CheckElement
int CheckElement(std::string &name)
Definition: RDBMaterialManager.cxx:50
NumberEquals
Definition: RDBMaterialManager.cxx:41
RDBMaterialManager::m_shieldmatcomponents
IRDBRecordset_ptr m_shieldmatcomponents
Definition: RDBMaterialManager.h:88
RDBMaterialManager::addMaterial
virtual void addMaterial(const std::string &space, GeoMaterial *material) override
Definition: RDBMaterialManager.cxx:671
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
NumberEquals::m_number
unsigned int m_number
Definition: RDBMaterialManager.cxx:46
RDBMaterialManager::m_toromaterials
IRDBRecordset_ptr m_toromaterials
Definition: RDBMaterialManager.h:91
AthCheckMacros.h
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
RDBMaterialManager::m_larmatcomponents
IRDBRecordset_ptr m_larmatcomponents
Definition: RDBMaterialManager.h:76
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
NameEquals::operator()
bool operator()(const GeoElement *e) const
Definition: RDBMaterialManager.cxx:34
RDBMaterialManager::m_sctmaterials
IRDBRecordset_ptr m_sctmaterials
Definition: RDBMaterialManager.h:83
TRTCalib_cfilter.detector
detector
Definition: TRTCalib_cfilter.py:241
NameEquals::NameEquals
NameEquals(const std::string &name)
Definition: RDBMaterialManager.cxx:33
NumberEquals::operator()
bool operator()(const GeoElement *e) const
Definition: RDBMaterialManager.cxx:44
IRDBRecord::getString
virtual const std::string & getString(const std::string &fieldName) const =0
Get string field value.
printMaterial
int printMaterial(GeoMaterial *&p_material)
Definition: RDBMaterialManager.cxx:88
RDBMaterialManager::m_materialMap
StoredMaterialManager::MaterialMap m_materialMap
Definition: RDBMaterialManager.h:96
RDBMaterialManager::m_muomaterials
IRDBRecordset_ptr m_muomaterials
Definition: RDBMaterialManager.h:77
RDBMaterialManager::m_trtmaterials
IRDBRecordset_ptr m_trtmaterials
Definition: RDBMaterialManager.h:71
cm3
#define cm3
RDBMaterialManager::m_sctmatcomponents
IRDBRecordset_ptr m_sctmatcomponents
Definition: RDBMaterialManager.h:84
DecodeVersionKey::node
const std::string & node() const
Return the version node.
Definition: DecodeVersionKey.cxx:97
python.SystemOfUnits.gram
int gram
Definition: SystemOfUnits.py:165
RDBMaterialManager::m_pixmaterials
IRDBRecordset_ptr m_pixmaterials
Definition: RDBMaterialManager.h:79
DataHandle.h
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
printFullMaterial
int printFullMaterial(GeoMaterial *&p_material)
Definition: RDBMaterialManager.cxx:100
RDBMaterialManager::m_stdmatcomponents
IRDBRecordset_ptr m_stdmatcomponents
Definition: RDBMaterialManager.h:74
RDBMaterialManager::m_elementVector
GeoEleVec m_elementVector
Definition: RDBMaterialManager.h:95
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
IRDBAccessSvc.h
Definition of the abstract IRDBAccessSvc interface.
RDBMaterialManager::m_trtmatcomponents
IRDBRecordset_ptr m_trtmatcomponents
Definition: RDBMaterialManager.h:72
RDBMaterialManager::m_muomatcomponents
IRDBRecordset_ptr m_muomatcomponents
Definition: RDBMaterialManager.h:78
lumiFormat.i
int i
Definition: lumiFormat.py:85
z
#define z
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
NameEquals::m_name
std::string m_name
Definition: RDBMaterialManager.cxx:36
DecodeVersionKey
This is a helper class to query the version tags from GeoModelSvc and determine the appropriate tag a...
Definition: DecodeVersionKey.h:18
DecodeVersionKey::tag
const std::string & tag() const
Return version tag.
Definition: DecodeVersionKey.cxx:91
GeoModel::GEO_RUN4
@ GEO_RUN4
Definition: IGeoDbTagSvc.h:21
IRDBRecord::getLong
virtual long getLong(const std::string &fieldName) const =0
Get long field value.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
RDBMaterialManager::readMaterialsFromDB
StatusCode readMaterialsFromDB(ISvcLocator *pSvcLocator)
Definition: RDBMaterialManager.cxx:141
IRDBRecordset_ptr
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition: IRDBAccessSvc.h:25
RDBMaterialManager::size
virtual size_t size() override
Definition: RDBMaterialManager.cxx:697
RDBMaterialManager::m_tilematerials
IRDBRecordset_ptr m_tilematerials
Definition: RDBMaterialManager.h:89
RDBMaterialManager::m_pixmatcomponents
IRDBRecordset_ptr m_pixmatcomponents
Definition: RDBMaterialManager.h:80
RDBMaterialManager::m_tilematcomponents
IRDBRecordset_ptr m_tilematcomponents
Definition: RDBMaterialManager.h:90
createCoolChannelIdFile.element_name
element_name
Definition: createCoolChannelIdFile.py:47
RDBMaterialManager::getMaterial
virtual const GeoMaterial * getMaterial(const std::string &name) override
Definition: RDBMaterialManager.cxx:376
RDBMaterialManager::m_toromatcomponents
IRDBRecordset_ptr m_toromatcomponents
Definition: RDBMaterialManager.h:92
python.selection.number
number
Definition: selection.py:20
RDBMaterialManager::m_stdmaterials
IRDBRecordset_ptr m_stdmaterials
Definition: RDBMaterialManager.h:73
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
RDBMaterialManager::printAll
virtual std::ostream & printAll(std::ostream &o=std::cout) const override
Definition: RDBMaterialManager.cxx:702
NumberEquals::NumberEquals
NumberEquals(unsigned int number)
Definition: RDBMaterialManager.cxx:43
ReadBadBitsFromCool.warn
warn
Definition: ReadBadBitsFromCool.py:43
RDBMaterialManager::getElement
virtual const GeoElement * getElement(const std::string &name) override
Definition: RDBMaterialManager.cxx:581
DecodeVersionKey.h
RDBMaterialManager::m_indetmaterials
IRDBRecordset_ptr m_indetmaterials
Definition: RDBMaterialManager.h:85
NameEquals
Definition: RDBMaterialManager.cxx:31
RDBMaterialManager::~RDBMaterialManager
virtual ~RDBMaterialManager()
RDBMaterialManager::RDBMaterialManager
RDBMaterialManager(ISvcLocator *pSvcLocator)
Definition: RDBMaterialManager.cxx:134
StoredMaterialManager::MaterialMapIterator
MaterialMap::const_iterator MaterialMapIterator
Definition: StoredMaterialManager.h:31
a
TList * a
Definition: liststreamerinfos.cxx:10
IRDBRecord.h
Definition of the abstract IRDBRecord interface.
RDBMaterialManager::buildSpecialMaterials
void buildSpecialMaterials()
Definition: RDBMaterialManager.cxx:719
IRDBRecord
IRDBRecord is one record in the IRDBRecordset object.
Definition: IRDBRecord.h:27
DEBUG
#define DEBUG
Definition: page_access.h:11
RDBMaterialManager::searchMaterialMap
GeoMaterial * searchMaterialMap(const std::string &name) const
Definition: RDBMaterialManager.cxx:317
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
mole
#define mole
IRDBRecord::getDouble
virtual double getDouble(const std::string &fieldName) const =0
Get double field value.
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
RDBMaterialManager::begin
virtual StoredMaterialManager::MaterialMapIterator begin() const override
Definition: RDBMaterialManager.cxx:687
IRDBRecordset.h
Definition of the abstract IRDBRecordset interface.
IGeoModelSvc.h
RDBMaterialManager::m_pixtbmaterials
IRDBRecordset_ptr m_pixtbmaterials
Definition: RDBMaterialManager.h:81
RDBMaterialManager::m_shieldmaterials
IRDBRecordset_ptr m_shieldmaterials
Definition: RDBMaterialManager.h:87
printElement
int printElement(GeoElement *&p_element)
Definition: RDBMaterialManager.cxx:60
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
RDBMaterialManager::end
virtual StoredMaterialManager::MaterialMapIterator end() const override
Definition: RDBMaterialManager.cxx:692
RDBMaterialManager::m_pixtbmatcomponents
IRDBRecordset_ptr m_pixtbmatcomponents
Definition: RDBMaterialManager.h:82
checkFileSG.ind
list ind
Definition: checkFileSG.py:118
RDBMaterialManager::m_elements
IRDBRecordset_ptr m_elements
Definition: RDBMaterialManager.h:69
RDBMaterialManager::searchElementVector
GeoElement * searchElementVector(const std::string &name) const
Definition: RDBMaterialManager.cxx:337
RDBMaterialManager::m_larmaterials
IRDBRecordset_ptr m_larmaterials
Definition: RDBMaterialManager.h:75
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37