ATLAS Offline Software
WriteExampleElectron.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 #include "WriteExampleElectron.h"
6 
7 // the user data-class defintions
13 #include "GaudiKernel/EventContext.h"
15 #include "StoreGate/WriteHandle.h"
16 
17 using namespace AthPoolEx;
18 
19 //___________________________________________________________________________
21  ISvcLocator* pSvcLocator)
22  : AthReentrantAlgorithm(name, pSvcLocator) {}
23 
24 //___________________________________________________________________________
26  ATH_MSG_INFO(name() << ": in initialize()");
27 
31  ATH_CHECK(m_decor1Key.initialize());
32  ATH_CHECK(m_decor2Key.initialize());
33 
34  return StatusCode::SUCCESS;
35 }
36 
37 //___________________________________________________________________________
38 StatusCode WriteExampleElectron::execute(const EventContext& ctx) const {
39  ATH_MSG_DEBUG("WriteExampleElectron in execute()");
40  std::size_t idx_trk = 0;
41  float idx_decor = 0.0f;
42 
43  auto elecCont = std::make_unique<xAOD::ExampleElectronContainer>();
44  auto elecStore = std::make_unique<xAOD::ExampleElectronAuxContainer>();
45  elecCont->setStore(elecStore.get());
46 
47  /*
48  * Convert ExampleTrack to xAOD::ExampleElectron
49  */
50 
52 
53  elecCont->push_back(std::make_unique<xAOD::ExampleElectron>());
54 
55  for (const ExampleTrack* track : *trackCont) {
56  ATH_MSG_INFO(name() << ": track # " << idx_trk << " pT = " << track->getPT()
57  << ".");
58 
59  // proceed to take this tracks pT
60  elecCont->back()->setPt(track->getPT());
61 
62  // Print out the pT that's being saved
63  ATH_MSG_INFO(name() << ": track # " << idx_trk
64  << "is an electron with pT = " << elecCont->back()->pt()
65  << ";");
66 
67  idx_trk++;
68  }
69 
72  ATH_CHECK(objs.record(std::move(elecCont), std::move(elecStore)));
73 
74  /*
75  * Writing Decorations
76  */
77 
78  // WriteDecorHandle for the decoration 'TestContainer.decor1'
80  ctx);
81 
82  // And for the second decoration 'TestContainer.decor2'
84  ctx);
85 
86  if (objs.isValid()) {
87  // Access example electrons
88  for (const xAOD::ExampleElectron* obj : *objs) {
89  hdl1(*obj) = 115.9 + 12.34 * idx_decor; // decor1
90  hdl2(*obj) = 114.9 + idx_decor; // decor2
91 
92  // Verify writing out two decorations
93  ATH_MSG_INFO(name() << ": DecorationWriter: decor1 = " << hdl1(*obj)
94  << ", decor2 = " << hdl2(*obj) << ". ");
95  idx_decor++;
96  }
97  } else {
98  ATH_MSG_ERROR(name() << ": objs is not valid");
99  }
100 
101  ATH_MSG_INFO(name() << ": registered all data");
102  return StatusCode::SUCCESS;
103 }
104 
105 //___________________________________________________________________________
107  ATH_MSG_INFO(name() << ": in finalize()");
108  return StatusCode::SUCCESS;
109 }
AthPoolEx::WriteExampleElectron::m_exampleTrackKey
SG::ReadHandleKey< ExampleTrackContainer > m_exampleTrackKey
Definition: WriteExampleElectron.h:40
xAOD::ExampleElectron_v1
Definition: ExampleElectron_v1.h:14
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthPoolEx::WriteExampleElectron::m_exampleElectronContainerKey
SG::WriteHandleKey< xAOD::ExampleElectronContainer > m_exampleElectronContainerKey
Definition: WriteExampleElectron.h:48
AthPoolEx::WriteExampleElectron::m_decor1Key
SG::WriteDecorHandleKey< xAOD::ExampleElectronContainer > m_decor1Key
Definition: WriteExampleElectron.h:52
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
ExampleElectronContainer.h
ExampleTrack
This class provides a dummy track data object for AthenaPool.
Definition: ExampleTrack.h:24
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
WriteHandle.h
Handle class for recording to StoreGate.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
WriteExampleElectron.h
This file contains the class definition for the WriteExampleElectron class.
checkFileSG.objs
list objs
Definition: checkFileSG.py:93
WriteDecorHandle.h
Handle class for adding a decoration to an object.
AthPoolEx::WriteExampleElectron::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: WriteExampleElectron.cxx:38
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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::WriteExampleElectron::m_decor2Key
SG::WriteDecorHandleKey< xAOD::ExampleElectronContainer > m_decor2Key
Definition: WriteExampleElectron.h:55
AthPoolEx::WriteExampleElectron::m_exampleHitKey
SG::ReadHandleKey< ExampleHitContainer > m_exampleHitKey
Definition: WriteExampleElectron.h:42
AthPoolEx::WriteExampleElectron::WriteExampleElectron
WriteExampleElectron(const std::string &name, ISvcLocator *pSvcLocator)
Standard Service Constructor.
Definition: WriteExampleElectron.cxx:20
ExampleElectronAuxContainer.h
AthPoolEx::WriteExampleElectron::initialize
virtual StatusCode initialize() override final
Gaudi Service Interface method implementations:
Definition: WriteExampleElectron.cxx:25
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
AthPoolEx::WriteExampleElectron::finalize
virtual StatusCode finalize() override final
Definition: WriteExampleElectron.cxx:106
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
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.
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
ExampleElectron.h
python.PyAthena.obj
obj
Definition: PyAthena.py:132