Gaudi Framework, version v23r2

Home   Generated: Thu Jun 28 2012
Public Member Functions | Public Attributes | Static Public Attributes

GaudiPython::Bindings::AppMgr Class Reference

Inheritance diagram for GaudiPython::Bindings::AppMgr:
Inheritance graph
[legend]
Collaboration diagram for GaudiPython::Bindings::AppMgr:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __new__
def __reset__
def __init__
def state
def FSMState
def targetFSMState
def loaddict
def service
def declSvcType
def createSvc
def services
def algorithm
def algorithms
def tool
def property
def datasvc
def evtsvc
def detsvc
def filerecordsvc
def evtsel
def histsvc
def ntuplesvc
def partsvc
def toolsvc
def optSvc
def readOptions
def addAlgorithm
def setAlgorithms
def removeAlgorithm
def config
def configure
def start
def run
def executeEvent
def execute
def runSelectedEvents
def exit
def __del__
 Custom destructor to ensure that the application is correctly finalized when exiting from python.

Public Attributes

 JobOptionsType
 OutputLevel
 topAlg

Static Public Attributes

 evtSvc = evtsvc
 histSvc = histsvc
 ntupleSvc = ntuplesvc
 evtSel = evtsel
 detSvc = detsvc
 toolSvc = toolsvc
 partSvc = partsvc

Detailed Description

Definition at line 627 of file Bindings.py.


Constructor & Destructor Documentation

def GaudiPython::Bindings::AppMgr::__init__ (   self,
  outputlevel = -1,
  joboptions = None,
  selfoptions = {},
  dllname = None,
  factname = None 
)

Definition at line 648 of file Bindings.py.

