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

Public Member Functions

 __init__ (self, name="HephaestusAuditor", mode='leak-check', **kw)
 initialize (self)
 finalize (self)
 before (self, evt_name, comp_name)
 after (self, evt_name, comp_name, sc)
 __getstate__ (self)
 __setstate__ (self, dct)
virtual StatusCode sysInitialize () override
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.

Public Attributes

list auditOn = kw[ 'auditOn' ]
str topSequenceName = kw[ 'topSequenceName' ]

Protected Member Functions

virtual bool setPyAttr (PyObject *pyobj) override
 attach the C++ component to its python cousin

Protected Attributes

int _evt = 0
 _memtrack = MemoryTracker
 _start = self._memtrack.start
 _stop = self._memtrack.stop
PyObjectm_self
 Pointer to self (from the python world)

Private Member Functions

 __setupMemoryTracker (self, mode, startup=True)

Detailed Description

Definition at line 13 of file Auditor.py.

Constructor & Destructor Documentation

◆ __init__()

python.Auditor.HephaestusAuditor.__init__ ( self,
name = "HephaestusAuditor",
mode = 'leak-check',
** kw )

Definition at line 14 of file Auditor.py.

14 def __init__( self, name = "HephaestusAuditor", mode = 'leak-check', **kw ):
15 kw[ 'name' ] = name
16 super( HephaestusAuditor, self ).__init__( **kw )
17
18 # event counter
19 self._evt = 0
20
21 # settable parameter: subselection to audit on
22 try:
23 self.auditOn = kw[ 'auditOn' ]
24 except KeyError:
25 self.auditOn = [ 'execute' ]
26
27 # settable parameter: determine event boundaries on the master sequence
28 try:
29 self.topSequenceName = kw[ 'topSequenceName' ]
30 except KeyError:
31 self.topSequenceName = 'AthMasterSeq'
32
33 self.__setupMemoryTracker( mode, True )
34

Member Function Documentation

◆ __getstate__()

python.Auditor.HephaestusAuditor.__getstate__ ( self)

Definition at line 92 of file Auditor.py.

92 def __getstate__( self ):
93 # determine mode used
94 mode = 'leak-check'
95 if self._memtrack.start != self._start:
96 mode = 'delete-check'
97
98 # the base class will try to pickle all parts of the dict indiscriminately ...
99 mtmod = self._memtrack
100 del self._memtrack
101 dct = super( HephaestusAuditor, self ).__getstate__()
102
103 # but need to be kept alive if the job does not end on the pickle (resetting
104 # in __setupMemoryTracker is fine, since it is cached in sys.modules)
105 self._memtrack = mtmod
106
107 # store mode used
108 dct[ 'mode' ] = mode
109
110 # store the module-level variables, as they may have been modified
111 dct[ 'GlobalSettings' ] = GlobalSettings
112
113 # store the pid of the current process: if we get re-loaded into the same
114 # process, then no restart should be done (this isn't foolproof, but there
115 # is no current way of checking otherwise)
116 import os
117 dct[ 'pid' ] = os.getpid()
118
119 return dct
120

◆ __setstate__()

python.Auditor.HephaestusAuditor.__setstate__ ( self,
dct )

Definition at line 121 of file Auditor.py.

121 def __setstate__( self, dct ):
122 super( HephaestusAuditor, self ).__setstate__( dct )
123
124 # copy the values instead of resetting the reference, in case it has
125 # been imported somewhere
126 for k,v in dct[ 'GlobalSettings' ].items():
127 GlobalSettings[ k ] = v
128
129 import os
130 self.__setupMemoryTracker( dct[ 'mode' ], dct[ 'pid' ] != os.getpid() )
131
132 # the following is a guess; similar problem really as start(), really
133 if dct[ 'pid' ] == os.getpid():
134 self._evt = dct[ '_evt' ]
135 else:
136 self._evt = 0

◆ __setupMemoryTracker()

python.Auditor.HephaestusAuditor.__setupMemoryTracker ( self,
mode,
startup = True )
private

