ATLAS Offline Software
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 
7 from AthenaPython.PyAthena import StatusCode
8 import 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 
151  self._test_matrix = {
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
grepfile.info
info
Definition: grepfile.py:38
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
python.Lib.PySgStressProducer.createData
def createData(self)
Definition: StoreGateTests/python/Lib.py:39
python.Lib.PyClidsTestWriter.__init__
def __init__(self, name='PyClidsTestWriter', **kw)
Definition: StoreGateTests/python/Lib.py:127
python.Lib.PySgStressProducer.NbrOfObjects
NbrOfObjects
Definition: StoreGateTests/python/Lib.py:19
python.Lib.PySgStressProducer.__init__
def __init__(self, name="PySgStressProducer", **kw)
Definition: StoreGateTests/python/Lib.py:13
python.Lib.PyClidsTestWriter.floatsName
floatsName
Definition: StoreGateTests/python/Lib.py:132
python.Lib.PyClidsTestWriter.uintsName
uintsName
Definition: StoreGateTests/python/Lib.py:131
PyAthena::Alg::initialize
virtual StatusCode initialize() override
Definition: PyAthenaAlg.cxx:60
PyAthena::Alg::execute
virtual StatusCode execute() override
Definition: PyAthenaAlg.cxx:93
ParticleTest.tp
tp
Definition: ParticleTest.py:25
python.Lib.PyClidsTestWriter.sg
sg
Definition: StoreGateTests/python/Lib.py:139
python.Lib.PyClidsTestWriter._test_matrix
_test_matrix
Definition: StoreGateTests/python/Lib.py:151
python.Lib.PyClidsTestWriter
Definition: StoreGateTests/python/Lib.py:122
python.Lib.PySgStressProducer.DataName
DataName
init base class
Definition: StoreGateTests/python/Lib.py:18
run_Egamma1_LArStrip_Fex.dump
dump
Definition: run_Egamma1_LArStrip_Fex.py:88
PyAthena::Alg::finalize
virtual StatusCode finalize() override
Definition: PyAthenaAlg.cxx:86
python.Lib.PyClidsTestWriter.testReadBack
def testReadBack(self)
Definition: StoreGateTests/python/Lib.py:184
python.Lib.PySgStressConsumer.NbrOfObjects
NbrOfObjects
Definition: StoreGateTests/python/Lib.py:85
python.Lib.PyClidsTestWriter.doublesName
doublesName
Definition: StoreGateTests/python/Lib.py:133
python.Lib.PySgStressProducer
Definition: StoreGateTests/python/Lib.py:10
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.Lib.PySgStressConsumer.DataName
DataName
init base class
Definition: StoreGateTests/python/Lib.py:84
python.Lib.PySgStressConsumer.readData
def readData(self)
Definition: StoreGateTests/python/Lib.py:99
python.Lib.PySgStressProducer.UseDataPool
UseDataPool
Definition: StoreGateTests/python/Lib.py:21
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
python.Lib.PyClidsTestWriter.intsName
intsName
init base class
Definition: StoreGateTests/python/Lib.py:130
python.Lib.PySgStressProducer.sg
sg
Definition: StoreGateTests/python/Lib.py:25
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
python.Lib.PySgStressProducer.ObjectsSize
ObjectsSize
Definition: StoreGateTests/python/Lib.py:20
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
PyAthena::Alg
Definition: PyAthenaAlg.h:33
python.Lib.PySgStressConsumer
Definition: StoreGateTests/python/Lib.py:76
python.Lib.PySgStressConsumer.sg
sg
Definition: StoreGateTests/python/Lib.py:89
python.Lib.PySgStressConsumer.__init__
def __init__(self, name="PySgStressProducer", **kw)
Definition: StoreGateTests/python/Lib.py:79
error
Definition: IImpactPoint3dEstimator.h:70