ATLAS Offline Software
Loading...
Searching...
No Matches
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
15HGTD_DetectorElementCondAlg::HGTD_DetectorElementCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
16 : ::AthCondAlgorithm(name, pSvcLocator)
17{
18}
19
21{
22 ATH_MSG_DEBUG("initialize " << name());
23
24 // Write Handle
25 ATH_CHECK(m_writeKey.initialize());
26
27 // We need the detector manager
29
30 return StatusCode::SUCCESS;
31}
32
33StatusCode 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
48 const InDetDD::HGTD_DetectorElementCollection* oldColl{m_detManager->getDetectorElementCollection()};
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.
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());
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
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 const Trk::Layer* layer{(*oldIt)->surface().associatedLayer()};
81 if (layer) {
82 //NOTE!!! associateLayer occurs here but it also occurs
83 //later in the layer builder
84 newEl->surface().associateLayer(*layer);
85 }
86 ++oldIt;
87 }
88
89 // Apply alignment using readCdo passed to HGTD_DetectorElement
90 for (InDetDD::HGTD_DetectorElement* newEl: *writeCdo) {
91 newEl->updateCache();
92 }
93
94 // Record WriteCondHandle
95 const std::size_t size{writeCdo->size()};
96 if (writeHandle.record(std::move(writeCdo)).isFailure()) {
97 ATH_MSG_FATAL("Could not record " << writeHandle.key()
98 << " with EventRange " << writeHandle.getRange()
99 << " into Conditions Store");
100 return StatusCode::FAILURE;
101 }
102 ATH_MSG_INFO("recorded new CDO " << writeHandle.key() << " with range " << writeHandle.getRange()
103 << " with size of " << size << " into Conditions Store");
104
105 return StatusCode::SUCCESS;
106}
#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.
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.
SG::WriteCondHandleKey< InDetDD::HGTD_DetectorElementCollection > m_writeKey
virtual StatusCode initialize() override final
const HGTD_DetectorManager * m_detManager
virtual StatusCode execute(const EventContext &ctx) const override final
HGTD_DetectorElementCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
Class to hold geometrical description of an HGTD detector element.
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
DataVector< HGTD_DetectorElement > HGTD_DetectorElementCollection