ATLAS Offline Software
Loading...
Searching...
No Matches
PixelDetectorElementCondAlg.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
15PixelDetectorElementCondAlg::PixelDetectorElementCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
16 : ::AthCondAlgorithm(name, pSvcLocator)
17{
18 declareProperty("ReadKey", m_readKey);
19}
20
22{
23 ATH_MSG_DEBUG("initialize " << name());
24
25 // Read Handle
26 ATH_CHECK(m_readKey.initialize());
27
28 // Write Handle
29 ATH_CHECK(m_writeKey.initialize());
30
31 // We need the detector manager
33
34 // used only if they exist
38
39 return StatusCode::SUCCESS;
40}
41
42StatusCode PixelDetectorElementCondAlg::execute(const EventContext& ctx) const
43{
44 ATH_MSG_DEBUG("execute " << name());
45
46 // ____________ Construct Write Cond Handle and check its validity ____________
48
49 // Do we have a valid Write Cond Handle for current time?
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
57 const InDetDD::SiDetectorElementCollection* oldColl{m_detManager->getDetectorElementCollection()};
58 if (oldColl==nullptr) {
59 ATH_MSG_FATAL("Null pointer is returned by getDetectorElementCollection()");
60 return StatusCode::FAILURE;
61 }
62
63 // ____________ Construct new Write Cond Object ____________
64 std::unique_ptr<InDetDD::SiDetectorElementCollection> writeCdo{std::make_unique<InDetDD::SiDetectorElementCollection>()};
65
66 // ____________ Get Read Cond Object ____________
68 const GeoAlignmentStore* readCdo{*readHandle};
69 if (readCdo==nullptr) {
70 ATH_MSG_FATAL("Null pointer to the read conditions object of " << m_readKey.key());
71 return StatusCode::FAILURE;
72 }
73
74 // Make sure we make a mixed IOV.
76
77 // Add dependency for IOV range
78 writeHandle.addDependency(readHandle);
79 // Additional dependencies for IOV range to limit lifetime to TrackingGeometry lifetime
80 if (!m_muonManagerKey.empty()) {
82 if (*muonDependency != nullptr) {
83 writeHandle.addDependency(muonDependency);
84 } else {
85 ATH_MSG_ERROR("MuonManager not found but configured");
86 return StatusCode::FAILURE;
87 }
88 }
89 if (!m_trtDetElContKey.empty()) {
91 if (*trtDependency != nullptr) {
92 writeHandle.addDependency(trtDependency);
93 } else {
94 ATH_MSG_ERROR("TRT DetEls not found but configured");
95 return StatusCode::FAILURE;
96 }
97 }
98 if (!m_SCT_readKey.empty()) {
100 if (*sctDependency != nullptr) {
101 writeHandle.addDependency(sctDependency);
102 } else {
103 ATH_MSG_ERROR("SCT AlignmentStore not found but configured");
104 return StatusCode::FAILURE;
105 }
106 }
107
108 // ____________ Update writeCdo using readCdo ____________
109 std::map<const InDetDD::SiDetectorElement*, const InDetDD::SiDetectorElement*> oldToNewMap;
110 oldToNewMap[nullptr] = nullptr;
111 writeCdo->resize(oldColl->size());
112 InDetDD::SiDetectorElementCollection::iterator newEl{writeCdo->begin()};
113 for (const InDetDD::SiDetectorElement* oldEl: *oldColl) {
114 *newEl = new InDetDD::SiDetectorElement(oldEl->identify(),
115 &(oldEl->design()),
116 oldEl->GeoVDetectorElement::getMaterialGeom(),
117 oldEl->getCommonItems(),
118 readCdo);
119 oldToNewMap[oldEl] = *newEl;
120 ++newEl;
121 }
122
123 // Set neighbours and other side
124 // Set layer to surface
126 for (InDetDD::SiDetectorElement* newEl: *writeCdo) {
127 if (oldToNewMap[(*oldIt)]!=newEl) {
128 ATH_MSG_ERROR("Old and new elements are not synchronized!");
129 }
130 newEl->setNextInEta(oldToNewMap[(*oldIt)->nextInEta()]);
131 newEl->setPrevInEta(oldToNewMap[(*oldIt)->prevInEta()]);
132 newEl->setNextInPhi(oldToNewMap[(*oldIt)->nextInPhi()]);
133 newEl->setPrevInPhi(oldToNewMap[(*oldIt)->prevInPhi()]);
134
135 //Note here we set the Layer but then is redo in
136 //Tracking Geometry which should be the last MT const correctness issue
137 const Trk::Layer* layer{(*oldIt)->surface().associatedLayer()};
138 if (layer) {
139 newEl->surface().associateLayer(*layer);
140 }
141 ++oldIt;
142 }
143
144 // Apply alignment using readCdo passed to SiDetectorElement
145 for (InDetDD::SiDetectorElement* newEl: *writeCdo) {
146 newEl->updateCache();
147 }
148
149 // Record WriteCondHandle
150 const std::size_t size{writeCdo->size()};
151 if (writeHandle.record(std::move(writeCdo)).isFailure()) {
152 ATH_MSG_FATAL("Could not record " << writeHandle.key()
153 << " with EventRange " << writeHandle.getRange()
154 << " into Conditions Store");
155 return StatusCode::FAILURE;
156 }
157 ATH_MSG_INFO("recorded new CDO " << writeHandle.key() << " with range " << writeHandle.getRange()
158 << " with size of " << size << " into Conditions Store");
159
160 return StatusCode::SUCCESS;
161}
#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.
SG::ReadCondHandleKey< GeoAlignmentStore > m_readKey
PixelDetectorElementCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteCondHandleKey< InDetDD::SiDetectorElementCollection > m_writeKey
SG::ReadCondHandleKey< InDetDD::TRT_DetElementContainer > m_trtDetElContKey
const InDetDD::PixelDetectorManager * m_detManager
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_muonManagerKey
virtual StatusCode initialize() override final
virtual StatusCode execute(const EventContext &ctx) const override final
SG::ReadCondHandleKey< GeoAlignmentStore > m_SCT_readKey
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