ATLAS Offline Software
Loading...
Searching...
No Matches
DMTestRead.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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 <print>
35#include <sstream>
36#include <cassert>
37
38
39namespace DMTest {
40
41
47DMTestRead::DMTestRead (const std::string& name, ISvcLocator* pSvcLocator)
48 : AthAlgorithm (name, pSvcLocator)
49{
50}
51
52
57template <class VEC>
58StatusCode DMTestRead::print_vec (const std::string& key) const
59{
60 if (!evtStore()->contains<VEC> (key))
61 {
62 ATH_MSG_INFO("{} not in SG; ignored.", key);
63 return StatusCode::SUCCESS;
64 }
65
66 const VEC* vec = nullptr;
67 ATH_CHECK( evtStore()->retrieve (vec, key) );
68 std::ostringstream ost;
69 std::print (ost, "{} as {}: ", key, ClassName<VEC>::name());
70 for (unsigned i=0; i < vec->size(); i++)
71 std::print (ost, "{} ", (*vec)[i]->m_x);
72 ATH_MSG_INFO (ost.str());
73
74 return StatusCode::SUCCESS;
75}
76
77
78StatusCode DMTestRead::print_elvec (const std::string& key) const
79{
80 const ELVec* vec = nullptr;
81 ATH_CHECK( evtStore()->retrieve (vec, key) );
82 std::vector<ElementLink<BVec> > el = vec->m_el;
83 std::ostringstream ost;
84 std::print (ost, "{}: ", key);
85 for (size_t i = 0; i < el.size(); i++) {
86 const DMTest::B* b = *el[i];
87 el[i].toPersistent();
88 std::print (ost, "{} ", b->m_x);
89 }
90 ATH_MSG_INFO (ost.str());
91 return StatusCode::SUCCESS;
92}
93
94
95StatusCode DMTestRead::remap_test() const
96{
97 const ELVec* vec = nullptr;
98 ATH_CHECK( evtStore()->retrieve (vec, "elv_remap") );
99
101 std::vector<ElementLink<BVec> > el2; // Transient
102 el2.resize (vec->m_el2_p.size());
103 for (size_t i=0; i < vec->m_el2_p.size(); i++)
104 elcnv.persToTrans (&vec->m_el2_p[i], &el2[i], msg());
105
106 std::ostringstream ost1;
107 std::print (ost1, "elv_remap: ");
108 for (size_t i = 0; i < el2.size(); i++) {
109 const DMTest::B* b = *el2[i];
110 std::print (ost1, "{} ", b->m_x);
111 }
112 ATH_MSG_INFO (ost1.str());
113
115 ElementLinkVector<BVec> elv2; // Transient
116 elvcnv.persToTrans (&vec->m_elv2_p, &elv2, msg());
117
118 std::ostringstream ost2;
119 std::print (ost2, "elv_remap v2: ");
120 for (size_t i = 0; i < elv2.size(); i++) {
121 const DMTest::B* b = *elv2[i];
122 std::print (ost2, "{} ", b->m_x);
123 }
124 ATH_MSG_INFO (ost2.str());
125
127 std::vector<DataLink<BVec> > dl2; // Transient
128 dl2.resize (vec->m_dl2_p.size());
129 for (size_t i=0; i < vec->m_dl2_p.size(); i++)
130 dlcnv.persToTrans (&vec->m_dl2_p[i], &dl2[i], msg());
131
132 const BVec* b3 = nullptr;
133 ATH_CHECK( evtStore()->retrieve (b3, "b3") );
134 assert (dl2[0].cptr() == b3);
135 assert (dl2[1].cptr() == b3);
136
137 return StatusCode::SUCCESS;
138}
139
140
144StatusCode DMTestRead::execute(const EventContext& /*ctx*/)
145{
146 // Test reading our four types.
147 ATH_CHECK( print_vec<BVec> ("bvec") );
148 ATH_CHECK( print_vec<BDer> ("bder") );
149 ATH_CHECK( print_vec<DVec> ("dvec") );
150 ATH_CHECK( print_vec<DDer> ("dder") );
151
152 // Test using implicit symlinks.
153 ATH_CHECK( print_vec<BVec> ("bder") );
154 ATH_CHECK( print_vec<BVec> ("dvec") );
155 ATH_CHECK( print_vec<BVec> ("dder") );
156 ATH_CHECK( print_vec<DVec> ("dder") );
157
158 ATH_CHECK( print_elvec ("elvec") );
159
161
162 return StatusCode::SUCCESS;
163}
164
165} // namespace DMTest
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x,...)
std::vector< size_t > vec
Helpers for checking error return status codes and reporting errors.
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.
ServiceHandle< StoreGateSvc > & evtStore()
static std::string name()
Return the name of class T as a string.
StatusCode remap_test() const
StatusCode print_elvec(const std::string &key) const
DMTestRead(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
virtual StatusCode execute(const EventContext &ctx) override
Algorithm event processing.
StatusCode print_vec(const std::string &key) const
Print out one of our test objects of type VEC from storegate.
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
ElementLinkVector implementation for standalone ROOT.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:116
Definition B.h:23
DataVector< DMTest::B > BVec
A DataVector containing the base class, B.
Base contained class for DataVector tests.
Definition B.h:34