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-2024 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 <sstream>
25
26
27
namespace
DMTest
{
28
29
33
StatusCode
xAODTestReadCVec::initialize
()
34
{
35
errorcheck::ReportMessage::hideErrorLocus
();
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
51
StatusCode
xAODTestReadCVec::execute
(
const
EventContext& ctx)
const
52
{
53
SG::ReadHandle<DMTest::CVec>
cvec (
m_cvecKey
, ctx);
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.
79
const
SG::AuxTypeRegistry
&
r
=
SG::AuxTypeRegistry::instance
();
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
}
137
SG::WriteHandle<DMTest::CVec>
writevec (
m_writeKey
, ctx);
138
ATH_CHECK
( writevec.
record
(std::move(vecnew), std::move(store)) );
139
}
140
141
return
StatusCode::SUCCESS;
142
}
143
144
145
}
// namespace DMTest
146
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:33
DMTest::xAODTestReadCVec::execute
virtual StatusCode execute(const EventContext &ctx) const override
Algorithm event processing.
Definition
xAODTestReadCVec.cxx:51
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