ATLAS Offline Software
TRRegionXMLHandler.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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  m_storeGate(nullptr),
36  m_initialLayoutIdDict(false)
37 {}
38 
39 void TRRegionXMLHandler::Process(const std::string& name)
40 {
41  ISvcLocator * svcLocator = Gaudi::svcLocator(); // from Bootstrap
42 
43  ATH_MSG_DEBUG("This is TRRegionXMLHandler. Handler called");
44 
45  StatusCode sc = svcLocator->service("StoreGateSvc", m_storeGate);
46  if( sc.isFailure() ) {
47  ATH_MSG_ERROR("Unable to locate StoreGate! Stopping!");
48  throw std::runtime_error("Unable to locate StoreGate!");
49  }
50  StoreGateSvc* detStore = nullptr;
51  sc = svcLocator->service( "DetectorStore", detStore);
52  if( sc.isFailure() ) {
53  ATH_MSG_ERROR("Unable to locate DetectorStore! Leaving!");
54  throw std::runtime_error("Unable to locate DetectorStore!");
55  }
56 
57  const IdDictManager * idDictMgr = nullptr;
58  if (StatusCode::SUCCESS == detStore->retrieve(idDictMgr, "IdDict")) {
59  if (idDictMgr) {
60  std::string tag = idDictMgr->manager()->tag();
62  (tag == "initial_layout" || tag == "destaged_layout");
63  }
64  } else {
65  ATH_MSG_FATAL("Could not retrieve geometry layout. TR process is not to be trusted in the following");
66  throw std::runtime_error("Could not retrieve geometry layout!");
67  }
68 
69  // Crack open the XML file
70  std::filebuf fb;
71  if (!fb.open(name,std::ios::in)){
72  ATH_MSG_FATAL("Could not open file " << name << " bombing out");
73  throw std::runtime_error("Could not open file!");
74  }
75  std::istream is(&fb);
77  read_xml(is, pt);
78 
79  for( boost::property_tree::ptree::value_type const& v : pt.get_child("FADS") ) {
80  if( v.first == "TRRegionParameters" ) {
81 
82  std::string volName=v.second.get<std::string>("<xmlattr>.RadiatorName");
83  double foilThickness=v.second.get<double>("<xmlattr>.RadiatorFoilThickness");
84  double gasThickness=v.second.get<double>("<xmlattr>.RadiatorGasThickness");
85  int regionFlag=v.second.get<int>("<xmlattr>.RadiatorBARRELorENDCAP");
86  std::string detectorPart=v.second.get<std::string>("<xmlattr>.DetectorPart");
87 
88  G4LogicalVolumeStore *g4lvs = G4LogicalVolumeStore::GetInstance();
89  unsigned int numberOfVolumes = 0;
90  for (const auto log_vol : *g4lvs){
91  if (volName == static_cast<const std::string&>(log_vol->GetName())) {
92  TRTRadiatorParameters rad( log_vol,
93  foilThickness,gasThickness,
94  (BEflag)regionFlag );
96  ++numberOfVolumes;
97  }
98  }
99 
100  if( numberOfVolumes == 0 ) {
101  // In case of destaged geometry (no C wheels) any missing volume
102  // except the radiators corresponding to the C wheels will cause
103  // the code to abort
104  if ( m_initialLayoutIdDict != 0 ) {
105  if ( ( volName!="TRT::MainRadiatorC" ) &&
106  ( volName!="TRT::ThinRadiatorC" ) ) {
107  ATH_MSG_FATAL(" Volume-name " << volName
108  <<" not found! Geometry layout "
110  std::abort();
111  }
112  }
113  } // Didn't get any volumes
114  } // Loop over region parameters objects
115  } // Loop over FADS things in the XML file
116 
117 }
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
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
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TRTTransitionRadiation::AddRadiatorParameters
void AddRadiatorParameters(TRTRadiatorParameters p)
Definition: TRTTransitionRadiation.cxx:81
TRRegionXMLHandler::m_initialLayoutIdDict
bool m_initialLayoutIdDict
Definition: TRRegionXMLHandler.h:22
TRRegionXMLHandler.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
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:195
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:39
TRTRadiatorParameters
Definition: TRTRadiatorParameters.h:12
python.PyAthena.v
v
Definition: PyAthena.py:157
IdDictManager::manager
const IdDictMgr * manager(void) const
Definition: IdDictManager.cxx:37
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
IdDictMgr::tag
const std::string & tag() const
Version tag.
Definition: IdDictMgr.cxx:92
python.SystemOfUnits.rad
int rad
Definition: SystemOfUnits.py:111