ATLAS Offline Software
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 
11 #include "ReWriteData.h"
12 
13 // the user data-class definitions
16 #include "StoreGate/ReadHandle.h"
17 #include "StoreGate/WriteHandle.h"
18 
19 #include <cmath>
20 
21 using namespace AthPoolEx;
22 
23 //___________________________________________________________________________
24 ReWriteData::ReWriteData(const std::string& name, ISvcLocator* pSvcLocator)
25  : AthReentrantAlgorithm(name, pSvcLocator)
26 {
27 }
28 //___________________________________________________________________________
30  ATH_MSG_INFO("in initialize()");
31  if (m_exampleHitKey.key().empty()) {
32  m_exampleTrackKey = "";
33  }
34  else {
37  }
38  return StatusCode::SUCCESS;
39 }
40 //___________________________________________________________________________
41 StatusCode ReWriteData::execute (const EventContext& ctx) const {
42  ATH_MSG_DEBUG("in execute()");
43 
44  if (!m_exampleHitKey.key().empty()) {
45 
46  // Take in the ExampleHit, obtain pT, eta and phi.
48  double pT = 0.0, eta = 0.0, phi = 0.0;
49  for (const ExampleHit* hit : *hitCont) {
50  ATH_MSG_INFO("Hit x = " << hit->getX() << " y = " << hit->getY() << " z = " << hit->getZ() << " detector = " << hit->getDetector());
51  pT = pT + sqrt(hit->getX() * hit->getX() + hit->getY() * hit->getY());
52  eta = eta + hit->getX() / hit->getZ();
53  phi = phi + hit->getX() / hit->getY();
54  }
55 
56  // Create an ExampleTrack object, set the hit values appropriately
57  auto trackObj = std::make_unique<ExampleTrack>();
58  trackObj->setPT(pT / hitCont->size());
59  trackObj->setEta(eta);
60  trackObj->setPhi(phi);
61  trackObj->setDetector("Track made in: " + (*hitCont->begin())->getDetector());
62  trackObj->getElementLink1()->toContainedElement(*hitCont, *hitCont->begin());
63  ATH_MSG_INFO("ElementLink1 = " << trackObj->getElement1()->getX());
64  trackObj->getElementLink2()->toIndexedElement(*hitCont, hitCont->size() - 1);
65  ATH_MSG_INFO("ElementLink2 = " << trackObj->getElement2()->getX());
66 
67  // ElementLink creation
68  ElementLink<ExampleHitContainer> eLink1, eLink2, eLink3;
69  eLink1.toContainedElement(*hitCont, *hitCont->begin());
70  trackObj->getElementLinkVector()->push_back(eLink1);
71  eLink2.toIndexedElement(*hitCont, 1);
72  trackObj->getElementLinkVector()->push_back(eLink2);
73  eLink3.toContainedElement(*hitCont, (*hitCont)[3]);
74  trackObj->getElementLinkVector()->push_back(eLink3);
75  ATH_MSG_INFO("Link ElementLinkVector = " << trackObj->getElementLinkVector()->size());
76  for (const auto& link : *trackObj->getElementLinkVector()) {
77  ATH_MSG_INFO("Element = " << (*link) << " : " << (*link)->getX());
78  }
79 
80  // Print out Navigable elements
81  trackObj->getNavigable()->putElement(hitCont.cptr(), *hitCont->begin());
82  trackObj->getNavigable()->putElement(hitCont.cptr(), (*hitCont)[5]);
83  ATH_MSG_INFO("Link Navigable = " << trackObj->getNavigable()->size());
84  for (const auto* elem : *trackObj->getNavigable()) {
85  ATH_MSG_INFO("Element = " << elem << " : " << elem->getX());
86  }
87 
88  // Print out WeightedNavigable elements
89  trackObj->getWeightedNavigable()->putElement(hitCont.cptr(), *hitCont->begin(), 3.33);
90  trackObj->getWeightedNavigable()->putElement(hitCont.cptr(), (*hitCont)[5], 1.11);
91  trackObj->getWeightedNavigable()->putElement(hitCont.cptr(), (*hitCont)[3], 5.55);
92  ATH_MSG_INFO("Link Weighted Navigable = " << trackObj->getWeightedNavigable()->size());
93  for (const auto* elem : *trackObj->getWeightedNavigable()) {
94  ATH_MSG_INFO("Element = " << elem << " : " << elem->getX());
95  }
96 
97  // Print out Track info
98  ATH_MSG_INFO("Track pt = " << trackObj->getPT() << " eta = " << trackObj->getEta() << " phi = " << trackObj->getPhi() << " detector = " << trackObj->getDetector());
99 
100  // Create Track container, record it.
101  auto trackCont = std::make_unique<ExampleTrackContainer>();
102  trackCont->push_back(std::move(trackObj));
104  ATH_CHECK( trackContH.record (std::move (trackCont)) );
105 
106  } // end if
107 
108  ATH_MSG_INFO("registered all data");
109  return StatusCode::SUCCESS;
110 }
111 //___________________________________________________________________________
113  ATH_MSG_INFO("in finalize()");
114  return StatusCode::SUCCESS;
115 }
CalculateHighPtTerm.pT
pT
Definition: ICHEP2016/CalculateHighPtTerm.py:57
AthPoolEx::ReWriteData::m_exampleTrackKey
SG::WriteHandleKey< ExampleTrackContainer > m_exampleTrackKey
Definition: ReWriteData.h:38
ReWriteData.h
This file contains the class definition for the ReWriteData class.
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
AthPoolEx::ReWriteData::ReWriteData
ReWriteData(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ReWriteData.cxx:24
python.getProblemFolderFromLogs.elem
elem
Definition: getProblemFolderFromLogs.py:90
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
AthPoolEx::ReWriteData::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: ReWriteData.cxx:41
WriteHandle.h
Handle class for recording to StoreGate.
AthPoolEx::ReWriteData::finalize
virtual StatusCode finalize() override final
Definition: ReWriteData.cxx:112
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ExampleHit
This class provides a dummy hit data object for AthenaPool.
Definition: ExampleHit.h:24
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
AthPoolEx::ReWriteData::initialize
virtual StatusCode initialize() override final
Gaudi Service Interface method implementations:
Definition: ReWriteData.cxx:29
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
AthPoolEx::ReWriteData::m_exampleHitKey
SG::ReadHandleKey< ExampleHitContainer > m_exampleHitKey
Definition: ReWriteData.h:37
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ExampleTrackContainer.h
This file contains the class definition for the ExampleTrackContainer class.
AthPoolEx
Definition: PassNoneFilter.h:16
ExampleHitContainer.h
This file contains the class definition for the ExampleHitContainer class.
ReadHandle.h
Handle class for reading from StoreGate.