ATLAS Offline Software
TRTAlignCondAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 // Gaudi
7 #include "GaudiKernel/MsgStream.h"
9 #include "TRTAlignCondAlg.h"
10 
11 
13  , ISvcLocator* pSvcLocator )
14  : ::AthAlgorithm(name,pSvcLocator)
15  , m_detManager(nullptr)
16 {
17 }
18 
20 = default;
21 
23 {
24  ATH_MSG_DEBUG("initialize " << name());
25 
26  // Read Condition Handles initialize
27  ATH_CHECK( m_readKeyRegular.initialize(!m_useDynamicFolders.value()) );
30 
31  // Write condition handles initialize
34 
36 
37  return StatusCode::SUCCESS;
38 }
39 
41 {
42  ATH_MSG_DEBUG("execute " << name());
43 
44  const EventContext& ctx = Gaudi::Hive::currentContext();
45  // ____________ Construct Write Cond Handles and check their validity ____________
47  if (writeHandleDetElCont.isValid()) {
48  ATH_MSG_DEBUG("CondHandle " << writeHandleDetElCont.fullKey() << " is already valid."
49  << ". In theory this should not be called, but may happen"
50  << " if multiple concurrent events are being processed out of order.");
51  return StatusCode::SUCCESS;
52  }
53 
54  std::unique_ptr<SG::WriteCondHandle<GeoAlignmentStore>> writeHandleAlignStore{};
55  if (!m_writeKeyAlignStore.empty()) {
56  writeHandleAlignStore = std::make_unique<SG::WriteCondHandle<GeoAlignmentStore>>(m_writeKeyAlignStore, ctx);
57  if (writeHandleAlignStore->isValid()) {
58  ATH_MSG_DEBUG("CondHandle " << writeHandleAlignStore->fullKey() << " is already valid."
59  << ". In theory this should not be called, but may happen"
60  << " if multiple concurrent events are being processed out of order.");
61  return StatusCode::SUCCESS;
62  }
63  }
64 
65  // ____________ Construct new Write Cond Object and its range ____________
66  std::unique_ptr<GeoAlignmentStore> writeCdoAlignStore{std::make_unique<GeoAlignmentStore>()};
67 
68  // ____________ Get Read Cond Objects ____________
69  // Container for passing read CDO-s over to the Detector Manager
70  InDetDD::RawAlignmentObjects readCdoContainer;
71 
73  if (unAlignedColl==nullptr) {
74  ATH_MSG_FATAL("Null pointer is returned by getDetectorElementCollection()");
75  return StatusCode::FAILURE;
76  }
77 
79  // 1. Dynamic folders
80 
81  // ** Global
83  // Get CDO and store it into container
84  const CondAttrListCollection* readCdoDynamicGlobal{*readHandleDynamicGlobal};
85  if(readCdoDynamicGlobal==nullptr) {
86  ATH_MSG_ERROR("Null pointer to the read conditions object: Dynamic Global");
87  return StatusCode::FAILURE;
88  }
89  readCdoContainer.emplace(m_readKeyDynamicGlobal.key(),readCdoDynamicGlobal);
90  // Add depdency for IOV-intersection
91  if (writeHandleAlignStore) writeHandleAlignStore->addDependency(readHandleDynamicGlobal);
92  writeHandleDetElCont.addDependency(readHandleDynamicGlobal);
93 
94  // ** Regular
96  // Get CDO and store it into container
97  const AlignableTransformContainer* readCdoDynamicRegular{*readHandleDynamicRegular};
98  if(readCdoDynamicRegular==nullptr) {
99  ATH_MSG_ERROR("Null pointer to the read conditions object: Dynamic Regular");
100  return StatusCode::FAILURE;
101  }
102  readCdoContainer.emplace(m_readKeyDynamicRegular.key(),readCdoDynamicRegular);
103  // Add depdency for IOV-intersection
104  if (writeHandleAlignStore) writeHandleAlignStore->addDependency(readHandleDynamicRegular);
105  writeHandleDetElCont.addDependency(readHandleDynamicRegular);
106  }
107  else {
108  // 2. Regular folder
110  // Get CDO and store it into container
111  const AlignableTransformContainer* readCdoRegular{*readHandleRegular};
112  if(readCdoRegular==nullptr) {
113  ATH_MSG_ERROR("Null pointer to the read conditions object: Regular");
114  return StatusCode::FAILURE;
115  }
116  readCdoContainer.emplace(m_readKeyRegular.key(),readCdoRegular);
117  //Add dependency for IOV-intersection
118  if (writeHandleAlignStore) writeHandleAlignStore->addDependency(readHandleRegular);
119  writeHandleDetElCont.addDependency(readHandleRegular);
120  }
121 
122  // ____________ Apply alignments to TRT GeoModel ____________
123  if(m_detManager->align(readCdoContainer, writeCdoAlignStore.get()).isFailure()) {
124  ATH_MSG_ERROR("Failed to apply alignments to TRT");
125  return StatusCode::FAILURE;
126  }
127 
129  if (alignedColl==nullptr) {
130  ATH_MSG_FATAL("Null pointer is returned by getDetectorElementCollection()");
131  return StatusCode::FAILURE;
132  }
133 
134  // ____________ Construct new Write Cond Object ____________
135  std::unique_ptr<InDetDD::TRT_DetElementContainer> writeCdoDetElCont{std::make_unique<InDetDD::TRT_DetElementContainer>()};
136 
137  // ____________ Update writeCdo using readCdo ____________
138  std::map<const InDetDD::TRT_EndcapElement*, InDetDD::TRT_EndcapElement*> oldToNewECMap;
139  std::map<const InDetDD::TRT_BarrelElement*, InDetDD::TRT_BarrelElement*> oldToNewBAMap;
140 
141  oldToNewECMap[nullptr] = nullptr;
142  oldToNewBAMap[nullptr] = nullptr;
143 
144  //Create new aligned detector elements
145  for (const InDetDD::TRT_BaseElement* oldEl : *alignedColl) {
146  InDetDD::TRT_BaseElement::Type type = oldEl->type();
147 
149  const InDetDD::TRT_EndcapElement* oldEl_Endcap = static_cast<const InDetDD::TRT_EndcapElement*>(oldEl);
150  //New encap element with new alignment created based on old element
151  InDetDD::TRT_EndcapElement* newEl = new InDetDD::TRT_EndcapElement(*oldEl_Endcap);
152  oldToNewECMap[oldEl_Endcap] = newEl;
153  writeCdoDetElCont->addEndcapElement(newEl);
154  } else if (type == InDetDD::TRT_BaseElement::BARREL) {
155  const InDetDD::TRT_BarrelElement* oldEl_Barrel = static_cast<const InDetDD::TRT_BarrelElement*>(oldEl);
156  //New barrel element with new alignment created based on old element
157  InDetDD::TRT_BarrelElement* newEl = new InDetDD::TRT_BarrelElement(*oldEl_Barrel);
158  oldToNewBAMap[oldEl_Barrel] = newEl;
159  writeCdoDetElCont->addBarrelElement(newEl);
160  } else {
161  ATH_MSG_FATAL("Unknown TRT detector element found");
162  return StatusCode::FAILURE;
163  }
164  }
165 
166  //Set detector elements links
167  for (auto pairOfEl : oldToNewECMap) {
168  if (!pairOfEl.first) continue; // skip nullptr
169  pairOfEl.second->setNextInZ(oldToNewECMap[pairOfEl.first->nextInZ()]);
170  pairOfEl.second->setPreviousInZ(oldToNewECMap[pairOfEl.first->previousInZ()]);
171  }
172  for (auto pairOfEl : oldToNewBAMap) {
173  if (!pairOfEl.first) continue; // skip nullptr
174  pairOfEl.second->setNextInR(oldToNewBAMap[pairOfEl.first->nextInR()]);
175  pairOfEl.second->setPreviousInR(oldToNewBAMap[pairOfEl.first->previousInR()]);
176  pairOfEl.second->setNextInPhi(oldToNewBAMap[pairOfEl.first->nextInPhi()]);
177  pairOfEl.second->setPreviousInPhi(oldToNewBAMap[pairOfEl.first->previousInPhi()]);
178  }
179 
180  // Update all detector elements caches
181  for (InDetDD::TRT_BaseElement* newEl : *(writeCdoDetElCont->getElements())) {
182  newEl->updateAllCaches();
183  }
184 
185  // Record WriteCondHandle
186  const std::size_t writeHandleDetElContSize{writeCdoDetElCont->getElements()->size()};
187 
188  writeCdoDetElCont->setNumerology(m_detManager->getNumerology());
189 
190  // Record the resulting CDO
191  if (writeHandleAlignStore != nullptr) {
192  if(writeHandleAlignStore->record(std::move(writeCdoAlignStore)).isFailure()) {
193  ATH_MSG_ERROR("Could not record GeoAlignmentStore " << writeHandleAlignStore->key()
194  << " with EventRange " << writeHandleAlignStore->getRange()
195  << " into Conditions Store");
196  return StatusCode::FAILURE;
197  }
198  ATH_MSG_INFO("recorded new CDO " << writeHandleAlignStore->key() << " with range "
199  << writeHandleAlignStore->getRange() << " into Conditions Store");
200  }
201 
202  if (writeHandleDetElCont.record(std::move(writeCdoDetElCont)).isFailure()) {
203  ATH_MSG_FATAL("Could not record " << writeHandleDetElCont.key()
204  << " with EventRange " << writeHandleDetElCont.getRange()
205  << " into Conditions Store");
206  return StatusCode::FAILURE;
207  }
208  ATH_MSG_INFO("recorded new CDO " << writeHandleDetElCont.key() << " with range "
209  << writeHandleDetElCont.getRange() << " with size of " << writeHandleDetElContSize << " into Conditions Store");
210 
211  return StatusCode::SUCCESS;
212 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TRTAlignCondAlg::m_readKeyDynamicRegular
SG::ReadCondHandleKey< AlignableTransformContainer > m_readKeyDynamicRegular
Definition: TRTAlignCondAlg.h:34
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
TRTAlignCondAlg::initialize
virtual StatusCode initialize() override
Definition: TRTAlignCondAlg.cxx:22
InDetDD::TRT_BarrelElement
Definition: TRT_BarrelElement.h:44
InDetDD::TRT_DetectorManager::getDetectorElementCollection
const TRT_DetElementCollection * getDetectorElementCollection() const
Access to Whole Collection of Elements ---------------------------------—.
Definition: TRT_DetectorManager.cxx:180
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TRT_DetectorManager.h
CondMultChanCollection
A CondMultChanCollection is a template class which can hold a collection of T* objects which are inte...
Definition: CondMultChanCollection.h:52
InDetDD::RawAlignmentObjects
std::map< std::string, const void * > RawAlignmentObjects
Definition: InDetDetectorManager.h:43
TRTAlignCondAlg::TRTAlignCondAlg
TRTAlignCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TRTAlignCondAlg.cxx:12
InDetDD::TRT_EndcapElement
Definition: TRT_EndcapElement.h:44
TRTAlignCondAlg::m_detManager
const InDetDD::TRT_DetectorManager * m_detManager
Definition: TRTAlignCondAlg.h:39
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
TRTAlignCondAlg::~TRTAlignCondAlg
virtual ~TRTAlignCondAlg() override
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
InDetDD::TRT_DetectorManager::getNumerology
TRT_Numerology * getNumerology()
Access Numerological information:---------------------------------------—.
Definition: TRT_DetectorManager.cxx:56
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TRTAlignCondAlg::execute
virtual StatusCode execute() override
Definition: TRTAlignCondAlg.cxx:40
InDetDD::TRT_BaseElement::ENDCAP
@ ENDCAP
Definition: TRT_BaseElement.h:61
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
InDetDD::TRT_BaseElement::BARREL
@ BARREL
Definition: TRT_BaseElement.h:61
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthAlgorithm
Definition: AthAlgorithm.h:47
InDetDD::TRT_BaseElement::Type
Type
Definition: TRT_BaseElement.h:61
TRTAlignCondAlg.h
TRTAlignCondAlg::m_readKeyDynamicGlobal
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyDynamicGlobal
Definition: TRTAlignCondAlg.h:33
TRTAlignCondAlg::m_writeKeyDetElCont
SG::WriteCondHandleKey< InDetDD::TRT_DetElementContainer > m_writeKeyDetElCont
Definition: TRTAlignCondAlg.h:37
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
InDetDD::InDetDetectorManager::align
StatusCode align(IOVSVC_CALLBACK_ARGS) const
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TRTAlignCondAlg::m_writeKeyAlignStore
SG::WriteCondHandleKey< GeoAlignmentStore > m_writeKeyAlignStore
Definition: TRTAlignCondAlg.h:36
InDetDD::TRT_DetElementCollection
Class to hold collection of TRT detector elements.
Definition: TRT_DetElementCollection.h:28
TRTAlignCondAlg::m_useDynamicFolders
Gaudi::Property< bool > m_useDynamicFolders
Definition: TRTAlignCondAlg.h:41
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
TRTAlignCondAlg::m_readKeyRegular
SG::ReadCondHandleKey< AlignableTransformContainer > m_readKeyRegular
Definition: TRTAlignCondAlg.h:35
InDetDD::TRT_BaseElement
Definition: TRT_BaseElement.h:57