ATLAS Offline Software
MeasurementMarkerAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 #include "MeasurementMarkerAlg.h"
5 
7 #include "StoreGate/ReadHandle.h"
10 
11 namespace MuonR4{
12 
15  using SegLinkVec_t = std::vector<SegLink_t>;
16 
18  using PrdLinkVec_t = std::vector<PrdLink_t>;
19 
22 
24  using namespace DerivationFramework;
25 
27  ATH_CHECK(m_segKey.initialize());
28  ATH_CHECK(m_readMarkKey.initialize());
29  ATH_CHECK(m_prdLinkKey.initialize());
30  ATH_CHECK(m_measKeys.initialize());
31  if (m_measKeys.empty()) {
32  ATH_MSG_FATAL("Please configure the measurement containers to decorate.");
33  return StatusCode::FAILURE;
34  }
35  const std::string decor = SG::decorKeyFromKey(m_readMarkKey.key());
36  for (const auto& key : m_measKeys) {
37  m_writeMarkKeys.emplace_back(key, decor);
38  if (m_segLink.value().size()) {
39  m_writeSegLinkKeys.emplace_back(key, m_segLink);
40  }
41  }
42  ATH_CHECK(m_writeMarkKeys.initialize());
43  ATH_CHECK(m_writeSegLinkKeys.initialize());
44  return StatusCode::SUCCESS;
45  }
46  StatusCode MeasurementMarkerAlg::execute(const EventContext& ctx) const{
47  const xAOD::MuonSegmentContainer* segments{nullptr};
48  ATH_CHECK(SG::get(segments, m_segKey, ctx));
50  SG::ReadDecorHandle<xAOD::MuonSegmentContainer, bool> readDecor{m_readMarkKey, ctx};
52 
53  std::unordered_map<const SG::AuxVectorData*, MarkerHandle_t> writeDecorMap{};
54  std::unordered_map<const SG::AuxVectorData*, LinkHandle_t> linkDecorMap{};
55  for (const WriteDecorKey_t& decorKey : m_writeMarkKeys) {
56  const xAOD::UncalibratedMeasurementContainer* measCont{nullptr};
57  ATH_CHECK(SG::get(measCont, decorKey.contHandleKey(), ctx));
58  writeDecorMap.emplace(std::make_pair(measCont, makeHandle(ctx, decorKey, false)));
59  }
60 
61  for (const WriteDecorKey_t& key : m_writeSegLinkKeys) {
62  const xAOD::UncalibratedMeasurementContainer* measCont{nullptr};
63  ATH_CHECK(SG::get(measCont, key.contHandleKey(), ctx));
64  linkDecorMap.emplace(std::make_pair(measCont, makeHandle(ctx, key, SegLinkVec_t{})));
65  }
66 
67  for (const xAOD::MuonSegment* seg : *segments) {
68  if (!readDecor(*seg)){
69  continue;
70  }
71  SegLink_t segLink{segments, seg->index()};
72  for (const PrdLink_t& link : prdLinks(*seg)) {
73  const auto* prd = (*link);
74  writeDecorMap.at(prd->container())(*prd) = readDecor(*seg);
75  if (m_segLink.value().empty()) {
76  continue;
77  }
78  linkDecorMap.at(prd->container())(*prd).push_back(segLink);
79  }
80  }
81  return StatusCode::SUCCESS;
82  }
83 }
SG::WriteDecorHandleKey
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Definition: StoreGate/StoreGate/WriteDecorHandleKey.h:89
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Utils.h
MuonR4::PrdCont_t
xAOD::UncalibratedMeasurementContainer PrdCont_t
Definition: xAODSegmentCnvAlg.cxx:19
ViewHelper::makeHandle
SG::ReadHandle< T > makeHandle(const SG::View *view, const SG::ReadHandleKey< T > &rhKey, const EventContext &context)
navigate from the TrigComposite to nearest view and fetch object from it
Definition: ViewHelper.h:265
xAOD::MuonSegment_v1
Class describing a MuonSegment.
Definition: MuonSegment_v1.h:33
MuonR4::MeasurementMarkerAlg::initialize
virtual StatusCode initialize() override final
Definition: MeasurementMarkerAlg.cxx:26
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
SG::get
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition: ReadCondHandle.h:287
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
MuonR4::PrdLinkVec_t
std::vector< PrdLink_t > PrdLinkVec_t
Definition: xAODSegmentCnvAlg.cxx:21
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
MuonR4::SegLink_t
ElementLink< MuonR4::SegmentContainer > SegLink_t
Definition: xAODSegmentCnvAlg.cxx:18
MuonR4::MeasurementMarkerAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: MeasurementMarkerAlg.cxx:46
SG::decorKeyFromKey
std::string decorKeyFromKey(const std::string &key, const std::string &deflt)
Extract the decoration part of key.
Definition: DecorKeyHelpers.cxx:42
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
xAOD::UncalibratedMeasurementContainer
UncalibratedMeasurementContainer_v1 UncalibratedMeasurementContainer
Define the version of the uncalibrated measurement container.
Definition: UncalibratedMeasurementContainer.h:14
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
MuonR4::SegLinkVec_t
std::vector< SegLink_t > SegLinkVec_t
Definition: MeasurementMarkerAlg.cxx:15
ReadDecorHandle.h
Handle class for reading a decoration on an object.
ReadHandle.h
Handle class for reading from StoreGate.
MeasurementMarkerAlg.h
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37