ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
DataModelTest
DataModelTestDataCommon
src
xAODTestReadCVec.cxx
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration.
3
*/
10
11
12
#include "
xAODTestReadCVec.h
"
13
#include "
DataModelTestDataCommon/CVec.h
"
14
#include "
DataModelTestDataCommon/C.h
"
15
#include "
DataModelTestDataCommon/CAuxContainer.h
"
16
#include "
StoreGate/ReadHandle.h
"
17
#include "
StoreGate/WriteHandle.h
"
18
#include "
AthContainers/AuxTypeRegistry.h
"
19
#include "
AthContainers/ConstAccessor.h
"
20
#include "AthLinks/ElementLink.h"
21
#include "
AthenaKernel/errorcheck.h
"
22
#include "GaudiKernel/System.h"
23
#include <memory>
24
#include <print>
25
#include <sstream>
26
27
28
namespace
DMTest
{
29
30
34
StatusCode
xAODTestReadCVec::initialize
()
35
{
36
errorcheck::ReportMessage::hideErrorLocus
();
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
{
54
SG::ReadHandle<DMTest::CVec>
cvec (
m_cvecKey
, ctx);
55
56
if
(
m_brief
) {
57
std::ostringstream ost;
58
std::print (ost,
"{} "
,
m_cvecKey
.key());
59
for
(
const
C
* c : *cvec) {
60
std::print (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.
80
const
SG::AuxTypeRegistry
&
r
=
SG::AuxTypeRegistry::instance
();
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
ATH_MSG_INFO
(
"{} aux items: {:n:s}"
,
m_cvecKey
.key(), names);
86
{
87
const
SG::IConstAuxStore* auxstore = cvec->getConstStore();
88
ATH_MSG_INFO
(
"Type of aux store: {}"
,
89
System::typeinfoName (
typeid
(*auxstore)));
90
}
91
92
for
(
const
C
* c : *cvec) {
93
std::ostringstream ost;
94
std::print (ost,
" anInt1 {} aFloat: {}"
, c->anInt(), c->aFloat());
95
if
(anInt2.
isAvailable
(*c))
96
std::print (ost,
" anInt2: {}"
, anInt2(*c));
97
if
(dInt1.
isAvailable
(*c))
98
std::print (ost,
" dInt1: {}"
, dInt1(*c));
99
if
(
m_testDecorSE
) {
100
if
(dVar1SE.
isAvailable
(*c))
101
std::print (ost,
" dVar1: {}"
, dVar1SE(*c));
102
}
103
else
{
104
if
(dVar1NoSE.
isAvailable
(*c))
105
std::print (ost,
" dVar1: {}"
, dVar1NoSE(*c));
106
}
107
if
(dInt100.
isAvailable
(*c))
108
std::print (ost,
" dInt100: {}"
, dInt100(*c));
109
if
(dInt150.
isAvailable
(*c))
110
std::print (ost,
" dInt150: {}"
, dInt150(*c));
111
if
(dInt200.
isAvailable
(*c))
112
std::print (ost,
" dInt200: {}"
, dInt200(*c));
113
if
(dInt250.
isAvailable
(*c))
114
std::print (ost,
" dInt250: {}"
, dInt250(*c));
115
if
(anInt10.
isAvailable
(*c))
116
std::print (ost,
" anInt10: {}"
, anInt10(*c));
117
if
(cEL.
isAvailable
(*c))
118
std::print (ost,
" cEL: {}[{}]"
,
119
cEL(*c).dataID(), cEL(*c).index());
120
std::println (ost);
121
122
ATH_MSG_INFO
(ost.str());
123
}
124
125
if
(!
m_writeKey
.key().empty()) {
126
auto
vecnew = std::make_unique<CVec>();
127
auto
store = std::make_unique<CAuxContainer>();
128
vecnew->setStore (store.get());
129
for
(
size_t
i = 0; i < cvec->size(); i++) {
130
vecnew->push_back (
new
C
);
131
*vecnew->back() = *(*cvec)[i];
132
}
133
SG::WriteHandle<DMTest::CVec>
writevec (
m_writeKey
, ctx);
134
ATH_CHECK
( writevec.
record
(std::move(vecnew), std::move(store)) );
135
}
136
137
return
StatusCode::SUCCESS;
138
}
139
140
141
}
// namespace DMTest
142
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
AuxTypeRegistry.h
Handle mappings between names and auxid_t.
CAuxContainer.h
Class used for testing xAOD data reading/writing.
CVec.h
Class used for testing xAOD data reading/writing.
C.h
Class used for testing xAOD data reading/writing.
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
errorcheck.h
Helpers for checking error return status codes and reporting errors.
ReadHandle.h
Handle class for reading from StoreGate.
WriteHandle.h
Handle class for recording to StoreGate.
DMTest::xAODTestReadCVec::initialize
virtual StatusCode initialize() override
Algorithm initialization; called at the beginning of the job.
Definition
xAODTestReadCVec.cxx:34
DMTest::xAODTestReadCVec::execute
virtual StatusCode execute(const EventContext &ctx) const override
Algorithm event processing.
Definition
xAODTestReadCVec.cxx:52
DMTest::xAODTestReadCVec::m_testDecorSE
BooleanProperty m_testDecorSE
Definition
xAODTestReadCVec.h:59
DMTest::xAODTestReadCVec::m_cvecKey
SG::ReadHandleKey< DMTest::CVec > m_cvecKey
Definition
xAODTestReadCVec.h:50
DMTest::xAODTestReadCVec::m_brief
BooleanProperty m_brief
Definition
xAODTestReadCVec.h:56
DMTest::xAODTestReadCVec::m_writeKey
SG::WriteHandleKey< DMTest::CVec > m_writeKey
Definition
xAODTestReadCVec.h:53
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition
AuxTypeRegistry.h:61
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition
AuxTypeRegistry.cxx:640
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition
ConstAccessor.h:55
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:66
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:71
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
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
r
int r
Definition
globals.cxx:22
DMTest
Definition
B.h:23
DMTest::C
C_v1 C
Definition
C.h:26
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition
AuxTypes.h:27
std::sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition
DVL_algorithms.h:554
xAODTestReadCVec.h
Algorithm to test reading xAOD data (CVec).
Generated on
for ATLAS Offline Software by
1.17.0