ATLAS Offline Software
Loading...
Searching...
No Matches
TRTAlignCondAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "GaudiKernel/MsgStream.h"
7#include "TRTAlignCondAlg.h"
8
9
10TRTAlignCondAlg::TRTAlignCondAlg(const std::string& name
11 , ISvcLocator* pSvcLocator )
12 : ::AthCondAlgorithm(name,pSvcLocator)
13{
14}
15
17= default;
18
20{
21 ATH_MSG_DEBUG("initialize " << name());
22
23 // Read Condition Handles initialize
24 ATH_CHECK( m_readKeyRegular.initialize(!m_useDynamicFolders.value()) );
27 ATH_CHECK( m_readKeySpecial.initialize() );
28
29 // Write condition handles initialize
31 ATH_CHECK( m_writeKeyDetElCont.initialize() );
32
33 ATH_CHECK(detStore()->retrieve(m_detManager,"TRT"));
34
35 return StatusCode::SUCCESS;
36}
37
38StatusCode TRTAlignCondAlg::execute(const EventContext& ctx) const
39{
40 ATH_MSG_DEBUG("execute " << name());
41
42 // ____________ Construct Write Cond Handles and check their validity ____________
44 if (writeHandleDetElCont.isValid()) {
45 ATH_MSG_DEBUG("CondHandle " << writeHandleDetElCont.fullKey() << " is already valid."
46 << ". In theory this should not be called, but may happen"
47 << " if multiple concurrent events are being processed out of order.");
48 return StatusCode::SUCCESS;
49 }
50
51 std::unique_ptr<SG::WriteCondHandle<GeoAlignmentStore>> writeHandleAlignStore{};
52 if (!m_writeKeyAlignStore.empty()) {
53 writeHandleAlignStore = std::make_unique<SG::WriteCondHandle<GeoAlignmentStore>>(m_writeKeyAlignStore, ctx);
54 if (writeHandleAlignStore->isValid()) {
55 ATH_MSG_DEBUG("CondHandle " << writeHandleAlignStore->fullKey() << " is already valid."
56 << ". In theory this should not be called, but may happen"
57 << " if multiple concurrent events are being processed out of order.");
58 return StatusCode::SUCCESS;
59 }
60 }
61
62 // ____________ Construct new Write Cond Object and its range ____________
63 std::unique_ptr<GeoAlignmentStore> writeCdoAlignStore{std::make_unique<GeoAlignmentStore>()};
64
65 // ____________ Get Read Cond Objects ____________
66 // Container for passing read CDO-s over to the Detector Manager
67 InDetDD::RawAlignmentObjects readCdoContainer;
68
69 const InDetDD::TRT_DetElementCollection* unAlignedColl{m_detManager->getDetectorElementCollection()};
70 if (unAlignedColl==nullptr) {
71 ATH_MSG_FATAL("Null pointer is returned by getDetectorElementCollection()");
72 return StatusCode::FAILURE;
73 }
74
76 // 1. Dynamic folders
77
78 // ** Global
80 // Get CDO and store it into container
81 const CondAttrListCollection* readCdoDynamicGlobal{*readHandleDynamicGlobal};
82 if(readCdoDynamicGlobal==nullptr) {
83 ATH_MSG_ERROR("Null pointer to the read conditions object: Dynamic Global");
84 return StatusCode::FAILURE;
85 }
86 readCdoContainer.emplace(m_readKeyDynamicGlobal.key(),readCdoDynamicGlobal);
87 // Add depdency for IOV-intersection
88 if (writeHandleAlignStore) writeHandleAlignStore->addDependency(readHandleDynamicGlobal);
89 writeHandleDetElCont.addDependency(readHandleDynamicGlobal);
90
91 // ** Regular
93 // Get CDO and store it into container
94 const AlignableTransformContainer* readCdoDynamicRegular{*readHandleDynamicRegular};
95 if(readCdoDynamicRegular==nullptr) {
96 ATH_MSG_ERROR("Null pointer to the read conditions object: Dynamic Regular");
97 return StatusCode::FAILURE;
98 }
99 readCdoContainer.emplace(m_readKeyDynamicRegular.key(),readCdoDynamicRegular);
100 // Add depdency for IOV-intersection
101 if (writeHandleAlignStore) writeHandleAlignStore->addDependency(readHandleDynamicRegular);
102 writeHandleDetElCont.addDependency(readHandleDynamicRegular);
103 }
104 else {
105 // 2. Regular folder
107 // Get CDO and store it into container
108 const AlignableTransformContainer* readCdoRegular{*readHandleRegular};
109 if(readCdoRegular==nullptr) {
110 ATH_MSG_ERROR("Null pointer to the read conditions object: Regular");
111 return StatusCode::FAILURE;
112 }
113 readCdoContainer.emplace(m_readKeyRegular.key(),readCdoRegular);
114 //Add dependency for IOV-intersection
115 if (writeHandleAlignStore) writeHandleAlignStore->addDependency(readHandleRegular);
116 writeHandleDetElCont.addDependency(readHandleRegular);
117 }
118
119 {
120 // Special folder
122 // Get CDO and store it into container
123 const TRTCond::StrawDxContainer* readCdoSpecial{*readHandleSpecial};
124 if(!readCdoSpecial) {
125 ATH_MSG_ERROR("Null pointer to the read conditions object: Special");
126 return StatusCode::FAILURE;
127 }
128 readCdoContainer.emplace(m_readKeySpecial.key(),readCdoSpecial);
129 //Add dependency for IOV-intersection
130 if (writeHandleAlignStore) writeHandleAlignStore->addDependency(readHandleSpecial);
131 writeHandleDetElCont.addDependency(readHandleSpecial);
132 }
133
134 // ____________ Apply alignments to TRT GeoModel ____________
135 if(m_detManager->align(readCdoContainer, writeCdoAlignStore.get()).isFailure()) {
136 ATH_MSG_ERROR("Failed to apply alignments to TRT");
137 return StatusCode::FAILURE;
138 }
139
140 const InDetDD::TRT_DetElementCollection* alignedColl{m_detManager->getDetectorElementCollection()};
141 if (alignedColl==nullptr) {
142 ATH_MSG_FATAL("Null pointer is returned by getDetectorElementCollection()");
143 return StatusCode::FAILURE;
144 }
145
146 // ____________ Construct new Write Cond Object ____________
147 std::unique_ptr<InDetDD::TRT_DetElementContainer> writeCdoDetElCont{std::make_unique<InDetDD::TRT_DetElementContainer>()};
148
149 // ____________ Update writeCdo using readCdo ____________
150 std::map<const InDetDD::TRT_EndcapElement*, InDetDD::TRT_EndcapElement*> oldToNewECMap;
151 std::map<const InDetDD::TRT_BarrelElement*, InDetDD::TRT_BarrelElement*> oldToNewBAMap;
152
153 oldToNewECMap[nullptr] = nullptr;
154 oldToNewBAMap[nullptr] = nullptr;
155
156 //Create new aligned detector elements
157 for (const InDetDD::TRT_BaseElement* oldEl : *alignedColl) {
159
161 const InDetDD::TRT_EndcapElement* oldEl_Endcap = static_cast<const InDetDD::TRT_EndcapElement*>(oldEl);
162 //New encap element with new alignment created based on old element
163 InDetDD::TRT_EndcapElement* newEl = new InDetDD::TRT_EndcapElement(*oldEl_Endcap);
164 oldToNewECMap[oldEl_Endcap] = newEl;
165 writeCdoDetElCont->addEndcapElement(newEl);
167 const InDetDD::TRT_BarrelElement* oldEl_Barrel = static_cast<const InDetDD::TRT_BarrelElement*>(oldEl);
168 //New barrel element with new alignment created based on old element
169 InDetDD::TRT_BarrelElement* newEl = new InDetDD::TRT_BarrelElement(*oldEl_Barrel);
170 oldToNewBAMap[oldEl_Barrel] = newEl;
171 writeCdoDetElCont->addBarrelElement(newEl);
172 } else {
173 ATH_MSG_FATAL("Unknown TRT detector element found");
174 return StatusCode::FAILURE;
175 }
176 }
177
178 //Set detector elements links
179 for (auto pairOfEl : oldToNewECMap) {
180 if (!pairOfEl.first) continue; // skip nullptr
181 pairOfEl.second->setNextInZ(oldToNewECMap[pairOfEl.first->nextInZ()]);
182 pairOfEl.second->setPreviousInZ(oldToNewECMap[pairOfEl.first->previousInZ()]);
183 }
184 for (auto pairOfEl : oldToNewBAMap) {
185 if (!pairOfEl.first) continue; // skip nullptr
186 pairOfEl.second->setNextInR(oldToNewBAMap[pairOfEl.first->nextInR()]);
187 pairOfEl.second->setPreviousInR(oldToNewBAMap[pairOfEl.first->previousInR()]);
188 pairOfEl.second->setNextInPhi(oldToNewBAMap[pairOfEl.first->nextInPhi()]);
189 pairOfEl.second->setPreviousInPhi(oldToNewBAMap[pairOfEl.first->previousInPhi()]);
190 }
191
192 // Update all detector elements caches
193 for (InDetDD::TRT_BaseElement* newEl : *(writeCdoDetElCont->getElements())) {
194 newEl->updateAllCaches(writeCdoAlignStore.get());
195 }
196
197 // Record WriteCondHandle
198 const std::size_t writeHandleDetElContSize{writeCdoDetElCont->getElements()->size()};
199
200 writeCdoDetElCont->setNumerology(m_detManager->getNumerology());
201
202 // Record the resulting CDO
203 if (writeHandleAlignStore != nullptr) {
204 if(writeHandleAlignStore->record(std::move(writeCdoAlignStore)).isFailure()) {
205 ATH_MSG_ERROR("Could not record GeoAlignmentStore " << writeHandleAlignStore->key()
206 << " with EventRange " << writeHandleAlignStore->getRange()
207 << " into Conditions Store");
208 return StatusCode::FAILURE;
209 }
210 ATH_MSG_INFO("recorded new CDO " << writeHandleAlignStore->key() << " with range "
211 << writeHandleAlignStore->getRange() << " into Conditions Store");
212 }
213
214 if (writeHandleDetElCont.record(std::move(writeCdoDetElCont)).isFailure()) {
215 ATH_MSG_FATAL("Could not record " << writeHandleDetElCont.key()
216 << " with EventRange " << writeHandleDetElCont.getRange()
217 << " into Conditions Store");
218 return StatusCode::FAILURE;
219 }
220 ATH_MSG_INFO("recorded new CDO " << writeHandleDetElCont.key() << " with range "
221 << writeHandleDetElCont.getRange() << " with size of " << writeHandleDetElContSize << " into Conditions Store");
222
223 return StatusCode::SUCCESS;
224}
CondMultChanCollection< AlignableTransform > AlignableTransformContainer
#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)
const ServiceHandle< StoreGateSvc > & detStore() const
Base class for conditions algorithms.
This class is a collection of AttributeLists where each one is associated with a channel number.
Extended TRT_BaseElement to describe a TRT readout element, this is a planar layer with n ( order of ...
Virtual base class of TRT readout elements.
Class to hold collection of TRT detector elements.
Extended class of a TRT_BaseElement to describe a readout elment in the endcap.
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
SG::ReadCondHandleKey< AlignableTransformContainer > m_readKeyDynamicRegular
SG::ReadCondHandleKey< TRTCond::StrawDxContainer > m_readKeySpecial
SG::ReadCondHandleKey< AlignableTransformContainer > m_readKeyRegular
TRTAlignCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteCondHandleKey< InDetDD::TRT_DetElementContainer > m_writeKeyDetElCont
SG::WriteCondHandleKey< GeoAlignmentStore > m_writeKeyAlignStore
const InDetDD::TRT_DetectorManager * m_detManager
virtual StatusCode initialize() override
virtual ~TRTAlignCondAlg() override
virtual StatusCode execute(const EventContext &ctx) const override
Gaudi::Property< bool > m_useDynamicFolders
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyDynamicGlobal
specialise to detector level
std::map< std::string, const void * > RawAlignmentObjects
ElementLink_p1< typename GenerateELinkIndexType_p1< typename LINK::index_type >::type > type