ATLAS Offline Software
Loading...
Searching...
No Matches
python.PyComps.PySgDumper Class Reference
Inheritance diagram for python.PyComps.PySgDumper:
Collaboration diagram for python.PyComps.PySgDumper:

Public Member Functions

 __init__ (self, name='PySgDumper', **kw)
 initialize (self)
 execute (self)
 finalize (self)
virtual StatusCode reinitialize () override
virtual StatusCode start () override
virtual StatusCode stop () override
virtual StatusCode sysInitialize () override
 Override sysInitialize.
virtual const char * typeName () const override
 return the std::type_info name of the underlying py-component This is used by concrete implementations to connect a python component to its C++ counter-part
virtual PyObjectself () override
 return associated python object.
virtual const DataObjIDColl & extraOutputDeps () const override
 Return the list of extra output dependencies.
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const

Public Attributes

 items = kw.get('items', '*')
 properties and data members
 exclude = kw.get('exclude', '')
str ofile = kw.get('ofile', '')
 sg = None
 handle to event store
 failed_dumps = set()
 list of objects and/or classes for which the dump failed ( (key, clid-or-class, 'reason'), ... )
 clidsvc = PyAthena.py_svc ('ClassIDSvc')

Protected Member Functions

virtual bool setPyAttr (PyObject *pyobj) override
 attach the C++ component to its python cousin
void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Protected Attributes

 _dumper_fct = get_dumper_fct
int _evt_nbr = 0
PyObjectm_self
 Pointer to self (from the python world)

Static Protected Attributes

tuple _ignore_clids

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

DataObjIDColl m_extendedExtraObjects
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default)
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default)
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Detailed Description

Definition at line 224 of file Event/PyDumper/python/PyComps.py.

Member Typedef Documentation

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< Algorithm > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ __init__()

python.PyComps.PySgDumper.__init__ ( self,
name = 'PySgDumper',
** kw )

Definition at line 231 of file Event/PyDumper/python/PyComps.py.

231 def __init__(self, name='PySgDumper', **kw):
232
233 kw['name'] = name
234 super(PySgDumper, self).__init__(**kw)
235
236
237 self.items = kw.get('items', '*')
238 self.exclude = kw.get('exclude', '')
239 self.ofile = kw.get('ofile', '')
240
241
242 self.sg = None
243
244
246 self.failed_dumps = set()
247 return
248
STL class.

Member Function Documentation

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< Algorithm > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ execute()

python.PyComps.PySgDumper.execute ( self)

Definition at line 295 of file Event/PyDumper/python/PyComps.py.

