ATLAS Offline Software
Loading...
Searching...
No Matches
DMTestRead.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
16
17#undef NDEBUG
18
19#include "DMTestRead.h"
30#include "GaudiKernel/MsgStream.h"
33#include <iostream>
34#include <sstream>
35#include <cassert>
36
37
38namespace DMTest {
39
40
46DMTestRead::DMTestRead (const std::string& name, ISvcLocator* pSvcLocator)
47 : AthAlgorithm (name, pSvcLocator)
48{
49}
50
51namespace {
52
53
59template <class VEC>
60StatusCode print_vec (MsgStream& log,
61 StoreGateSvc* sg,
62 const std::string& key,
63 const std::string& context)
64{
65 if (!sg->contains<VEC> (key))
66 {
67 log << MSG::INFO << key << " not in SG; ignored." << endmsg;
68 return StatusCode::SUCCESS;
69 }
70
71 const VEC* vec;
72 CHECK_WITH_CONTEXT( sg->retrieve (vec, key), context );
73 std::ostringstream ost;
74 ost << key << " as " << ClassName<VEC>::name() << ": ";
75 for (unsigned i=0; i < vec->size(); i++)
76 ost << (*vec)[i]->m_x << " ";
77 log << MSG::INFO << ost.str() << endmsg;
78
79 return StatusCode::SUCCESS;
80}
81
82
83StatusCode print_elvec (MsgStream& log,
84 StoreGateSvc* sg,
85 const std::string& key,
86 const std::string& context)
87{
88 const ELVec* vec;
89 CHECK_WITH_CONTEXT( sg->retrieve (vec, key), context );
90 std::vector<ElementLink<BVec> > el = vec->m_el;
91 std::ostringstream ost;
92 ost << key << ": ";
93 for (size_t i = 0; i < el.size(); i++) {
94 const DMTest::B* b = *el[i];
95 el[i].toPersistent();
96 ost << b->m_x << " ";
97 }
98 log << MSG::INFO << ost.str() << endmsg;
99 return StatusCode::SUCCESS;
100}
101
102
103StatusCode remap_test (MsgStream& log, StoreGateSvc* sg)
104{
105 const ELVec* vec;
106 CHECK_WITH_CONTEXT( sg->retrieve (vec, "elv_remap"), "remap_test" );
107
108 ElementLinkCnv_p3<ElementLink<BVec> > elcnv;
109 std::vector<ElementLink<BVec> > el2; // Transient
110 el2.resize (vec->m_el2_p.size());
111 for (size_t i=0; i < vec->m_el2_p.size(); i++)
112 elcnv.persToTrans (&vec->m_el2_p[i], &el2[i], log);
113
114 std::ostringstream ost1;
115 ost1 << "elv_remap: ";
116 for (size_t i = 0; i < el2.size(); i++) {
117 const DMTest::B* b = *el2[i];
118 ost1 << b->m_x << " ";
119 }
120 log << MSG::INFO << ost1.str() << endmsg;
121
122 ElementLinkVectorCnv_p1<ElementLinkVector<BVec> > elvcnv;
123 ElementLinkVector<BVec> elv2; // Transient
124 elvcnv.persToTrans (&vec->m_elv2_p, &elv2, log);
125
126 std::ostringstream ost2;
127 ost2 << "elv_remap v2: ";
128 for (size_t i = 0; i < elv2.size(); i++) {
129 const DMTest::B* b = *elv2[i];
130 ost2 << b->m_x << " ";
131 }
132 log << MSG::INFO << ost2.str() << endmsg;
133
134 DataLinkCnv_p1<DataLink<BVec> > dlcnv;
135 std::vector<DataLink<BVec> > dl2; // Transient
136 dl2.resize (vec->m_dl2_p.size());
137 for (size_t i=0; i < vec->m_dl2_p.size(); i++)
138 dlcnv.persToTrans (&vec->m_dl2_p[i], &dl2[i], log);
139
140 const BVec* b3;
141 CHECK_WITH_CONTEXT( sg->retrieve (b3, "b3"), "remap_test" );
142 assert (dl2[0].cptr() == b3);
143 assert (dl2[1].cptr() == b3);
144
145 return StatusCode::SUCCESS;
146}
147
148
149} // anonymous namespace
150
151
156{
157 StoreGateSvc* sg = &*evtStore();
158
159 // Test reading our four types.
160 CHECK( print_vec<BVec> (msg(), sg, "bvec", name()) );
161 CHECK( print_vec<BDer> (msg(), sg, "bder", name()) );
162 CHECK( print_vec<DVec> (msg(), sg, "dvec", name()) );
163 CHECK( print_vec<DDer> (msg(), sg, "dder", name()) );
164
165 // Test using implicit symlinks.
166 CHECK( print_vec<BVec> (msg(), sg, "bder", name()) );
167 CHECK( print_vec<BVec> (msg(), sg, "dvec", name()) );
168 CHECK( print_vec<BVec> (msg(), sg, "dder", name()) );
169 CHECK( print_vec<DVec> (msg(), sg, "dder", name()) );
170
171 CHECK( print_elvec (msg(), sg, "elvec", name()) );
172
173 CHECK( remap_test (msg(), sg) );
174
175 return StatusCode::SUCCESS;
176}
177
178} // namespace DMTest
#define endmsg
std::vector< size_t > vec
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
#define CHECK_WITH_CONTEXT(...)
Evaluate an expression and check for errors, with an explicitly specified context name.
This file contains the class definition for the DataLinkCnv_p1 class and DataLinkVectorCnv_p1 class.
Class used for testing the new DataVector inheritance scheme.
Class used for testing the new DataVector inheritance scheme.
Class used for testing the new DataVector inheritance scheme.
Class used for testing new ElementLink.
This file contains the class definition for the ElementLinkCnv_p3 class.
This file contains the class definition for the ElementLinkVectorCnv_p1 class.
Define macros for attributes used to control the static checker.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
MsgStream & msg() const
static std::string name()
Return the name of class T as a string.
DMTestRead(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
virtual StatusCode execute() override
Algorithm event processing.
virtual void persToTrans(const PersDLink_t *pers, DLink_t *trans, MsgStream &log) const override
void persToTrans(const PersLink_t &pers, Link_t &trans, MsgStream &log) const
void persToTrans(const PersLinkVect_t &pers, LinkVect_t &trans, MsgStream &log) const
The Athena Transient Store API.
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
bool contains(const TKEY &key) const
Look up a keyed object in TDS (compare also tryRetrieve) returns false if object not available in TDS...
Definition B.h:23
DataVector< DMTest::B > BVec
A DataVector containing the base class, B.
::StatusCode StatusCode
StatusCode definition for legacy code.