ATLAS Offline Software
HGTD_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 
15 HGTD_DetectorElementCondAlg::HGTD_DetectorElementCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
16  : ::AthReentrantAlgorithm(name, pSvcLocator)
17 {
18 }
19 
21 {
22  ATH_MSG_DEBUG("initialize " << name());
23 
24  // Write Handle
26 
27  // We need the detector manager
29 
30  return StatusCode::SUCCESS;
31 }
32 
33 StatusCode HGTD_DetectorElementCondAlg::execute(const EventContext& ctx) const
34 {
35  ATH_MSG_DEBUG("execute " << name());
36 
37  // ____________ Construct Write Cond Handle and check its validity ____________
39 
40  // Do we have a valid Write Cond Handle for current time?
41  if (writeHandle.isValid()) {
42  ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
43  << ". In theory this should not be called, but may happen"
44  << " if multiple concurrent events are being processed out of order.");
45  return StatusCode::SUCCESS;
46  }
47 
49  if (oldColl==nullptr) {
50  ATH_MSG_FATAL("Null pointer is returned by getDetectorElementCollection()");
51  return StatusCode::FAILURE;
52  }
53 
54  // ____________ Construct new Write Cond Object ____________
55  std::unique_ptr<InDetDD::HGTD_DetectorElementCollection> writeCdo{std::make_unique<InDetDD::HGTD_DetectorElementCollection>()};
56 
57  // Make sure we make a mixed IOV.
58  writeHandle.addDependency (IOVInfiniteRange::infiniteMixed());
59 
60  // ____________ Update writeCdo ____________
61  std::map<const InDetDD::HGTD_DetectorElement*, const InDetDD::HGTD_DetectorElement*> oldToNewMap;
62  oldToNewMap[nullptr] = nullptr;
63  writeCdo->resize(oldColl->size(), nullptr);
65  for (const InDetDD::HGTD_DetectorElement* oldEl: *oldColl) {
66  *newEl = new InDetDD::HGTD_DetectorElement(oldEl->identify(),
67  &(oldEl->design()),
68  oldEl->GeoVDetectorElement::getMaterialGeom(),
69  oldEl->getCommonItems());
70  oldToNewMap[oldEl] = *newEl;
71  ++newEl;
72  }
73 
74  // Set layer to surface
75  InDetDD::HGTD_DetectorElementCollection::const_iterator oldIt{oldColl->begin()};
76  for (InDetDD::HGTD_DetectorElement* newEl: *writeCdo) {
77  if (oldToNewMap[(*oldIt)]!=newEl) {
78  ATH_MSG_ERROR("Old and new elements are not synchronized!");
79  }
80  // Layer of old element is set by HGTD_LayerBuilderCond::registerSurfacesToLayer.
81  const Trk::Layer* layer{(*oldIt)->surface().associatedLayer()};
82  if (layer) {
83  newEl->surface().associateLayer(*layer);
84  }
85  ++oldIt;
86  }
87 
88  // Apply alignment using readCdo passed to HGTD_DetectorElement
89  for (InDetDD::HGTD_DetectorElement* newEl: *writeCdo) {
90  newEl->setCache();
91  }
92 
93  // Record WriteCondHandle
94  const std::size_t size{writeCdo->size()};
95  if (writeHandle.record(std::move(writeCdo)).isFailure()) {
96  ATH_MSG_FATAL("Could not record " << writeHandle.key()
97  << " with EventRange " << writeHandle.getRange()
98  << " into Conditions Store");
99  return StatusCode::FAILURE;
100  }
101  ATH_MSG_INFO("recorded new CDO " << writeHandle.key() << " with range " << writeHandle.getRange()
102  << " with size of " << size << " into Conditions Store");
103 
104  return StatusCode::SUCCESS;
105 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Surface.h
HGTD_DetectorElementCondAlg::m_detManagerName
StringProperty m_detManagerName
Definition: HGTD_DetectorElementCondAlg.h:34
IOVInfiniteRange::infiniteMixed
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
Definition: IOVInfiniteRange.h:55
InDetDD::HGTD_DetectorElement
Definition: HGTD_DetectorElement.h:40
Layer.h
HGTD_DetectorManager::getDetectorElementCollection
const InDetDD::HGTD_DetectorElementCollection * getDetectorElementCollection() const
access to whole collection via Iterators
Definition: HGTD_DetectorManager.cxx:79
HGTD_DetectorElementCondAlg.h
HGTD_DetectorManager.h
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
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
HGTD_DetectorElementCondAlg::m_writeKey
SG::WriteCondHandleKey< InDetDD::HGTD_DetectorElementCollection > m_writeKey
Definition: HGTD_DetectorElementCondAlg.h:32
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
HGTD_DetectorElementCondAlg::HGTD_DetectorElementCondAlg
HGTD_DetectorElementCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: HGTD_DetectorElementCondAlg.cxx:15
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
HGTD_DetectorElement.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IOVInfiniteRange.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
HGTD_DetectorElementCondAlg::initialize
virtual StatusCode initialize() override final
Definition: HGTD_DetectorElementCondAlg.cxx:20
HGTD_DetectorElementCondAlg::m_detManager
const HGTD_DetectorManager * m_detManager
Definition: HGTD_DetectorElementCondAlg.h:35
HGTD_DetectorElementCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: HGTD_DetectorElementCondAlg.cxx:33
InDetDD::HGTD_DetectorElementCollection
Definition: HGTD_DetectorElementCollection.h:29
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
Trk::Layer
Definition: Layer.h:73