ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
StoreGateTests
python
StoreGateTests/python/Lib.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
3
# @file: StoreGateTests/python/Lib.py
4
# @purpose: a set of Py-components to tests py-record performances
5
# @author: Sebastien Binet <binet@cern.ch>
6
7
from
AthenaPython.PyAthena
import
StatusCode
8
import
AthenaPython.PyAthena
as
PyAthena
9
import
ROOT
10
11
class
PySgStressProducer
(
PyAthena.Alg
):
12
"""A simple python algorithm to create PayLoads
13
"""
14
def
__init__
(self, name = "PySgStressProducer", **kw):
15
16
kw[
'name'
] = name
17
super(PySgStressProducer,self).
__init__
(**kw)
18
19
if
'DataName'
not
in
kw: self.
DataName
=
"MyData"
20
if
'NbrOfObjects'
not
in
kw: self.
NbrOfObjects
= 1000
21
if
'ObjectsSize'
not
in
kw: self.
ObjectsSize
= 100
22
if
'UseDataPool'
not
in
kw: self.
UseDataPool
=
False
23
24
def
initialize
(self):
25
self.
msg
.info(
"Initializing %s"
, self.
name
)
26
self.
sg
= PyAthena.py_svc (
"StoreGateSvc"
)
27
if
not
self.
sg
:
28
self.
msg
.error (
"could not retrieve event store"
)
29
return
StatusCode.Failure
30
#PyROOTFixes.fix_dv_container( "SgTests::PayLoadDv" )
31
return
StatusCode.Success
32
33
def
execute
(self):
34
self.
msg
.
debug
(
"Executing %s..."
, self.
name
)
35
if
self.
createData
() != StatusCode.Success:
36
self.
msg
.
error
(
"Could not create PayLoad data !!"
)
37
return
StatusCode.Failure
38
return
StatusCode.Success
39
40
def
createData
(self):
41
_makePayLoadDv = PyAthena.SgTests.PayLoadDv
42
_makePayLoad = PyAthena.SgTests.PayLoad
43
_sg_record = self.
sg
.record
44
_sg_setConst = self.
sg
.setConst
45
46
allGood =
True
47
for
i
in
range(self.
NbrOfObjects
):
48
outName =
"%s_payload_%i"
% (self.
DataName
, i)
49
dv = _makePayLoadDv()
50
data = _makePayLoad()
51
dv.push_back( data )
52
ROOT.SetOwnership (data,
False
)
53
try
:
54
_sg_record(dv, outName)
55
except
Exception:
56
del dv
57
self.
msg
.
error
(
"Could not store data at [%s] !!"
, outName )
58
allGood =
False
59
if
allGood
and
not
_sg_setConst(dv).isSuccess():
# noqa: F821
60
self.
msg
.warning(
"Could not setConst data at [%s] !!"
, outName)
61
62
# filling data
63
data = data.m_data
64
data.reserve( self.
ObjectsSize
)
65
pback = data.push_back
66
for
j
in
range(self.
ObjectsSize
): pback( j )
67
pass
# loop over NbrOfObjects
68
if
allGood:
return
StatusCode.Success
69
return
StatusCode.Failure
70
71
def
finalize
(self):
72
self.
msg
.info(
"Finalizing %s..."
, self.
name
)
73
return
StatusCode.Success
74
75
pass
# PySgStressProducer
76
77
78
class
PySgStressConsumer
(
PyAthena.Alg
):
79
"""A simple python algorithm to retrieve PayLoads
80
"""
81
def
__init__
(self, name = "PySgStressProducer", **kw):
82
83
kw[
'name'
] = name
84
super(PySgStressConsumer,self).
__init__
(**kw)
85
86
if
'DataName'
not
in
kw: self.
DataName
=
"MyData"
87
if
'NbrOfObjects'
not
in
kw: self.
NbrOfObjects
= 1000
88
89
def
initialize
(self):
90
self.
msg
.info(
"Initializing %s..."
, self.
name
)
91
self.
sg
= PyAthena.py_svc(
"StoreGateSvc"
)
92
if
not
self.
sg
:
93
self.
msg
.error (
"could not retrieve event store"
)
94
return
StatusCode.Failure
95
return
StatusCode.Success
96
97
def
execute
(self):
98
self.
msg
.
debug
(
"Executing %s..."
, self.
name
)
99
return
self.
readData
()
100
101
def
readData
(self):
102
allGood =
True
103
for
i
in
range(self.
NbrOfObjects
):
104
outName =
"%s_payload_%i"
% (self.
DataName
, i)
105
dv = self.
sg
.retrieve(
"SgTests::PayLoadDv"
, outName )
106
if
dv
is
None
:
107
self.
msg
.
error
(
"Could not retrieve payload !!"
)
108
allGood =
False
109
110
data = dv.at(0).m_data
111
if
data.empty():
112
self.
msg
.
error
(
"**NOT** my data!!"
)
113
allGood =
False
114
if
allGood:
return
StatusCode.Success
115
return
StatusCode.Failure
116
117
def
finalize
(self):
118
self.
msg
.info(
"Finalizing %s..."
, self.
name
)
119
return
StatusCode.Success
120
121
pass
# class PySgStressConsumer
122
123
124
class
PyClidsTestWriter
(
PyAthena.Alg
):
125
"""A simple algorithm to put simple objects (std::vector<T>, builtins)
126
into StoreGate and see what happens
127
"""
128
129
def
__init__
(self, name='PyClidsTestWriter', **kw):
130
131
super(PyClidsTestWriter,self).
__init__
(**kw)
132
self.
intsName
= kw.get(
'intsName'
,
'TestInts'
)
133
self.
uintsName
= kw.get(
'uintsName'
,
'TestUInts'
)
134
self.
floatsName
= kw.get(
'floatsName'
,
'TestFloats'
)
135
self.
doublesName
= kw.get(
'doublesName'
,
'TestDoubles'
)
136
137
return
138
139
def
initialize
(self):
140
self.
msg
.info(
"initializing..."
)
141
self.
sg
= PyAthena.py_svc(
'StoreGateSvc'
)
142
if
not
self.
sg
:
143
self.
msg
.
error
(
"Could not retrieve StoreGateSvc !"
)
144
return
StatusCode.Failure
145
146
_info = self.
msg
.info
147
_info(
"Configuration:"
)
148
_info(
" - ints: [%s]"
, self.
intsName
)
149
_info(
" - uints: [%s]"
, self.
uintsName
)
150
_info(
" - floats: [%s]"
, self.
floatsName
)
151
_info(
" - doubles: [%s]"
, self.
doublesName
)
152
153
self.
_test_matrix
= {
154
'std::vector<int>'
: self.
intsName
,
155
'std::vector<unsigned int>'
: self.
uintsName
,
156
'std::vector<float>'
: self.
floatsName
,
157
'std::vector<double>'
: self.
doublesName
,
158
}
159
return
StatusCode.Success
160
161
def
execute
(self):
162
allGood =
True
163
_error = self.
msg
.error
164
self.
msg
.info(
"running execute..."
)
165
166
for
tpName,sgKey
in
self.
_test_matrix
.items():
167
tp = getattr(PyAthena, tpName)
168
cont = tp()
169
cont.reserve(100)
170
for
i
in
range(100): cont.push_back(i)
171
try
:
172
self.
sg
[sgKey] = cont
173
except
Exception
as
err:
174
_error(
"Could not record '%s' at [%s] !"
,tpName,sgKey)
175
_error(err)
176
allGood =
False
177
178
if
not
allGood:
return
StatusCode.Failure
179
self.
sg
.
dump
()
180
import
sys
181
sys.stdout.flush()
182
sys.stderr.flush()
183
184
return
self.
testReadBack
()
185
186
def
testReadBack
(self):
187
allGood =
True
188
_info = self.
msg
.info
189
for
tpName,sgKey
in
self.
_test_matrix
.items():
190
cont = self.
sg
.retrieve(tpName,sgKey)
191
if
not
cont: _info(
'Could not retrieve [%s] !'
,sgKey)
192
cont = [cont[i]
for
i
in
range(10)]
193
_info(
'[%s] content: %s'
, sgKey,cont)
194
if
len( [i
for
i
in
range(10)
if
i != cont[i]] ) > 0:
195
self.
msg
.
error
(
'[%s] content is NOT as expected !!'
)
196
allGood =
False
197
if
not
allGood:
return
StatusCode.Failure
198
return
StatusCode.Success
199
200
def
finalize
(self):
201
self.
msg
.info(
"finalize..."
)
202
return
StatusCode.Success
203
204
pass
# class PyClidsTestWriter
debug
const bool debug
Definition
MakeUncertaintyPlots.cxx:53
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition
AthCommonMsg.h:24
PyAthena::Alg
Definition
PyAthenaAlg.h:33
PyAthena::Alg::finalize
virtual StatusCode finalize() override
Definition
PyAthenaAlg.cxx:86
PyAthena::Alg::initialize
virtual StatusCode initialize() override
Definition
PyAthenaAlg.cxx:60
python.Lib.PyClidsTestWriter
Definition
StoreGateTests/python/Lib.py:124
python.Lib.PyClidsTestWriter.intsName
intsName
init base class
Definition
StoreGateTests/python/Lib.py:132
python.Lib.PyClidsTestWriter.doublesName
doublesName
Definition
StoreGateTests/python/Lib.py:135
python.Lib.PyClidsTestWriter.execute
execute(self)
Definition
StoreGateTests/python/Lib.py:161
python.Lib.PyClidsTestWriter.uintsName
uintsName
Definition
StoreGateTests/python/Lib.py:133
python.Lib.PyClidsTestWriter.floatsName
floatsName
Definition
StoreGateTests/python/Lib.py:134
python.Lib.PyClidsTestWriter.sg
sg
Definition
StoreGateTests/python/Lib.py:141
python.Lib.PyClidsTestWriter._test_matrix
dict _test_matrix
Definition
StoreGateTests/python/Lib.py:153
python.Lib.PyClidsTestWriter.testReadBack
testReadBack(self)
Definition
StoreGateTests/python/Lib.py:186
python.Lib.PyClidsTestWriter.__init__
__init__(self, name='PyClidsTestWriter', **kw)
Definition
StoreGateTests/python/Lib.py:129
python.Lib.PySgStressConsumer
Definition
StoreGateTests/python/Lib.py:78
python.Lib.PySgStressConsumer.execute
execute(self)
Definition
StoreGateTests/python/Lib.py:97
python.Lib.PySgStressConsumer.NbrOfObjects
int NbrOfObjects
Definition
StoreGateTests/python/Lib.py:87
python.Lib.PySgStressConsumer.readData
readData(self)
Definition
StoreGateTests/python/Lib.py:101
python.Lib.PySgStressConsumer.sg
sg
Definition
StoreGateTests/python/Lib.py:91
python.Lib.PySgStressConsumer.__init__
__init__(self, name="PySgStressProducer", **kw)
Definition
StoreGateTests/python/Lib.py:81
python.Lib.PySgStressConsumer.DataName
str DataName
Definition
StoreGateTests/python/Lib.py:86
python.Lib.PySgStressConsumer.name
name
Definition
StoreGateTests/python/Lib.py:90
python.Lib.PySgStressProducer
Definition
StoreGateTests/python/Lib.py:11
python.Lib.PySgStressProducer.sg
sg
Definition
StoreGateTests/python/Lib.py:26
python.Lib.PySgStressProducer.createData
createData(self)
Definition
StoreGateTests/python/Lib.py:40
python.Lib.PySgStressProducer.name
name
Definition
StoreGateTests/python/Lib.py:25
python.Lib.PySgStressProducer.__init__
__init__(self, name="PySgStressProducer", **kw)
Definition
StoreGateTests/python/Lib.py:14
python.Lib.PySgStressProducer.execute
execute(self)
Definition
StoreGateTests/python/Lib.py:33
python.Lib.PySgStressProducer.ObjectsSize
int ObjectsSize
Definition
StoreGateTests/python/Lib.py:21
python.Lib.PySgStressProducer.UseDataPool
bool UseDataPool
Definition
StoreGateTests/python/Lib.py:22
python.Lib.PySgStressProducer.NbrOfObjects
int NbrOfObjects
Definition
StoreGateTests/python/Lib.py:20
python.Lib.PySgStressProducer.DataName
str DataName
Definition
StoreGateTests/python/Lib.py:19
dump
-event-from-file
error
Definition
IImpactPoint3dEstimator.h:72
Generated on
for ATLAS Offline Software by
1.17.0