Definition at line 35 of file Auditor.py.

35 def __setupMemoryTracker( self, mode, startup = True ):
36 # get going immediately, so that this is the first memory hook
37 import MemoryTracker
38 self._memtrack = MemoryTracker
39
40 if mode == 'leak-check':
41 self._start = self._memtrack.start
42 self._stop = self._memtrack.stop
43
44 if startup or 'full' in self.auditOn:
45 self._memtrack.save()
46 self._memtrack.install()
47
48 elif mode == 'delete-check':
49 import DeleteChecker
50 self._start = DeleteChecker.start
51 self._stop = DeleteChecker.stop
52
53 else:
54 raise RuntimeError( 'unknown mode: %s (expected leak-check or delete-check)' % mode )
55
56 # for full, just get going and never look back
57 if 'full' in self.auditOn:
58 self._start()
59

◆ after()

python.Auditor.HephaestusAuditor.after ( self,
evt_name,
comp_name,
sc )

Definition at line 86 of file Auditor.py.

86 def after( self, evt_name, comp_name, sc ):
87 if not self.auditOn or evt_name.lower() in self.auditOn:
88 self._stop()
89 return
90

◆ before()

python.Auditor.HephaestusAuditor.before ( self,
evt_name,
comp_name )

Definition at line 76 of file Auditor.py.

76 def before( self, evt_name, comp_name ):
77 if not self.auditOn or evt_name.lower() in self.auditOn:
78 if (self._memtrack.configure() & self._memtrack.PROFILE):
79 if GlobalSettings[ 'event-based' ] and evt_name.lower() == 'execute'\
80 and comp_name == self.topSequenceName:
81 self._evt += 1
82 self._memtrack._profname( GlobalSettings[ 'label' ] + '_execute.%d' % self._evt )
83 self._start()
84 return
85
bool configure(asg::AnaToolHandle< ITrigGlobalEfficiencyCorrectionTool > &tool, ToolHandleArray< IAsgElectronEfficiencyCorrectionTool > &electronEffToolsHandles, ToolHandleArray< IAsgElectronEfficiencyCorrectionTool > &electronSFToolsHandles, ToolHandleArray< CP::IMuonTriggerScaleFactors > &muonToolsHandles, ToolHandleArray< IAsgPhotonEfficiencyCorrectionTool > &photonEffToolsHandles, ToolHandleArray< IAsgPhotonEfficiencyCorrectionTool > &photonSFToolsHandles, const std::string &triggers, const std::map< std::string, std::string > &legsPerTool, unsigned long nToys, bool debug)

◆ finalize()

python.Auditor.HephaestusAuditor.finalize ( self)

Definition at line 70 of file Auditor.py.

70 def finalize( self ):
71 if 'full-athena' in self.auditOn:
72 self._stop()
73
74 return PyAthena.StatusCode.Success
75

◆ initialize()

python.Auditor.HephaestusAuditor.initialize ( self)

Definition at line 60 of file Auditor.py.

60 def initialize( self ):
61 if 'full-athena' in self.auditOn:
62 self._start()
63
64 if (self._memtrack.configure() & self._memtrack.PROFILE):
65 if not GlobalSettings[ 'event-based' ]:
66 self._memtrack._profname( GlobalSettings[ 'label' ] )
67
68 return PyAthena.StatusCode.Success
69
void initialize()

◆ self()

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

return associated python object.

BORROWED reference.

Implements IPyComponent.

Definition at line 68 of file PyAthenaAud.h.

68{ return m_self; }
PyObject * m_self
Pointer to self (from the python world)
Definition PyAthenaAud.h:90

◆ setPyAttr()

bool PyAthena::Aud::setPyAttr ( PyObject * pyobj)
overrideprotectedvirtualinherited

attach the C++ component to its python cousin

Implements IPyComponent.

Definition at line 130 of file PyAthenaAud.cxx.