00648                                                                           {},
00649                  dllname = None, factname = None) :
00650         global _gaudi
00651         if _gaudi : return
00652         # Protection against multiple calls to exit() if the finalization fails
00653         self.__dict__['_exit_called'] = False
00654         # keep the Gaudi namespace around (so it is still available during atexit shutdown)...
00655         self.__dict__['_gaudi_ns'] = Gaudi
00656         try:
00657             from GaudiKernel.Proxy.Configurable import expandvars
00658         except ImportError:
00659             # pass-through implementation if expandvars is not defined (AthenaCommon)
00660             expandvars = lambda data : data
00661         if dllname and factname:
00662             self.__dict__['_appmgr'] = gbl.Gaudi.createApplicationMgr(dllname,factname)
00663         elif dllname:
00664             self.__dict__['_appmgr'] = gbl.Gaudi.createApplicationMgr(dllname)
00665         else:
00666             self.__dict__['_appmgr'] = gbl.Gaudi.createApplicationMgr()
00667         self.__dict__['_svcloc'] = gbl.Gaudi.svcLocator()
00668         self.__dict__['_algmgr'] = InterfaceCast(gbl.IAlgManager)(self._appmgr)
00669         self.__dict__['_evtpro'] = InterfaceCast(gbl.IEventProcessor)(self._appmgr)
00670         self.__dict__['_svcmgr'] = InterfaceCast(gbl.ISvcManager)(self._appmgr)
00671         self.__dict__['pyalgorithms'] = []
00672         iService.__init__(self, 'ApplicationMgr', self._appmgr )
00673         #------python specific initialization-------------------------------------
00674         if self.FSMState() < Gaudi.StateMachine.CONFIGURED :  # Not yet configured
00675             self.JobOptionsType = 'NONE'
00676             if joboptions :
00677                 from GaudiKernel.ProcessJobOptions import importOptions
00678                 importOptions(joboptions)
00679             # Ensure that the ConfigurableUser instances have been applied
00680             import GaudiKernel.Proxy.Configurable
00681             if hasattr(GaudiKernel.Proxy.Configurable, "applyConfigurableUsers"):
00682                 GaudiKernel.Proxy.Configurable.applyConfigurableUsers()
00683             # This is the default and could be overridden with "selfopts"
00684             self.OutputLevel = 3
00685             selfprops = Configurable.allConfigurables.get('ApplicationMgr',{})
00686             if selfprops : selfprops = expandvars(selfprops.getValuedProperties())
00687             for p,v in selfprops.items()   : setattr(self, p, v)
00688             for p,v in selfoptions.items() : setattr(self, p, v)
00689             # Override job options
00690             if outputlevel != -1 : self.OutputLevel = outputlevel
00691             self.configure()
00692         #---MessageSvc------------------------------------------------------------
00693         ms = self.service('MessageSvc')
00694         if 'MessageSvc' in Configurable.allConfigurables:
00695             msprops = Configurable.allConfigurables['MessageSvc']
00696             ms = self.service('MessageSvc')
00697             if hasattr(msprops,"getValuedProperties"):
00698                 msprops = expandvars(msprops.getValuedProperties())
00699             for p,v in msprops.items():
00700                 setattr(ms, p, v)
00701         if outputlevel != -1 : ms.OutputLevel = outputlevel
00702         #---JobOptions------------------------------------------------------------
00703         self.__dict__['_optsvc'] = InterfaceCast(gbl.IJobOptionsSvc)(Helper.service(self._svcloc,'JobOptionsSvc'))
00704         #------Configurables initialization (part2)-------------------------------
00705         for n in getNeededConfigurables():
00706             c = Configurable.allConfigurables[n]
00707             if n in ['ApplicationMgr','MessageSvc'] : continue # These are already done---
00708             for p, v in  c.getValuedProperties().items() :
00709                 v = expandvars(v)
00710                 # Note: AthenaCommon.Configurable does not have Configurable.PropertyReference
00711                 if hasattr(Configurable,"PropertyReference") and type(v) == Configurable.PropertyReference:
00712                 # this is done in "getFullName", but the exception is ignored,
00713                 # so we do it again to get it
00714                     v = v.__resolve__()
00715                 if   type(v) == str : v = '"%s"' % v # need double quotes
00716                 elif type(v) == long: v = '%d'   % v # prevent pending 'L'
00717                 self._optsvc.addPropertyToCatalogue(n, StringProperty(p,str(v)))
00718         if hasattr(Configurable,"_configurationLocked"):
00719             Configurable._configurationLocked = True
00720 
00721         # Ensure that the exit method is called when exiting from Python
00722         import atexit
00723         atexit.register(self.exit)
00724 
00725         #---Hack to avoid bad interactions with the ROOT exit handler
00726         # Look for an exit handler installed by ROOT
00727         root_handler_installed = False
00728         for h in atexit._exithandlers:
00729             func = h[0]
00730             if hasattr(func, "__module__") and func.__module__ == "ROOT":
00731                 root_handler_installed = True
00732                 break
00733 
00734         # If the handler is not yet installed, let's install our private version
00735         # that detects that the ROOT exit handler is installed and add our own
00736         # after it to ensure it is called before.
00737         if not root_handler_installed:
00738             orig_register = atexit.register
00739             def register(func, *targs, **kargs):
00740                 orig_register(func, *targs, **kargs)
00741                 if hasattr(func, "__module__") and func.__module__ == "ROOT":
00742                     orig_register(self.exit)
00743                     # we do not need to remove out handler from the list because
00744                     # it can be safely called more than once
00745             register.__doc__ = (orig_register.__doc__ +
00746                                 "\nNote: version hacked by GaudiPython to work " +
00747                                 "around a problem with the ROOT exit handler")
00748             atexit.register = register
00749 
def GaudiPython::Bindings::AppMgr::__del__ (   self )

Custom destructor to ensure that the application is correctly finalized when exiting from python.

Definition at line 980 of file Bindings.py.

00981                      :
        self.exit()

Member Function Documentation

def GaudiPython::Bindings::AppMgr::__new__ (   cls,
  args,
  kwargs 
)

Definition at line 628 of file Bindings.py.

00629                                         :
00630         global _gaudi
00631         if not _gaudi :
00632             newobj = object.__new__( cls )
00633             cls.__init__(newobj, *args, **kwargs)
00634             _gaudi = newobj
        return _gaudi
def GaudiPython::Bindings::AppMgr::__reset__ (   self )

Definition at line 635 of file Bindings.py.

