ATLAS Offline Software
ReWriteData.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
11 #include "ReWriteData.h"
12 
13 // the user data-class defintions
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 }
31 //___________________________________________________________________________
33  ATH_MSG_INFO("in initialize()");
34  if (m_exampleHitKey.key().empty()) {
35  m_exampleTrackKey = "";
36  }
37  else {
40  }
41  return StatusCode::SUCCESS;
42 }
43 //___________________________________________________________________________
44 StatusCode ReWriteData::execute (const EventContext& ctx) const {
45  ATH_MSG_DEBUG("in execute()");
46 
47  if (!m_exampleHitKey.key().empty()) {
48 
49  // Take in the ExampleHit, obtain pT, eta and phi.
51  double pT = 0.0, eta = 0.0, phi = 0.0;
52  for (const ExampleHit* hit : *hitCont) {
53  ATH_MSG_INFO("Hit x = " << hit->getX() << " y = " << hit->getY() << " z = " << hit->getZ() << " detector = " << hit->getDetector());
54  pT = pT + sqrt(hit->getX() * hit->getX() + hit->getY() * hit->getY());
55  eta = eta + hit->getX() / hit->getZ();
56  phi = phi + hit->getX() / hit->getY();
57  }
58 
59  // Create an ExampleTrack object, set the hit values appropriately
60  auto trackObj = std::make_unique<ExampleTrack>();
61  trackObj->setPT(pT / hitCont->size());
62  trackObj->setEta(eta);
63  trackObj->setPhi(phi);
64  trackObj->setDetector("Track made in: " + (*hitCont->begin())->getDetector());
65  trackObj->getElementLink1()->toContainedElement(*hitCont, *hitCont->begin());
66  ATH_MSG_INFO("ElementLink1 = " << trackObj->getElement1()->getX());
67  trackObj->getElementLink2()->toIndexedElement(*hitCont, hitCont->size() - 1);
68  ATH_MSG_INFO("ElementLink2 = " << trackObj->getElement2()->getX());
69 
70  // ElementLink creation
71  ElementLink<ExampleHitContainer> eLink1, eLink2, eLink3;
72  eLink1.toContainedElement(*hitCont, *hitCont->begin());
73  trackObj->getElementLinkVector()->push_back(eLink1);
74  eLink2.toIndexedElement(*hitCont, 1);
75  trackObj->getElementLinkVector()->push_back(eLink2);
76  eLink3.toContainedElement(*hitCont, (*hitCont)[3]);
77  trackObj->getElementLinkVector()->push_back(eLink3);
78  ATH_MSG_INFO("Link ElementLinkVector = " << trackObj->getElementLinkVector()->size());
79  for (ElementLinkVector<ExampleHitContainer>::iterator iter = trackObj->getElementLinkVector()->begin(); iter != trackObj->getElementLinkVector()->end(); ++iter) {
80  ATH_MSG_INFO("Element = " << (**iter) << " : " << (**iter)->getX());
81  }
82 
83  // Print out Navigable elements
84  trackObj->getNavigable()->putElement(hitCont.cptr(), *hitCont->begin());
85  trackObj->getNavigable()->putElement(hitCont.cptr(), (*hitCont)[5]);
86  ATH_MSG_INFO("Link Navigable = " << trackObj->getNavigable()->size());
87  for (Navigable<ExampleHitContainer>::object_iter iter = trackObj->getNavigable()->begin(); iter != trackObj->getNavigable()->end(); ++iter) {
88  ATH_MSG_INFO("Element = " << (*iter) << " : " << (*iter)->getX());
89  }
90 
91  // Print out WeightedNavigable elements
92  trackObj->getWeightedNavigable()->putElement(hitCont.cptr(), *hitCont->begin(), 3.33);
93  trackObj->getWeightedNavigable()->putElement(hitCont.cptr(), (*hitCont)[5], 1.11);
94  trackObj->getWeightedNavigable()->putElement(hitCont.cptr(), (*hitCont)[3], 5.55);
95  ATH_MSG_INFO("Link Weighted Navigable = " << trackObj->getWeightedNavigable()->size());
96  for (Navigable<ExampleHitContainer, double>::object_iter iter = trackObj->getWeightedNavigable()->begin(); iter != trackObj->getWeightedNavigable()->end(); ++iter) {
97  ATH_MSG_INFO("Element = " << (*iter) << " : " << (*iter)->getX());
98  }
99 
100  // Print out Track info
101  ATH_MSG_INFO("Track pt = " << trackObj->getPT() << " eta = " << trackObj->getEta() << " phi = " << trackObj->getPhi() << " detector = " << trackObj->getDetector());
102 
103  // Create Track container, record it.
104  auto trackCont = std::make_unique<ExampleTrackContainer>();
105  trackCont->push_back(std::move(trackObj));
107  ATH_CHECK( trackContH.record (std::move (trackCont)) );
108 
109  } // end if
110 
111  ATH_MSG_INFO("registered all data");
112  return StatusCode::SUCCESS;
113 }
114 //___________________________________________________________________________
116  ATH_MSG_INFO("in finalize()");
117  return StatusCode::SUCCESS;
118 }
AthPoolEx::ReWriteData::~ReWriteData
virtual ~ReWriteData()
Destructor.
Definition: ReWriteData.cxx:29
CalculateHighPtTerm.pT
pT
Definition: ICHEP2016/CalculateHighPtTerm.py:57
AthPoolEx::ReWriteData::m_exampleTrackKey
SG::WriteHandleKey< ExampleTrackContainer > m_exampleTrackKey
Definition: ReWriteData.h:40
ElementLinkVector::begin
iterator begin()
Definition: AthLinks/ElementLinkVector.h:272
ReWriteData.h
This file contains the class definition for the ReWriteData class.
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthPoolEx::ReWriteData::ReWriteData
ReWriteData(const std::string &name, ISvcLocator *pSvcLocator)
Standard Service Constructor.
Definition: ReWriteData.cxx:24
Navigable::begin
virtual object_iter begin() const
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
AthPoolEx::ReWriteData::initialize
virtual StatusCode initialize() override
Gaudi Service Interface method implementations:
Definition: ReWriteData.cxx:32
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
WriteHandle.h
Handle class for recording to StoreGate.
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
ElementLinkVector
ElementLinkVector implementation for standalone ROOT.
Definition: AthLinks/ElementLinkVector.h:27
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
Navigable
Navigable template generalization to handle navigation.
Definition: Navigable.h:93
AthPoolEx::ReWriteData::m_exampleHitKey
SG::ReadHandleKey< ExampleHitContainer > m_exampleHitKey
Definition: ReWriteData.h:39
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
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.
AthPoolEx::ReWriteData::finalize
virtual StatusCode finalize() override
Definition: ReWriteData.cxx:115
AthPoolEx::ReWriteData::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: ReWriteData.cxx:44
NavigableIterator::end
NavigableIterator end()
Definition: NavigableIterator.h:179