ATLAS Offline Software
xAODTestWriteJVec.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
3  */
12 #include "xAODTestWriteJVec.h"
15 #include "StoreGate/WriteHandle.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 
41 {
42  ATH_CHECK( m_cvecKey.initialize() );
44  ATH_CHECK( m_jvecInfoKey.initialize (SG::AllowEmpty) );
45  ATH_CHECK( m_jvecDecorKey.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 
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 
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()) {
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
DMTest::JVec_v1::setSVec
void setSVec(const std::vector< std::string > &v)
Definition: JVec_v1.cxx:49
DMTest::xAODTestWriteJVec::m_jvecInfoDecorKey
SG::WriteDecorHandleKey< DMTest::JVec > m_jvecInfoDecorKey
Definition: xAODTestWriteJVec.h:71
DMTest::JVec_v1::setIVec
void setIVec(const std::vector< int > &v)
Definition: JVec_v1.cxx:25
DMTest::xAODTestWriteJVec::m_jvecDecorKey
SG::WriteDecorHandleKey< DMTest::JVecContainer > m_jvecDecorKey
Definition: xAODTestWriteJVec.h:68
DMTest::JVec_v1::setLVec
void setLVec(const std::vector< ElementLink< CVec > > &v)
Definition: JVec_v1.cxx:61
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
x
#define x
DMTest::xAODTestWriteJVec::m_cvecKey
SG::ReadHandleKey< DMTest::CVec > m_cvecKey
Definition: xAODTestWriteJVec.h:59
DMTest::JVec_v1
For testing jagged vectors.
Definition: JVec_v1.h:36
WriteHandle.h
Handle class for recording to StoreGate.
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
hist_file_dump.f
f
Definition: hist_file_dump.py:135
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
DMTest::xAODTestWriteJVec::decorJVec
StatusCode decorJVec(const EventContext &ctx) const
Definition: xAODTestWriteJVec.cxx:123
xAODTestWriteJVec.h
For testing jagged vectors.
DMTest::xAODTestWriteJVec::m_jvecContainerKey
SG::WriteHandleKey< DMTest::JVecContainer > m_jvecContainerKey
Definition: xAODTestWriteJVec.h:62
DMTest::JVec_v1::setFVec
void setFVec(const std::vector< float > &v)
Definition: JVec_v1.cxx:37
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
python.PyAthena.v
v
Definition: PyAthena.py:154
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
JVecAuxInfo.h
For testing jagged vectors.
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
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::fillJVec
StatusCode fillJVec(const std::string &key1, const CVec &cvec1, size_t ndx, JVec &jvec) const
Definition: xAODTestWriteJVec.cxx:93
JVecAuxContainer.h
For testing jagged vectors.
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
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.
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
DMTest::xAODTestWriteJVec::initialize
virtual StatusCode initialize() override
Algorithm initialization; called at the beginning of the job.
Definition: xAODTestWriteJVec.cxx:40
DMTest
Definition: B.h:23
module_driven_slicing.key1
key1
Definition: module_driven_slicing.py:158