ATLAS Offline Software
Loading...
Searching...
No Matches
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"
17#include <numeric>
18
19
20namespace {
21
22
24template <class CONT, class T>
25void xiota (CONT& v, T x)
26{
27 std::iota (v.begin(), v.end(), x);
28}
29
30
31} // anonymous namespace
32
33
34namespace DMTest {
35
36
41{
42 ATH_CHECK( m_cvecKey.initialize() );
47 return StatusCode::SUCCESS;
48}
49
50
54StatusCode xAODTestWriteJVec::execute (const EventContext& ctx) const
55{
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
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
93StatusCode 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
123StatusCode xAODTestWriteJVec::decorJVec (const EventContext& ctx) const
124{
125 if (!m_jvecDecorKey.empty()) {
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()) {
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
#define ATH_CHECK
Evaluate an expression and check for errors.
For testing jagged vectors.
For testing jagged vectors.
Handle class for adding a decoration to an object.
Handle class for recording to StoreGate.
#define x
void setFVec(const std::vector< float > &v)
Definition JVec_v1.cxx:37
void setIVec(const std::vector< int > &v)
Definition JVec_v1.cxx:25
void setLVec(const std::vector< ElementLink< CVec > > &v)
Definition JVec_v1.cxx:61
void setSVec(const std::vector< std::string > &v)
Definition JVec_v1.cxx:49
SG::WriteDecorHandleKey< DMTest::JVecContainer > m_jvecDecorKey
SG::WriteDecorHandleKey< DMTest::JVec > m_jvecInfoDecorKey
SG::WriteHandleKey< DMTest::JVecContainer > m_jvecContainerKey
StatusCode fillJVec(const std::string &key1, const CVec &cvec1, size_t ndx, JVec &jvec) const
SG::ReadHandleKey< DMTest::CVec > m_cvecKey
virtual StatusCode execute(const EventContext &ctx) const override
Algorithm event processing.
SG::WriteHandleKey< DMTest::JVec > m_jvecInfoKey
StatusCode decorJVec(const EventContext &ctx) const
virtual StatusCode initialize() override
Algorithm initialization; called at the beginning of the job.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
Handle class for adding a decoration to an object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Definition B.h:23
CVec_v1 CVec
Definition CVec.h:26
JVec_v1 JVec
Definition JVec.h:23
For testing jagged vectors.