ATLAS Offline Software
Loading...
Searching...
No Matches
xAODTestReadCVec.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
3 */
10
11
12#include "xAODTestReadCVec.h"
20#include "AthLinks/ElementLink.h"
22#include "GaudiKernel/System.h"
23#include <memory>
24#include <sstream>
25
26
27namespace DMTest {
28
29
34{
36
37 if (m_testDecorSE) {
38 SG::ConstAccessor<float> dVar1 ("dVar1");
39 }
40
41 ATH_CHECK( m_cvecKey.initialize() );
42 if (!m_writeKey.key().empty())
43 ATH_CHECK( m_writeKey.initialize() );
44 return StatusCode::SUCCESS;
45}
46
47
51StatusCode xAODTestReadCVec::execute (const EventContext& ctx) const
52{
54
55 if (m_brief) {
56 std::ostringstream ost;
57 ost << m_cvecKey.key() << " ";
58 for (const C* c : *cvec) {
59 ost << c->anInt() << " ";
60 }
61 ATH_MSG_INFO (ost.str());
62 return StatusCode::SUCCESS;
63 }
64
65 const static SG::ConstAccessor<int> anInt2 ("anInt2");
66 const static SG::ConstAccessor<int> anInt10 ("anInt10");
67 const static SG::ConstAccessor<int> dInt1 ("dInt1");
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 // testing schema evolution
75 const static SG::ConstAccessor<float> dVar1SE (m_testDecorSE ? "dVar1" : "dxVar1");
76 const static SG::ConstAccessor<int> dVar1NoSE (m_testDecorSE ? "dxVar1" : "dVar1");
77
78 // Ordering of auxid is not reliable. Sort by name.
80 std::vector<std::string> names;
81 for (SG::auxid_t auxid : cvec->getAuxIDs())
82 names.push_back (r.getName(auxid));
83 std::sort (names.begin(), names.end());
84 std::ostringstream ost1;
85 ost1 << m_cvecKey.key() << " aux items: ";
86 for (const std::string& n : names)
87 ost1 << n << " ";
88 ATH_MSG_INFO (ost1.str());
89 {
90 const SG::IConstAuxStore* auxstore = cvec->getConstStore();
91 ATH_MSG_INFO("Type of aux store: "
92 << System::typeinfoName (typeid (*auxstore)));
93 }
94
95 for (const C* c : *cvec) {
96 std::ostringstream ost;
97 ost << " anInt1 " << c->anInt()
98 << " aFloat: " << c->aFloat();
99 if (anInt2.isAvailable(*c))
100 ost << " anInt2: " << anInt2(*c);
101 if (dInt1.isAvailable(*c))
102 ost << " dInt1: " << dInt1(*c);
103 if (m_testDecorSE) {
104 if (dVar1SE.isAvailable(*c))
105 ost << " dVar1: " << dVar1SE(*c);
106 }
107 else {
108 if (dVar1NoSE.isAvailable(*c))
109 ost << " dVar1: " << dVar1NoSE(*c);
110 }
111 if (dInt100.isAvailable(*c))
112 ost << " dInt100: " << dInt100(*c);
113 if (dInt150.isAvailable(*c))
114 ost << " dInt150: " << dInt150(*c);
115 if (dInt200.isAvailable(*c))
116 ost << " dInt200: " << dInt200(*c);
117 if (dInt250.isAvailable(*c))
118 ost << " dInt250: " << dInt250(*c);
119 if (anInt10.isAvailable(*c))
120 ost << " anInt10: " << anInt10(*c);
121 if (cEL.isAvailable(*c))
122 ost << " cEL: " << cEL(*c).dataID()
123 << "[" << cEL(*c).index() << "]";
124 ost << "\n";
125
126 ATH_MSG_INFO (ost.str());
127 }
128
129 if (!m_writeKey.key().empty()) {
130 auto vecnew = std::make_unique<CVec>();
131 auto store = std::make_unique<CAuxContainer>();
132 vecnew->setStore (store.get());
133 for (size_t i = 0; i < cvec->size(); i++) {
134 vecnew->push_back (new C);
135 *vecnew->back() = *(*cvec)[i];
136 }
138 ATH_CHECK( writevec.record(std::move(vecnew), std::move(store)) );
139 }
140
141 return StatusCode::SUCCESS;
142}
143
144
145} // namespace DMTest
146
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x,...)
Handle mappings between names and auxid_t.
Class used for testing xAOD data reading/writing.
Class used for testing xAOD data reading/writing.
Class used for testing xAOD data reading/writing.
Helper class to provide constant type-safe access to aux data.
Helpers for checking error return status codes and reporting errors.
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
virtual StatusCode initialize() override
Algorithm initialization; called at the beginning of the job.
virtual StatusCode execute(const EventContext &ctx) const override
Algorithm event processing.
BooleanProperty m_testDecorSE
SG::ReadHandleKey< DMTest::CVec > m_cvecKey
SG::WriteHandleKey< DMTest::CVec > m_writeKey
Handle mappings between names and auxid_t.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
static void hideErrorLocus(bool flag=true)
If set to true, hide the source file and line number in the output.
int r
Definition globals.cxx:22
Definition B.h:23
C_v1 C
Definition C.h:26
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Algorithm to test reading xAOD data (CVec).