ATLAS Offline Software
Loading...
Searching...
No Matches
WriteExampleElectron.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7// the user data-class definitions
13#include "GaudiKernel/EventContext.h"
16
17using namespace AthPoolEx;
18
19//___________________________________________________________________________
21 ISvcLocator* pSvcLocator)
22 : AthReentrantAlgorithm(name, pSvcLocator) {}
23
24//___________________________________________________________________________
26 ATH_MSG_INFO(name() << ": in initialize()");
27
29 ATH_CHECK(m_exampleTrackKey.initialize());
30 ATH_CHECK(m_exampleHitKey.initialize());
31 ATH_CHECK(m_decor1Key.initialize());
32 ATH_CHECK(m_decor2Key.initialize());
33
34 return StatusCode::SUCCESS;
35}
36
37//___________________________________________________________________________
38StatusCode 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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#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.
Handle class for adding a decoration to an object.
Handle class for recording to StoreGate.
This file contains the class definition for the WriteExampleElectron class.
WriteExampleElectron(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteDecorHandleKey< xAOD::ExampleElectronContainer > m_decor1Key
SG::WriteDecorHandleKey< xAOD::ExampleElectronContainer > m_decor2Key
SG::ReadHandleKey< ExampleHitContainer > m_exampleHitKey
virtual StatusCode execute(const EventContext &ctx) const override final
SG::ReadHandleKey< ExampleTrackContainer > m_exampleTrackKey
virtual StatusCode finalize() override final
virtual StatusCode initialize() override final
Gaudi Service Interface method implementations:
SG::WriteHandleKey< xAOD::ExampleElectronContainer > m_exampleElectronContainerKey
An algorithm that can be simultaneously executed in multiple threads.
This class provides a dummy track data object for AthenaPool.
Handle class for adding a decoration to an object.
ExampleElectron_v1 ExampleElectron