295 def execute(self):
296 _debug= self.msg.debug
297 _info = self.msg.info
298 _warn = self.msg.warning
299 _add_fail = self.failed_dumps.add
300 _info('==> processing event [%s]...', self._evt_nbr)
301 self.ofile.writelines (['%s\n'%('='*40),
302 '==> evt nbr [%s]\n' % self._evt_nbr])
303 self._evt_nbr += 1
304
305 if self.items is None:
306 elist = self.exclude.split(',')
307 proxies = self.sg.proxies()
308 sg = dict()
309 _typename = self.clidsvc.typename
310 for p in proxies:
311 clid = p.clID()
312 if clid in self._ignore_clids:
313 continue
314 n = str(p.name())
315 tp = _typename(clid)
316 if n == 'Input': continue
317 if n.endswith('Aux.'): continue
318 if n.endswith('_DELETED'): continue
319 if not p.isValid(): continue
320 excluded = False
321 for exc in elist:
322 if fnmatch (n, exc) or (tp and fnmatch(tp, exc)):
323 excluded = True
324 break
325 if excluded:
326 continue
327 if tp:
328 sg[n] = tp
329 else:
330 self.msg.warning ('no typename for key=[%s], clid=[%i]',
331 n, clid)
332 _add_fail ((n,clid,'no typename from clid'))
333
334 items = [(i[1], i[0]) for i in sg.items() if i[1] != "EventInfo"]
335 items.sort()
336 evt_info = [(clid, key) for key,clid in sg.items() if clid=="EventInfo"]
337 if len(evt_info)==1:
338 items.insert (0, evt_info[0])
339 else:
340 items = self.items
341
342 _retrieve = self.sg.retrieve
343 _get = self.sg.__getitem__
344 for cont_type, cont_key in items:
345 _debug ('dumping object [%s#%s]', cont_type, cont_key)
346 try:
347 if cont_type is None:
348 o = _get (cont_key)
349 else:
350 o = _retrieve (cont_type, cont_key)
351 if o is None:
352 _add_fail ((cont_key, cont_type, 'retrieve failed'))
353 if self._evt_nbr==1:
354 _warn ('could not retrieve object [%s#%s]',
355 cont_type, cont_key)
356 continue
357 try:
358 dumper = self._dumper_fct (klass=o.__class__,
359 ofile=self.ofile)
360 except RuntimeError as err:
361 _add_fail ((cont_key, cont_type, 'dump failed ' + str(err)))
362 if self._evt_nbr==1:
363 _warn (err)
364 continue
365 self.ofile.writelines (
366 ['%s%s[%s/%s]%s\n'%(
367 os.linesep,
368 '-'*10,
369 o.__class__.__name__,
370 cont_key,
371 '-'*10)
372 ]
373 )
374 self.ofile.flush()
375 dumper (o)
376 self.ofile.flush()
377 except Exception as err:
378 traceback.print_exc()
379 _add_fail ((cont_key, cont_type, 'sg-retrieve failed'))
380 if self._evt_nbr==1:
381 _warn ('caught exception:\n%s', err)
382 _warn ('could not retrieve object [%s#%s]',
383 cont_type, cont_key)
384 continue
385 return StatusCode.Success
386
387
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ extraOutputDeps()

const DataObjIDColl & AthAlgorithm::extraOutputDeps ( ) const
overridevirtualinherited

Return the list of extra output dependencies.

This list is extended to include symlinks implied by inheritance relations.

Definition at line 50 of file AthAlgorithm.cxx.

51{
52 // If we didn't find any symlinks to add, just return the collection
53 // from the base class. Otherwise, return the extended collection.
54 if (!m_extendedExtraObjects.empty()) {
56 }
57 return Algorithm::extraOutputDeps();
58}
DataObjIDColl m_extendedExtraObjects

◆ finalize()

python.PyComps.PySgDumper.finalize ( self)

Definition at line 388 of file Event/PyDumper/python/PyComps.py.

388 def finalize(self):
389 self.msg.info ('==> finalize...')
390 self.msg.info ('processed [%s] events', self._evt_nbr)
391
392 self.ofile.flush()
393 if hasattr(self.ofile,'name'):
394 o_name = self.ofile.name
395 else:
396 o_name = '<unnamed file>'
397 import sys
398 if not (self.ofile is sys.stdout) and \
399 not (self.ofile is sys.stderr) and \
400 not (o_name in ['/dev/stdout', '/dev/stderr',]):
401 self.ofile.close()
402
403 _info = self.msg.info
404 if len(self.failed_dumps)>0:
405 _info ("the following objects could not be dumped:")
406 from collections import defaultdict
407 reasons = defaultdict(list)
408 for name,klass,reason in self.failed_dumps:
409 reasons[reason].append ((name,klass))
410 for reason in reasons.keys():
411 _info (' ==> [%s]', reason)
412 for name,klass in reasons[reason]:
413 _info (" [%s#%s]", klass, name)
414 return StatusCode.Success
415

◆ initialize()

python.PyComps.PySgDumper.initialize ( self)

Definition at line 249 of file Event/PyDumper/python/PyComps.py.

