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