ATLAS Offline Software
SCT_DetectorTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
12 
15 
18 #include "StoreGate/DataHandle.h"
21 
23 #include "SGTools/DataProxy.h"
24 
27 
28 //
29 // Constructor
30 //
32  const std::string& name,
33  const IInterface* parent)
35  m_cosmic{false},
36  m_manager{nullptr},
37  m_geoDbTagSvc{"GeoDbTagSvc", name},
38  m_geometryDBSvc{"InDetGeometryDBSvc", name}
39 {
40  // Get parameter values from jobOptions file
41  declareProperty("GeoDbTagSvc", m_geoDbTagSvc);
42  declareProperty("GeometryDBSvc", m_geometryDBSvc);
43 }
44 
45 //
46 // Create the Geometry via the factory corresponding to this tool
47 //
48 
51 {
52 
53  // Get the detector configuration.
54  ATH_CHECK(m_geoDbTagSvc.retrieve());
55 
56  ServiceHandle<IRDBAccessSvc> accessSvc(m_geoDbTagSvc->getParamSvcName(),name());
57  ATH_CHECK(accessSvc.retrieve());
58 
59  // Print the SCT version tag:
60  std::string detectorTag{""};
61  std::string detectorNode{""};
62  GeoModelIO::ReadGeoModel* sqliteReader = m_geoDbTagSvc->getSqliteReader();
63 
64  if(!sqliteReader) {
65 
66  DecodeVersionKey versionKey{&*m_geoDbTagSvc, "SCT"};
67  // Issue error if AUTO.
68  if (versionKey.tag() == "AUTO") {
69  ATH_MSG_ERROR("AUTO Atlas version. Please select a version.");
70  }
71  ATH_MSG_INFO("Building SCT with Version Tag: " << versionKey.tag() << " at Node: " << versionKey.node());
72 
73  detectorTag = versionKey.tag();
74  detectorNode = versionKey.node();
75 
76  std::string sctVersionTag{accessSvc->getChildTag("SCT", detectorTag, detectorNode)};
77 
78  ATH_MSG_INFO("SCT Version: " << sctVersionTag);
79  // Check if version is empty. If so, then the SCT cannot be built. This may or may not be intentional. We
80  // just issue an INFO message.
81 
82  if (sctVersionTag.empty()) {
83  ATH_MSG_INFO("No SCT Version. SCT will not be built.");
84  } else {
85 
86  if (versionKey.custom()) {
87  ATH_MSG_WARNING("SCT_DetectorTool: Detector Information coming from a custom configuration!!");
88  } else {
89  ATH_MSG_DEBUG("SCT_DetectorTool: Detector Information coming from the database and job options IGNORED.");
90  ATH_MSG_DEBUG("Keys for SCT Switches are " << detectorTag << " " << detectorNode);
91  }
92 
93  }
94  }
95  std::string versionName;
96  IRDBRecordset_ptr switchSet{accessSvc->getRecordsetPtr("SctSwitches", detectorTag, detectorNode)};
97  const IRDBRecord* switches{(*switchSet)[0]};
98  m_detectorName.setValue(switches->getString("DETECTORNAME"));
99  m_cosmic = false;
100  if (not switches->isFieldNull("COSMICLAYOUT")) {
101  m_cosmic = switches->getInt("COSMICLAYOUT");
102  }
103  if (not switches->isFieldNull("VERSIONNAME")) {
104  versionName = switches->getString("VERSIONNAME");
105  }
106 
107  if (versionName.empty()) {
108  if (m_cosmic) {
109  versionName = "SR1";
110  }
111  }
112 
113  ATH_MSG_DEBUG("Creating the SCT");
114  ATH_MSG_DEBUG("SCT Geometry Options: ");
115  ATH_MSG_DEBUG(" Alignable: " << (m_alignable.value() ? "true" : "false"));
116  ATH_MSG_DEBUG(" CosmicLayout: " << (m_cosmic ? "true" : "false"));
117  ATH_MSG_DEBUG(" VersionName: " << versionName);
118 
119 
121  options.setAlignable(m_alignable.value());
122  options.setDynamicAlignFolders(m_useDynamicAlignFolders.value());
123  m_manager = nullptr;
124 
125  //
126  // Locate the top level experiment node
127  //
128  GeoModelExperiment* theExpt{nullptr};
129  ATH_CHECK(detStore()->retrieve(theExpt, "ATLAS"));
130 
131  // Retrieve the Geometry DB Interface
132  ATH_CHECK(m_geometryDBSvc.retrieve());
133 
134  // Pass athena services to factory, etc
135  m_athenaComps.setDetStore(detStore().operator->());
138  m_athenaComps.setRDBAccessSvc(&*accessSvc);
139  const SCT_ID* idHelper{nullptr};
140  ATH_CHECK(detStore()->retrieve(idHelper, "SCT_ID"));
141  m_athenaComps.setIdHelper(idHelper);
142 
143  //
144  // This strange way of casting is to avoid an
145  // utterly brain damaged compiler warning.
146  //
147  GeoPhysVol* world{&*theExpt->getPhysVol()};
148 
149  // If we are using the SQLite reader, then we are not building the raw geometry but
150  // just locating it and attaching to readout geometry and various other actions
151  // taken in this factory.
152  if (sqliteReader){
153 
154  msg(MSG::INFO)<<"Building the geometry from the SQLite file"<<endmsg;
155  //Build the raw geometry from the SQLite file
156  SCT_DetectorFactoryLite theSCT{sqliteReader, &m_athenaComps, options};
157 
158  theSCT.create(world);
159  m_manager = theSCT.getDetectorManager();
160  }
161  else
162  {
164  theSCT.create(world);
165  m_manager = theSCT.getDetectorManager();
166  }
167 
168 
169  if (m_manager==nullptr) {
170  ATH_MSG_FATAL("SCT_DetectorManager not created");
171  return StatusCode::FAILURE;
172  }
173 
174  // Get the manager from the factory and store it in the detector store.
175  // m_detector is non constant so I can not set it to a const pointer.
176  // m_detector = theSCT.getDetectorManager();
177 
178  ATH_MSG_DEBUG("Registering SCT_DetectorManager. ");
179  ATH_CHECK(detStore()->record(m_manager, m_manager->getName()));
180  theExpt->addManager(m_manager);
181 
182  // Create a symLink to the SiDetectorManager base class
183  const SiDetectorManager* siDetManager{m_manager};
184  ATH_CHECK(detStore()->symLink(m_manager, siDetManager));
185 
186  return StatusCode::SUCCESS;
187 }
188 
189 StatusCode
191 {
193  if (proxy) {
194  proxy->reset();
195  m_manager = nullptr;
196  }
197  return StatusCode::SUCCESS;
198 }
199 
200 StatusCode
201 SCT_DetectorTool::registerCallback ATLAS_NOT_THREAD_SAFE () // Thread unsafe detStore()->regFcn (callback) is used.
202 {
203  StatusCode sc{StatusCode::FAILURE};
204  if (m_alignable.value()) {
205  if (m_useDynamicAlignFolders.value()) {
206 
207  if (detStore()->contains<CondAttrListCollection>(m_run2L1Folder.value())) {
208  ATH_MSG_DEBUG("Registering callback on global Container with folder " << m_run2L1Folder.value());
210  ATH_CHECK(detStore()->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool*>(this), calc, m_run2L1Folder.value()));
211  sc = StatusCode::SUCCESS;
212  } else {
213  ATH_MSG_WARNING("Unable to register callback on global Container with folder " << m_run2L1Folder.value());
214  return StatusCode::FAILURE;
215  }
216 
217  if (detStore()->contains<CondAttrListCollection>(m_run2L2Folder.value())) {
218  ATH_MSG_DEBUG("Registering callback on global Container with folder " << m_run2L2Folder.value());
220  ATH_CHECK(detStore()->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool*>(this), calc, m_run2L2Folder.value()));
221  sc = StatusCode::SUCCESS;
222  } else {
223  ATH_MSG_WARNING("Unable to register callback on global Container with folder " << m_run2L2Folder.value());
224  return StatusCode::FAILURE;
225  }
226 
227  if (detStore()->contains<AlignableTransformContainer>(m_run2L3Folder.value())) {
228  ATH_MSG_DEBUG("Registering callback on AlignableTransformContainer with folder " << m_run2L3Folder.value());
230  ATH_CHECK(detStore()->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool*>(this), atc, m_run2L3Folder.value()));
231  sc = StatusCode::SUCCESS;
232  } else {
233  ATH_MSG_WARNING("Unable to register callback on AlignableTransformContainer with folder " << m_run2L3Folder.value());
234  return StatusCode::FAILURE;
235  }
236 
237  } else {
238 
239  if (detStore()->contains<AlignableTransformContainer>(m_run1Folder.value())) {
240  ATH_MSG_DEBUG("Registering callback on AlignableTransformContainer with folder " << m_run1Folder.value());
242  ATH_CHECK(detStore()->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool*>(this), atc, m_run1Folder.value()));
243  sc = StatusCode::SUCCESS;
244  } else {
245  ATH_MSG_WARNING("Unable to register callback on AlignableTransformContainer with folder "
246  << m_run1Folder.value() << ", Alignment disabled (only if no Run2 scheme is loaded)!");
247  return StatusCode::FAILURE;
248  }
249  }
250 
251  } else {
252  ATH_MSG_INFO("Alignment disabled. No callback registered");
253  // We return failure otherwise it will try and register
254  // a GeoModelSvc callback associated with this callback.
255  return StatusCode::FAILURE;
256  }
257  return sc;
258 }
259 
260 StatusCode
262 {
263  if (m_manager==nullptr) {
264  ATH_MSG_FATAL("Manager does not exist");
265  return StatusCode::FAILURE;
266  }
267  if (m_alignable.value()) {
268  return m_manager->align(I, keys);
269  } else {
270  ATH_MSG_DEBUG("Alignment disabled. No alignments applied");
271  return StatusCode::SUCCESS;
272  }
273 }
SCT_DetectorFactory
Definition: SCT_DetectorFactory.h:23
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
SCT_DetectorTool::m_useDynamicAlignFolders
BooleanProperty m_useDynamicAlignFolders
Definition: SCT_DetectorTool.h:42
SCT_DetectorTool::m_athenaComps
SCT_GeoModelAthenaComps m_athenaComps
Definition: SCT_DetectorTool.h:47
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SCT_DetectorTool::create
virtual StatusCode create() override final
Definition: SCT_DetectorTool.cxx:50
InDetDD::SCT_DetectorManager
Definition: SCT_DetectorManager.h:49
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
SCT_DetectorTool.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SCT_DetectorFactoryLite
Definition: SCT_DetectorFactoryLite.h:33
SCT_MaterialManager.h
SCT_DataBase.h
SCT_DetectorTool::m_detectorName
StringProperty m_detectorName
Definition: SCT_DetectorTool.h:40
SCT_DetectorTool::m_cosmic
bool m_cosmic
Definition: SCT_DetectorTool.h:43
SCT_Options.h
GeoModelExperiment
Definition: GeoModelExperiment.h:32
SCT_GeoModelAthenaComps::setIdHelper
void setIdHelper(const SCT_ID *idHelper)
Definition: SCT_GeoModelAthenaComps.cxx:13
IOVSVC_CALLBACK_ARGS_P
#define IOVSVC_CALLBACK_ARGS_P(I, K)
short hand for IOVSvc call back argument list, to be used when access to formal arguments is needed,...
Definition: IOVSvcDefs.h:42
SCT_DetectorTool::SCT_DetectorTool
SCT_DetectorTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: SCT_DetectorTool.cxx:31
IGeoModelTool::align
virtual StatusCode align(IOVSVC_CALLBACK_ARGS)=0
DataHandle.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
SCT_Options
Definition: SCT_Options.h:12
GeoModelExperiment.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SCT_DetectorFactory.h
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AlignableTransformContainer.h
DecodeVersionKey
This is a helper class to query the version tags from GeoModelSvc and determine the appropriate tag a...
Definition: DecodeVersionKey.h:18
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
SCT_DetectorFactoryLite.h
SCT_DetectorTool::clear
virtual StatusCode clear() override final
Definition: SCT_DetectorTool.cxx:190
test_pyathena.parent
parent
Definition: test_pyathena.py:15
GeoModelTool
Definition: GeoModelTool.h:17
InDetDD::AthenaComps::setRDBAccessSvc
void setRDBAccessSvc(IRDBAccessSvc *)
Definition: InDetDDAthenaComps.cxx:27
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
python.AtlRunQueryLib.options
options
Definition: AtlRunQueryLib.py:379
IRDBRecordset_ptr
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition: IRDBAccessSvc.h:25
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
InDetDD::InDetDetectorManager::align
StatusCode align(IOVSVC_CALLBACK_ARGS) const
DataHandle< CondAttrListCollection >
DecodeVersionKey.h
SCT_DetectorTool::m_geometryDBSvc
ServiceHandle< IGeometryDBSvc > m_geometryDBSvc
Definition: SCT_DetectorTool.h:50
IRDBRecord.h
Definition of the abstract IRDBRecord interface.
IGeoModelTool
Definition: IGeoModelTool.h:12
SCT_ID
Definition: SCT_ID.h:68
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
IRDBRecord
IRDBRecord is one record in the IRDBRecordset object.
Definition: IRDBRecord.h:27
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
InDetDD::AthenaComps::setGeometryDBSvc
void setGeometryDBSvc(IGeometryDBSvc *)
Definition: InDetDDAthenaComps.cxx:32
InDetDD::SiDetectorManager
Definition: SiDetectorManager.h:60
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
I
#define I(x, y, z)
Definition: MD5.cxx:116
IRDBRecordset.h
Definition of the abstract IRDBRecordset interface.
SCT_DetectorManager.h
SCT_DetectorTool::align
virtual StatusCode align(IOVSVC_CALLBACK_ARGS) override
Definition: SCT_DetectorTool.cxx:261
SG::DataProxy
Definition: DataProxy.h:44
beamspotnt.calc
calc
Definition: bin/beamspotnt.py:1252
SCT_DetectorTool::m_manager
const InDetDD::SCT_DetectorManager * m_manager
Definition: SCT_DetectorTool.h:45
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
ATLAS_NOT_THREAD_SAFE
StatusCode SCT_DetectorTool::registerCallback ATLAS_NOT_THREAD_SAFE()
Install fatal handler with default options.
Definition: SCT_DetectorTool.cxx:201
SCT_DetectorTool::m_geoDbTagSvc
ServiceHandle< IGeoDbTagSvc > m_geoDbTagSvc
Definition: SCT_DetectorTool.h:49
SCT_DetectorTool::m_alignable
BooleanProperty m_alignable
Definition: SCT_DetectorTool.h:41
ServiceHandle< IRDBAccessSvc >
DataProxy.h