ATLAS Offline Software
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 
20 MuonDetectorCondAlg::MuonDetectorCondAlg(const std::string &name, ISvcLocator *pSvcLocator) :
21  AthReentrantAlgorithm(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<<","
38  <<m_applyILines<<","<<m_applyMdtAsBuilt<<","
40  return StatusCode::SUCCESS;
41 }
42 
43 StatusCode 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  }
56  writeHandle.addDependency(IOVInfiniteRange::infiniteRunLB());
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 
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  bool success=false;
79  if(!readMmPass.isValid()){
80  ATH_MSG_ERROR("Cannot find conditions data container for MM passivation!");
81  return StatusCode::FAILURE;
82  }
83  writeHandle.addDependency(readMmPass);
84  success = theBuilder.BuildReadoutGeometry(MuonMgrData.get(), readMmPass.cptr());
85  }
86  else {
87  success = theBuilder.BuildReadoutGeometry(MuonMgrData.get(), nullptr);
88  }
89  if(!success){
90  ATH_MSG_FATAL("unable to add NSW ReadoutGeometry in the MuonDetectorManager in conditions store");
91  return StatusCode::FAILURE;
92  }
93  }
94 
95  // =======================
96  // Update CSC Internal Alignment if requested
97  // =======================
98 
99  if (!m_readILineKey.empty()) {
100  SG::ReadCondHandle<ALineContainer> readILinesHandle{m_readILineKey, ctx};
101  if (!readILinesHandle.isValid()){
102  ATH_MSG_FATAL("Failed to retrieve the CSC I-line container "<<readILinesHandle.fullKey());
103  return StatusCode::FAILURE;
104  }
105  writeHandle.addDependency(readILinesHandle);
106  ATH_CHECK(MuonMgrData->updateCSCInternalAlignmentMap(**readILinesHandle));
107  }
108 
109  // =======================
110  // Update MdtAsBuiltMapContainer if requested BEFORE updating ALINES and BLINES
111  // =======================
112  if (!m_readMdtAsBuiltKey.empty()) {
114  if (!readMdtAsBuiltHandle.isValid()) {
115  ATH_MSG_FATAL("Failed to load Mdt as-built container "<<m_readMdtAsBuiltKey.fullKey());
116  return StatusCode::FAILURE;
117  }
118  writeHandle.addDependency(readMdtAsBuiltHandle);
119  ATH_CHECK(MuonMgrData->updateMdtAsBuiltParams(**readMdtAsBuiltHandle));
120  }
121 
122  // =======================
123  // Set NSW as-built geometry if requested
124  // =======================
125  if (!m_readNswAsBuiltKey.empty()) {
127  if(!readNswAsBuilt.isValid()) {
128  ATH_MSG_ERROR("Cannot find conditions data container for NSW as-built!");
129  return StatusCode::FAILURE;
130  }
131  writeHandle.addDependency(readNswAsBuilt);
132  MuonMgrData->setNswAsBuilt(*readNswAsBuilt);
133  }
134 
137  if(!readsTGCAsBuilt2.isValid()){
138  ATH_MSG_ERROR("Cannot find conditions data container for sTGC as-built 2");
139  return StatusCode::FAILURE;
140  }
141  writeHandle.addDependency(readsTGCAsBuilt2);
142  MuonMgrData->setsTGCAsBuilt2(*readsTGCAsBuilt2);
143  }
144 
145 
146  // =======================
147  // Update Alignment, ALINES
148  // =======================
149  if (m_applyALines) {
150  SG::ReadCondHandle<ALineContainer> readALinesHandle{m_readALineKey, ctx};
151  if (!readALinesHandle.isValid()) {
152  ATH_MSG_FATAL("Failed to load ALine container "<<m_readALineKey.fullKey());
153  return StatusCode::FAILURE;
154  }
155  writeHandle.addDependency(readALinesHandle);
156  ATH_CHECK(MuonMgrData->updateAlignment(**readALinesHandle));
157  } else ATH_MSG_INFO("Do not apply the A Lines of the alignment");
158 
159  // =======================
160  // Update Deformations, BLINES
161  // =======================
162  if (m_applyBLines) {
163  SG::ReadCondHandle<BLineContainer> readBLinesHandle{m_readBLineKey, ctx};
164  if (!readBLinesHandle.isValid()) {
165  ATH_MSG_FATAL("Failed to load B line container "<<m_readBLineKey.fullKey());
166  return StatusCode::FAILURE;
167  }
168  writeHandle.addDependency(readBLinesHandle);
169  ATH_CHECK (MuonMgrData->updateDeformations(**readBLinesHandle));
170  } else ATH_MSG_INFO("Do not apply the B Lines of the alignment");
171 
172  // !!!!!!!! UPDATE ANYTHING ELSE ???????
173  ATH_CHECK(copyInertMaterial(*MuonMgrData));
174  MuonMgrData->addTreeTop(world);
175  /* Short check that the reference count of the new universe is indeed 2 (1 from the experiment & 1 from the world Ptr) */
176  if (world->refCount() != 2) {
177  ATH_MSG_FATAL("The leaking reference counter to the GeoModel world detected "<<world->refCount());
178  return StatusCode::FAILURE;
179  }
180  ATH_CHECK(writeHandle.record(std::move(MuonMgrData)));
181  ATH_MSG_INFO("recorded new " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
182 
183  return StatusCode::SUCCESS;
184 }
186  const MuonGM::MuonDetectorManager *MuonDetMgrDS{nullptr};
187  ATH_CHECK(detStore()->retrieve(MuonDetMgrDS));
188 
189  // In the new geomodel, there is only one GeoModel tree and it is pre-built. In that
190  // case these pointers are the same and one should not copy to self.
191  if (MuonDetMgrDS->getTreeTop(0)==detMgr.getTreeTop(0)) return StatusCode::SUCCESS;
192  // ---------------------------------------------------------------------------------
193 
194  PVLink condMgrWorld{detMgr.getTreeTop(0)};
195 
196  GeoVolumeCursor detStoreCursor{MuonDetMgrDS->getTreeTop(0)};
197  while (!detStoreCursor.atEnd()) {
198  PVConstLink worldNode(detStoreCursor.getVolume());
199  const Amg::Transform3D transform{detStoreCursor.getTransform()};
200  const GeoLogVol* logVol = worldNode->getLogVol();
201  const std::string_view vname = logVol->getName();
202  detStoreCursor.next();
203  if (vname.find("Station") != std::string::npos) continue;
205  const GeoVPhysVol& pvConstLink = *worldNode;
206  ATH_MSG_DEBUG("Volume in the static world "<<vname<<" "<<typeid(pvConstLink).name()
207  <<"children: "<<worldNode->getNChildNodes()<<" cursor: "<<Amg::toString(transform));
208  condMgrWorld->add(make_intrusive<GeoTransform>(transform));
209  condMgrWorld->add(const_pointer_cast(worldNode));
210  }
211  return StatusCode::SUCCESS;
212 }
213 
214 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
MuonDetectorCondAlg::m_applysTGCAsBuilt2
Gaudi::Property< bool > m_applysTGCAsBuilt2
Definition: MuonDetectorCondAlg.h:39
GeoModelExperiment::getPhysVol
GeoPhysVol * getPhysVol()
Destructor.
Definition: GeoModelExperiment.cxx:21
BuildNSWReadoutGeometry.h
MuonDetectorCondAlg::m_condMmPassivKey
SG::ReadCondHandleKey< NswPassivationDbData > m_condMmPassivKey
Definition: MuonDetectorCondAlg.h:62
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
MuonDetectorCondAlg::MuonDetectorCondAlg
MuonDetectorCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MuonDetectorCondAlg.cxx:20
CondCont.h
Hold mappings of ranges to condition objects.
CondAttrListCollection.h
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
MuonDetectorCondAlg::m_readNswAsBuiltKey
SG::ReadCondHandleKey< NswAsBuiltDbData > m_readNswAsBuiltKey
Definition: MuonDetectorCondAlg.h:60
MuonDetectorCondAlg::m_iGeoModelTool
ToolHandle< MuonDetectorTool > m_iGeoModelTool
Definition: MuonDetectorCondAlg.h:51
MuonGM::MuonDetectorManager::addTreeTop
void addTreeTop(PVLink)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:117
MuonDetectorCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: MuonDetectorCondAlg.cxx:43
MuonGM::MuonDetectorManager::updateCSCInternalAlignmentMap
StatusCode updateCSCInternalAlignmentMap(const ALineContainer &cscIntAline)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:511
GeoModelExperiment
Definition: GeoModelExperiment.h:32
MuonGM::MuonDetectorManager::updateMdtAsBuiltParams
StatusCode updateMdtAsBuiltParams(const MdtAsBuiltContainer &a)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:555
MuonDetectorCondAlg::m_applyALines
Gaudi::Property< bool > m_applyALines
Apply translations and rotations to align the Muon stations.
Definition: MuonDetectorCondAlg.h:45
MuonDetectorCondAlg::m_readBLineKey
SG::ReadCondHandleKey< BLineContainer > m_readBLineKey
Definition: MuonDetectorCondAlg.h:56
MuonGM::MuonDetectorManager::mmIdHelper
const MmIdHelper * mmIdHelper() const
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonDetectorManager.h:244
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
MuonDetectorTool.h
MuonDetectorCondAlg::m_readILineKey
SG::ReadCondHandleKey< ALineContainer > m_readILineKey
Definition: MuonDetectorCondAlg.h:57
MuonDetectorCondAlg.h
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
MuonDetectorCondAlg::m_applyNswAsBuilt
Gaudi::Property< bool > m_applyNswAsBuilt
Definition: MuonDetectorCondAlg.h:37
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
MuonDetectorCondAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MuonDetectorCondAlg.h:52
MuonDetectorCondAlg::copyInertMaterial
StatusCode copyInertMaterial(MuonGM::MuonDetectorManager &detMgr) const
Definition: MuonDetectorCondAlg.cxx:185
BchCleanup.mgr
mgr
Definition: BchCleanup.py:294
GeoModelExperiment.h
MuonDetectorCondAlg::m_applyBLines
Gaudi::Property< bool > m_applyBLines
Apply the chamber deformation model (Mdts + Nsw)
Definition: MuonDetectorCondAlg.h:47
MuonGM::MuonDetectorManager::updateDeformations
StatusCode updateDeformations(const BLineContainer &a)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:433
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ClassID_traits.h
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
BuildNSWReadoutGeometry
Definition: BuildNSWReadoutGeometry.h:15
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
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
IOVInfiniteRange::infiniteRunLB
static EventIDRange infiniteRunLB()
Produces an EventIDRange that is infinite in RunLumi and invalid in Time.
Definition: IOVInfiniteRange.h:39
MuonGM::MuonDetectorManager::stgcIdHelper
const sTgcIdHelper * stgcIdHelper() const
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonDetectorManager.h:241
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MuonDetectorCondAlg::m_readALineKey
SG::ReadCondHandleKey< ALineContainer > m_readALineKey
Definition: MuonDetectorCondAlg.h:55
IOVInfiniteRange.h
MuonDetectorCondAlg::m_readsTGCAsBuilt2Key
SG::ReadCondHandleKey< sTGCAsBuiltData2 > m_readsTGCAsBuilt2Key
Definition: MuonDetectorCondAlg.h:61
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MuonGM::MuonDetectorManager::setsTGCAsBuilt2
void setsTGCAsBuilt2(const sTGCAsBuiltData2 *stgcAsBuilt2)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:596
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
MuonDetectorCondAlg::m_readMdtAsBuiltKey
SG::ReadCondHandleKey< MdtAsBuiltContainer > m_readMdtAsBuiltKey
Definition: MuonDetectorCondAlg.h:59
MuonDetectorCondAlg::m_applyILines
Gaudi::Property< bool > m_applyILines
Apply internal transformations on the CSCs.
Definition: MuonDetectorCondAlg.h:49
MuonDetectorCondAlg::m_writeDetectorManagerKey
SG::WriteCondHandleKey< MuonGM::MuonDetectorManager > m_writeDetectorManagerKey
Definition: MuonDetectorCondAlg.h:65
MuonGM::MuonDetectorManager
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonDetectorManager.h:50
MuonDetectorCondAlg::m_applyMdtAsBuilt
Gaudi::Property< bool > m_applyMdtAsBuilt
Definition: MuonDetectorCondAlg.h:42
GeoPrimitivesToStringConverter.h
MuonGM::MuonDetectorManager::getTreeTop
virtual PVConstLink getTreeTop(unsigned int i) const
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:115
MuonGM::MuonDetectorManager::setNswAsBuilt
void setNswAsBuilt(const NswAsBuiltDbData *nswAsBuiltData)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:592
MuonGM::MuonDetectorManager::updateAlignment
StatusCode updateAlignment(const ALineContainer &a)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:325
MuonDetectorCondAlg::m_applyMmPassivation
Gaudi::Property< bool > m_applyMmPassivation
Definition: MuonDetectorCondAlg.h:35
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
CLASS_DEF.h
macros to associate a CLID to a type
MuonDetectorCondAlg::initialize
virtual StatusCode initialize() override final
Definition: MuonDetectorCondAlg.cxx:23