ATLAS Offline Software
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
python.Auditor.HephaestusAuditor Class Reference
Inheritance diagram for python.Auditor.HephaestusAuditor:
Collaboration diagram for python.Auditor.HephaestusAuditor:

Public Member Functions

def __init__ (self, name="HephaestusAuditor", mode='leak-check', **kw)
 
def initialize (self)
 
def finalize (self)
 
def before (self, evt_name, comp_name)
 
def after (self, evt_name, comp_name, sc)
 
def __getstate__ (self)
 
def __setstate__ (self, dct)
 
virtual StatusCode initialize () override
 Gaudi Aud Implementation. More...
 
virtual StatusCode sysInitialize () override
 
virtual StatusCode finalize () 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 More...
 
virtual void py_before (IAuditor::StandardEventType, const std::string &)
 Audit the start of a standard "event". More...
 
virtual void py_before (IAuditor::CustomEventTypeRef, const std::string &)
 Audit the start of a custom "event". More...
 
virtual void py_after (IAuditor::StandardEventType, const std::string &, const StatusCode &)
 Audit the end of a standard "event". More...
 
virtual void py_after (IAuditor::CustomEventTypeRef, const std::string &, const StatusCode &)
 Audit the end of a custom "event". More...
 
virtual PyObjectself () override
 return associated python object. More...
 
 DeclareInterfaceID (IPyComponent, 1, 0)
 

Public Attributes

 auditOn
 
 topSequenceName
 

Protected Member Functions

virtual bool setPyAttr (PyObject *pyobj) override
 attach the C++ component to its python cousin More...
 
virtual void before (StandardEventType, INamedInterface *) override
 Auditor interface More...
 
virtual void before (StandardEventType, const std::string &) override
 
virtual void before (CustomEventTypeRef, INamedInterface *) override
 
virtual void before (CustomEventTypeRef, const std::string &) override
 
virtual void after (StandardEventType, INamedInterface *, const StatusCode &) override
 
virtual void after (StandardEventType, const std::string &, const StatusCode &) override
 
virtual void after (CustomEventTypeRef, INamedInterface *, const StatusCode &) override
 
virtual void after (CustomEventTypeRef, const std::string &, const StatusCode &) override
 
virtual void beforeInitialize (INamedInterface *) override
 
virtual void afterInitialize (INamedInterface *) override
 
virtual void beforeReinitialize (INamedInterface *) override
 
virtual void afterReinitialize (INamedInterface *) override
 
virtual void beforeExecute (INamedInterface *) override
 
virtual void afterExecute (INamedInterface *, const StatusCode &) override
 
virtual void beforeFinalize (INamedInterface *) override
 
virtual void afterFinalize (INamedInterface *) override
 

Protected Attributes

PyObjectm_self
 Pointer to self (from the python world) More...
 

Private Member Functions

def __setupMemoryTracker (self, mode, startup=True)
 

Private Attributes

 _evt
 
 _memtrack
 
 _start
 
 _stop
 

Detailed Description

Definition at line 13 of file Auditor.py.

Constructor & Destructor Documentation

◆ __init__()

def 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__()

def 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__()

def 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  global GlobalSettings
127  for k,v in dct[ 'GlobalSettings' ].items():
128  GlobalSettings[ k ] = v
129 
130  import os
131  self.__setupMemoryTracker( dct[ 'mode' ], dct[ 'pid' ] != os.getpid() )
132 
133  # the following is a guess; similar problem really as start(), really
134  if dct[ 'pid' ] == os.getpid():
135  self._evt = dct[ '_evt' ]
136  else:
137  self._evt = 0

◆ __setupMemoryTracker()

def 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() [1/5]

void PyAthena::Aud::after ( CustomEventTypeRef  evt,
const std::string &  comp,
const StatusCode &  sc 
)
overrideprotectedvirtualinherited

Definition at line 149 of file PyAthenaAud.cxx.

151 {
152  py_after (evt, comp, sc);
153 }

◆ after() [2/5]

void PyAthena::Aud::after ( CustomEventTypeRef  evt,
INamedInterface *  comp,
const StatusCode &  sc 
)
overrideprotectedvirtualinherited

