ATLAS Offline Software
Loading...
Searching...
No Matches
AthenaPoolTestDataReader.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
14
15// INCLUDE HEADER FILES:
16
27#include "EventInfo/EventInfo.h"
29#include "EventInfo/EventID.h"
30#include "EventInfo/EventType.h"
32
33#include <algorithm>
34#include <sstream>
35
37 ISvcLocator* pSvcLocator):
38 AthAlgorithm(name, pSvcLocator)
39{}
40
43
45{
46 return StatusCode::SUCCESS;
47}
48
50{
51
52 ATH_MSG_DEBUG("Executing AthenaPoolTestDataReader" );
53
54
55 // Retrieve collections
56
57 // A's only
58
59 std::string test1;
60 std::string test2;
61 bool error = false;
62
64 ATH_CHECK( evtStore()->retrieve(col, "AthenaPoolTestCollection_1") );
65
66
67 ATH_MSG_DEBUG("Collection of A's" );
68 int i = 0;
69 for (const IAthenaPoolTestData* elt : *col) {
70 ATH_MSG_DEBUG( "Read: " << elt->printWhoYouAre() );
71 AthenaPoolTestA data(i+1, i+2);
72 ATH_MSG_DEBUG( "Should be: " << data.printWhoYouAre() );
73 test1 = elt->printWhoYouAre();
74 test2 = data.printWhoYouAre();
75 if (test1 != test2) {
76 ATH_MSG_ERROR( "Incorrect data: in/out " << test1 << " " << test2 );
77 error = true;
78 }
79 ++i;
80 }
81
82
83 // B's only
84
85 ATH_CHECK( evtStore()->retrieve(col, "AthenaPoolTestCollection_2") );
86
87 ATH_MSG_DEBUG("Collection of B's" );
88 i = 0;
89 for (const IAthenaPoolTestData* elt : *col) {
90 ATH_MSG_DEBUG( "Read: " << elt->printWhoYouAre() );
91 AthenaPoolTestB data(i+11, i+12);
92 ATH_MSG_DEBUG( "Should be: " << data.printWhoYouAre() );
93 test1 = elt->printWhoYouAre();
94 test2 = data.printWhoYouAre();
95 if (test1 != test2) {
96 ATH_MSG_ERROR( "Incorrect data: in/out " << test1 << " " << test2 );
97 error = true;
98 }
99 ++i;
100 }
101
102
103 // A's and B's
104
105 ATH_CHECK( evtStore()->retrieve(col, "AthenaPoolTestCollection_3") );
106
107 ATH_MSG_DEBUG("Collection of A's and B's" );
108 i = 0;
109 for (const IAthenaPoolTestData* elt : *col) {
110 ATH_MSG_DEBUG( "Read: " << elt->printWhoYouAre() );
111 if (i < 3) {
112 AthenaPoolTestA data(i+21, i+22);
113 ATH_MSG_DEBUG( "Should be: " << data.printWhoYouAre() );
114 test1 = elt->printWhoYouAre();
115 test2 = data.printWhoYouAre();
116 if (test1 != test2) {
117 ATH_MSG_ERROR( "Incorrect data: in/out " << test1 << " " << test2 );
118 error = true;
119 }
120 }
121 else {
122 AthenaPoolTestB data(i+21, i+22);
123 ATH_MSG_DEBUG( "Should be: " << data.printWhoYouAre() );
124 test1 = elt->printWhoYouAre();
125 test2 = data.printWhoYouAre();
126 if (test1 != test2) {
127 ATH_MSG_ERROR( "Incorrect data: in/out " << test1 << " " << test2 );
128 error = true;
129 }
130 }
131 ++i;
132 }
133
134
135 // C's only
136
137 ATH_CHECK( evtStore()->retrieve(col, "AthenaPoolTestCollection_4") );
138
139 ATH_MSG_DEBUG("Collection of C's" );
140 i = 0;
141 for (const IAthenaPoolTestData* elt : *col) {
142 ATH_MSG_DEBUG( "Read: " << elt->printWhoYouAre() );
143 AthenaPoolTestC data(0, 0, i+3, i+4);
144 ATH_MSG_DEBUG( "Should be: " << data.printWhoYouAre() );
145 test1 = elt->printWhoYouAre();
146 test2 = data.printWhoYouAre();
147 if (test1 != test2) {
148 ATH_MSG_ERROR( "Incorrect data: in/out " << test1 << " " << test2 );
149 error = true;
150 }
151 ++i;
152 }
153
154
155 // D's only
156
157 ATH_CHECK( evtStore()->retrieve(col, "AthenaPoolTestCollection_5") );
158
159 ATH_MSG_DEBUG("Collection of D's" );
160 i = 0;
161 for (const IAthenaPoolTestData* elt : *col) {
162 ATH_MSG_DEBUG( "Read: " << elt->printWhoYouAre() );
163 AthenaPoolTestD data(0, 0, i+13, i+14, i+15, i+16);
164 ATH_MSG_DEBUG( "Should be: " << data.printWhoYouAre() );
165 test1 = elt->printWhoYouAre();
166 test2 = data.printWhoYouAre();
167 if (test1 != test2) {
168 ATH_MSG_ERROR( "Incorrect data: in/out " << test1 << " " << test2 );
169 error = true;
170 }
171 ++i;
172 }
173
174
175 // Test for CLHEP matrix
176
177 // Now create a write 10 Hit objects
178 //bool readMatrix = false;
179 bool readMatrix = true;
180 if (readMatrix) {
181 const AthenaPoolTestMatrix* matrix = nullptr;
182 for ( int i = 0; i < 3; ++i ) {
183 std::stringstream stream;
184 stream << "AthenaPoolTestMatrix_" << i;
185 std::string key(stream.str());
186 ATH_CHECK( evtStore()->retrieve(matrix, key) );
187 ATH_MSG_DEBUG("Retrieved matrix " << i + 1 << " " << key );
188
189 const HepGeom::Point3D<double>& point = matrix->point();
190 const HepGeom::Point3D<double>& point1 = matrix->point1();
191 ATH_MSG_DEBUG(" Points (by value,by ptr) x,y,z : "
192 << point.x() << " "
193 << point.y() << " "
194 << point.z() << " "
195 << ", x,y,z "
196 << point1.x() << " "
197 << point1.y() << " "
198 << point1.z() << " ");
199 const CLHEP::HepMatrix& smallMatrix = matrix->smallMatrix();
200 ATH_MSG_DEBUG(" Small matrix : ( " << smallMatrix.num_row() << ", " << smallMatrix.num_col() << " ) " );
201 stream.clear();
202 stream << " values: ";
203 for (int i = 0; i < smallMatrix.num_row(); ++i) {
204 for (int j = 0; j < smallMatrix.num_col(); ++ j) {
205 stream << smallMatrix[i][j] << ", ";
206 }
207 }
208 ATH_MSG_VERBOSE(stream.str());
209
210 const CLHEP::HepMatrix& bigMatrix = matrix->bigMatrix();
211 ATH_MSG_DEBUG(" Big matrix : ( " << bigMatrix.num_row() << ", " << bigMatrix.num_col() << " ) " );
212 stream.clear();
213 stream << " values: ";
214 for (int i = 0; i < bigMatrix.num_row(); ++i) {
215 for (int j = 0; j < bigMatrix.num_col(); ++ j) {
216 stream << bigMatrix[i][j] << ", ";
217 }
218 }
219 ATH_MSG_VERBOSE(stream.str());
220 ATH_MSG_DEBUG(" Other matrices : " );
221 for ( int ii = 0; ii < matrix->numberOfMatrices(); ++ii ) {
222 const CLHEP::HepMatrix& matrx = matrix->matrix( ii );
223 ATH_MSG_DEBUG(" ( " << matrx.num_row() << ", " << matrx.num_col() << " ) " );
224 stream.clear();
225 stream << " values: ";
226 for (int i = 0; i < matrx.num_row(); ++i) {
227 for (int j = 0; j < matrx.num_col(); ++ j) {
228 stream << matrx[i][j] << ", ";
229 }
230 }
231 ATH_MSG_VERBOSE(stream.str());
232 }
233
234 // print out matrix maps
235 AthenaPoolTestMatrix::matrixMaps_t mats = matrix->matrixMaps();
236
237 ATH_MSG_DEBUG(" Matrix maps : " << mats.size() );
238 std::map<unsigned int, CLHEP::HepMatrix>& mp0 = mats[0];
239 std::map<unsigned int, CLHEP::HepMatrix>& mp1 = mats[1];
240 std::map<unsigned int, CLHEP::HepMatrix>::const_iterator itmp = mp0.begin();
241 ATH_MSG_DEBUG(" Key, row, column " << (*itmp).first << " "
242 << (*itmp).second.num_row() << ", " << (*itmp).second.num_col() );
243 ++itmp;
244 ATH_MSG_DEBUG(" Key, row, column " << (*itmp).first << " "
245 << (*itmp).second.num_row() << ", " << (*itmp).second.num_col() );
246 itmp = mp1.begin();
247 ATH_MSG_DEBUG(" Key, row, column " << (*itmp).first << " "
248 << (*itmp).second.num_row() << ", " << (*itmp).second.num_col() );
249 ++itmp;
250 ATH_MSG_DEBUG(" Key, row, column " << (*itmp).first << " "
251 << (*itmp).second.num_row() << ", " << (*itmp).second.num_col() );
252
253 // Print out the transform:
254 ATH_MSG_DEBUG(" Matrix transform: " );
255 const HepGeom::Transform3D& trans = matrix->trans();
256 ATH_MSG_DEBUG(" Matrix transform: " );
257 ATH_MSG_DEBUG(" xx " << trans(0,0) );
258 ATH_MSG_DEBUG(" xy " << trans(0,1) );
259 ATH_MSG_DEBUG(" xz " << trans(0,2) );
260 ATH_MSG_DEBUG(" yx " << trans(1,0) );
261 ATH_MSG_DEBUG(" yy " << trans(1,1) );
262 ATH_MSG_DEBUG(" yz " << trans(1,2) );
263 ATH_MSG_DEBUG(" zx " << trans(2,0) );
264 ATH_MSG_DEBUG(" zy " << trans(2,1) );
265 ATH_MSG_DEBUG(" zz " << trans(2,2) );
266 ATH_MSG_DEBUG(" dx " << trans(3,0) );
267 ATH_MSG_DEBUG(" dy " << trans(3,1) );
268 ATH_MSG_DEBUG(" dz " << trans(3,2) );
269
270 }
271 }
272
273
274
275 // Read in nested collections
276
277 bool readMap = true;
278 const AthenaPoolTestMap* tmapPtr;
279 if (evtStore()->retrieve(tmapPtr, "AthenaPoolMap").isFailure()) {
280 ATH_MSG_ERROR("Unable to retrieve AthenaPoolMap object ");
281 readMap = false;
282 }
283 else {
284 ATH_MSG_DEBUG("Retrieved AthenaPoolMap" );
285 }
286
287 if (readMap) {
288
289 const AthenaPoolTestMap& tmap = *tmapPtr;
290
291 typedef AthenaPoolTestMapData::Deposit deposit_t;
292 typedef std::vector<deposit_t> deposit_vec;
293
294 deposit_vec deposits;
295
296 //deposit_t deposit;
297
298 // Printout data
299 AthenaPoolTestMap::const_iterator itm = tmap.begin();
300 AthenaPoolTestMap::const_iterator endm = tmap.end();
301 for (; itm != endm; ++itm) {
302
303 std::stringstream stream;
304 stream << "AthenaPoolTestMap: key " << (*itm).first
305 << " word " << (*itm).second.word()
306 << " Deposits: (barCode, evtIndx, wgt) ";
307
308 deposits.clear();
309 (*itm).second.deposits(deposits);
310 for (unsigned int i = 0; i < deposits.size(); ++i) {
311 AthenaPoolTestMapDataLink& link = deposits[i].first;
312 stream << link.barcode() << " "
313 << link.eventIndex() << " "
314 << deposits[i].second << " ";
315 }
316 ATH_MSG_DEBUG(stream.str());
317 }
318 }
319
320
321 // Read back dummy classes
322
323 const dummy_A* dummyA;
324 if (evtStore()->retrieve(dummyA, "Dummy_A").isFailure() ) {
325 ATH_MSG_ERROR("Could not retrieve Dummy_A");
326 }
327 else {
328 ATH_MSG_DEBUG("Read back dummy_A class " );
329 }
330 const std::vector<dummy_B>& b = dummyA->dummy();
331 ATH_MSG_DEBUG("Dummy A: size B " << b.size() );
332 for (unsigned int i = 0; i < b.size(); ++i) {
333 const std::vector<dummy_C>& c = b[i].dummy();
334 ATH_MSG_DEBUG("Dummy B: size C " << c.size() );
335 for (unsigned int j = 0; j < c.size(); ++j) {
336 ATH_MSG_DEBUG("i,c: " << j << " " << c[j].value() );
337 }
338 }
339
340 // dummy_E, D
341
342 const dummy_E* dummyE;
343 ATH_CHECK( evtStore()->retrieve(dummyE, "Dummy_E") );
344 const std::vector<const dummy_D*>& d = dummyE->dummy();
345 ATH_MSG_DEBUG("Dummy E: size D " << d.size() );
346 for (unsigned int i = 0; i < d.size(); ++i) {
347 ATH_MSG_DEBUG("Dummy D: value " << d[i]->value() );
348 }
349
350
351 // Read PileupEventInfo
352
353 // Normal EventInfo
354 const EventInfo * evt = nullptr;
355 ATH_CHECK( evtStore()->retrieve( evt, "McEventInfo" ) );
356 ATH_MSG_DEBUG( "Normal EventInfo" );
357 ATH_MSG_DEBUG( "Event ID: ["
358 << evt->event_ID()->event_number() << ":"
359 << evt->event_ID()->time_stamp() << "] " );
360 ATH_MSG_DEBUG( *(evt->event_ID()) );
361 {
362 std::stringstream stream;
363 stream << "Event type: user type "
364 << evt->event_type()->user_type();
365 for (unsigned int i = 0; i < evt->event_type()->n_mc_event_weights (); ++i)
366 stream<< " weight " << i << ": " << evt->event_type()->mc_event_weight(i);
367 ATH_MSG_DEBUG(stream.str());
368 }
369
370 // Check interactions per crossing
371 ATH_MSG_DEBUG( "Actual interatctions per crossing: "
372 << evt->actualInteractionsPerCrossing() << " and ave: "
373 << evt->averageInteractionsPerCrossing() );
374
375 // We only loop up to Lumi and not nDets since Lumi is set separately
376 for (unsigned int i = 0; i < EventInfo::Lumi; ++i) {
377 ATH_MSG_DEBUG( "Subdet: " << i << " flags "
378 << MSG::hex << evt->eventFlags(EventInfo::EventFlagSubDet(i)) << MSG::dec );
379 EventInfo::EventFlagErrorState error = evt->errorState(EventInfo::EventFlagSubDet(i));
380 if (error == EventInfo::NotSet)
381 ATH_MSG_DEBUG( "Subdet: " << i << " error state: NotSet " );
382 else if (error == EventInfo::Warning)
383 ATH_MSG_DEBUG( "Subdet: " << i << " error state: Warning " );
384 else if (error == EventInfo::Error)
385 ATH_MSG_DEBUG( "Subdet: " << i << " error state: Error " );
386 }
387
388
389 // PileupEventInfo as itself
390 const PileUpEventInfo* pevt = nullptr;
391 ATH_CHECK( evtStore()->retrieve( pevt, "OverlayEvent" ) );
392 ATH_MSG_DEBUG( "PileUpEventInfo" );
393 ATH_MSG_DEBUG( "Event ID: ["
394 << pevt->event_ID()->run_number() << ","
395 << pevt->event_ID()->event_number() << ":"
396 << pevt->event_ID()->time_stamp() << "] " );
397 ATH_MSG_DEBUG( *(pevt->event_ID()) );
398 ATH_MSG_DEBUG( "Event type: user type "
399 << pevt->event_type()->user_type() );
400
401 {
402 std::stringstream stream;
403 stream << "Trigger info: status " << pevt->trigger_info()->statusElement()
404 << " extLvl1ID " << pevt->trigger_info()->extendedLevel1ID()
405 << " lvl1Type " << pevt->trigger_info()->level1TriggerType()
406 << " lvl1Info ";
407 for (unsigned int i = 0; i < pevt->trigger_info()->level1TriggerInfo().size(); ++i) {
408 stream << pevt->trigger_info()->level1TriggerInfo()[i] << " ";
409 }
410 stream << "lvl2Info ";
411 for (unsigned int i = 0; i < pevt->trigger_info()->level2TriggerInfo().size(); ++i) {
412 stream << pevt->trigger_info()->level2TriggerInfo()[i] << " ";
413 }
414 stream << "EventFilterInfo ";
415 for (unsigned int i = 0; i < pevt->trigger_info()->eventFilterInfo().size(); ++i) {
416 stream << pevt->trigger_info()->eventFilterInfo()[i] << " ";
417 }
418 stream << "EventFilterInfo ";
419 for (unsigned int i = 0; i < pevt->trigger_info()->streamTags().size(); ++i) {
420 stream << " i " << i << " name " << pevt->trigger_info()->streamTags()[i].name();
421 stream << " type " << pevt->trigger_info()->streamTags()[i].type();
422 stream << " ObeyLumi " << pevt->trigger_info()->streamTags()[i].obeysLumiblock();
423 }
424 ATH_MSG_DEBUG(stream.str());
425 }
426
427 // Get normal event info as a sub-event info
428 ATH_MSG_DEBUG( "SubEventInfos" );
429 PileUpEventInfo::SubEvent::const_iterator it = pevt->beginSubEvt();
430 PileUpEventInfo::SubEvent::const_iterator end = pevt->endSubEvt();
431 if (it == end) {
432 ATH_MSG_DEBUG( "None found" );
433 }
434 for (; it != end; ++it) {
435 const EventInfo* sevt = (*it).pSubEvt;
436 ATH_MSG_DEBUG( "Time, index "
437 << (*it).time() << " " << (*it).index() );
438 if (sevt) {
439 ATH_MSG_DEBUG( "Event ID: ["
440 << sevt->event_ID()->run_number() << ","
441 << sevt->event_ID()->event_number() << ":"
442 << sevt->event_ID()->time_stamp() << "] " );
443 ATH_MSG_DEBUG( "Event type: user type "
444 << sevt->event_type()->user_type() );
445 ATH_MSG_DEBUG( "Pileup time, index type "
446 << it->time() << " " << it->index() );
447 }
448 else {
449 ATH_MSG_DEBUG( "Subevent is null ptr " );
450 }
451 }
452
453 if (error) return (StatusCode::FAILURE);
454
455 return StatusCode::SUCCESS;
456}
457
459{
460 return StatusCode::SUCCESS;
461}
462
463
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Class definition for AthenaPoolTestA.
Class definition for AthenaPoolTestB.
Class definition for AthenaPoolTestC.
Class definition for AthenaPoolTestD.
Test Algorithm for POOL I/O tests, reads AthenaPoolData objects from the transient store.
Class definition for AthenaPoolTestMatrix.
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
This class provides general information about an event.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Class definition for IAthenaPoolTestCollection.
This class provides information about an overlaid event.
size_t size() const
Number of registered mappings.
This class contains trigger related information.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Simple class with two int's for testing pool i/o from Athena.
Simple class with int,int,float,double for testing pool i/o from Athena.
Simple class with four int's divided among protected/private for testing pool i/o from Athena.
Simple class with HepGeom::Point3D<double> for testing pool i/o from Athena.
~AthenaPoolTestDataReader()
Algorithm destructor.
virtual StatusCode execute()
Algorithm execute once per event.
virtual StatusCode finalize()
Algorithm finalize at end of job.
virtual StatusCode initialize()
Algorithm initialize at begin of job.
AthenaPoolTestDataReader(const std::string &name, ISvcLocator *pSvcLocator)
Algorithm constructor.
std::pair< AthenaPoolTestMapDataLink, float > Deposit
Simple class with various CLHEP classes for testing pool i/o from Athena.
std::vector< std::map< unsigned int, CLHEP::HepMatrix > > matrixMaps_t
EventID * event_ID()
the unique identification of the event.
TriggerInfo * trigger_info()
trigger information (ptr may be NULL)
EventType * event_type()
the type of the event, e.g. simulation, testbeam, etc
std::string user_type(void) const
Access to user type.
Definition EventType.cxx:94
Interface class for AthenaPoolTest i/o tests with DataVector.
Interface class for AthenaPoolTest i/o tests.
This class provides information about an overlaid event.
SubEvent::iterator endSubEvt()
SubEvent::iterator beginSubEvt()
number_type level1TriggerType() const
get level1 trigger type
const std::vector< number_type > & eventFilterInfo() const
get event filter trigger info
number_type extendedLevel1ID() const
get extended level1 ID
number_type statusElement() const
get status element
const std::vector< number_type > & level1TriggerInfo() const
get level1 trigger info
const std::vector< StreamTag > & streamTags() const
get stream tags
const std::vector< number_type > & level2TriggerInfo() const
get level2 trigger info
test nested vectors - problem seen in root3/4 transition
Definition dummy_A.h:51
const std::vector< dummy_B > & dummy() const
Definition dummy_A.h:55
Test derived class that contains a list of parent classes.
Definition dummy_E.h:42
const std::vector< const dummy_D * > & dummy() const
Definition dummy_E.h:47
int test1(int argc, char *argv[])