00636                        :
00637         global _gaudi
00638         # Stop, Finalize and Terminate the current AppMgr
00639         self.exit()
00640         # release interfaces
00641         self._evtpro.release()
00642         self._svcloc.release()
00643         self._appmgr.release()
00644         # Reset the C++ globals
00645         gbl.Gaudi.setInstance(makeNullPointer('ISvcLocator'))
00646         gbl.Gaudi.setInstance(makeNullPointer('IAppMgrUI'))
00647         # Reset the Python global
        _gaudi = None
def GaudiPython::Bindings::AppMgr::addAlgorithm (   self,
  alg 
)
Add an Algorithm to the list of Top algorithms. It can be either a instance of
    an Algorithm class or it name 

Definition at line 825 of file Bindings.py.

00826                                 :
00827         """ Add an Algorithm to the list of Top algorithms. It can be either a instance of
00828             an Algorithm class or it name """
00829         if type(alg) is  str :
00830             self.topAlg += [alg]
00831         else :
00832             self.pyalgorithms.append(alg)
00833             setOwnership(alg,0)
00834             if self.targetFSMState() >= Gaudi.StateMachine.INITIALIZED :
00835                 alg.sysInitialize()
00836                 if self.targetFSMState() == Gaudi.StateMachine.RUNNING :
00837                     alg.sysStart()
            self.topAlg += [alg.name()]
def GaudiPython::Bindings::AppMgr::algorithm (   self,
  name,
  createIf = False 
)

Definition at line 773 of file Bindings.py.

00774                                                   :
00775         alg = Helper.algorithm( self._algmgr, name , createIf )
00776         if not alg : return iAlgorithm ( name       , alg )
        else       : return iAlgorithm ( alg.name() , alg )
def GaudiPython::Bindings::AppMgr::algorithms (   self )

Definition at line 777 of file Bindings.py.

00778                          :
00779         l = self._algmgr.getAlgorithms()
00780         nl = l.__class__(l)  # get a copy
00781         s = []
00782         for i in range(l.size()) :
00783             s.append(nl.front().name())
00784             nl.pop_front()
        return s
def GaudiPython::Bindings::AppMgr::config (   self,
  args 
)
Simple utility to perform the configuration of Gaudi application.
It reads the set of input job-options files, and set few
additional parameters 'options' through the usage of temporary *.opts file
Usage:
gaudi.config( files   = [ '$GAUSSOPTS/Gauss.opts'                     ,
                  '$DECFILESROOT/options/10022_010.0GeV.opts' ] ,
      options = [ 'EventSelector.PrintFreq   =   5  '         ] )

Definition at line 864 of file Bindings.py.

00865                                :
00866         """
00867         Simple utility to perform the configuration of Gaudi application.
00868         It reads the set of input job-options files, and set few
00869         additional parameters 'options' through the usage of temporary *.opts file
00870         Usage:
00871         gaudi.config( files   = [ '$GAUSSOPTS/Gauss.opts'                     ,
00872                                   '$DECFILESROOT/options/10022_010.0GeV.opts' ] ,
00873                       options = [ 'EventSelector.PrintFreq   =   5  '         ] )
00874         """
00875         files  = args.get('files',[])
00876         for file in files :
00877             sc = self.readOptions(file)
00878             if sc.isFailure() :
00879                 raise RuntimeError , ' Unable to read file "' + file +'" '
00880         options  = args.get('options',None)
00881         if options :
00882             import tempfile
00883             tmpfilename = tempfile.mktemp()
00884             tmpfile     = open( tmpfilename, 'w' )
00885             tmpfile.write ( '#pragma print on  \n' )
00886             tmpfile.write ( '/// File         "' + tmpfilename+'" generated by GaudiPython \n\n' )
00887             for opt in options :
00888                 if type(options) is dict :
00889                     tmpfile.write( ' \t ' + opt + ' = '+ options[opt]+ ' ;  // added by GaudiPython \n' )
00890                 else :
00891                     tmpfile.write( ' \t ' + opt + ' ;  // added by GaudiPython \n' )
00892             tmpfile.write ( '/// End of  file "' + tmpfilename+'" generated by GaudiPython \n\n' )
00893             tmpfile.close()
00894             sc = self.readOptions( tmpfilename )
00895             if sc.isFailure() :
00896                 raise RuntimeError , ' Unable to read file "' + tmpfilename +'" '
00897             os.remove( tmpfilename )
00898         # We need to make sure that the options are taken by the ApplicationMgr
00899         if self.FSMState() != Gaudi.StateMachine.OFFLINE : # The state is already configured, so we need to do something....
00900 
00901             ## get job-options-service, @see class iJobOptSvc
00902             jos   = self.optSvc()
00903 
00904             ## list of all libraries
00905             _dlls = jos.getProperty   ( self.name() , 'DLLs'   )
00906             ## take care about libraries : APPEND if not done yet
00907             if _dlls :
00908                 libs = [ l for l in _dlls if not l in self.DLLs ]
00909                 if libs : self.DLLs  += libs
00910 
00911             ## all external services
00912             _svcs = jos.getProperty   ( self.name() , 'ExtSvc' )
00913             ## take care about services : APPEND  if not done yet
00914             if _svcs :
00915                 svcs = [ s for s in _svcs if not s in self.ExtSvc ]
00916                 if svcs : self.ExtSvc += svcs
00917 
00918             ## get all properties
00919             props = jos.getProperties ( self.name() )
00920             ## finally treat all other properties (presumably scalar properties)
00921             for key in props :
00922                 if 'DLLS' == key or 'EXTSVC' == key : continue
00923                 self.__setattr__( key , props[key] )
        return SUCCESS                                           # RETURN
