ATLAS Offline Software
xAODTestWritePLinks.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 "xAODTestWritePLinks.h"
15 #include "StoreGate/WriteHandle.h"
17 #include "StoreGate/ReadHandle.h"
18 
19 
20 namespace DMTest {
21 
22 
27 {
28  ATH_CHECK( m_cvecKey.initialize() );
29  ATH_CHECK( m_ctrigKey.initialize() );
36  return StatusCode::SUCCESS;
37 }
38 
39 
43 StatusCode xAODTestWritePLinks::execute (const EventContext& ctx) const
44 {
45  SG::ReadHandle<CVec> cvec (m_cvecKey, ctx);
46  SG::ReadHandle<CVec> ctrig (m_ctrigKey, ctx);
47 
48  if (!m_plinksContainerKey.empty()) {
49  auto plinkscont = std::make_unique<PLinksContainer>();
50  auto plinksauxcont = std::make_unique<PLinksAuxContainer>();
51  plinkscont->setStore (plinksauxcont.get());
52  for (size_t i = 0; i < 5; i++) {
53  plinkscont->push_back (std::make_unique<PLinks>());
54  ATH_CHECK( fillPLinks (m_cvecKey.key(), *cvec,
55  m_ctrigKey.key(), *ctrig,
56  i + ctx.evt(),
57  *plinkscont->back()) );
58  }
59 
61  ATH_CHECK( plinksContH.record (std::move (plinkscont),
62  std::move (plinksauxcont)) );
63  }
64 
65  if (!m_plinksInfoKey.empty()) {
66  auto plinksinfo = std::make_unique<PLinks>();
67  auto plinksauxinfo = std::make_unique<PLinksAuxInfo>();
68  plinksinfo->setStore (plinksauxinfo.get());
69  ATH_CHECK( fillPLinks (m_cvecKey.key(), *cvec,
70  m_ctrigKey.key(), *ctrig,
71  ctx.evt() + 3,
72  *plinksinfo) );
73 
74  SG::WriteHandle<PLinks> plinksInfoH (m_plinksInfoKey, ctx);
75  ATH_CHECK( plinksInfoH.record (std::move (plinksinfo),
76  std::move (plinksauxinfo)) );
77  }
78 
79  ATH_CHECK( decorPLinks (ctx,
80  m_cvecKey.key(), *cvec,
81  m_ctrigKey.key(), *ctrig) );
82 
83  return StatusCode::SUCCESS;
84 }
85 
86 
87 auto xAODTestWritePLinks::makeLink (const std::string& key1,
88  const CVec& cvec1,
89  const std::string& key2,
90  const CVec& cvec2,
91  size_t ndx) const -> EL
92 {
93  if ((ndx%3) == 0 && !cvec1.empty()) {
94  return EL (key1, (ndx % cvec1.size()));
95  }
96  else if ((ndx%3) == 1 && !cvec2.empty()) {
97  return EL (key2, (ndx % cvec2.size()));
98  }
99  // else leave it null
100  return EL();
101 }
102 
103 
105  const CVec& cvec1,
106  const std::string& key2,
107  const CVec& cvec2,
108  size_t ndx,
109  PLinks& plinks) const
110 {
111  plinks.setPLink (makeLink (key1, cvec1, key2, cvec2, ndx));
112  std::vector<EL> v;
113  for (size_t i = 0; i < ndx%5; ++i) {
114  v.emplace_back (makeLink (key1, cvec1, key2, cvec2, ndx+i+1));
115  }
116  plinks.setVLinks (v);
117  return StatusCode::SUCCESS;
118 }
119 
120 
122  const std::string& key1,
123  const CVec& cvec1,
124  const std::string& key2,
125  const CVec& cvec2) const
126 {
127  if (!m_plinksDecorLinkKey.empty()) {
129  size_t ndx = ctx.evt();
130  for (const PLinks* plinks : *decor) {
131  decor (*plinks) = makeLink (key1, cvec1, key2, cvec2, ndx);
132  ++ndx;
133  }
134  }
135 
136  if (!m_plinksDecorVLinksKey.empty()) {
138  size_t ndx = ctx.evt() + 3;
139  for (const PLinks* plinks : *decor) {
140  std::vector<EL> v;
141  for (size_t i = 0; i < ndx%5; ++i) {
142  v.emplace_back (makeLink (key1, cvec1, key2, cvec2, ndx+i+1));
143  }
144  decor (*plinks) = v;
145  ++ndx;
146  }
147  }
148 
149  if (!m_plinksInfoDecorLinkKey.empty()) {
151  size_t ndx = ctx.evt() + 4;
152  decor (*decor) = makeLink (key1, cvec1, key2, cvec2, ndx);
153  }
154 
155  if (!m_plinksInfoDecorVLinksKey.empty()) {
157  size_t ndx = ctx.evt() + 7;
158  std::vector<EL> v;
159  for (size_t i = 0; i < ndx%5; ++i) {
160  v.emplace_back (makeLink (key1, cvec1, key2, cvec2, ndx+i+1));
161  }
162  decor (*decor) = v;
163  }
164 
165  return StatusCode::SUCCESS;
166 }
167 
168 
169 } // namespace DMTest
DMTest::EL
ElementLink< CVec > EL
Definition: xAODTestWriteCLinks.cxx:22
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
module_driven_slicing.key2
key2
Definition: module_driven_slicing.py:159
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.
PLinksAuxContainer.h
For testing packed links.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
python.PyAthena.v
v
Definition: PyAthena.py:154
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
PLinksAuxInfo.h
For testing packed links.
ReadHandle.h
Handle class for reading from StoreGate.
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
DMTest
Definition: B.h:23
module_driven_slicing.key1
key1
Definition: module_driven_slicing.py:158