131{
132 // now we tell the PyObject which C++ object it is the cousin of.
133 RootUtils::PyGILStateEnsure ensure;
134 PyObject* pyobj = TPython::CPPInstance_FromVoidPtr
135 ( (void*)this, this->typeName() );
136 if ( !pyobj ) {
137 PyErr_Clear();
138 // try PyAthena::Aud
139 pyobj = TPython::CPPInstance_FromVoidPtr ((void*)this, "PyAthena::Aud");
140 MsgStream msg( msgSvc(), name() );
141 msg << MSG::INFO
142 << "could not dyncast component [" << name() << "] to a python "
143 << "object of type [" << this->typeName() << "] (probably a missing "
144 << "dictionary)" << endmsg
145 << "fallback to [PyAthena::Aud]..."
146 << endmsg;
147 }
148 if ( !pyobj ) {
149 PyErr_Clear();
150 MsgStream msg( msgSvc(), name() );
151 msg << MSG::WARNING << "Could not dyncast component ["
152 << name() << "] to a pyobject of type ["
153 << this->typeName() << "]"
154 << endmsg;
155 } else {
156 if ( -1 == PyObject_SetAttrString(o, "_cppHandle", pyobj) ) {
157 PyErr_Clear();
158 MsgStream msg( msgSvc(), name() );
159 msg << MSG::WARNING
160 << "Could not attach C++ handle [" << name() << "] to its python "
161 << "cousin !"
162 << endmsg;
163 if ( -1 == PyObject_SetAttrString(o, "_cppHandle", Py_None) ) {
164 PyErr_Clear();
165 msg << MSG::WARNING
166 << "could not attach a dummy C++ handle [" << name() << "] to its "
167 << "python cousin !"
168 << endmsg;
169 }
170 } else {
171 return true;
172 }
173 }
174 return false;
175}
#define endmsg
_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...
msgSvc
Provide convenience handles for various services.
Definition StdJOSetup.py:36
MsgStream & msg
Definition testRead.cxx:32

◆ sysInitialize()

StatusCode PyAthena::Aud::sysInitialize ( )
overridevirtualinherited

Definition at line 67 of file PyAthenaAud.cxx.

68{
69 ServiceHandle<IPyComponentMgr> pyMgr
70 ( "PyAthena::PyComponentMgr/PyComponentMgr", name() );
71 if ( !pyMgr.retrieve().isSuccess() ) {
72 return StatusCode::FAILURE;
73 }
74
75 // first retrieve our python object cousin...
76 m_self = pyMgr->pyObject( this );
77
78 if ( m_self == Py_None ) {
79 return StatusCode::FAILURE;
80 }
81
82 // re-route to usual sysInit...
83 return Gaudi::Auditor::sysInitialize();
84}

◆ typeName()

const char * PyAthena::Aud::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 97 of file PyAthenaAud.cxx.

98{
99 static const std::string tname = System::typeinfoName(typeid(*this));
100 return tname.c_str();
101}

Member Data Documentation

◆ _evt

python.Auditor.HephaestusAuditor._evt = 0
protected

Definition at line 19 of file Auditor.py.

◆ _memtrack

python.Auditor.HephaestusAuditor._memtrack = MemoryTracker
protected

Definition at line 38 of file Auditor.py.

◆ _start

python.Auditor.HephaestusAuditor._start = self._memtrack.start
protected

Definition at line 41 of file Auditor.py.

◆ _stop

python.Auditor.HephaestusAuditor._stop = self._memtrack.stop
protected

Definition at line 42 of file Auditor.py.

◆ auditOn

list python.Auditor.HephaestusAuditor.auditOn = kw[ 'auditOn' ]

Definition at line 23 of file Auditor.py.

◆ m_self

PyObject* PyAthena::Aud::m_self
protectedinherited

Pointer to self (from the python world)

Definition at line 90 of file PyAthenaAud.h.

◆ topSequenceName

str python.Auditor.HephaestusAuditor.topSequenceName = kw[ 'topSequenceName' ]

Definition at line 29 of file Auditor.py.


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