def GaudiPython::Bindings::AppMgr::configure (   self )

Definition at line 924 of file Bindings.py.

00925                         :
        return self._appmgr.configure()
def GaudiPython::Bindings::AppMgr::createSvc (   self,
  name 
)

Definition at line 763 of file Bindings.py.

00764                                :
        return Helper.service( self._svcloc, name, True )
def GaudiPython::Bindings::AppMgr::datasvc (   self,
  name 
)

Definition at line 791 of file Bindings.py.

00792                             :
00793         if self.state() == Gaudi.StateMachine.CONFIGURED :  self.initialize()
00794         svc = Helper.service( self._svcloc, name )
        return iDataSvc(name, svc)
def GaudiPython::Bindings::AppMgr::declSvcType (   self,
  svcname,
  svctype 
)

Definition at line 761 of file Bindings.py.

00762                                              :
        self._svcmgr.declareSvcType(svcname, svctype)
def GaudiPython::Bindings::AppMgr::detsvc (   self )

Definition at line 797 of file Bindings.py.

00798                      :
        return self.datasvc('DetectorDataSvc')
def GaudiPython::Bindings::AppMgr::evtsel (   self )

Definition at line 801 of file Bindings.py.

00802                     :
00803         if self.state() == Gaudi.StateMachine.CONFIGURED :  self.initialize()
00804         if not hasattr(self,'_evtsel') : self.__dict__['_evtsel'] = iEventSelector()
        return self._evtsel
def GaudiPython::Bindings::AppMgr::evtsvc (   self )

Definition at line 795 of file Bindings.py.

00796                      :
        return self.datasvc('EventDataSvc')
def GaudiPython::Bindings::AppMgr::execute (   self )

Definition at line 938 of file Bindings.py.

00939                       :
        return self._evtpro.executeEvent()
def GaudiPython::Bindings::AppMgr::executeEvent (   self )

Definition at line 936 of file Bindings.py.

00937                            :
        return self._evtpro.executeEvent()
def GaudiPython::Bindings::AppMgr::exit (   self )

Definition at line 967 of file Bindings.py.

00968                   :
00969         # Protection against multiple calls to exit() if the finalization fails
00970         if not self._exit_called:
00971             self.__dict__['_exit_called'] = True
00972             Gaudi = self._gaudi_ns
00973             if self.FSMState() == Gaudi.StateMachine.RUNNING:
00974                 self._appmgr.stop().ignore()
00975             if self.FSMState() == Gaudi.StateMachine.INITIALIZED:
00976                 self._appmgr.finalize().ignore()
00977             if self.FSMState() == Gaudi.StateMachine.CONFIGURED:
00978                 self._appmgr.terminate()
        return SUCCESS
def GaudiPython::Bindings::AppMgr::filerecordsvc (   self )

Definition at line 799 of file Bindings.py.

00800                             :
        return self.datasvc('FileRecordDataSvc')