249 def initialize(self):
250 self.msg.info('==> initialize...')
251 self.sg = PyAthena.py_svc('StoreGateSvc')
252 if not self.sg:
253 self.msg.error('could not retrieve StoreGateSvc')
254 return StatusCode.Failure
255
256 self.clidsvc = PyAthena.py_svc ('ClassIDSvc')
257 if not self.clidsvc:
258 self.msg.error ('could not retrieve ClassIDSvc')
259 return StatusCode.Failure
260
261 try:
262 self.items = _decode_item_list(self.items, self.msg)
263 except Exception as err:
264 self.msg.error(err)
265 return StatusCode.Failure
266
267 if self.ofile is None or self.ofile == '':
268 from time import time
269 self.ofile = open('pysgdump_%s.log'%int(time()*100), 'w')
270 pass
271 elif isinstance(self.ofile, str):
272 self.ofile = open(self.ofile, 'w')
273 elif isinstance(self.ofile, IOBase):
274 pass
275 else:
276 self.msg.error("don't know how to handle ofile value/type [%s/%s]!",
277 str(self.ofile), type(self.ofile))
278 return StatusCode.Failure
279
280 from PyDumper.Dumpers import get_dumper_fct
281 self._dumper_fct = get_dumper_fct
282
283 if hasattr(self.ofile, 'name'):
284 ofile_name = self.ofile.name
285 else:
286 ofile_name = '<temporary unnamed file>'
287
288 self.msg.info ('dumping containers %s',
289 '<ALL>' if self.items is None else self.items)
290 self.msg.info ('into [%s]', ofile_name)
291
292 self._evt_nbr = 0
293 return StatusCode.Success
294
void initialize()

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< Algorithm > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ msg()

MsgStream & AthCommonMsg< Algorithm >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msgLvl()

bool AthCommonMsg< Algorithm >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< Algorithm > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ reinitialize()

StatusCode Alg::reinitialize ( )
overridevirtualinherited

Definition at line 67 of file PyAthenaAlg.cxx.

68{
69 ATH_MSG_INFO("Re-Initializing " << name() << "...");
70 return PyAthena::callPyMethod( m_self, "sysReinitialize" );
71}
#define ATH_MSG_INFO(x)
PyObject * m_self
Pointer to self (from the python world)
Definition PyAthenaAlg.h:96

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< Algorithm > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ self()

virtual PyObject * PyAthena::Alg::self ( )
inlineoverridevirtualinherited

return associated python object.

BORROWED reference.

Implements IPyComponent.

Definition at line 71 of file PyAthenaAlg.h.

71{ return m_self; }

◆ setPyAttr()

bool Alg::setPyAttr ( PyObject * pyobj)
overrideprotectedvirtualinherited

attach the C++ component to its python cousin

Implements IPyComponent.

Definition at line 143 of file PyAthenaAlg.cxx.

144{
145 // now we tell the PyObject which C++ object it is the cousin of.
146 RootUtils::PyGILStateEnsure ensure;
147 PyObject* pyobj = TPython::CPPInstance_FromVoidPtr
148 ( (void*)this, this->typeName() );
149 if ( !pyobj ) {
150 PyErr_Clear();
151 // try PyAthena::Alg
152 pyobj = TPython::CPPInstance_FromVoidPtr ((void*)this, "PyAthena::Alg");
154 ("could not dyncast component [" << name() << "] to a python "
155 << "object of type [" << this->typeName() << "] (probably a missing "
156 << "dictionary)" << endmsg
157 << "fallback to [PyAthena::Alg]...");
158 }
159 if ( !pyobj ) {
160 PyErr_Clear();
161 ATH_MSG_WARNING("Could not dyncast component ["
162 << name() << "] to a pyobject of type ["
163 << this->typeName() << "]");
164 } else {
165 if ( -1 == PyObject_SetAttrString(o, "_cppHandle", pyobj) ) {
166 PyErr_Clear();
168 ("Could not attach C++ handle [" << name() << "] to its python "
169 << "cousin !");
170 if ( -1 == PyObject_SetAttrString(o, "_cppHandle", Py_None) ) {
171 PyErr_Clear();
173 ("could not attach a dummy C++ handle [" << name() << "] to its "
174 "python cousin !");
175 }
176 } else {
177 return true;
178 }
179 }
180 return false;
181}
#define endmsg
#define ATH_MSG_WARNING(x)
_object PyObject
virtual const char * typeName() const override
return the std::type_info name of the underlying py-component This is used by concrete implementation...

◆ start()

StatusCode Alg::start ( )
overridevirtualinherited

Definition at line 74 of file PyAthenaAlg.cxx.

75{
76 return PyAthena::callPyMethod( m_self, "sysStart" );
77}

◆ stop()

