ATLAS Offline Software
TRRegionXMLHandler.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // class header
6 #include "TRRegionXMLHandler.h"
7 
8 // package includes
10 #include "TRTTransitionRadiation.h"
11 
12 // Athena includes
14 #include "IdDict/IdDictMgr.h"
15 
16 // Gaudi includes
17 #include "GaudiKernel/ISvcLocator.h"
18 #include "GaudiKernel/Bootstrap.h"
19 
20 // Geant4 includes
21 #include "G4LogicalVolumeStore.hh" // For logical volume setup
22 
23 // For XML parsigin
24 #include "boost/property_tree/xml_parser.hpp"
25 #include "boost/property_tree/ptree.hpp"
26 
27 // STL includes
28 #include <iostream>
29 #include <fstream>
30 #include <string>
31 #include <stdexcept>
32 
34  AthMessaging("TRRegionXMLHandler"),
35  m_theProcess(tr)
36 {}
37 
38 void TRRegionXMLHandler::Process(const std::string& name)
39 {
40  ISvcLocator * svcLocator = Gaudi::svcLocator(); // from Bootstrap
41 
42  ATH_MSG_DEBUG("This is TRRegionXMLHandler. Handler called");
43 
44  SmartIF<StoreGateSvc> smartSG{svcLocator->service("StoreGateSvc")};
45  if (smartSG) { m_storeGate = smartSG.get(); }
46  if( !m_storeGate ) {
47  ATH_MSG_ERROR("Unable to locate StoreGate! Stopping!");
48  throw std::runtime_error("Unable to locate StoreGate!");
49  }
50  SmartIF<StoreGateSvc> detStore{svcLocator->service( "DetectorStore")};
51  if( !detStore ) {
52  ATH_MSG_ERROR("Unable to locate DetectorStore! Leaving!");
53  throw std::runtime_error("Unable to locate DetectorStore!");
54  }
55 
56  const IdDictManager * idDictMgr{};
57  if (StatusCode::SUCCESS == detStore->retrieve(idDictMgr, "IdDict")) {
58  if (idDictMgr) {
59  std::string tag = idDictMgr->manager()->tag();
61  (tag == "initial_layout" || tag == "destaged_layout");
62  }
63  } else {
64  ATH_MSG_FATAL("Could not retrieve geometry layout. TR process is not to be trusted in the following");
65  throw std::runtime_error("Could not retrieve geometry layout!");
66  }
67 
68  // Crack open the XML file
69  std::filebuf fb;
70  if (!fb.open(name,std::ios::in)){
71  ATH_MSG_FATAL("Could not open file " << name << " bombing out");
72  throw std::runtime_error("Could not open file!");
73  }
74  std::istream is(&fb);
76  read_xml(is, pt);
77 
78  for( boost::property_tree::ptree::value_type const& v : pt.get_child("FADS") ) {
79  if( v.first == "TRRegionParameters" ) {
80 
81  std::string volName=v.second.get<std::string>("<xmlattr>.RadiatorName");
82  double foilThickness=v.second.get<double>("<xmlattr>.RadiatorFoilThickness");
83  double gasThickness=v.second.get<double>("<xmlattr>.RadiatorGasThickness");
84  int regionFlag=v.second.get<int>("<xmlattr>.RadiatorBARRELorENDCAP");
85  std::string detectorPart=v.second.get<std::string>("<xmlattr>.DetectorPart");
86 
87  G4LogicalVolumeStore *g4lvs = G4LogicalVolumeStore::GetInstance();
88  unsigned int numberOfVolumes = 0;
89  for (const auto log_vol : *g4lvs){
90  if (volName == static_cast<const std::string&>(log_vol->GetName())) {
91  TRTRadiatorParameters rad( log_vol,
92  foilThickness,gasThickness,
93  (BEflag)regionFlag );
95  ++numberOfVolumes;
96  }
97  }
98 
99  if( numberOfVolumes == 0 ) {
100  // In case of destaged geometry (no C wheels) any missing volume
101  // except the radiators corresponding to the C wheels will cause
102  // the code to abort
103  if ( m_initialLayoutIdDict != 0 ) {
104  if ( ( volName!="TRT::MainRadiatorC" ) &&
105  ( volName!="TRT::ThinRadiatorC" ) ) {
106  ATH_MSG_FATAL(" Volume-name " << volName
107  <<" not found! Geometry layout "
109  std::abort();
110  }
111  }
112  } // Didn't get any volumes
113  } // Loop over region parameters objects
114  } // Loop over FADS things in the XML file
115 
116 }
IdDictMgr.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
TRTTransitionRadiation::AddRadiatorParameters
void AddRadiatorParameters(const TRTRadiatorParameters &p)
Definition: TRTTransitionRadiation.cxx:81
TRTTransitionRadiation
Definition: TRTTransitionRadiation.h:20
TRRegionXMLHandler::m_theProcess
TRTTransitionRadiation * m_theProcess
Definition: TRRegionXMLHandler.h:20
test_pyathena.pt
pt
Definition: test_pyathena.py:11
IdDictManager.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TRRegionXMLHandler::m_initialLayoutIdDict
bool m_initialLayoutIdDict
Definition: TRRegionXMLHandler.h:22
TRRegionXMLHandler.h
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
python.SystemOfUnits.rad
float rad
Definition: SystemOfUnits.py:126
BEflag
BEflag
Definition: TRTRadiatorParameters.h:10
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
ptree
boost::property_tree::ptree ptree
Definition: JsonFileLoader.cxx:16
TRTRadiatorParameters.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
IdDictManager
IdDictManager is the interface to identifier dictionaries.
Definition: IdDictManager.h:26
TRTTransitionRadiation.h
TRRegionXMLHandler::Process
void Process(const std::string &name)
Definition: TRRegionXMLHandler.cxx:38
TRTRadiatorParameters
Definition: TRTRadiatorParameters.h:12
python.PyAthena.v
v
Definition: PyAthena.py:154
TRRegionXMLHandler::m_storeGate
StoreGateSvc * m_storeGate
Definition: TRRegionXMLHandler.h:21
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:23
TRRegionXMLHandler::TRRegionXMLHandler
TRRegionXMLHandler(TRTTransitionRadiation *)
Definition: TRRegionXMLHandler.cxx:33