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