ATLAS Offline Software
Loading...
Searching...
No Matches
MuonDetectorCondAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
15#include "GeoModelKernel/GeoVolumeCursor.h"
16#include "GeoModelKernel/GeoPhysVol.h"
18#include <fstream>
19
20MuonDetectorCondAlg::MuonDetectorCondAlg(const std::string &name, ISvcLocator *pSvcLocator) :
21 AthCondAlgorithm(name, pSvcLocator) {}
22
24 ATH_MSG_DEBUG("Initializing ...");
25 // Read Handles
26 ATH_CHECK(m_iGeoModelTool.retrieve());
27
36 ATH_CHECK(m_idHelperSvc.retrieve());
38 ATH_MSG_INFO("Initialize successful -- "<<m_applyALines<<", "<<m_applyBLines<<","
41 return StatusCode::SUCCESS;
42}
43
44StatusCode MuonDetectorCondAlg::execute(const EventContext& ctx) const {
45 ATH_MSG_DEBUG("execute " << name());
46
47 // =======================
48 // Conditions handle
49 // =======================
51 if (writeHandle.isValid()) {
52 ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
53 << ". In theory this should not be called, but may happen"
54 << " if multiple concurrent events are being processed out of order.");
55 return StatusCode::SUCCESS;
56 }
58
59 GeoModelExperiment *theExpt = nullptr;
60 ATH_CHECK(detStore()->retrieve(theExpt, "ATLAS"));
63 PVConstLink ATLASWorld = theExpt->getPhysVol();
64 GeoIntrusivePtr<GeoPhysVol> world{make_intrusive<GeoPhysVol>(ATLASWorld->getLogVol())};
65
66
67 MuonGM::MuonDetectorManager *mgr{nullptr};
68 ATH_CHECK (m_iGeoModelTool->createFactory(mgr, world));
69 std::unique_ptr<MuonGM::MuonDetectorManager> MuonMgrData(mgr);
70
71 // =======================
72 // Add NSW to the MuonDetectorManager by calling BuildReadoutGeometry from MuonAGDDToolHelper
73 // =======================
74
75 if (MuonMgrData->mmIdHelper() && MuonMgrData->stgcIdHelper()) {
76 BuildNSWReadoutGeometry theBuilder{};
77 if(!theBuilder.BuildReadoutGeometry(MuonMgrData.get())){
78 ATH_MSG_FATAL("unable to add NSW ReadoutGeometry in the MuonDetectorManager in conditions store");
79 return StatusCode::FAILURE;
80 }
83 if(!readMmPass.isValid()){
84 ATH_MSG_ERROR("Cannot find conditions data container for MM passivation!");
85 return StatusCode::FAILURE;
86 }
87 writeHandle.addDependency(readMmPass);
88 MuonMgrData->setMMPassivation(readMmPass.cptr());
89 }
90 }
91
92 // =======================
93 // Update CSC Internal Alignment if requested
94 // =======================
95
96 if (!m_readILineKey.empty()) {
98 if (!readILinesHandle.isValid()){
99 ATH_MSG_FATAL("Failed to retrieve the CSC I-line container "<<readILinesHandle.fullKey());
100 return StatusCode::FAILURE;
101 }
102 writeHandle.addDependency(readILinesHandle);
103 ATH_CHECK(MuonMgrData->updateCSCInternalAlignmentMap(**readILinesHandle));
104 }
105
106 // =======================
107 // Update MdtAsBuiltMapContainer if requested BEFORE updating ALINES and BLINES
108 // =======================
109 if (!m_readMdtAsBuiltKey.empty()) {
111 if (!readMdtAsBuiltHandle.isValid()) {
112 ATH_MSG_FATAL("Failed to load Mdt as-built container "<<m_readMdtAsBuiltKey.fullKey());
113 return StatusCode::FAILURE;
114 }
115 writeHandle.addDependency(readMdtAsBuiltHandle);
116 ATH_CHECK(MuonMgrData->updateMdtAsBuiltParams(**readMdtAsBuiltHandle));
117 }
118
119 // =======================
120 // Set NSW as-built geometry if requested
121 // =======================
122 if (!m_readNswAsBuiltKey.empty()) {
124 if(!readNswAsBuilt.isValid()) {
125 ATH_MSG_ERROR("Cannot find conditions data container for NSW as-built!");
126 return StatusCode::FAILURE;
127 }
128 writeHandle.addDependency(readNswAsBuilt);
129 MuonMgrData->setNswAsBuilt(*readNswAsBuilt);
130 }
131
132 if(!m_readsTGCAsBuiltKey.empty()){
134 if(!readsTGCAsBuilt.isValid()){
135 ATH_MSG_ERROR("Cannot find conditions data container for sTGC as-built");
136 return StatusCode::FAILURE;
137 }
138 writeHandle.addDependency(readsTGCAsBuilt);
139 MuonMgrData->setsTGCAsBuilt(*readsTGCAsBuilt);
140 }
141
142 if(!m_readMmAsBuilt2Key.empty()){
144 if(!readMmAsBuilt2.isValid()){
145 ATH_MSG_ERROR("Cannot find conditions data container for MM as-built 2");
146 return StatusCode::FAILURE;
147 }
148 writeHandle.addDependency(readMmAsBuilt2);
149 MuonMgrData->setMmAsBuilt2(*readMmAsBuilt2);
150 }
151
152
153 // =======================
154 // Update Alignment, ALINES
155 // =======================
156 if (m_applyALines) {
158 if (!readALinesHandle.isValid()) {
159 ATH_MSG_FATAL("Failed to load ALine container "<<m_readALineKey.fullKey());
160 return StatusCode::FAILURE;
161 }
162 writeHandle.addDependency(readALinesHandle);
163 ATH_CHECK(MuonMgrData->updateAlignment(**readALinesHandle));
164 } else ATH_MSG_INFO("Do not apply the A Lines of the alignment");
165
166 // =======================
167 // Update Deformations, BLINES
168 // =======================
169 if (m_applyBLines) {
171 if (!readBLinesHandle.isValid()) {
172 ATH_MSG_FATAL("Failed to load B line container "<<m_readBLineKey.fullKey());
173 return StatusCode::FAILURE;
174 }
175 writeHandle.addDependency(readBLinesHandle);
176 ATH_CHECK (MuonMgrData->updateDeformations(**readBLinesHandle));
177 } else ATH_MSG_INFO("Do not apply the B Lines of the alignment");
178
179 // !!!!!!!! UPDATE ANYTHING ELSE ???????
180 ATH_CHECK(copyInertMaterial(*MuonMgrData));
181 MuonMgrData->addTreeTop(world);
182 /* Short check that the reference count of the new universe is indeed 2 (1 from the experiment & 1 from the world Ptr) */
183 if (world->refCount() != 2) {
184 ATH_MSG_FATAL("The leaking reference counter to the GeoModel world detected "<<world->refCount());
185 return StatusCode::FAILURE;
186 }
187 ATH_CHECK(writeHandle.record(std::move(MuonMgrData)));
188 ATH_MSG_INFO("recorded new " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
189
190 return StatusCode::SUCCESS;
191}
193 const MuonGM::MuonDetectorManager *MuonDetMgrDS{nullptr};
194 ATH_CHECK(detStore()->retrieve(MuonDetMgrDS));
195
196 // In the new geomodel, there is only one GeoModel tree and it is pre-built. In that
197 // case these pointers are the same and one should not copy to self.
198 if (MuonDetMgrDS->getTreeTop(0)==detMgr.getTreeTop(0)) return StatusCode::SUCCESS;
199 // ---------------------------------------------------------------------------------
200
201 PVLink condMgrWorld{detMgr.getTreeTop(0)};
202
203 GeoVolumeCursor detStoreCursor{MuonDetMgrDS->getTreeTop(0)};
204 while (!detStoreCursor.atEnd()) {
205 PVConstLink worldNode(detStoreCursor.getVolume());
206 const Amg::Transform3D transform{detStoreCursor.getTransform()};
207 const GeoLogVol* logVol = worldNode->getLogVol();
208 const std::string_view vname = logVol->getName();
209 detStoreCursor.next();
210 if (vname.find("Station") != std::string::npos) continue;
212 const GeoVPhysVol& pvConstLink = *worldNode;
213 ATH_MSG_DEBUG("Volume in the static world "<<vname<<" "<<typeid(pvConstLink).name()
214 <<"children: "<<worldNode->getNChildNodes()<<" cursor: "<<Amg::toString(transform));
215 condMgrWorld->add(make_intrusive<GeoTransform>(transform));
216 condMgrWorld->add(const_pointer_cast(worldNode));
217 }
218 return StatusCode::SUCCESS;
219}
220
221
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
Hold mappings of ranges to condition objects.
macros to associate a CLID to a type
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
const ServiceHandle< StoreGateSvc > & detStore() const
Base class for conditions algorithms.
static bool BuildReadoutGeometry(MuonGM::MuonDetectorManager *mgr)
GeoPhysVol * getPhysVol()
Destructor.
static EventIDRange infiniteRunLB()
Produces an EventIDRange that is infinite in RunLumi and invalid in Time.
SG::ReadCondHandleKey< ALineContainer > m_readILineKey
Gaudi::Property< bool > m_applyBLines
Apply the chamber deformation model (Mdts + Nsw)
Gaudi::Property< bool > m_applyNswAsBuilt
StatusCode copyInertMaterial(MuonGM::MuonDetectorManager &detMgr) const
SG::ReadCondHandleKey< BLineContainer > m_readBLineKey
virtual StatusCode initialize() override final
SG::ReadCondHandleKey< sTGCAsBuiltData > m_readsTGCAsBuiltKey
ToolHandle< MuonDetectorTool > m_iGeoModelTool
SG::ReadCondHandleKey< NswAsBuiltDbData > m_readNswAsBuiltKey
Gaudi::Property< bool > m_applyALines
Apply translations and rotations to align the Muon stations.
SG::WriteCondHandleKey< MuonGM::MuonDetectorManager > m_writeDetectorManagerKey
SG::ReadCondHandleKey< ALineContainer > m_readALineKey
MuonDetectorCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
SG::ReadCondHandleKey< NswPassivationDbData > m_condMmPassivKey
Gaudi::Property< bool > m_applysTGCAsBuilt
SG::ReadCondHandleKey< MdtAsBuiltContainer > m_readMdtAsBuiltKey
virtual StatusCode execute(const EventContext &ctx) const override final
SG::ReadCondHandleKey< sTGCAsBuiltData > m_readMmAsBuilt2Key
Gaudi::Property< bool > m_applyMdtAsBuilt
Gaudi::Property< bool > m_applyMmPassivation
Gaudi::Property< bool > m_applyMmAsBuilt2
Gaudi::Property< bool > m_applyILines
Apply internal transformations on the CSCs.
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
const DataObjID & fullKey() const
const_pointer_type cptr()
const std::string & key() const
void addDependency(const EventIDRange &range)
const EventIDRange & getRange() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Eigen::Affine3d Transform3D