ATLAS Offline Software
Loading...
Searching...
No Matches
ReWriteData.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
9
10#include "ReWriteData.h"
11
12// the user data-class definitions
17
18#include <cmath>
19
20using namespace AthPoolEx;
21
22//___________________________________________________________________________
23ReWriteData::ReWriteData(const std::string& name, ISvcLocator* pSvcLocator)
24 : AthReentrantAlgorithm(name, pSvcLocator)
25{
26}
27//___________________________________________________________________________
29 ATH_MSG_INFO("in initialize()");
30 if (m_exampleHitKey.key().empty()) {
32 }
33 else {
34 ATH_CHECK( m_exampleHitKey.initialize() );
35 ATH_CHECK( m_exampleTrackKey.initialize() );
36 }
37 return StatusCode::SUCCESS;
38}
39//___________________________________________________________________________
40StatusCode ReWriteData::execute (const EventContext& ctx) const {
41 ATH_MSG_DEBUG("in execute()");
42
43 if (!m_exampleHitKey.key().empty()) {
44
45 // Take in the ExampleHit, obtain pT, eta and phi.
47 double pT = 0.0, eta = 0.0, phi = 0.0;
48 for (const ExampleHit* hit : *hitCont) {
49 ATH_MSG_INFO("Hit x = " << hit->getX() << " y = " << hit->getY() << " z = " << hit->getZ() << " detector = " << hit->getDetector());
50 pT = pT + sqrt(hit->getX() * hit->getX() + hit->getY() * hit->getY());
51 eta = eta + hit->getX() / hit->getZ();
52 phi = phi + hit->getX() / hit->getY();
53 }
54
55 // Create an ExampleTrack object, set the hit values appropriately
56 auto trackObj = std::make_unique<ExampleTrack>();
57 trackObj->setPT(pT / hitCont->size());
58 trackObj->setEta(eta);
59 trackObj->setPhi(phi);
60 trackObj->setDetector("Track made in: " + (*hitCont->begin())->getDetector());
61 trackObj->getElementLink1()->toContainedElement(*hitCont, *hitCont->begin());
62 ATH_MSG_INFO("ElementLink1 = " << trackObj->getElement1()->getX());
63 trackObj->getElementLink2()->toIndexedElement(*hitCont, hitCont->size() - 1);
64 ATH_MSG_INFO("ElementLink2 = " << trackObj->getElement2()->getX());
65
66 // ElementLink creation
67 ElementLink<ExampleHitContainer> eLink1, eLink2, eLink3;
68 eLink1.toContainedElement(*hitCont, *hitCont->begin());
69 trackObj->getElementLinkVector()->push_back(eLink1);
70 eLink2.toIndexedElement(*hitCont, 1);
71 trackObj->getElementLinkVector()->push_back(eLink2);
72 eLink3.toContainedElement(*hitCont, (*hitCont)[3]);
73 trackObj->getElementLinkVector()->push_back(eLink3);
74 ATH_MSG_INFO("Link ElementLinkVector = " << trackObj->getElementLinkVector()->size());
75 for (const auto link : *trackObj->getElementLinkVector()) {
76 ATH_MSG_INFO("Element = " << (*link)->getX());
77 }
78
79 // Print out Navigable elements
80 trackObj->getNavigable()->putElement(hitCont.cptr(), *hitCont->begin());
81 trackObj->getNavigable()->putElement(hitCont.cptr(), (*hitCont)[5]);
82 ATH_MSG_INFO("Link Navigable = " << trackObj->getNavigable()->size());
83 for (const auto* elem : *trackObj->getNavigable()) {
84 ATH_MSG_INFO("Element = " << elem->getX());
85 }
86
87 // Print out WeightedNavigable elements
88 trackObj->getWeightedNavigable()->putElement(hitCont.cptr(), *hitCont->begin(), 3.33);
89 trackObj->getWeightedNavigable()->putElement(hitCont.cptr(), (*hitCont)[5], 1.11);
90 trackObj->getWeightedNavigable()->putElement(hitCont.cptr(), (*hitCont)[3], 5.55);
91 ATH_MSG_INFO("Link Weighted Navigable = " << trackObj->getWeightedNavigable()->size());
92 for (const auto* elem : *trackObj->getWeightedNavigable()) {
93 ATH_MSG_INFO("Element = " << elem->getX());
94 }
95
96 // Print out Track info
97 ATH_MSG_INFO("Track pt = " << trackObj->getPT() << " eta = " << trackObj->getEta() << " phi = " << trackObj->getPhi() << " detector = " << trackObj->getDetector());
98
99 // Create Track container, record it.
100 auto trackCont = std::make_unique<ExampleTrackContainer>();
101 trackCont->push_back(std::move(trackObj));
103 ATH_CHECK( trackContH.record (std::move (trackCont)) );
104
105 } // end if
106
107 ATH_MSG_INFO("registered all data");
108 return StatusCode::SUCCESS;
109}
110//___________________________________________________________________________
112 ATH_MSG_INFO("in finalize()");
113 return StatusCode::SUCCESS;
114}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
This file contains the class definition for the ExampleHitContainer class.
This file contains the class definition for the ExampleTrackContainer class.
bool hit(const Container &ids, int pdgId)
This file contains the class definition for the ReWriteData class.
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
ReWriteData(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override final
Gaudi Service Interface method implementations:
virtual StatusCode execute(const EventContext &ctx) const override final
SG::WriteHandleKey< ExampleTrackContainer > m_exampleTrackKey
Definition ReWriteData.h:38
SG::ReadHandleKey< ExampleHitContainer > m_exampleHitKey
Definition ReWriteData.h:37
virtual StatusCode finalize() override final
An algorithm that can be simultaneously executed in multiple threads.
This class provides a dummy hit data object for AthenaPool.
Definition ExampleHit.h:24
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.