ATLAS Offline Software
xAODTestReadCVec.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
3  */
12 #include "xAODTestReadCVec.h"
16 #include "StoreGate/ReadHandle.h"
17 #include "StoreGate/WriteHandle.h"
20 #include "AthLinks/ElementLink.h"
22 #include "CxxUtils/StrFormat.h"
23 #include "GaudiKernel/System.h"
24 #include <memory>
25 #include <sstream>
26 
27 
28 namespace DMTest {
29 
30 
35 {
37 
38  if (m_testDecorSE) {
39  SG::ConstAccessor<float> dVar1 ("dVar1");
40  }
41 
42  ATH_CHECK( m_cvecKey.initialize() );
43  if (!m_writeKey.key().empty())
44  ATH_CHECK( m_writeKey.initialize() );
45  return StatusCode::SUCCESS;
46 }
47 
48 
52 StatusCode xAODTestReadCVec::execute (const EventContext& ctx) const
53 {
55 
56  if (m_brief) {
57  std::ostringstream ost;
58  ost << m_cvecKey.key() << " ";
59  for (const C* c : *cvec) {
60  ost << c->anInt() << " ";
61  }
62  ATH_MSG_INFO (ost.str());
63  return StatusCode::SUCCESS;
64  }
65 
66  const static SG::ConstAccessor<int> anInt2 ("anInt2");
67  const static SG::ConstAccessor<int> anInt10 ("anInt10");
68  const static SG::ConstAccessor<int> dInt1 ("dInt1");
69  const static SG::ConstAccessor<int> dInt100 ("dInt100");
70  const static SG::ConstAccessor<int> dInt150 ("dInt150");
71  const static SG::ConstAccessor<int> dInt200 ("dInt200");
72  const static SG::ConstAccessor<int> dInt250 ("dInt250");
73  const static SG::ConstAccessor<ElementLink<DMTest::CVec> > cEL ("cEL");
74 
75  // testing schema evolution
76  const static SG::ConstAccessor<float> dVar1SE (m_testDecorSE ? "dVar1" : "dxVar1");
77  const static SG::ConstAccessor<int> dVar1NoSE (m_testDecorSE ? "dxVar1" : "dVar1");
78 
79  // Ordering of auxid is not reliable. Sort by name.
81  std::vector<std::string> names;
82  for (SG::auxid_t auxid : cvec->getAuxIDs())
83  names.push_back (r.getName(auxid));
84  std::sort (names.begin(), names.end());
85  std::ostringstream ost1;
86  ost1 << m_cvecKey.key() << " aux items: ";
87  for (const std::string& n : names)
88  ost1 << n << " ";
89  ATH_MSG_INFO (ost1.str());
90  {
91  const SG::IConstAuxStore* auxstore = cvec->getConstStore();
92  ATH_MSG_INFO("Type of aux store: "
93  << System::typeinfoName (typeid (*auxstore)));
94  }
95 
96  for (const C* c : *cvec) {
97  std::ostringstream ost;
98  ost << " anInt1 " << c->anInt()
99  << " aFloat: " << c->aFloat();
100  if (anInt2.isAvailable(*c))
101  ost << " anInt2: " << anInt2(*c);
102  if (dInt1.isAvailable(*c))
103  ost << " dInt1: " << dInt1(*c);
104  if (m_testDecorSE) {
105  if (dVar1SE.isAvailable(*c))
106  ost << " dVar1: " << dVar1SE(*c);
107  }
108  else {
109  if (dVar1NoSE.isAvailable(*c))
110  ost << " dVar1: " << dVar1NoSE(*c);
111  }
112  if (dInt100.isAvailable(*c))
113  ost << " dInt100: " << dInt100(*c);
114  if (dInt150.isAvailable(*c))
115  ost << " dInt150: " << dInt150(*c);
116  if (dInt200.isAvailable(*c))
117  ost << " dInt200: " << dInt200(*c);
118  if (dInt250.isAvailable(*c))
119  ost << " dInt250: " << dInt250(*c);
120  if (anInt10.isAvailable(*c))
121  ost << " anInt10: " << anInt10(*c);
122  if (cEL.isAvailable(*c))
123  ost << " cEL: " << cEL(*c).dataID()
124  << "[" << cEL(*c).index() << "]";
125  ost << "\n";
126 
127  ATH_MSG_INFO (ost.str());
128  }
129 
130  if (!m_writeKey.key().empty()) {
131  auto vecnew = std::make_unique<CVec>();
132  auto store = std::make_unique<CAuxContainer>();
133  vecnew->setStore (store.get());
134  for (size_t i = 0; i < cvec->size(); i++) {
135  vecnew->push_back (new C);
136  *vecnew->back() = *(*cvec)[i];
137  }
139  ATH_CHECK( writevec.record(std::move(vecnew), std::move(store)) );
140  }
141 
142  return StatusCode::SUCCESS;
143 }
144 
145 
146 } // namespace DMTest
147 
beamspotman.r
def r
Definition: beamspotman.py:676
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:71
python.trigbs_prescaleL1.ost
ost
Definition: trigbs_prescaleL1.py:104
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:640
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CAuxContainer.h
Class used for testing xAOD data reading/writing.
DMTest::xAODTestReadCVec::execute
virtual StatusCode execute(const EventContext &ctx) const override
Algorithm event processing.
Definition: xAODTestReadCVec.cxx:52
DMTest::C_v1
Definition: C_v1.h:27
SG::ConstAccessor< float >
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition: AuxTypeRegistry.h:61
WriteHandle.h
Handle class for recording to StoreGate.
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
StrFormat.h
Provide helper functions to create formatted strings.
CVec.h
Class used for testing xAOD data reading/writing.
DMTest::xAODTestReadCVec::m_writeKey
SG::WriteHandleKey< DMTest::CVec > m_writeKey
Definition: xAODTestReadCVec.h:53
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
python.subdetectors.mmg.names
names
Definition: mmg.py:8
C.h
Class used for testing xAOD data reading/writing.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DMTest::xAODTestReadCVec::m_testDecorSE
BooleanProperty m_testDecorSE
Definition: xAODTestReadCVec.h:59
errorcheck::ReportMessage::hideErrorLocus
static void hideErrorLocus(bool flag=true)
If set to true, hide the source file and line number in the output.
Definition: errorcheck.cxx:197
errorcheck.h
Helpers for checking error return status codes and reporting errors.
DMTest::xAODTestReadCVec::initialize
virtual StatusCode initialize() override
Algorithm initialization; called at the beginning of the job.
Definition: xAODTestReadCVec.cxx:34
xAODTestReadCVec.h
Algorithm to test reading xAOD data (CVec)
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
DMTest::xAODTestReadCVec::m_brief
BooleanProperty m_brief
Definition: xAODTestReadCVec.h:56
AuxTypeRegistry.h
Handle mappings between names and auxid_t.
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
ReadHandle.h
Handle class for reading from StoreGate.
SG::IConstAuxStore
Interface for const operations on an auxiliary store.
Definition: IConstAuxStore.h:64
python.compressB64.c
def c
Definition: compressB64.py:93
DMTest::xAODTestReadCVec::m_cvecKey
SG::ReadHandleKey< DMTest::CVec > m_cvecKey
Definition: xAODTestReadCVec.h:50
DMTest
Definition: B.h:23