def GaudiPython::Bindings::AppMgr::FSMState (   self )

Definition at line 751 of file Bindings.py.

00751 : return self._isvc.FSMState()
def GaudiPython::Bindings::AppMgr::histsvc (   self,
  name = 'HistogramDataSvc' 
)

Definition at line 805 of file Bindings.py.

00806                                                :
00807         svc = Helper.service( self._svcloc, name )
        return iHistogramSvc(name, svc)
def GaudiPython::Bindings::AppMgr::loaddict (   self,
  dict 
)

Definition at line 753 of file Bindings.py.

00754                              :
        loaddict(dict)
def GaudiPython::Bindings::AppMgr::ntuplesvc (   self,
  name = 'NTupleSvc' 
)

Definition at line 808 of file Bindings.py.

00809                                           :
00810         if name not in self.ExtSvc : self.ExtSvc += [name]
00811 #    if self.HistogramPersistency == 'NONE' : self.HistogramPersistency = 'ROOT'
00812         svc = Helper.service( self._svcloc, name, True )
        return iNTupleSvc(name, svc)
def GaudiPython::Bindings::AppMgr::optSvc (   self,
  name = 'JobOptionsSvc' 
)

Definition at line 820 of file Bindings.py.

00821                                             :
00822         svc = Helper.service( self._svcloc, name, True )
        return iJobOptSvc(name, svc)
def GaudiPython::Bindings::AppMgr::partsvc (   self )

Definition at line 813 of file Bindings.py.

00814                        :
00815         if self.FSMState() == Gaudi.StateMachine.CONFIGURED :  self.initialize()
00816         svc = Helper.service( self._svcloc, 'ParticlePropertySvc' )
        return InterfaceCast(gbl.IParticlePropertySvc)(svc)
def GaudiPython::Bindings::AppMgr::property (   self,
  name 
)

Definition at line 787 of file Bindings.py.

00788                                 :
00789         if name in self.algorithms() : return self.algorithm( name )
00790         elif name in self.services() : return self.service(name )
        else :                         return iProperty( name )
def GaudiPython::Bindings::AppMgr::readOptions (   self,
  file 
)

Definition at line 823 of file Bindings.py.

00824                                 :
        return self._optsvc.readOptions(file)
def GaudiPython::Bindings::AppMgr::removeAlgorithm (   self,
  alg 
)
Remove an Algorithm to the list of Top algorithms. It can be either a instance of
    an Algorithm class or it name 

Definition at line 853 of file Bindings.py.

00854                                    :
00855         """ Remove an Algorithm to the list of Top algorithms. It can be either a instance of
00856             an Algorithm class or it name """
00857         tmp = self.topAlg
00858         if type(alg) is  str :
00859             tmp.remove(alg)
00860         else :
00861             tmp.remove(alg.name())
00862             self.pyalgorithms.remove(alg)
00863             setOwnership(alg,1)
        self.topAlg = tmp
def GaudiPython::Bindings::AppMgr::run (   self,
  n 
)

Definition at line 928 of file Bindings.py.

00929                      :
00930         if self.FSMState() == Gaudi.StateMachine.CONFIGURED :
00931             sc = self.initialize()
00932             if sc.isFailure(): return sc
00933         if self.FSMState() == Gaudi.StateMachine.INITIALIZED :
00934             sc = self.start()
00935             if sc.isFailure(): return sc
        return self._evtpro.executeRun(n)
def GaudiPython::Bindings::AppMgr::runSelectedEvents (   self,
  pfn,
  events 
)

Definition at line 940 of file Bindings.py.