StatusCode Alg::stop ( )
overridevirtualinherited

Definition at line 80 of file PyAthenaAlg.cxx.

81{
82 return PyAthena::callPyMethod( m_self, "sysStop" );
83}

◆ sysInitialize()

StatusCode Alg::sysInitialize ( )
overridevirtualinherited

Override sysInitialize.

Override sysInitialize from the base class.

Loop through all output handles, and if they're WriteCondHandles, automatically register them and this Algorithm with the CondSvc

Scan through all outputHandles, and if they're WriteCondHandles, register them with the CondSvc

Reimplemented from AthAlgorithm.

Definition at line 105 of file PyAthenaAlg.cxx.

106{
107 ServiceHandle<IPyComponentMgr> pyMgr
108 ( "PyAthena::PyComponentMgr/PyComponentMgr", name() );
109 if ( !pyMgr.retrieve().isSuccess() ) {
110 ATH_MSG_ERROR("Could not retrieve service [" << pyMgr.typeAndName()
111 << "] !!");
112 return StatusCode::FAILURE;
113 }
114
115 // first retrieve our python object cousin...
116 m_self = pyMgr->pyObject( this );
117
118 if ( m_self == Py_None ) {
119 ATH_MSG_ERROR("Wrapped PyObject is NONE !");
120 return StatusCode::FAILURE;
121 }
122
123 // re-route to usual sysInit...
125}
#define ATH_MSG_ERROR(x)
virtual StatusCode sysInitialize() override
Override sysInitialize.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< Algorithm > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ typeName()

const char * Alg::typeName ( ) const
overridevirtualinherited

return the std::type_info name of the underlying py-component This is used by concrete implementations to connect a python component to its C++ counter-part

Implements IPyComponent.

Definition at line 132 of file PyAthenaAlg.cxx.

133{
134 static const std::string tname = System::typeinfoName(typeid(*this));
135 return tname.c_str();
136}

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ _dumper_fct

python.PyComps.PySgDumper._dumper_fct = get_dumper_fct
protected

Definition at line 281 of file Event/PyDumper/python/PyComps.py.

◆ _evt_nbr

python.PyComps.PySgDumper._evt_nbr = 0
protected

Definition at line 292 of file Event/PyDumper/python/PyComps.py.

◆ _ignore_clids

tuple python.PyComps.PySgDumper._ignore_clids
staticprotected
Initial value:
= (
1118613496, # old ParticleJetContainer class
222376821, # DataHeader
55596997, # EventContext
)

Definition at line 226 of file Event/PyDumper/python/PyComps.py.

◆ clidsvc

python.PyComps.PySgDumper.clidsvc = PyAthena.py_svc ('ClassIDSvc')

Definition at line 256 of file Event/PyDumper/python/PyComps.py.

◆ exclude

python.PyComps.PySgDumper.exclude = kw.get('exclude', '')

Definition at line 238 of file Event/PyDumper/python/PyComps.py.

◆ failed_dumps

python.PyComps.PySgDumper.failed_dumps = set()

list of objects and/or classes for which the dump failed ( (key, clid-or-class, 'reason'), ... )

Definition at line 246 of file Event/PyDumper/python/PyComps.py.

◆ items

python.PyComps.PySgDumper.items = kw.get('items', '*')

properties and data members

Definition at line 237 of file Event/PyDumper/python/PyComps.py.

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< Algorithm > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< Algorithm > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_extendedExtraObjects

DataObjIDColl AthAlgorithm::m_extendedExtraObjects
privateinherited

Definition at line 79 of file AthAlgorithm.h.

◆ m_self

PyObject* PyAthena::Alg::m_self
protectedinherited

Pointer to self (from the python world)

Definition at line 96 of file PyAthenaAlg.h.

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< Algorithm > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< Algorithm > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.

◆ ofile

python.PyComps.PySgDumper.ofile = kw.get('ofile', '')

Definition at line 239 of file Event/PyDumper/python/PyComps.py.

◆ sg

python.PyComps.PySgDumper.sg = None

handle to event store

Definition at line 242 of file Event/PyDumper/python/PyComps.py.


The documentation for this class was generated from the following file: