ATLAS Offline Software
Loading...
Searching...
No Matches
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
15SCT_DetectorElementCondAlg::SCT_DetectorElementCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
16 : ::AthCondAlgorithm(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
29 ATH_CHECK(m_readKey.initialize());
30
31 // Write Handle
32 ATH_CHECK(m_writeKey.initialize());
33
35
36 // used only if they exist
40
41 return StatusCode::SUCCESS;
42}
43
44StatusCode 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
59 const InDetDD::SiDetectorElementCollection* oldColl{m_detManager->getDetectorElementCollection()};
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.
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());
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
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 //Note here we set the Layer. But then is reset by the
138 //Tracking Geometry. The later should be the last
139 //const correctness MT issue
140 const Trk::Layer* layer{(*oldIt)->surface().associatedLayer()};
141 if (layer) {
142 newEl->surface().associateLayer(*layer);
143 }
144 ++oldIt;
145 }
146
147 // Apply alignment using readCdo passed to SiDetectorElement
148 for (InDetDD::SiDetectorElement* newEl: *writeCdo) {
149 newEl->updateCache();
150 }
151
152 // Record WriteCondHandle
153 const std::size_t size{writeCdo->size()};
154 if (writeHandle.record(std::move(writeCdo)).isFailure()) {
155 ATH_MSG_FATAL("Could not record " << writeHandle.key()
156 << " with EventRange " << writeHandle.getRange()
157 << " into Conditions Store");
158 return StatusCode::FAILURE;
159 }
160 ATH_MSG_INFO("recorded new CDO " << writeHandle.key() << " with range " << writeHandle.getRange() << " with size of " << size << " into Conditions Store");
161
162 return StatusCode::SUCCESS;
163}
164
166{
167 ATH_MSG_DEBUG("finalize " << name());
168
169 return StatusCode::SUCCESS;
170}
#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)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
Base class for conditions algorithms.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
Ensure that the extensions for the Vector3D are properly loaded.
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
Class to hold the SiDetectorElement objects to be put in the detector store.
Class to hold geometrical description of a silicon detector element.
virtual StatusCode initialize() override final
SCT_DetectorElementCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
const InDetDD::SCT_DetectorManager * m_detManager
SG::ReadCondHandleKey< GeoAlignmentStore > m_readKey
virtual StatusCode execute(const EventContext &ctx) const override final
SG::ReadCondHandleKey< GeoAlignmentStore > m_pixelReadKey
SG::ReadCondHandleKey< InDetDD::TRT_DetElementContainer > m_trtDetElContKey
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_muonManagerKey
SG::WriteCondHandleKey< InDetDD::SiDetectorElementCollection > m_writeKey
virtual StatusCode finalize() override final
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
Base Class for a Detector Layer in the Tracking realm.
Definition Layer.h:72