Definition at line 143 of file PyAthenaAud.cxx.

144 {
145  py_after (evt, comp->name(), sc);
146 }

◆ after() [3/5]

def 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 

◆ after() [4/5]

void PyAthena::Aud::after ( StandardEventType  evt,
const std::string &  comp,
const StatusCode &  sc 
)
overrideprotectedvirtualinherited

Definition at line 137 of file PyAthenaAud.cxx.

138 {
139  py_after (evt, comp, sc);
140 }

◆ after() [5/5]

void PyAthena::Aud::after ( StandardEventType  evt,
INamedInterface *  comp,
const StatusCode &  sc 
)
overrideprotectedvirtualinherited

Definition at line 131 of file PyAthenaAud.cxx.

132 {
133  py_after (evt, comp->name(), sc);
134 }

◆ afterExecute()

void PyAthena::Aud::afterExecute ( INamedInterface *  comp,
const StatusCode &  sc 
)
overrideprotectedvirtualinherited

Definition at line 187 of file PyAthenaAud.cxx.

188 {
189  py_after (IAuditor::Execute, comp->name(), sc);
190 }

◆ afterFinalize()

void PyAthena::Aud::afterFinalize ( INamedInterface *  comp)
overrideprotectedvirtualinherited

Definition at line 199 of file PyAthenaAud.cxx.

200 {
201  py_after (IAuditor::Finalize, comp->name(), StatusCode::SUCCESS);
202 }

◆ afterInitialize()

void PyAthena::Aud::afterInitialize ( INamedInterface *  comp)
overrideprotectedvirtualinherited

Definition at line 163 of file PyAthenaAud.cxx.

164 {
165  py_after (IAuditor::Initialize, comp->name(), StatusCode::SUCCESS);
166 }

◆ afterReinitialize()

void PyAthena::Aud::afterReinitialize ( INamedInterface *  comp)
overrideprotectedvirtualinherited

Definition at line 175 of file PyAthenaAud.cxx.

176 {
177  py_after (IAuditor::ReInitialize, comp->name(), StatusCode::SUCCESS);
178 }

◆ before() [1/5]

void PyAthena::Aud::before ( CustomEventTypeRef  evt,
const std::string &  comp 
)
overrideprotectedvirtualinherited

Definition at line 125 of file PyAthenaAud.cxx.

126 {
127  py_before (evt, comp);
128 }

◆ before() [2/5]

void PyAthena::Aud::before ( CustomEventTypeRef  evt,
INamedInterface *  comp 
)
overrideprotectedvirtualinherited

Definition at line 119 of file PyAthenaAud.cxx.

120 {
121  py_before (evt, comp->name());
122 }

◆ before() [3/5]

def 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 

◆ before() [4/5]

void PyAthena::Aud::before ( StandardEventType  evt,
const std::string &  comp 
)
overrideprotectedvirtualinherited

Definition at line 113 of file PyAthenaAud.cxx.

114 {
115  py_before (evt, comp);
116 }

◆ before() [5/5]

void PyAthena::Aud::before ( StandardEventType  evt,
INamedInterface *  comp 
)
overrideprotectedvirtualinherited

Auditor interface

Definition at line 107 of file PyAthenaAud.cxx.

108 {
109  py_before (evt, comp->name());
110 }

◆ beforeExecute()

void PyAthena::Aud::beforeExecute ( INamedInterface *  comp)
overrideprotectedvirtualinherited

Definition at line 181 of file PyAthenaAud.cxx.

182 {
183  py_before (IAuditor::Execute, comp->name());
184 }

◆ beforeFinalize()

void PyAthena::Aud::beforeFinalize ( INamedInterface *  comp)
overrideprotectedvirtualinherited

Definition at line 193 of file PyAthenaAud.cxx.

194 {
195  py_before (IAuditor::Finalize, comp->name());
196 }

◆ beforeInitialize()

void PyAthena::Aud::beforeInitialize ( INamedInterface *  comp)
overrideprotectedvirtualinherited

Definition at line 157 of file PyAthenaAud.cxx.

