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
35 ATH_CHECK(m_idHelperSvc.retrieve());
37 ATH_MSG_INFO("Initialize successful -- "<<m_applyALines<<", "<<m_applyBLines<<","
40 return StatusCode::SUCCESS;
41}
42
43StatusCode MuonDetectorCondAlg::execute(const EventContext& ctx) const {
44 ATH_MSG_DEBUG("execute " << name());
45
46 // =======================
47 // Conditions handle
48 // =======================
50 if (writeHandle.isValid()) {
51 ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
52 << ". In theory this should not be called, but may happen"
53 << " if multiple concurrent events are being processed out of order.");
54 return StatusCode::SUCCESS;
55 }
57
58 GeoModelExperiment *theExpt = nullptr;
59 ATH_CHECK(detStore()->retrieve(theExpt, "ATLAS"));
62 PVConstLink ATLASWorld = theExpt->getPhysVol();
63 GeoIntrusivePtr<GeoPhysVol> world{make_intrusive<GeoPhysVol>(ATLASWorld->getLogVol())};
64
65
66 MuonGM::MuonDetectorManager *mgr{nullptr};
67 ATH_CHECK (m_iGeoModelTool->createFactory(mgr, world));
68 std::unique_ptr<MuonGM::MuonDetectorManager> MuonMgrData(mgr);
69
70 // =======================
71 // Add NSW to the MuonDetectorManager by calling BuildReadoutGeometry from MuonAGDDToolHelper
72 // =======================
73
74 if (MuonMgrData->mmIdHelper() && MuonMgrData->stgcIdHelper()) {
75 BuildNSWReadoutGeometry theBuilder{};
76 if(!theBuilder.BuildReadoutGeometry(MuonMgrData.get())){
77 ATH_MSG_FATAL("unable to add NSW ReadoutGeometry in the MuonDetectorManager in conditions store");
78 return StatusCode::FAILURE;
79 }
82 if(!readMmPass.isValid()){
83 ATH_MSG_ERROR("Cannot find conditions data container for MM passivation!");
84 return StatusCode::FAILURE;
85 }
86 writeHandle.addDependency(readMmPass);
87 MuonMgrData->setMMPassivation(readMmPass.cptr());
88 }
89 }
90
91 // =======================
92 // Update CSC Internal Alignment if requested
93 // =======================
94
95 if (!m_readILineKey.empty()) {
97 if (!readILinesHandle.isValid()){
98 ATH_MSG_FATAL("Failed to retrieve the CSC I-line container "<<readILinesHandle.fullKey());
99 return StatusCode::FAILURE;
100 }
101 writeHandle.addDependency(readILinesHandle);
102 ATH_CHECK(MuonMgrData->updateCSCInternalAlignmentMap(**readILinesHandle));
103 }
104
105 // =======================
106 // Update MdtAsBuiltMapContainer if requested BEFORE updating ALINES and BLINES
107 // =======================
108 if (!m_readMdtAsBuiltKey.empty()) {
110 if (!readMdtAsBuiltHandle.isValid()) {
111 ATH_MSG_FATAL("Failed to load Mdt as-built container "<<m_readMdtAsBuiltKey.fullKey());
112 return StatusCode::FAILURE;
113 }
114 writeHandle.addDependency(readMdtAsBuiltHandle);
115 ATH_CHECK(MuonMgrData->updateMdtAsBuiltParams(**readMdtAsBuiltHandle));
116 }
117
118 // =======================
119 // Set NSW as-built geometry if requested
120 // =======================
121 if (!m_readNswAsBuiltKey.empty()) {
123 if(!readNswAsBuilt.isValid()) {
124 ATH_MSG_ERROR("Cannot find conditions data container for NSW as-built!");
125 return StatusCode::FAILURE;
126 }
127 writeHandle.addDependency(readNswAsBuilt);
128 MuonMgrData->setNswAsBuilt(*readNswAsBuilt);
129 }
130
131 if(!m_readsTGCAsBuiltKey.empty()){
133 if(!readsTGCAsBuilt.isValid()){
134 ATH_MSG_ERROR("Cannot find conditions data container for sTGC as-built");
135 return StatusCode::FAILURE;
136 }
137 writeHandle.addDependency(readsTGCAsBuilt);
138 MuonMgrData->setsTGCAsBuilt(*readsTGCAsBuilt);
139 }
140
141
142 // =======================
143 // Update Alignment, ALINES
144 // =======================
145 if (m_applyALines) {
147 if (!readALinesHandle.isValid()) {
148 ATH_MSG_FATAL("Failed to load ALine container "<<m_readALineKey.fullKey());
149 return StatusCode::FAILURE;
150 }
151 writeHandle.addDependency(readALinesHandle);
152 ATH_CHECK(MuonMgrData->updateAlignment(**readALinesHandle));
153 } else ATH_MSG_INFO("Do not apply the A Lines of the alignment");
154
155 // =======================
156 // Update Deformations, BLINES
157 // =======================
158 if (m_applyBLines) {
160 if (!readBLinesHandle.isValid()) {
161 ATH_MSG_FATAL("Failed to load B line container "<<m_readBLineKey.fullKey());
162 return StatusCode::FAILURE;
163 }
164 writeHandle.addDependency(readBLinesHandle);
165 ATH_CHECK (MuonMgrData->updateDeformations(**readBLinesHandle));
166 } else ATH_MSG_INFO("Do not apply the B Lines of the alignment");
167
168 // !!!!!!!! UPDATE ANYTHING ELSE ???????
169 ATH_CHECK(copyInertMaterial(*MuonMgrData));
170 MuonMgrData->addTreeTop(world);
171 /* Short check that the reference count of the new universe is indeed 2 (1 from the experiment & 1 from the world Ptr) */
172 if (world->refCount() != 2) {
173 ATH_MSG_FATAL("The leaking reference counter to the GeoModel world detected "<<world->refCount());
174 return StatusCode::FAILURE;
175 }
176 ATH_CHECK(writeHandle.record(std::move(MuonMgrData)));
177 ATH_MSG_INFO("recorded new " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
178
179 return StatusCode::SUCCESS;
180}
182 const MuonGM::MuonDetectorManager *MuonDetMgrDS{nullptr};
183 ATH_CHECK(detStore()->retrieve(MuonDetMgrDS));
184
185 // In the new geomodel, there is only one GeoModel tree and it is pre-built. In that
186 // case these pointers are the same and one should not copy to self.
187 if (MuonDetMgrDS->getTreeTop(0)==detMgr.getTreeTop(0)) return StatusCode::SUCCESS;
188 // ---------------------------------------------------------------------------------
189
190 PVLink condMgrWorld{detMgr.getTreeTop(0)};
191
192 GeoVolumeCursor detStoreCursor{MuonDetMgrDS->getTreeTop(0)};
193 while (!detStoreCursor.atEnd()) {
194 PVConstLink worldNode(detStoreCursor.getVolume());
195 const Amg::Transform3D transform{detStoreCursor.getTransform()};
196 const GeoLogVol* logVol = worldNode->getLogVol();
197 const std::string_view vname = logVol->getName();
198 detStoreCursor.next();
199 if (vname.find("Station") != std::string::npos) continue;
201 const GeoVPhysVol& pvConstLink = *worldNode;
202 ATH_MSG_DEBUG("Volume in the static world "<<vname<<" "<<typeid(pvConstLink).name()
203 <<"children: "<<worldNode->getNChildNodes()<<" cursor: "<<Amg::toString(transform));
204 condMgrWorld->add(make_intrusive<GeoTransform>(transform));
205 condMgrWorld->add(const_pointer_cast(worldNode));
206 }
207 return StatusCode::SUCCESS;
208}
209
210
#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
Gaudi::Property< bool > m_applyMdtAsBuilt
Gaudi::Property< bool > m_applyMmPassivation
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