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  SG::ConstAccessor<float> dVar1 ("dVar1");
39 
40  ATH_CHECK( m_cvecKey.initialize() );
41  if (!m_writeKey.key().empty())
42  ATH_CHECK( m_writeKey.initialize() );
43  return StatusCode::SUCCESS;
44 }
45 
46 
50 StatusCode xAODTestReadCVec::execute (const EventContext& ctx) const
51 {
53 
54  if (m_brief) {
55  std::ostringstream ost;
56  ost << m_cvecKey.key() << " ";
57  for (const C* c : *cvec) {
58  ost << c->anInt() << " ";
59  }
60  ATH_MSG_INFO (ost.str());
61  return StatusCode::SUCCESS;
62  }
63 
64  const static SG::ConstAccessor<int> anInt2 ("anInt2");
65  const static SG::ConstAccessor<int> anInt10 ("anInt10");
66  const static SG::ConstAccessor<int> dInt1 ("dInt1");
67  const static SG::ConstAccessor<float> dVar1 ("dVar1"); // testing schema evolution
68  const static SG::ConstAccessor<int> dInt100 ("dInt100");
69  const static SG::ConstAccessor<int> dInt150 ("dInt150");
70  const static SG::ConstAccessor<int> dInt200 ("dInt200");
71  const static SG::ConstAccessor<int> dInt250 ("dInt250");
72  const static SG::ConstAccessor<ElementLink<DMTest::CVec> > cEL ("cEL");
73 
74  // Ordering of auxid is not reliable. Sort by name.
76  std::vector<std::string> names;
77  for (SG::auxid_t auxid : cvec->getAuxIDs())
78  names.push_back (r.getName(auxid));
79  std::sort (names.begin(), names.end());
80  std::ostringstream ost1;
81  ost1 << m_cvecKey.key() << " aux items: ";
82  for (const std::string& n : names)
83  ost1 << n << " ";
84  ATH_MSG_INFO (ost1.str());
85  {
86  const SG::IConstAuxStore* auxstore = cvec->getConstStore();
87  ATH_MSG_INFO("Type of aux store: "
88  << System::typeinfoName (typeid (*auxstore)));
89  }
90 
91  for (const C* c : *cvec) {
92  std::ostringstream ost;
93  ost << " anInt1 " << c->anInt()
94  << " aFloat: " << c->aFloat();
95  if (anInt2.isAvailable(*c))
96  ost << " anInt2: " << anInt2(*c);
97  if (dInt1.isAvailable(*c))
98  ost << " dInt1: " << dInt1(*c);
99  if (dVar1.isAvailable(*c))
100  ost << " dVar1: " << dVar1(*c);
101  if (dInt100.isAvailable(*c))
102  ost << " dInt100: " << dInt100(*c);
103  if (dInt150.isAvailable(*c))
104  ost << " dInt150: " << dInt150(*c);
105  if (dInt200.isAvailable(*c))
106  ost << " dInt200: " << dInt200(*c);
107  if (dInt250.isAvailable(*c))
108  ost << " dInt250: " << dInt250(*c);
109  if (anInt10.isAvailable(*c))
110  ost << " anInt10: " << anInt10(*c);
111  if (cEL.isAvailable(*c))
112  ost << " cEL: " << cEL(*c).dataID()
113  << "[" << cEL(*c).index() << "]";
114  ost << "\n";
115 
116  ATH_MSG_INFO (ost.str());
117  }
118 
119  if (!m_writeKey.key().empty()) {
120  auto vecnew = std::make_unique<CVec>();
121  auto store = std::make_unique<CAuxContainer>();
122  vecnew->setStore (store.get());
123  for (size_t i = 0; i < cvec->size(); i++) {
124  vecnew->push_back (new C);
125  *vecnew->back() = *(*cvec)[i];
126  }
128  ATH_CHECK( writevec.record(std::move(vecnew), std::move(store)) );
129  }
130 
131  return StatusCode::SUCCESS;
132 }
133 
134 
135 } // namespace DMTest
136 
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:50
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
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