ATLAS Offline Software
Loading...
Searching...
No Matches
xAODTestRead.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
10
11
12#include "xAODTestRead.h"
25#include <memory>
26#include <sstream>
27
28
29namespace DMTest {
30
31
36{
37 ATH_CHECK( m_ctrigReadKey.initialize() );
39 ATH_CHECK( m_cvecWDReadKey.initialize() );
43 return StatusCode::SUCCESS;
44}
45
46
50StatusCode xAODTestRead::execute (const EventContext& ctx) const
51{
52 ATH_MSG_INFO (ctx.evt()+1);
53
54 static const C::Accessor<int> anInt2 ("anInt2");
55 static const C::Accessor<int> anInt10 ("anInt10");
56 static const C::Accessor<int> dInt1 ("dInt1");
57 static const C::Accessor<int> dInt100 ("dInt100");
58 static const C::Accessor<int> dInt150 ("dInt150");
59 static const C::Accessor<int> dInt200 ("dInt200");
60
61 // Ordering of auxid is not reliable. Sort by name.
63 std::vector<std::string> names;
64
66
67 names.clear();
68 for (SG::auxid_t auxid : ctrig->getAuxIDs())
69 names.push_back (r.getName(auxid));
70 std::sort (names.begin(), names.end());
71 std::ostringstream ost1;
72 ost1 << "ctrig aux items: ";
73 for (const std::string& n : names)
74 ost1 << n << " ";
75 ATH_MSG_INFO (ost1.str());
76
77 for (const C* c : *ctrig) {
78 std::ostringstream ost;
79 ost << " anInt1 " << c->anInt()
80 << " aFloat: " << c->aFloat()
81 << " anInt2: " << anInt2(*c)
82 << " dInt1: " << dInt1(*c);
83 if (dInt100.isAvailable(*c))
84 ost << " dInt100: " << dInt100(*c);
85 if (dInt150.isAvailable(*c))
86 ost << " dInt150: " << dInt150(*c);
87 if (dInt200.isAvailable(*c))
88 ost << " dInt200: " << dInt200(*c);
89 if (anInt10.isAvailable(*c))
90 ost << " anInt10: " << anInt10(*c);
91 ATH_MSG_INFO (ost.str());
92 }
93
94 if (!m_ctrigWriteKey.empty()) {
95 auto ctrignew = std::make_unique<CVec>();
96 auto trig_store = std::make_unique<CTrigAuxContainer>();
97 ctrignew->setStore (trig_store.get());
98 for (size_t i = 0; i < ctrig->size(); i++) {
99 ctrignew->push_back (new C);
100 *ctrignew->back() = *(*ctrig)[i];
101 }
102 SG::WriteHandle<CVec> ctrigWrite (m_ctrigWriteKey, ctx);
103 ATH_CHECK( ctrigWrite.record (std::move(ctrignew),
104 std::move(trig_store)) );
105 }
106
107 if (!m_gvecReadKey.empty()) {
108 ATH_CHECK( read_gvec (ctx) );
109 }
110
112 //ATH_CHECK( read_cview() );
113
114 return StatusCode::SUCCESS;
115}
116
117
121StatusCode xAODTestRead::read_cvec_with_data (const EventContext& ctx) const
122{
124
125 static const C::Accessor<int> anInt10 ("anInt10");
126 std::ostringstream ost;
127 ost << m_cvecWDReadKey.key() << " " << vec->meta1 << ":";
128 for (const C* c : *vec) {
129 ost << " " << c->anInt();
130 if (anInt10.isAvailable(*c))
131 ost << "(" << anInt10(*c) << ")";
132 }
133 ATH_MSG_INFO (ost.str());
134
135 if (!m_cvecWDWriteKey.empty()) {
136 auto vecnew = std::make_unique<CVecWithData>();
137 auto store = std::make_unique<CAuxContainer>();
138 vecnew->setStore (store.get());
139 for (size_t i = 0; i < vec->size(); i++) {
140 vecnew->push_back (new C);
141 *vecnew->back() = *(*vec)[i];
142 }
144 ATH_CHECK( cvecWDWrite.record (std::move(vecnew),
145 std::move(store)) );
146 }
147
148 return StatusCode::SUCCESS;
149}
150
151
155StatusCode xAODTestRead::read_gvec (const EventContext& ctx) const
156{
159
160 std::vector<std::string> names;
161 for (SG::auxid_t auxid : gvec->getAuxIDs())
162 names.push_back (r.getName(auxid));
163 std::sort (names.begin(), names.end());
164 std::ostringstream ost3;
165 ost3 << "gvec aux items: ";
166 for (const std::string& n : names)
167 ost3 << n << " ";
168 ost3 << "\n";
169 for (const G* g : *gvec) {
170 ost3 << " anInt " << g->anInt();
171 ost3 << " gFloat " << g->gFloat();
172 ost3 << " gvFloat ";
173 for (float f : g->gvFloat())
174 ost3 << f << " ";
175 ost3 << "\n";
176 }
177 ATH_MSG_INFO (ost3.str());
178
179 if (!m_gvecWriteKey.empty()) {
180 auto gvecnew = std::make_unique<GVec>();
181 auto gstore = std::make_unique<GAuxContainer>();
182 gvecnew->setStore (gstore.get());
183 for (size_t i = 0; i < gvec->size(); i++) {
184 gvecnew->push_back (new G);
185 *gvecnew->back() = *(*gvec)[i];
186 }
187 SG::WriteHandle<GVec> gvecWrite (m_gvecWriteKey, ctx);
188 ATH_CHECK( gvecWrite.record (std::move(gvecnew),
189 std::move(gstore)) );
190 }
191
192 return StatusCode::SUCCESS;
193}
194
195
196#if 0
200StatusCode xAODTestRead::read_cview() const
201{
202 if (!evtStore()->contains<CView> (m_readPrefix + "cview")) {
203 ATH_MSG_INFO( "(No " << m_readPrefix << "cview view container.)" );
204 return StatusCode::SUCCESS;
205 }
206
207 const CView* cview = nullptr;
208 static const C::Accessor<int> anInt10 ("anInt10");
209 CHECK( evtStore()->retrieve (cview, m_readPrefix + "cview") );
210 std::ostringstream ost;
211 ost << m_readPrefix << "cview:";
212 for (const C* c : *cview) {
213 ost << " " << c->anInt();
214 if (anInt10.isAvailable(*c))
215 ost << "(" << anInt10(*c) << ")";
216 }
217 ATH_MSG_INFO (ost.str());
218
219 if (!m_writePrefix.empty()) {
220 bool LOCKED = false;
221 CHECK (evtStore()->record (std::make_unique<CView> (*cview),
222 m_writePrefix + "cview", LOCKED));
223 }
224
225 return StatusCode::SUCCESS;
226}
227#endif
228
229
234{
235 return StatusCode::SUCCESS;
236}
237
238
239} // namespace DMTest
240
#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.
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.
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
Handle mappings between names and auxid_t.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
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:114
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.