ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Database
AthenaPOOL
AthenaPoolExample
AthenaPoolExampleAlgorithms
src
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
5
#include "
WriteExampleElectron.h
"
6
7
// the user data-class definitions
8
#include "
AthenaPoolExampleData/ExampleElectron.h
"
9
#include "
AthenaPoolExampleData/ExampleElectronAuxContainer.h
"
10
#include "
AthenaPoolExampleData/ExampleElectronContainer.h
"
11
#include "
AthenaPoolExampleData/ExampleHitContainer.h
"
12
#include "
AthenaPoolExampleData/ExampleTrackContainer.h
"
13
#include "GaudiKernel/EventContext.h"
14
#include "
StoreGate/WriteDecorHandle.h
"
15
#include "
StoreGate/WriteHandle.h
"
16
17
using namespace
AthPoolEx
;
18
19
//___________________________________________________________________________
20
WriteExampleElectron::WriteExampleElectron
(
const
std::string& name,
21
ISvcLocator* pSvcLocator)
22
:
AthReentrantAlgorithm
(name, pSvcLocator) {}
23
24
//___________________________________________________________________________
25
StatusCode
WriteExampleElectron::initialize
() {
26
ATH_MSG_INFO
(name() <<
": in initialize()"
);
27
28
ATH_CHECK
(
m_exampleElectronContainerKey
.initialize());
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
//___________________________________________________________________________
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
51
SG::ReadHandle<ExampleTrackContainer>
trackCont(
m_exampleTrackKey
, ctx);
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
70
SG::WriteHandle<xAOD::ExampleElectronContainer>
objs(
71
m_exampleElectronContainerKey
, ctx);
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'
79
SG::WriteDecorHandle<xAOD::ExampleElectronContainer, float>
hdl1(
m_decor1Key
,
80
ctx);
81
82
// And for the second decoration 'TestContainer.decor2'
83
SG::WriteDecorHandle<xAOD::ExampleElectronContainer, float>
hdl2(
m_decor2Key
,
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
//___________________________________________________________________________
106
StatusCode
WriteExampleElectron::finalize
() {
107
ATH_MSG_INFO
(name() <<
": in finalize()"
);
108
return
StatusCode::SUCCESS;
109
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x,...)
Definition
AthMsgStreamMacros.h:43
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x,...)
Definition
AthMsgStreamMacros.h:47
ATH_MSG_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
ExampleElectronAuxContainer.h
ExampleElectronContainer.h
ExampleElectron.h
ExampleHitContainer.h
This file contains the class definition for the ExampleHitContainer class.
ExampleTrackContainer.h
This file contains the class definition for the ExampleTrackContainer class.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
WriteHandle.h
Handle class for recording to StoreGate.
WriteExampleElectron.h
This file contains the class definition for the WriteExampleElectron class.
AthPoolEx::WriteExampleElectron::WriteExampleElectron
WriteExampleElectron(const std::string &name, ISvcLocator *pSvcLocator)
Definition
WriteExampleElectron.cxx:20
AthPoolEx::WriteExampleElectron::m_decor1Key
SG::WriteDecorHandleKey< xAOD::ExampleElectronContainer > m_decor1Key
Definition
WriteExampleElectron.h:50
AthPoolEx::WriteExampleElectron::m_decor2Key
SG::WriteDecorHandleKey< xAOD::ExampleElectronContainer > m_decor2Key
Definition
WriteExampleElectron.h:53
AthPoolEx::WriteExampleElectron::m_exampleHitKey
SG::ReadHandleKey< ExampleHitContainer > m_exampleHitKey
Definition
WriteExampleElectron.h:40
AthPoolEx::WriteExampleElectron::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition
WriteExampleElectron.cxx:38
AthPoolEx::WriteExampleElectron::m_exampleTrackKey
SG::ReadHandleKey< ExampleTrackContainer > m_exampleTrackKey
Definition
WriteExampleElectron.h:38
AthPoolEx::WriteExampleElectron::finalize
virtual StatusCode finalize() override final
Definition
WriteExampleElectron.cxx:106
AthPoolEx::WriteExampleElectron::initialize
virtual StatusCode initialize() override final
Gaudi Service Interface method implementations:
Definition
WriteExampleElectron.cxx:25
AthPoolEx::WriteExampleElectron::m_exampleElectronContainerKey
SG::WriteHandleKey< xAOD::ExampleElectronContainer > m_exampleElectronContainerKey
Definition
WriteExampleElectron.h:46
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
ExampleTrack
This class provides a dummy track data object for AthenaPool.
Definition
ExampleTrack.h:24
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition
StoreGate/StoreGate/WriteDecorHandle.h:100
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:73
AthPoolEx
Definition
PassNoneFilter.h:16
xAOD::ExampleElectron
ExampleElectron_v1 ExampleElectron
Definition
ExampleElectron.h:12
Generated on
for ATLAS Offline Software by
1.17.0