158 {
160 }

◆ beforeReinitialize()

void PyAthena::Aud::beforeReinitialize ( INamedInterface *  comp)
overrideprotectedvirtualinherited

Definition at line 169 of file PyAthenaAud.cxx.

170 {
171  py_before (IAuditor::ReInitialize, comp->name());
172 }

◆ DeclareInterfaceID()

IPyComponent::DeclareInterfaceID ( IPyComponent  ,
,
 
)
inherited

◆ finalize() [1/2]

StatusCode PyAthena::Aud::finalize ( )
overridevirtualinherited

Definition at line 86 of file PyAthenaAud.cxx.

87 {
88  return PyAthena::callPyMethod( m_self, "sysFinalize" );
89 }

◆ finalize() [2/2]

def 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() [1/2]

StatusCode PyAthena::Aud::initialize ( )
overridevirtualinherited

Gaudi Aud Implementation.

Definition at line 60 of file PyAthenaAud.cxx.

61 {
62  return PyAthena::callPyMethod( m_self, "sysInitialize" );
63 }

◆ initialize() [2/2]

def 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 

◆ py_after() [1/2]

void PyAthena::Aud::py_after ( IAuditor::CustomEventTypeRef  evt,
const std::string &  component,
const StatusCode &  sc 
)
virtualinherited

Audit the end of a custom "event".

Definition at line 246 of file PyAthenaAud.cxx.

249 {
250  return PyAthena::pyAudit (m_self,
251  "after", evt.c_str(), component.c_str(), sc);
252 }

◆ py_after() [2/2]

void PyAthena::Aud::py_after ( IAuditor::StandardEventType  evt,
const std::string &  component,
const StatusCode &  sc 
)
virtualinherited

Audit the end of a standard "event".

Definition at line 228 of file PyAthenaAud.cxx.

231 {
232  const char* evtname = 0;
233  switch (evt) {
234  case Initialize: evtname = "initialize"; break;
235  case ReInitialize: evtname = "reinitialize"; break;
236  case Execute: evtname = "execute"; break;
237  case Finalize: evtname = "finalize"; break;
238  case Start: evtname = "start"; break;
239  case Stop: evtname = "stop"; break;
240  case ReStart: evtname = "restart"; break;
241  }
242  return PyAthena::pyAudit (m_self, "after", evtname, component.c_str(), sc);
243 }

◆ py_before() [1/2]

void PyAthena::Aud::py_before ( IAuditor::CustomEventTypeRef  evt,
const std::string &  component 
)
virtualinherited

Audit the start of a custom "event".

Definition at line 222 of file PyAthenaAud.cxx.

223 {
224  return PyAthena::pyAudit (m_self, "before", evt.c_str(), component.c_str());
225 }

◆ py_before() [2/2]

void PyAthena::Aud::py_before ( IAuditor::StandardEventType  evt,
const std::string &  component 
)
virtualinherited

Audit the start of a standard "event".

Definition at line 206 of file PyAthenaAud.cxx.

207 {
208  const char* evtname = 0;
209  switch (evt) {
210  case Initialize: evtname = "initialize"; break;
211  case ReInitialize: evtname = "reinitialize"; break;
212  case Execute: evtname = "execute"; break;
213  case Finalize: evtname = "finalize"; break;
214  case Start: evtname = "start"; break;
215  case Stop: evtname = "stop"; break;
216  case ReStart: evtname = "restart"; break;
217  }
218  return PyAthena::pyAudit (m_self, "before", evtname, component.c_str());
219 }

◆ self()

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

return associated python object.

BORROWED reference.

Implements IPyComponent.

Definition at line 76 of file PyAthenaAud.h.

76 { return m_self; }

◆ setPyAttr()

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

attach the C++ component to its python cousin

Implements IPyComponent.

Definition at line 260 of file PyAthenaAud.cxx.

