ATLAS Offline Software
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 
15 PixelDetectorElementCondAlg::PixelDetectorElementCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
16  : ::AthReentrantAlgorithm(name, pSvcLocator)
17 {
18  declareProperty("ReadKey", m_readKey);
19 }
20 
22 {
23  ATH_MSG_DEBUG("initialize " << name());
24 
25  // Read Handle
27 
28  // Write Handle
30 
31  // We need the detector manager
33 
34  // used only if they exist
38 
39  return StatusCode::SUCCESS;
40 }
41 
42 StatusCode 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 
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.
75  writeHandle.addDependency (IOVInfiniteRange::infiniteMixed());
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(), nullptr);
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
125  InDetDD::SiDetectorElementCollection::const_iterator oldIt{oldColl->begin()};
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  // Layer of old element is set by InDet::SiLayerBuilder::registerSurfacesToLayer.
136  const Trk::Layer* layer{(*oldIt)->surface().associatedLayer()};
137  if (layer) {
138  newEl->surface().associateLayer(*layer);
139  }
140  ++oldIt;
141  }
142 
143  // Apply alignment using readCdo passed to SiDetectorElement
144  for (InDetDD::SiDetectorElement* newEl: *writeCdo) {
145  newEl->setCache();
146  }
147 
148  // Record WriteCondHandle
149  const std::size_t size{writeCdo->size()};
150  if (writeHandle.record(std::move(writeCdo)).isFailure()) {
151  ATH_MSG_FATAL("Could not record " << writeHandle.key()
152  << " with EventRange " << writeHandle.getRange()
153  << " into Conditions Store");
154  return StatusCode::FAILURE;
155  }
156  ATH_MSG_INFO("recorded new CDO " << writeHandle.key() << " with range " << writeHandle.getRange()
157  << " with size of " << size << " into Conditions Store");
158 
159  return StatusCode::SUCCESS;
160 }
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
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Surface.h
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
IOVInfiniteRange::infiniteMixed
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
Definition: IOVInfiniteRange.h:55
Layer.h
PixelDetectorElementCondAlg::m_trtDetElContKey
SG::ReadCondHandleKey< InDetDD::TRT_DetElementContainer > m_trtDetElContKey
Definition: PixelDetectorElementCondAlg.h:49
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
PixelDetectorElementCondAlg::m_readKey
SG::ReadCondHandleKey< GeoAlignmentStore > m_readKey
Definition: PixelDetectorElementCondAlg.h:39
PixelDetectorElementCondAlg::m_SCT_readKey
SG::ReadCondHandleKey< GeoAlignmentStore > m_SCT_readKey
Definition: PixelDetectorElementCondAlg.h:51
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
PixelDetectorElementCondAlg::initialize
virtual StatusCode initialize() override final
Definition: PixelDetectorElementCondAlg.cxx:21
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
InDetDD::PixelDetectorManager::getDetectorElementCollection
virtual const SiDetectorElementCollection * getDetectorElementCollection() const override
access to whole collection via Iterators
Definition: PixelDetectorManager.cxx:105
PixelDetectorManager.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
PixelDetectorElementCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: PixelDetectorElementCondAlg.cxx:42
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
PixelDetectorElementCondAlg::m_detManager
const InDetDD::PixelDetectorManager * m_detManager
Definition: PixelDetectorElementCondAlg.h:54
IOVInfiniteRange.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
PixelDetectorElementCondAlg.h
SiDetectorElement.h
PixelDetectorElementCondAlg::PixelDetectorElementCondAlg
PixelDetectorElementCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: PixelDetectorElementCondAlg.cxx:15
PixelDetectorElementCondAlg::m_detManagerName
StringProperty m_detManagerName
Definition: PixelDetectorElementCondAlg.h:53
PixelDetectorElementCondAlg::m_muonManagerKey
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_muonManagerKey
Definition: PixelDetectorElementCondAlg.h:47
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
PixelDetectorElementCondAlg::m_writeKey
SG::WriteCondHandleKey< InDetDD::SiDetectorElementCollection > m_writeKey
Definition: PixelDetectorElementCondAlg.h:42
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
Trk::Layer
Definition: Layer.h:73