ATLAS Offline Software
InDetServMatTool.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 "InDetServMatTool.h"
7 #include "InDetServMatFactory.h"
10 
15 #include "StoreGate/StoreGateSvc.h"
20 #include "GaudiKernel/ServiceHandle.h"
21 #include "GaudiKernel/ToolHandle.h"
22 
24 #include "SGTools/DataProxy.h"
25 
29 InDetServMatTool::InDetServMatTool( const std::string& type, const std::string& name, const IInterface* parent )
31  m_geoDbTagSvc("GeoDbTagSvc",name),
32  m_geometryDBSvc("InDetGeometryDBSvc",name),
33  m_builderTool("")
34 {
35  declareProperty("DevVersion",m_devVersion);
36  declareProperty("OverrideVersionName", m_overrideVersionName);
37  declareProperty("GeometryDBSvc", m_geometryDBSvc);
38  declareProperty("ServiceBuilderTool", m_builderTool);
39  declareProperty("GeoDbTagSvc", m_geoDbTagSvc);
40  // add here the properties
41 }
46 {
47  delete m_athenaComps;
48 }
49 
54 {
55 
56 
57  if (m_devVersion) {
58  msg(MSG::WARNING) << "You are using a development version. There are no guarantees of stability"
59  << endmsg;
60  }
61 
62  //
63  // Locate the top level experiment node
64  //
65  GeoModelExperiment * theExpt;
66  if (StatusCode::SUCCESS != detStore()->retrieve( theExpt, "ATLAS" )) {
67  msg(MSG::ERROR)
68  << "Could not find GeoModelExperiment ATLAS"
69  << endmsg;
70  return (StatusCode::FAILURE);
71  }
72 
73  StatusCode result = StatusCode::SUCCESS;
74 
75 
76  // Get the detector configuration.
77  StatusCode sc = m_geoDbTagSvc.retrieve();
78  if (sc.isFailure()) {
79  msg(MSG::FATAL) << "Could not locate GeoDbTagSvc" << endmsg;
80  return (StatusCode::FAILURE);
81  }
82 
83  ServiceHandle<IRDBAccessSvc> accessSvc(m_geoDbTagSvc->getParamSvcName(),name());
84  ATH_CHECK( accessSvc.retrieve());
85 
86  GeoPhysVol *world=&*theExpt->getPhysVol();
87 
88  GeoModelIO::ReadGeoModel* sqliteReader = m_geoDbTagSvc->getSqliteReader();
89 
90  if (sqliteReader) {
91  InDetServMatFactory_Lite factoryLite;;
92  factoryLite.create(world);
93  m_manager = factoryLite.getDetectorManager();
94  }
95  else {
96  DecodeVersionKey versionKey(&*m_geoDbTagSvc, "InnerDetector");
97 
98  std::string versionTag = accessSvc->getChildTag("InDetServices", versionKey.tag(), versionKey.node());
99  if(msgLvl(MSG::DEBUG)) msg() << "versionTag=" << versionTag <<" %%%"<< endmsg;
100 
101  // If versionTag is NULL then don't build.
102  if (versionTag.empty()) {
103  msg(MSG::INFO) << "No InDetService Version. InDetService will not be built." << endmsg;
104  if(msgLvl(MSG::DEBUG)) msg() << "InnerDetector Version Tag: " << versionKey.tag() << " at Node: "
105  << versionKey.node() << endmsg;
106  return StatusCode::SUCCESS;
107  }
108 
109  if(msgLvl(MSG::DEBUG)) msg() << "Keys for InDetServMat Switches are " << versionKey.tag() << " " << versionKey.node() << endmsg;
110 
111  std::string versionName;
112  std::string descrName="noDescr";
113  if (!accessSvc->getChildTag("InDetServSwitches", versionKey.tag(), versionKey.node()).empty()) {
114  IRDBRecordset_ptr switchSet = accessSvc->getRecordsetPtr("InDetServSwitches", versionKey.tag(), versionKey.node());
115  const IRDBRecord *switchTable = (*switchSet)[0];
116  versionName = switchTable->getString("VERSIONNAME");
117  if (!switchTable->isFieldNull("DESCRIPTION")) descrName = switchTable->getString("DESCRIPTION");
118  }
119 
120  if (!m_overrideVersionName.empty()) {
121  versionName = m_overrideVersionName;
122  msg(MSG::INFO) << "Overriding version name: " << versionName << endmsg;
123  }
124 
125  msg(MSG::INFO) << "Building Inner Detector Service Material. Version: " << versionName << endmsg;
126 
127  // Retrieve the Geometry DB Interface
128  sc = m_geometryDBSvc.retrieve();
129  if (sc.isFailure()) {
130  msg(MSG::FATAL) << "Could not locate Geometry DB Interface: " << m_geometryDBSvc.name() << endmsg;
131  return (StatusCode::FAILURE);
132  }
133 
134  // Pass athena services to factory, etc
136  m_athenaComps->setDetStore(detStore().operator->());
138  m_athenaComps->setRDBAccessSvc(&*accessSvc);
140 
141  // Retrieve builder tool (SLHC only)
142  if (versionName == "SLHC") {
143  if (!m_builderTool.empty()) {
144  sc = m_builderTool.retrieve();
145  if (!sc.isFailure()) {
146  msg(MSG::INFO) << "Service builder tool retrieved: " << m_builderTool << endmsg;
148  } else {
149  msg(MSG::ERROR) << "Could not retrieve " << m_builderTool << ", some services will not be built." << endmsg;
150  }
151  } else {
152  // This will become an error once the tool is ready.
153  //msg(MSG::ERROR) << "Service builder tool not specified. Some services will not be built" << endmsg;
154  msg(MSG::INFO) << "Service builder tool not specified." << endmsg;
155  }
156  }
157 
158  if(!m_detector) {
159  try {
160  if(!m_devVersion) {
161  if (versionName == "CSC") {
162  if(msgLvl(MSG::DEBUG)) msg() << " InDetServMat Factory CSC " << endmsg;
164  theIDSM.create(world);
165  m_manager=theIDSM.getDetectorManager();
166  } else {
167  // Unrecognized name.
168  msg(MSG::ERROR) << " Unrecognized VersionName: " << versionName << endmsg;
169  return StatusCode::FAILURE;
170  }
171  } else { // Development Versions
172  // CSC
173  if(msgLvl(MSG::DEBUG)) msg() << " InDetServMat Factory Development version " << endmsg;
175  theIDSM.create(world);
176  m_manager=theIDSM.getDetectorManager();
177  }
178  }
179  catch (const std::bad_alloc&) {
180  msg(MSG::FATAL) << "Could not create new InDetServMatNode!" << endmsg;
181  return StatusCode::FAILURE;
182  }
183  }
184  }
185  if (m_manager) {
186  theExpt->addManager(m_manager);
187  CHECK( detStore()->record (m_manager, m_manager->getName()) );
188  } else {
189  msg(MSG::FATAL) << "Could not create InDetServMatManager!" << endmsg;
190  return StatusCode::FAILURE;
191  }
192  return result;
193 }
194 
196 {
198  if(proxy) {
199  proxy->reset();
200  m_manager = nullptr;
201  }
202  return StatusCode::SUCCESS;
203 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
InDetServMatTool::~InDetServMatTool
virtual ~InDetServMatTool() override
Destructor.
Definition: InDetServMatTool.cxx:45
InDetServMatAthenaComps
Class to hold various Athena components.
Definition: InDetServMatAthenaComps.h:13
GeoModelExperiment::getPhysVol
GeoPhysVol * getPhysVol()
Destructor.
Definition: GeoModelExperiment.cxx:21
get_generator_info.result
result
Definition: get_generator_info.py:21
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
InDetServMatTool::InDetServMatTool
InDetServMatTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor(s)
Definition: InDetServMatTool.cxx:29
IGeometryDBSvc.h
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
InDetServMatTool::clear
virtual StatusCode clear() override
Definition: InDetServMatTool.cxx:195
InDetServMatFactory_Lite
Definition: InDetServMatFactory_Lite.h:13
IRDBRecord::getString
virtual const std::string & getString(const std::string &fieldName) const =0
Get string field value.
GeoModelExperiment
Definition: GeoModelExperiment.h:32
InDetServMatTool::create
virtual StatusCode create() override
Create the Detector Node corresponding to this tool.
Definition: InDetServMatTool.cxx:53
DecodeVersionKey::node
const std::string & node() const
Return the version node.
Definition: DecodeVersionKey.cxx:99
InDetServMatAthenaComps.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
InDetDD::AthenaComps::setGeoDbTagSvc
void setGeoDbTagSvc(IGeoDbTagSvc *)
Definition: InDetDDAthenaComps.cxx:22
InDetDD::AthenaComps::setDetStore
void setDetStore(StoreGateSvc *)
Definition: InDetDDAthenaComps.cxx:17
GeoModelExperiment.h
InDetServMatFactory::getDetectorManager
virtual const InDetDD::InDetServMatManager * getDetectorManager() const override
Definition: InDetServMatFactory.cxx:278
InDetServMatTool::m_athenaComps
InDetServMatAthenaComps * m_athenaComps
Definition: InDetServMatTool.h:43
IRDBAccessSvc.h
Definition of the abstract IRDBAccessSvc interface.
IInDetServMatBuilderTool.h
InDetServMatFactory
Definition: InDetServMatFactory.h:15
ClassID_traits.h
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
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
DecodeVersionKey
This is a helper class to query the version tags from GeoModelSvc and determine the appropriate tag a...
Definition: DecodeVersionKey.h:18
InDetServMatAthenaComps::setBuilderTool
void setBuilderTool(IInDetServMatBuilderTool *builderTool)
Definition: InDetServMatAthenaComps.cxx:15
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
test_pyathena.parent
parent
Definition: test_pyathena.py:15
DecodeVersionKey::tag
const std::string & tag() const
Return version tag.
Definition: DecodeVersionKey.cxx:93
GeoModelTool
Definition: GeoModelTool.h:17
InDetServMatTool::m_overrideVersionName
std::string m_overrideVersionName
Definition: InDetServMatTool.h:41
InDetDD::AthenaComps::setRDBAccessSvc
void setRDBAccessSvc(IRDBAccessSvc *)
Definition: InDetDDAthenaComps.cxx:27
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
InDetServMatTool::m_geometryDBSvc
ServiceHandle< IGeometryDBSvc > m_geometryDBSvc
Definition: InDetServMatTool.h:37
InDetServMatTool::m_geoDbTagSvc
ServiceHandle< IGeoDbTagSvc > m_geoDbTagSvc
Definition: InDetServMatTool.h:36
IRDBRecordset_ptr
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition: IRDBAccessSvc.h:25
InDetServMatTool::m_builderTool
ToolHandle< IInDetServMatBuilderTool > m_builderTool
Definition: InDetServMatTool.h:38
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
GeoModelTool::m_detector
GeoVDetectorManager * m_detector
Definition: GeoModelTool.h:36
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
errorcheck.h
Helpers for checking error return status codes and reporting errors.
DecodeVersionKey.h
InDetServMatTool::m_manager
const InDetDD::InDetServMatManager * m_manager
Definition: InDetServMatTool.h:42
GeoModelExperiment::addManager
void addManager(const GeoVDetectorManager *)
Definition: GeoModelExperiment.cxx:40
InDetServMatTool.h
IRDBRecord.h
Definition of the abstract IRDBRecord interface.
IRDBRecord::isFieldNull
virtual bool isFieldNull(const std::string &fieldName) const =0
Check if the field value is NULL.
InDetServMatTool::m_devVersion
bool m_devVersion
Definition: InDetServMatTool.h:40
IRDBRecord
IRDBRecord is one record in the IRDBRecordset object.
Definition: IRDBRecord.h:27
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
InDetDD::AthenaComps::setGeometryDBSvc
void setGeometryDBSvc(IGeometryDBSvc *)
Definition: InDetDDAthenaComps.cxx:32
InDetServMatFactory_Lite::getDetectorManager
virtual const InDetDD::InDetServMatManager * getDetectorManager() const override
Definition: InDetServMatFactory_Lite.cxx:22
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
IRDBRecordset.h
Definition of the abstract IRDBRecordset interface.
SG::DataProxy
Definition: DataProxy.h:44
InDetServMatFactory.h
StoreGateSvc.h
InDetServMatFactory_Lite.h
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
IGeoDbTagSvc.h
InDetServMatFactory::create
virtual void create(GeoPhysVol *world) override
Definition: InDetServMatFactory.cxx:50
InDetServMatFactory_Lite::create
virtual void create(GeoPhysVol *world) override
Definition: InDetServMatFactory_Lite.cxx:11
ServiceHandle< IRDBAccessSvc >
DataProxy.h