ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_DetectorTool.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#include "TRT_DetectorTool.h"
8
10
15
19#include "SGTools/DataProxy.h"
20
21#include <memory>
22
24//
25TRT_DetectorTool::TRT_DetectorTool( const std::string& type, const std::string& name, const IInterface* parent )
26 : GeoModelTool( type, name, parent )
27{
28}
29
31//
33{
34 // Get the detector configuration.
35 ATH_CHECK( m_geoDbTagSvc.retrieve());
36
37 ServiceHandle<IRDBAccessSvc> accessSvc(m_geoDbTagSvc->getParamSvcName(),name());
38 ATH_CHECK( accessSvc.retrieve());
39
40 // Locate the top level experiment node
41 GeoModelExperiment* theExpt{nullptr};
42 ATH_CHECK(detStore()->retrieve(theExpt,"ATLAS"));
43 GeoPhysVol *world = theExpt->getPhysVol();
44
45 // Retrieve the Geometry DB Interface
46 ATH_CHECK( m_geometryDBSvc.retrieve() );
47
48 // Pass athena services to factory, etc
49 m_athenaComps.setDetStore(detStore().operator->());
50 m_athenaComps.setGeoDbTagSvc(m_geoDbTagSvc.get());
51 m_athenaComps.setRDBAccessSvc(accessSvc.get());
52 m_athenaComps.setGeometryDBSvc(m_geometryDBSvc.get());
53
54 std::unique_ptr<TRTStrawStatusAccessor> strawStatusAccessor;
55 ATH_CHECK(m_sumTool.retrieve(DisableTool{ !m_dumpStrawStatus }));
57 // Read Straw Statuses from the ASCII file
58 strawStatusAccessor = std::make_unique<TRTStrawStatusAccessor>();
59 const std::string strawStatusPath = PathResolverFindCalibFile(m_strawStatusFile);
60 if (strawStatusPath.empty()) {
61 ATH_MSG_ERROR("Failed to resolve path for StrawStatusFile: " << m_strawStatusFile << ", the job will fail now.");
62 return StatusCode::FAILURE;
63 }
64 ATH_MSG_VERBOSE("StrawStatusFile: " << m_strawStatusFile << ", resolved path: " << strawStatusPath);
65 strawStatusAccessor->fill(strawStatusPath);
66 }
67
68 GeoModelIO::ReadGeoModel* sqliteReader = m_geoDbTagSvc->getSqliteReader();
69 //
70 // If we are using the SQLite reader, then we are not building the raw geometry but
71 // just locating it and attaching to readout geometry and various other actions
72 // taken in this factory.
73 //
74 if (sqliteReader) {
75 ATH_MSG_INFO( " Building TRT geometry from GeoModel factory TRTDetectorFactory_Lite" );
76 TRTDetectorFactory_Lite theTRTFactory(sqliteReader,
78 std::move(strawStatusAccessor),
83 );
84
85 theTRTFactory.create(world);
86 m_manager=theTRTFactory.getDetectorManager();
87 }
88 else {
89 DecodeVersionKey versionKey(m_geoDbTagSvc.get(), "TRT");
90
91 ATH_MSG_INFO( "Building TRT with Version Tag: "<< versionKey.tag() << " at Node: " << versionKey.node() );
92
93 // Print the TRT version tag:
94 std::string trtVersionTag = accessSvc->getChildTag("TRT", versionKey.tag(), versionKey.node());
95 ATH_MSG_INFO("TRT Version: " << trtVersionTag );
96
97 // Check if version is empty. If so, then the TRT cannot be built. This may or may not be intentional. We
98 // just issue an INFO message.
99 if (trtVersionTag.empty()) {
100 ATH_MSG_INFO("No TRT Version. TRT will not be built." );
101 return StatusCode::SUCCESS;
102 }
103
104 ATH_MSG_DEBUG( "Keys for TRT Switches are " << versionKey.tag() << " " << versionKey.node() );
105 IRDBRecordset_ptr switchSet = accessSvc->getRecordsetPtr("TRTSwitches", versionKey.tag(), versionKey.node());
106 const IRDBRecord *switches = (*switchSet)[0];
107
108 if (switches->getInt("DC1COMPATIBLE")) {
109 ATH_MSG_ERROR( "DC1COMPATIBLE flag set in database, but DC1 is no longer supported in the code!!");
110 return StatusCode::FAILURE;
111 }
112
113 m_DC2CompatibleBarrelCoordinates = switches->getInt("DC2COMPATIBLE");
114 m_useOldActiveGasMixture = ( switches->getInt("GASVERSION") == 0 );
115 m_initialLayout = switches->getInt("INITIALLAYOUT");
116
117 // Check if the new switches exists:
119 if ( switches->getInt("DOARGONMIXTURE") == 0) { m_doArgonMixture = false; }
120 else if ( switches->getInt("DOARGONMIXTURE") == 1) { m_doArgonMixture = true; }
121
122 if ( switches->getInt("DOKRYPTONMIXTURE") == 0) { m_doKryptonMixture = false; }
123 else if ( switches->getInt("DOKRYPTONMIXTURE") == 1) { m_doKryptonMixture = true; }
124 }
125
126 ATH_MSG_INFO( "Creating the TRT" );
127 ATH_MSG_INFO( "TRT Geometry Options:" << std::boolalpha );
128 ATH_MSG_INFO( " UseOldActiveGasMixture = " << m_useOldActiveGasMixture );
129 ATH_MSG_INFO( " Do Argon = " << m_doArgonMixture );
130 ATH_MSG_INFO( " Do Krypton = " << m_doKryptonMixture );
131 ATH_MSG_INFO( " DC2CompatibleBarrelCoordinates = " << m_DC2CompatibleBarrelCoordinates );
132 ATH_MSG_INFO( " InitialLayout = " << m_initialLayout );
133 ATH_MSG_INFO( " Alignable = " << m_alignable );
134 ATH_MSG_INFO( " VersioName = " << switches->getString("VERSIONNAME") );
135
136 ATH_MSG_INFO( " Building TRT geometry from GeoModel factory TRTDetectorFactory_Full" );
137
139 m_dumpStrawStatus ? m_sumTool.get() : nullptr,
140 std::move(strawStatusAccessor),
147 );
148 theTRTFactory.create(world);
149 m_manager=theTRTFactory.getDetectorManager();
150
151 }
152
153 // Register the TRTDetectorNode instance with the Transient Detector Store
154 if (!m_manager) return StatusCode::FAILURE;
155
156 theExpt->addManager(m_manager);
157 ATH_CHECK(detStore()->record(m_manager,m_manager->getName()));
158 return StatusCode::SUCCESS;
159}
160
161
162
163StatusCode
164TRT_DetectorTool::registerCallback ATLAS_NOT_THREAD_SAFE () // Thread unsafe StoreGateSvc::regFcn method and DataHandle template are used.
165{
166 // This callback is kept because the folder never changes.
167
168 MsgStream log(msgSvc(), name());
169
170 // If we fail to register any callbacks we return FAILURE. This just tells GeoModelSvc that
171 // no callbacks were registered. It will continue normally but without any alignments.
172 StatusCode sc = StatusCode::FAILURE;
173
174 if (m_alignable) {
175
176
177 if (m_useDynamicAlignFolders){ // Regular alignment new schema
178 std::string folderName = "/TRT/AlignL1/TRT";
179 if (detStore()->contains<CondAttrListCollection>(folderName)) {
180 msg(MSG::DEBUG) << "Registering callback on global Container with folder " << folderName << endmsg;
182 StatusCode trttmp = detStore()->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool*>(this), calc, folderName);
183 // We don't expect this to fail as we have already checked that the detstore contains the object.
184 if (trttmp.isFailure()) {
185 msg(MSG::ERROR) << "Problem when register callback on global Container with folder " << folderName <<endmsg;
186 } else {
187 sc = StatusCode::SUCCESS;
188 }
189 } else {
190 msg(MSG::WARNING) << "Unable to register callback on global Container with folder " << folderName <<endmsg;
191 return StatusCode::FAILURE;
192 }
193
194 folderName = "/TRT/AlignL2";
195 if (detStore()->contains<AlignableTransformContainer>(folderName)) {
196 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Registering callback on AlignableTransformContainer with folder " << folderName << endmsg;
198 StatusCode sctmp = detStore()->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool *>(this), atc, folderName);
199 if(sctmp.isFailure()) {
200 msg(MSG::ERROR) << "Problem when register callback on AlignableTransformContainer with folder " << folderName <<endmsg;
201 } else {
202 sc = StatusCode::SUCCESS;
203 }
204 }
205 else {
206 msg(MSG::WARNING) << "Unable to register callback on AlignableTransformContainer with folder "
207 << folderName << endmsg;
208 return StatusCode::FAILURE;
209 }
210 }
211 else { // Regular alignment old schema
212 std::string folderName = "/TRT/Align";
213 if (detStore()->contains<AlignableTransformContainer>(folderName)) {
214 msg(MSG::DEBUG) << "Registering callback on AlignableTransformContainer with folder " << folderName << endmsg;
216 StatusCode sctmp = detStore()->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool *>(this), atc, folderName);
217 // We don't expect this to fail as we have already checked that the detstore contains the object.
218 if (sctmp.isFailure()) {
219 msg(MSG::ERROR) << "Problem when register callback on AlignableTransformContainer with folder " << folderName <<endmsg;
220 } else {
221 sc = StatusCode::SUCCESS;
222 }
223 } else {
224 msg(MSG::WARNING) << "Unable to register callback on AlignableTransformContainer with folder "
225 << folderName << ", Alignments disabled! (Only if no Run2 schema is loaded)" << endmsg;
226 }
227 }
228
229
230 // Fine alignment
231 {
232 std::string folderName = "/TRT/Calib/DX";
233 if (detStore()->contains<TRTCond::StrawDxContainer>(folderName)) {
234 msg(MSG::DEBUG) << "Registering callback on StrawDxContainer with folder " << folderName << endmsg;
236 StatusCode sctmp = detStore()->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool*>(this), sdc, folderName);
237 // We don't expect this to fail as we have already checked that the detstore contains the object.
238 if (sctmp.isFailure()) {
239 msg(MSG::ERROR) << "Problem when register callback on StrawDxContainer with folder " << folderName <<endmsg;
240 } else {
241 sc = StatusCode::SUCCESS;
242 }
243 } else {
244 msg(MSG::DEBUG) << "Unable to register callback on StrawDxContainer with folder " << folderName <<endmsg;
245 }
246 }
247
248 } else {
249 msg(MSG::INFO) << "Alignment disabled. No callback registered" << endmsg;
250 // We return failure otherwise it will try and register
251 // a GeoModelSvc callback associated with this callback.
252 }
253
254 return sc;
255}
256
258{
259 SG::DataProxy* proxy = detStore()->proxy(ClassID_traits<InDetDD::TRT_DetectorManager>::ID(),m_manager->getName());
260 if(proxy) {
261 proxy->reset();
262 m_manager = nullptr;
263 }
264 return StatusCode::SUCCESS;
265}
266
267
268StatusCode
269TRT_DetectorTool::align ATLAS_NOT_THREAD_SAFE (IOVSVC_CALLBACK_ARGS_P(I,keys))
270//The manager align call invalidates all elements
271{
272 MsgStream log(msgSvc(), name());
273 if (!m_manager) {
274 msg(MSG::WARNING) << "Manager does not exist" << endmsg;
275 return StatusCode::FAILURE;
276 }
277 if (m_alignable) {
278 return const_cast<InDetDD::TRT_DetectorManager*>(m_manager)->align(I,keys);
279 } else {
280 msg(MSG::DEBUG) << "Alignment disabled. No alignments applied" << endmsg;
281 return StatusCode::SUCCESS;
282 }
283}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
#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
Definition of the abstract IRDBAccessSvc interface.
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition of the abstract IRDBRecord interface.
Definition of the abstract IRDBRecordset interface.
static Double_t sc
#define I(x, y, z)
Definition MD5.cxx:116
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Class for storing/accessing trt endpoint corrections data.
StatusCode TRT_DetectorTool::registerCallback ATLAS_NOT_THREAD_SAFE()
Install fatal handler with default options.
an iterator over instances of a given type in StoreGateSvc.
Definition DataHandle.h:43
This is a helper class to query the version tags from GeoModelSvc and determine the appropriate tag a...
const std::string & tag() const
Return version tag.
const std::string & node() const
Return the version node.
GeoPhysVol * getPhysVol()
Destructor.
void addManager(const GeoVDetectorManager *)
IRDBRecord is one record in the IRDBRecordset object.
Definition IRDBRecord.h:27
virtual const std::string & getString(const std::string &fieldName) const =0
Get string field value.
virtual int getInt(const std::string &fieldName) const =0
Get int field value.
The Detector Manager for all TRT Detector elements, it acts as the interface to the detector elements...
This class creates the TRT Geometry.
virtual void create(GeoPhysVol *world) override
virtual const InDetDD::TRT_DetectorManager * getDetectorManager() const override
virtual void create(GeoPhysVol *world) override
virtual const InDetDD::TRT_DetectorManager * getDetectorManager() const override
InDetDD::AthenaComps m_athenaComps
Gaudi::Property< bool > m_dumpStrawStatus
virtual StatusCode create() override final
Gaudi::Property< bool > m_useOldActiveGasMixture
Gaudi::Property< bool > m_DC2CompatibleBarrelCoordinates
Gaudi::Property< bool > m_doArgonMixture
Gaudi::Property< bool > m_doKryptonMixture
Gaudi::Property< bool > m_alignable
ServiceHandle< IGeoDbTagSvc > m_geoDbTagSvc
ToolHandle< ITRT_StrawStatusSummaryTool > m_sumTool
const InDetDD::TRT_DetectorManager * m_manager
Gaudi::Property< std::string > m_strawStatusFile
Gaudi::Property< bool > m_useDynamicAlignFolders
virtual StatusCode clear() override final
TRT_DetectorTool(const std::string &type, const std::string &name, const IInterface *parent)
ServiceHandle< IGeometryDBSvc > m_geometryDBSvc
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
MsgStream & msg
Definition testRead.cxx:32