261 {
262  // now we tell the PyObject which C++ object it is the cousin of.
264  PyObject* pyobj = TPython::CPPInstance_FromVoidPtr
265  ( (void*)this, this->typeName() );
266  if ( !pyobj ) {
267  PyErr_Clear();
268  // try PyAthena::Aud
269  pyobj = TPython::CPPInstance_FromVoidPtr ((void*)this, "PyAthena::Aud");
270  MsgStream msg( msgSvc(), name() );
271  msg << MSG::INFO
272  << "could not dyncast component [" << name() << "] to a python "
273  << "object of type [" << this->typeName() << "] (probably a missing "
274  << "dictionary)" << endmsg
275  << "fallback to [PyAthena::Aud]..."
276  << endmsg;
277  }
278  if ( !pyobj ) {
279  PyErr_Clear();
280  MsgStream msg( msgSvc(), name() );
281  msg << MSG::WARNING << "Could not dyncast component ["
282  << name() << "] to a pyobject of type ["
283  << this->typeName() << "]"
284  << endmsg;
285  } else {
286  if ( -1 == PyObject_SetAttrString(o, "_cppHandle", pyobj) ) {
287  PyErr_Clear();
288  MsgStream msg( msgSvc(), name() );
289  msg << MSG::WARNING
290  << "Could not attach C++ handle [" << name() << "] to its python "
291  << "cousin !"
292  << endmsg;
293  if ( -1 == PyObject_SetAttrString(o, "_cppHandle", Py_None) ) {
294  PyErr_Clear();
295  msg << MSG::WARNING
296  << "could not attach a dummy C++ handle [" << name() << "] to its "
297  << "python cousin !"
298  << endmsg;
299  }
300  } else {
301  return true;
302  }
303  }
304  return false;
305 }

◆ sysInitialize()

StatusCode PyAthena::Aud::sysInitialize ( )
overridevirtualinherited

Definition at line 66 of file PyAthenaAud.cxx.

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

◆ 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 96 of file PyAthenaAud.cxx.

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

Member Data Documentation

◆ _evt

python.Auditor.HephaestusAuditor._evt
private

Definition at line 19 of file Auditor.py.

◆ _memtrack

python.Auditor.HephaestusAuditor._memtrack
private

Definition at line 38 of file Auditor.py.

◆ _start

python.Auditor.HephaestusAuditor._start
private

Definition at line 41 of file Auditor.py.

◆ _stop

python.Auditor.HephaestusAuditor._stop
private

Definition at line 42 of file Auditor.py.

◆ auditOn

python.Auditor.HephaestusAuditor.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 123 of file PyAthenaAud.h.

◆ topSequenceName

python.Auditor.HephaestusAuditor.topSequenceName

Definition at line 29 of file Auditor.py.


The documentation for this class was generated from the following file:
plotting.yearwise_luminosity_vs_mu.comp
comp
Definition: yearwise_luminosity_vs_mu.py:24
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:53
configure
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)
Definition: TrigGlobEffCorrValidation.cxx:514
PyAthena::Aud::py_before
virtual void py_before(IAuditor::StandardEventType, const std::string &)
Audit the start of a standard "event".
Definition: PyAthenaAud.cxx:206
initialize
void initialize()
Definition: run_EoverP.cxx:894
PyAthena::Aud::py_after
virtual void py_after(IAuditor::StandardEventType, const std::string &, const StatusCode &)
Audit the end of a standard "event".
Definition: PyAthenaAud.cxx:228
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
RootUtils::PyGILStateEnsure
Definition: PyAthenaGILStateEnsure.h:20
LArPulseShapeRunConfig.Execute
Execute
Definition: LArPulseShapeRunConfig.py:62
checkTP.save
def save(self, fileName="./columbo.out")
Definition: checkTP.py:178
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
PyAthena::Aud::typeName
virtual const char * typeName() const override
return the std::type_info name of the underlying py-component This is used by concrete implementation...
Definition: PyAthenaAud.cxx:96
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
jobOptions.Initialize
Initialize
Definition: jobOptions.pA.py:28
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
PyAthena::Aud::m_self
PyObject * m_self
Pointer to self (from the python world)
Definition: PyAthenaAud.h:123
PyObject
_object PyObject
Definition: IPyComponent.h:26
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
ServiceHandle
Definition: ClusterMakerTool.h:37