00941                                             :
00942         if self.FSMState() == Gaudi.StateMachine.CONFIGURED :
00943             sc = self.initialize()
00944             if sc.isFailure(): return sc
00945         if self.FSMState() == Gaudi.StateMachine.INITIALIZED :
00946             sc = self.start()
00947             if sc.isFailure(): return sc
00948         #--- Access a number of services ----
00949         if not hasattr(self,'_perssvc'): self.__dict__['_perssvc'] = self.service('EventPersistencySvc','IAddressCreator')
00950         if not hasattr(self,'_filecat'): self.__dict__['_filecat'] = self.service('FileCatalog','Gaudi::IFileCatalog')
00951         if not hasattr(self,'_evtmgr'):  self.__dict__['_evtmgr']  = self.service('EventDataSvc','IDataManagerSvc')
00952         #--- Get FID from PFN and number of events in file
00953         if pfn.find('PFN:') == 0: pfn = pfn[4:]
00954         fid, maxevt = _getFIDandEvents(pfn)
00955         #--- Add FID into catalog if needed ---
00956         if not self._filecat.existsFID(fid) : self._filecat.registerPFN(fid, pfn, '')
00957         #--- Loop over events
00958         if type(events) is not list : events = (events,)
00959         for evt in events :
00960             #--- Create POOL Address from Generic Address
00961             gadd = gbl.GenericAddress(0x202, 1, fid, '/Event', 0, evt)
00962             oadd = makeNullPointer('IOpaqueAddress')
00963             self._perssvc.createAddress(gadd.svcType(),gadd.clID(),gadd.par(),gadd.ipar(),oadd)
00964             #--- Clear TES, set root and run all algorithms
00965             self._evtmgr.clearStore()
00966             self._evtmgr.setRoot('/Event',oadd)
            self._evtpro.executeEvent()
def GaudiPython::Bindings::AppMgr::service (   self,
  name,
  interface = None 
)

Definition at line 755 of file Bindings.py.

00756                                               :
00757         svc = Helper.service( self._svcloc, name )
00758         if interface :
00759             return InterfaceCast(interface)(svc)
00760         else :
            return iService(name, svc )
def GaudiPython::Bindings::AppMgr::services (   self )

Definition at line 765 of file Bindings.py.

00766                        :
00767         l = self._svcloc.getServices()
00768         nl = l.__class__(l)  # get a copy
00769         s = []
00770         for i in range(l.size()) :
00771             s.append(nl.front().name())
00772             nl.pop_front()
        return s
def GaudiPython::Bindings::AppMgr::setAlgorithms (   self,
  algs 
)
Set the list of Top Algorithms.
    It can be an individual of a list of algorithms names or instances 

Definition at line 838 of file Bindings.py.

00839                                   :
00840         """ Set the list of Top Algorithms.
00841             It can be an individual of a list of algorithms names or instances """
00842         if type(algs) is not list : algs = [algs]
00843         names = []
00844         for alg in algs :
00845             if type(alg) is str : names.append(alg)
00846             else :
00847                 self.pyalgorithms.append(alg)
00848                 if self.targetFSMState() >= Gaudi.StateMachine.INITIALIZED :
00849                     alg.sysInitialize()
00850                     if self.targetFSMState() == Gaudi.StateMachine.RUNNING :
00851                         alg.sysStart()
00852                 names.append(alg.name())
        self.topAlg = names
def GaudiPython::Bindings::AppMgr::start (   self )

Definition at line 926 of file Bindings.py.

00927                     :
        return self._appmgr.start()
def GaudiPython::Bindings::AppMgr::state (   self )

Definition at line 750 of file Bindings.py.

00750 : return self._isvc.FSMState()
def GaudiPython::Bindings::AppMgr::targetFSMState (   self )

Definition at line 752 of file Bindings.py.

00752 : return self._isvc.targetFSMState()
def GaudiPython::Bindings::AppMgr::tool (   self,
  name 
)

Definition at line 785 of file Bindings.py.

00786                           :
        return iAlgTool(name)
def GaudiPython::Bindings::AppMgr::toolsvc (   self,
  name = 'ToolSvc' 
)

Definition at line 817 of file Bindings.py.

00818                                       :
00819         svc = Helper.service( self._svcloc, name, True )
        return iToolSvc(name, svc)

Member Data Documentation

Definition at line 986 of file Bindings.py.

Definition at line 985 of file Bindings.py.

Definition at line 982 of file Bindings.py.

Definition at line 983 of file Bindings.py.

Definition at line 648 of file Bindings.py.

Definition at line 984 of file Bindings.py.

Definition at line 648 of file Bindings.py.

Definition at line 988 of file Bindings.py.

Definition at line 987 of file Bindings.py.

Definition at line 839 of file Bindings.py.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Thu Jun 28 2012 23:27:52 for Gaudi Framework, version v23r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004