ATLAS Offline Software
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 
17 #undef NDEBUG
18 
19 #include "DMTestRead.h"
29 #include "StoreGate/StoreGateSvc.h"
30 #include "GaudiKernel/MsgStream.h"
33 #include <iostream>
34 #include <sstream>
35 #include <cassert>
36 
37 
38 namespace DMTest {
39 
40 
46 DMTestRead::DMTestRead (const std::string& name, ISvcLocator* pSvcLocator)
47  : AthAlgorithm (name, pSvcLocator)
48 {
49 }
50 
51 namespace {
52 
53 
59 template <class VEC>
60 StatusCode 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 
83 StatusCode 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 
103 StatusCode remap_test (MsgStream& log, StoreGateSvc* sg)
104 {
105  const ELVec* vec;
106  CHECK_WITH_CONTEXT( sg->retrieve (vec, "elv_remap"), "remap_test" );
107 
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 
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 
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
StoreGateSvc::contains
bool contains(const TKEY &key) const
Look up a keyed object in TDS (compare also tryRetrieve) returns false if object not available in TDS...
ElementLinkCnv_p3
Definition: ElementLinkCnv_p3.h:27
DMTestRead.h
CHECK_WITH_CONTEXT
#define CHECK_WITH_CONTEXT(...)
Evaluate an expression and check for errors, with an explicitly specified context name.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:396
ElementLinkCnv_p3.h
This file contains the class definition for the ElementLinkCnv_p3 class.
python.trigbs_prescaleL1.ost
ost
Definition: trigbs_prescaleL1.py:104
ElementLinkCnv_p3::persToTrans
void persToTrans(const PersLink_t &pers, Link_t &trans, MsgStream &log) const
ELVec.h
Class used for testing new ElementLink.
DataLinkCnv_p1.h
This file contains the class definition for the DataLinkCnv_p1 class and DataLinkVectorCnv_p1 class.
ElementLinkVectorCnv_p1
Definition: ElementLinkVectorCnv_p1.h:28
BDer.h
DVec.h
Class used for testing the new DataVector inheritance scheme.
ElementLinkVectorCnv_p1.h
This file contains the class definition for the ElementLinkVectorCnv_p1 class. NOTE: it should be inc...
ElementLinkVector
ElementLinkVector implementation for standalone ROOT.
Definition: AthLinks/ElementLinkVector.h:65
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
ElementLinkVectorCnv_p1::persToTrans
void persToTrans(const PersLinkVect_t &pers, LinkVect_t &trans, MsgStream &log) const
StoreGateSvc::retrieve
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:125
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DMTest::DMTestRead::execute
virtual StatusCode execute() override
Algorithm event processing.
Definition: DMTestRead.cxx:155
ClassName::name
static std::string name()
Return the name of class T as a string.
DMTest::B
Base contained class for DataVector tests.
Definition: B.h:34
DataLinkCnv_p1::persToTrans
virtual void persToTrans(const PersDLink_t *pers, DLink_t *trans, MsgStream &log) const override
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
AthAlgorithm
Definition: AthAlgorithm.h:47
ClassName.h
BVec.h
Class used for testing the new DataVector inheritance scheme.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
errorcheck.h
Helpers for checking error return status codes and reporting errors.
DMTest::BVec
DataVector< DMTest::B > BVec
A DataVector containing the base class, B.
Definition: DataModelTestDataRead/DataModelTestDataRead/BVec.h:35
DDer.h
Class used for testing the new DataVector inheritance scheme.
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
ElementLinkVector::size
size_type size() const
Definition: AthLinks/ElementLinkVector.h:294
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
checker_macros.h
Define macros for attributes used to control the static checker.
StoreGateSvc.h
DMTest
Definition: B.h:23
DataLinkCnv_p1
Definition: DataLinkCnv_p1.h:23
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
DMTest::DMTestRead::DMTestRead
DMTestRead(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: DMTestRead.cxx:46