ATLAS Offline Software
Loading...
Searching...
No Matches
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
7from AthenaPython.PyAthena import StatusCode
8import AthenaPython.PyAthena as PyAthena
9import ROOT
10
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
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
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
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
const bool debug
virtual StatusCode finalize() override
virtual StatusCode initialize() override
__init__(self, name='PyClidsTestWriter', **kw)
__init__(self, name="PySgStressProducer", **kw)
__init__(self, name="PySgStressProducer", **kw)
-event-from-file