ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
DataModelTest
DataModelTestDataCommon
src
xAODTestWriteJVec.cxx
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
3
*/
10
11
12
#include "
xAODTestWriteJVec.h
"
13
#include "
DataModelTestDataCommon/JVecAuxContainer.h
"
14
#include "
DataModelTestDataCommon/JVecAuxInfo.h
"
15
#include "
StoreGate/WriteHandle.h
"
16
#include "
StoreGate/WriteDecorHandle.h
"
17
#include <numeric>
18
19
20
namespace
{
21
22
24
template
<
class
CONT,
class
T>
25
void
xiota (CONT& v, T
x
)
26
{
27
std::iota (
v
.begin(),
v
.end(),
x
);
28
}
29
30
31
}
// anonymous namespace
32
33
34
namespace
DMTest
{
35
36
40
StatusCode
xAODTestWriteJVec::initialize
()
41
{
42
ATH_CHECK
(
m_cvecKey
.initialize() );
43
ATH_CHECK
(
m_jvecContainerKey
.initialize (
SG::AllowEmpty
) );
44
ATH_CHECK
(
m_jvecInfoKey
.initialize (
SG::AllowEmpty
) );
45
ATH_CHECK
(
m_jvecDecorKey
.initialize (
SG::AllowEmpty
) );
46
ATH_CHECK
(
m_jvecInfoDecorKey
.initialize (
SG::AllowEmpty
) );
47
return
StatusCode::SUCCESS;
48
}
49
50
54
StatusCode
xAODTestWriteJVec::execute
(
const
EventContext& ctx)
const
55
{
56
SG::ReadHandle<CVec>
cvec (
m_cvecKey
, ctx);
57
58
if
(!
m_jvecContainerKey
.empty()) {
59
auto
jveccont = std::make_unique<JVecContainer>();
60
auto
jvecauxcont = std::make_unique<JVecAuxContainer>();
61
jveccont->setStore (jvecauxcont.get());
62
63
for
(
size_t
i = 0; i < 5; i++) {
64
jveccont->push_back (std::make_unique<JVec>());
65
ATH_CHECK
(
fillJVec
(
m_cvecKey
.key(), *cvec,
66
i + ctx.evt(),
67
*jveccont->back()) );
68
}
69
70
SG::WriteHandle<JVecContainer>
jvecContH (
m_jvecContainerKey
, ctx);
71
ATH_CHECK
( jvecContH.
record
(std::move (jveccont),
72
std::move (jvecauxcont)) );
73
}
74
75
if
(!
m_jvecInfoKey
.empty()) {
76
auto
jvecinfo = std::make_unique<JVec>();
77
auto
jvecauxinfo = std::make_unique<JVecAuxInfo>();
78
jvecinfo->setStore (jvecauxinfo.get());
79
ATH_CHECK
(
fillJVec
(
m_cvecKey
.key(), *cvec,
80
ctx.evt() + 1001, *jvecinfo) );
81
82
SG::WriteHandle<JVec>
jvecInfoH (
m_jvecInfoKey
, ctx);
83
ATH_CHECK
( jvecInfoH.
record
(std::move (jvecinfo),
84
std::move (jvecauxinfo)) );
85
}
86
87
ATH_CHECK
(
decorJVec
(ctx) );
88
89
return
StatusCode::SUCCESS;
90
}
91
92
93
StatusCode
xAODTestWriteJVec::fillJVec
(
const
std::string& key1,
94
const
CVec
& cvec1,
95
size_t
ndx,
JVec
& jvec)
const
96
{
97
std::vector<int> vi (ndx%5);
98
xiota (vi, ndx+100);
99
jvec.
setIVec
(vi);
100
101
std::vector<float> vf ((ndx+1)%5);
102
xiota (vf, ndx+200.5f);
103
jvec.
setFVec
(vf);
104
105
std::vector<std::string> vs ((ndx+2)%5);
106
for
(
size_t
i = 0; i < vs.size(); i++) {
107
vs[i] =
"str"
+ std::to_string(ndx+i+450);
108
}
109
jvec.
setSVec
(vs);
110
111
std::vector<ElementLink<CVec> > vl ((ndx+3)%5);
112
for
(
size_t
i = 0; i < vl.size(); i++) {
113
if
(!cvec1.
empty
()) {
114
vl[i].resetWithKeyAndIndex (key1, (ndx+i)%cvec1.
size
());
115
}
116
}
117
jvec.
setLVec
(vl);
118
119
return
StatusCode::SUCCESS;
120
}
121
122
123
StatusCode
xAODTestWriteJVec::decorJVec
(
const
EventContext& ctx)
const
124
{
125
if
(!
m_jvecDecorKey
.empty()) {
126
SG::WriteDecorHandle<JVecContainer, SG::JaggedVecElt<double>
> decor (
m_jvecDecorKey
, ctx);
127
size_t
ndx = ctx.evt();
128
for
(
const
JVec
* jvec : *decor) {
129
std::vector<double> vd ((ndx+2)%5);
130
xiota (vd, ndx+300.5f);
131
decor (*jvec) = vd;
132
++ndx;
133
}
134
}
135
136
if
(!
m_jvecInfoDecorKey
.empty()) {
137
SG::WriteDecorHandle<JVec, SG::JaggedVecElt<double>
> decor (
m_jvecInfoDecorKey
, ctx);
138
size_t
ndx = ctx.evt() + 4;
139
std::vector<double> vd ((ndx+2)%5);
140
xiota (vd, ndx+400.5f);
141
decor (*decor) = vd;
142
}
143
144
return
StatusCode::SUCCESS;
145
}
146
147
148
}
// namespace DMTest
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
JVecAuxContainer.h
For testing jagged vectors.
JVecAuxInfo.h
For testing jagged vectors.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
WriteHandle.h
Handle class for recording to StoreGate.
x
#define x
DMTest::JVec_v1::setLVec
void setLVec(std::span< const ElementLink< CVec > > v)
DMTest::JVec_v1::setFVec
void setFVec(std::span< const float > v)
DMTest::JVec_v1::setIVec
void setIVec(std::span< const int > v)
DMTest::JVec_v1::setSVec
void setSVec(std::span< const std::string > v)
DMTest::xAODTestWriteJVec::m_jvecDecorKey
SG::WriteDecorHandleKey< DMTest::JVecContainer > m_jvecDecorKey
Definition
xAODTestWriteJVec.h:68
DMTest::xAODTestWriteJVec::m_jvecInfoDecorKey
SG::WriteDecorHandleKey< DMTest::JVec > m_jvecInfoDecorKey
Definition
xAODTestWriteJVec.h:71
DMTest::xAODTestWriteJVec::m_jvecContainerKey
SG::WriteHandleKey< DMTest::JVecContainer > m_jvecContainerKey
Definition
xAODTestWriteJVec.h:62
DMTest::xAODTestWriteJVec::fillJVec
StatusCode fillJVec(const std::string &key1, const CVec &cvec1, size_t ndx, JVec &jvec) const
Definition
xAODTestWriteJVec.cxx:93
DMTest::xAODTestWriteJVec::m_cvecKey
SG::ReadHandleKey< DMTest::CVec > m_cvecKey
Definition
xAODTestWriteJVec.h:59
DMTest::xAODTestWriteJVec::execute
virtual StatusCode execute(const EventContext &ctx) const override
Algorithm event processing.
Definition
xAODTestWriteJVec.cxx:54
DMTest::xAODTestWriteJVec::m_jvecInfoKey
SG::WriteHandleKey< DMTest::JVec > m_jvecInfoKey
Definition
xAODTestWriteJVec.h:65
DMTest::xAODTestWriteJVec::decorJVec
StatusCode decorJVec(const EventContext &ctx) const
Definition
xAODTestWriteJVec.cxx:123
DMTest::xAODTestWriteJVec::initialize
virtual StatusCode initialize() override
Algorithm initialization; called at the beginning of the job.
Definition
xAODTestWriteJVec.cxx:40
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
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
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
DMTest
Definition
B.h:23
DMTest::CVec
CVec_v1 CVec
Definition
CVec.h:26
DMTest::JVec
JVec_v1 JVec
Definition
JVec.h:23
SG::AllowEmpty
@ AllowEmpty
Definition
StoreGate/StoreGate/VarHandleKey.h:27
python.PyAthena.v
v
Definition
PyAthena.py:153
xAODTestWriteJVec.h
For testing jagged vectors.
Generated on
for ATLAS Offline Software by
1.17.0