ATLAS Offline Software
Loading...
Searching...
No Matches
xAODTestRead.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
10
11
12#include "xAODTestRead.h"
25#include <memory>
26#include <print>
27#include <sstream>
28
29
30namespace DMTest {
31
32
37{
38 ATH_CHECK( m_ctrigReadKey.initialize() );
40 ATH_CHECK( m_cvecWDReadKey.initialize() );
44 return StatusCode::SUCCESS;
45}
46
47
51StatusCode xAODTestRead::execute (const EventContext& ctx) const
52{
53 ATH_MSG_INFO (ctx.evt()+1);
54
55 static const C::Accessor<int> anInt2 ("anInt2");
56 static const C::Accessor<int> anInt10 ("anInt10");
57 static const C::Accessor<int> dInt1 ("dInt1");
58 static const C::Accessor<int> dInt100 ("dInt100");
59 static const C::Accessor<int> dInt150 ("dInt150");
60 static const C::Accessor<int> dInt200 ("dInt200");
61
62 // Ordering of auxid is not reliable. Sort by name.
64 std::vector<std::string> names;
65
67
68 names.clear();
69 for (SG::auxid_t auxid : ctrig->getAuxIDs())
70 names.push_back (r.getName(auxid));
71 std::sort (names.begin(), names.end());
72 ATH_MSG_INFO ("ctrig aux items: {:n:s}", names);
73
74 for (const C* c : *ctrig) {
75 std::ostringstream ost;
76 std::print (ost, " anInt1 {} aFloat: {} anInt2: {} dInt1: {}",
77 c->anInt(), c->aFloat(), anInt2(*c), dInt1(*c));
78 if (dInt100.isAvailable(*c))
79 std::print (ost, " dInt100: {}", dInt100(*c));
80 if (dInt150.isAvailable(*c))
81 std::print (ost, " dInt150: {}", dInt150(*c));
82 if (dInt200.isAvailable(*c))
83 std::print (ost, " dInt200: {}", dInt200(*c));
84 if (anInt10.isAvailable(*c))
85 std::print (ost, " anInt10: {}", anInt10(*c));
86 ATH_MSG_INFO (ost.str());
87 }
88
89 if (!m_ctrigWriteKey.empty()) {
90 auto ctrignew = std::make_unique<CVec>();
91 auto trig_store = std::make_unique<CTrigAuxContainer>();
92 ctrignew->setStore (trig_store.get());
93 for (size_t i = 0; i < ctrig->size(); i++) {
94 ctrignew->push_back (new C);
95 *ctrignew->back() = *(*ctrig)[i];
96 }
97 SG::WriteHandle<CVec> ctrigWrite (m_ctrigWriteKey, ctx);
98 ATH_CHECK( ctrigWrite.record (std::move(ctrignew),
99 std::move(trig_store)) );
100 }
101
102 if (!m_gvecReadKey.empty()) {
103 ATH_CHECK( read_gvec (ctx) );
104 }
105
107 //ATH_CHECK( read_cview() );
108
109 return StatusCode::SUCCESS;
110}
111
112
116StatusCode xAODTestRead::read_cvec_with_data (const EventContext& ctx) const
117{
119
120 static const C::Accessor<int> anInt10 ("anInt10");
121 std::ostringstream ost;
122 std::print (ost, "{} {}:", m_cvecWDReadKey.key(), vec->meta1);
123 for (const C* c : *vec) {
124 std::print (ost, " {}", c->anInt());
125 if (anInt10.isAvailable(*c))
126 std::print (ost, "({})", anInt10(*c));
127 }
128 ATH_MSG_INFO (ost.str());
129
130 if (!m_cvecWDWriteKey.empty()) {
131 auto vecnew = std::make_unique<CVecWithData>();
132 auto store = std::make_unique<CAuxContainer>();
133 vecnew->setStore (store.get());
134 for (size_t i = 0; i < vec->size(); i++) {
135 vecnew->push_back (new C);
136 *vecnew->back() = *(*vec)[i];
137 }
139 ATH_CHECK( cvecWDWrite.record (std::move(vecnew),
140 std::move(store)) );
141 }
142
143 return StatusCode::SUCCESS;
144}
145
146
150StatusCode xAODTestRead::read_gvec (const EventContext& ctx) const
151{
154
155 std::vector<std::string> names;
156 for (SG::auxid_t auxid : gvec->getAuxIDs())
157 names.push_back (r.getName(auxid));
158 std::sort (names.begin(), names.end());
159 std::ostringstream ost3;
160 std::println (ost3, "gvec aux items: {:n:s}", names);
161 for (const G* g : *gvec) {
162 std::println (ost3, " anInt {} gFloat {} gvFloat {:n}",
163 g->anInt(), g->gFloat(), g->gvFloat());
164 }
165 ATH_MSG_INFO (ost3.str());
166
167 if (!m_gvecWriteKey.empty()) {
168 auto gvecnew = std::make_unique<GVec>();
169 auto gstore = std::make_unique<GAuxContainer>();
170 gvecnew->setStore (gstore.get());
171 for (size_t i = 0; i < gvec->size(); i++) {
172 gvecnew->push_back (new G);
173 *gvecnew->back() = *(*gvec)[i];
174 }
175 SG::WriteHandle<GVec> gvecWrite (m_gvecWriteKey, ctx);
176 ATH_CHECK( gvecWrite.record (std::move(gvecnew),
177 std::move(gstore)) );
178 }
179
180 return StatusCode::SUCCESS;
181}
182
183
184#if 0
188StatusCode xAODTestRead::read_cview() const
189{
190 if (!evtStore()->contains<CView> (m_readPrefix + "cview")) {
191 ATH_MSG_INFO( "(No {}cview view container.)", m_readPrefix );
192 return StatusCode::SUCCESS;
193 }
194
195 const CView* cview = nullptr;
196 static const C::Accessor<int> anInt10 ("anInt10");
197 CHECK( evtStore()->retrieve (cview, m_readPrefix + "cview") );
198 std::ostringstream ost;
199 std::print (ost, "{}cview:", m_readPrefix);
200 for (const C* c : *cview) {
201 std::print (ost, " {}", c->anInt());
202 if (anInt10.isAvailable(*c))
203 std::print (ost, "({})", anInt10(*c));
204 }
205 ATH_MSG_INFO (ost.str());
206
207 if (!m_writePrefix.empty()) {
208 bool LOCKED = false;
209 CHECK (evtStore()->record (std::make_unique<CView> (*cview),
210 m_writePrefix + "cview", LOCKED));
211 }
212
213 return StatusCode::SUCCESS;
214}
215#endif
216
217
222{
223 return StatusCode::SUCCESS;
224}
225
226
227} // namespace DMTest
228
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x,...)
Handle mappings between names and auxid_t.
Class used for testing xAOD data reading/writing.
Class used for testing xAOD data reading/writing.
Test writing a container with metadata.
Class used for testing xAOD data reading/writing.
Class used for testing xAOD data reading/writing.
std::vector< size_t > vec
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
Test for xAOD auto schema evolution.
Test for xAOD auto schema evolution.
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
ServiceHandle< StoreGateSvc > & evtStore()
StatusCode read_cvec_with_data(const EventContext &ctx) const
Test reading container with additional data.
SG::WriteHandleKey< DMTest::CVec > m_ctrigWriteKey
SG::WriteHandleKey< DMTest::GVec > m_gvecWriteKey
SG::ReadHandleKey< DMTest::GVec > m_gvecReadKey
virtual StatusCode finalize() override
Algorithm finalization; called at the end of the job.
SG::WriteHandleKey< DMTest::CVecWithData > m_cvecWDWriteKey
StatusCode read_gvec(const EventContext &ctx) const
Test reading GVec object.
virtual StatusCode execute(const EventContext &ctx) const override
Algorithm event processing.
virtual StatusCode initialize() override
Algorithm initialization; called at the beginning of the job.
SG::ReadHandleKey< DMTest::CVecWithData > m_cvecWDReadKey
SG::ReadHandleKey< DMTest::CVec > m_ctrigReadKey
Test reading view container.
Handle mappings between names and auxid_t.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
int r
Definition globals.cxx:22
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:116
struct color C
Definition B.h:23
C_v1 C
Definition C.h:26
CView_v1 CView
Definition CView.h:26
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Algorithm to test reading xAOD data.