ATLAS Offline Software
SCT_DetectorElementCondAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
9 #include "TrkGeometry/Layer.h"
10 #include "TrkSurfaces/Surface.h"
12 
13 #include <map>
14 
15 SCT_DetectorElementCondAlg::SCT_DetectorElementCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
16  : ::AthReentrantAlgorithm(name, pSvcLocator)
17  , m_readKey{"SCTAlignmentStore", "SCTAlignmentStore"}
18  , m_detManagerName("SCT")
19 {
20  declareProperty("ReadKey", m_readKey);
21  declareProperty("DetManagerName", m_detManagerName);
22 }
23 
25 {
26  ATH_MSG_DEBUG("initialize " << name());
27 
28  // Read Handle
30 
31  // Write Handle
33 
35 
36  // used only if they exist
40 
41  return StatusCode::SUCCESS;
42 }
43 
44 StatusCode SCT_DetectorElementCondAlg::execute(const EventContext& ctx) const
45 {
46  ATH_MSG_DEBUG("execute " << name());
47 
48  // ____________ Construct Write Cond Handle and check its validity ____________
50 
51  // Do we have a valid Write Cond Handle for current time?
52  if (writeHandle.isValid()) {
53  ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
54  << ". In theory this should not be called, but may happen"
55  << " if multiple concurrent events are being processed out of order.");
56  return StatusCode::SUCCESS;
57  }
58 
60  if (oldColl==nullptr) {
61  ATH_MSG_FATAL("Null pointer is returned by getDetectorElementCollection()");
62  return StatusCode::FAILURE;
63  }
64 
65  // ____________ Construct new Write Cond Object ____________
66  std::unique_ptr<InDetDD::SiDetectorElementCollection> writeCdo{std::make_unique<InDetDD::SiDetectorElementCollection>()};
67 
68  // ____________ Get Read Cond Object ____________
70  const GeoAlignmentStore* readCdo{*readHandle};
71  if (readCdo==nullptr) {
72  ATH_MSG_FATAL("Null pointer to the read conditions object of " << m_readKey.key());
73  return StatusCode::FAILURE;
74  }
75 
76  // Make sure we make a mixed IOV.
77  writeHandle.addDependency (IOVInfiniteRange::infiniteMixed());
78 
79  // Add dependency
80  writeHandle.addDependency(readHandle);
81  // Additional dependencies for IOV range to limit lifetime to TrackingGeometry lifetime
82  if (!m_muonManagerKey.empty()) {
84  if (*muonDependency != nullptr) {
85  writeHandle.addDependency(muonDependency);
86  } else {
87  ATH_MSG_ERROR("MuonManager not found but configured");
88  return StatusCode::FAILURE;
89  }
90  }
91  if (!m_trtDetElContKey.empty()) {
93  if (*trtDependency != nullptr) {
94  writeHandle.addDependency(trtDependency);
95  } else {
96  ATH_MSG_ERROR("TRT DetEls not found but configured");
97  return StatusCode::FAILURE;
98  }
99  }
100  if (!m_pixelReadKey.empty()) {
102  if (*pixelDependency != nullptr) {
103  writeHandle.addDependency(pixelDependency);
104  } else {
105  ATH_MSG_ERROR("Pixel AlignmentStore not found but configured");
106  return StatusCode::FAILURE;
107  }
108  }
109 
110  // ____________ Update writeCdo using readCdo ____________
111  std::map<const InDetDD::SiDetectorElement*, const InDetDD::SiDetectorElement*> oldToNewMap;
112  oldToNewMap[nullptr] = nullptr;
113  writeCdo->resize(oldColl->size(), nullptr);
114  InDetDD::SiDetectorElementCollection::iterator newEl{writeCdo->begin()};
115  for (const InDetDD::SiDetectorElement* oldEl: *oldColl) {
116  *newEl = new InDetDD::SiDetectorElement(oldEl->identify(),
117  &(oldEl->design()),
118  oldEl->GeoVDetectorElement::getMaterialGeom(),
119  oldEl->getCommonItems(),
120  readCdo);
121  oldToNewMap[oldEl] = *newEl;
122  ++newEl;
123  }
124 
125  // Set neighbours and other side
126  // Set layer to surface
127  InDetDD::SiDetectorElementCollection::const_iterator oldIt{oldColl->begin()};
128  for (InDetDD::SiDetectorElement* newEl: *writeCdo) {
129  if (oldToNewMap[(*oldIt)]!=newEl) {
130  ATH_MSG_ERROR("Old and new elements are not synchronized!");
131  }
132  newEl->setNextInEta(oldToNewMap[(*oldIt)->nextInEta()]);
133  newEl->setPrevInEta(oldToNewMap[(*oldIt)->prevInEta()]);
134  newEl->setNextInPhi(oldToNewMap[(*oldIt)->nextInPhi()]);
135  newEl->setPrevInPhi(oldToNewMap[(*oldIt)->prevInPhi()]);
136  newEl->setOtherSide(oldToNewMap[(*oldIt)->otherSide()]);
137  // Layer of old element is set by InDet::SiLayerBuilder::registerSurfacesToLayer.
138  const Trk::Layer* layer{(*oldIt)->surface().associatedLayer()};
139  if (layer) {
140  newEl->surface().associateLayer(*layer);
141  }
142  ++oldIt;
143  }
144 
145  // Apply alignment using readCdo passed to SiDetectorElement
146  for (InDetDD::SiDetectorElement* newEl: *writeCdo) {
147  newEl->setCache();
148  }
149 
150  // Record WriteCondHandle
151  const std::size_t size{writeCdo->size()};
152  if (writeHandle.record(std::move(writeCdo)).isFailure()) {
153  ATH_MSG_FATAL("Could not record " << writeHandle.key()
154  << " with EventRange " << writeHandle.getRange()
155  << " into Conditions Store");
156  return StatusCode::FAILURE;
157  }
158  ATH_MSG_INFO("recorded new CDO " << writeHandle.key() << " with range " << writeHandle.getRange() << " with size of " << size << " into Conditions Store");
159 
160  return StatusCode::SUCCESS;
161 }
162 
164 {
165  ATH_MSG_DEBUG("finalize " << name());
166 
167  return StatusCode::SUCCESS;
168 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
GeoAlignmentStore
Ensure that the extensions for the Vector3D are properly loaded.
Definition: GeoAlignmentStore.h:24
SCT_DetectorElementCondAlg::m_detManager
const InDetDD::SCT_DetectorManager * m_detManager
Definition: SCT_DetectorElementCondAlg.h:52
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SCT_DetectorElementCondAlg::m_detManagerName
std::string m_detManagerName
Definition: SCT_DetectorElementCondAlg.h:51
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SCT_DetectorElementCondAlg::initialize
virtual StatusCode initialize() override final
Definition: SCT_DetectorElementCondAlg.cxx:24
Surface.h
SCT_DetectorElementCondAlg::m_writeKey
SG::WriteCondHandleKey< InDetDD::SiDetectorElementCollection > m_writeKey
Definition: SCT_DetectorElementCondAlg.h:40
SCT_DetectorElementCondAlg::m_muonManagerKey
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_muonManagerKey
Definition: SCT_DetectorElementCondAlg.h:45
SCT_DetectorElementCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: SCT_DetectorElementCondAlg.cxx:44
IOVInfiniteRange::infiniteMixed
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
Definition: IOVInfiniteRange.h:55
Layer.h
SCT_DetectorElementCondAlg::SCT_DetectorElementCondAlg
SCT_DetectorElementCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SCT_DetectorElementCondAlg.cxx:15
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SCT_DetectorElementCondAlg::finalize
virtual StatusCode finalize() override final
Definition: SCT_DetectorElementCondAlg.cxx:163
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
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
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
InDetDD::SCT_DetectorManager::getDetectorElementCollection
virtual const SiDetectorElementCollection * getDetectorElementCollection() const override
access to whole collectiom
Definition: SCT_DetectorManager.cxx:88
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
SCT_DetectorElementCondAlg::m_pixelReadKey
SG::ReadCondHandleKey< GeoAlignmentStore > m_pixelReadKey
Definition: SCT_DetectorElementCondAlg.h:49
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SCT_DetectorElementCondAlg::m_trtDetElContKey
SG::ReadCondHandleKey< InDetDD::TRT_DetElementContainer > m_trtDetElContKey
Definition: SCT_DetectorElementCondAlg.h:47
IOVInfiniteRange.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
SCT_DetectorElementCondAlg.h
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
SiDetectorElement.h
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
SCT_DetectorManager.h
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
SCT_DetectorElementCondAlg::m_readKey
SG::ReadCondHandleKey< GeoAlignmentStore > m_readKey
Definition: SCT_DetectorElementCondAlg.h:39
Trk::Layer
Definition: Layer.h:73