| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

DybPythonAlg.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 '''
00003 DayaBay wrapper class for Python-based GaudiAlgorithm
00004 
00005 Provides some additional conveniences, like automatic access to the
00006 MessageSvc
00007 '''
00008 # dandwyer@caltech.edu  2009-05-05
00009 
00010 __all__ = [ 'DybPythonAlg' ]
00011 
00012 # Load GaudiPython
00013 from GaudiPython.GaudiAlgs import GaudiAlgo
00014 from GaudiPython import SUCCESS, FAILURE
00015 from GaudiPython import gbl
00016 from GaudiKernel.Constants import VERBOSE, DEBUG, INFO, WARNING, ERROR, FATAL
00017 from GaudiKernel import SystemOfUnits as units
00018 from GaudiPython import iDataSvc
00019 from DybPython.Util import irange
00020 from DybPython.iStatsSvc import iStatsSvc
00021 
00022 from GaudiPython import loaddict
00023 loaddict('libHepMCRflx')        # for HepMC Python wrappers
00024 
00025 # Base DayaBay Python Algorithm
00026 class DybPythonAlg(GaudiAlgo):
00027     "Base DayaBay Python Algorithm"
00028     def __init__(self,name = None):
00029 
00030         '''
00031         Create a DybPythonAlg.  The name is the class name by default.
00032         If sub class overrides this method it must be explicitly called like:
00033 
00034         DybPythonAlg.__init__(self,name)
00035         or
00036         DybPythonAlg.__init__(self)
00037         '''
00038 
00039         if not name: name = self.__class__.__name__
00040         GaudiAlgo.__init__(self,name)
00041         self.msgSvc = None
00042         self.archiveSvc = None
00043         self.stats = iStatsSvc(self)
00044         return
00045 
00046     def initialize(self):
00047 
00048         '''Initialize the algorithm.  If sub classes overrides this
00049         method they must call it explicitly near the beginning like:
00050 
00051         sc = DybPythonAlg.initialize(self)
00052         if sc.isFailure(): return sc
00053         # ... now do my own initialization ...
00054         '''
00055 
00056         status = GaudiAlgo.initialize(self)
00057         if not status.isSuccess(): return status
00058         # Get handle to message svc
00059         self.msgSvc = self.svc('IMessageSvc','MessageSvc')
00060         if self.msgSvc == None:
00061             print "DybPythonAlg.initialize(): Failed to get MessageSvc"
00062             return FAILURE
00063         return SUCCESS
00064 
00065     def _initializeAES(self):
00066         # Get handle to archive data svc if it is available
00067         if self.archiveSvc != None:
00068             self.warning("Archive data service already initialized.")
00069             return SUCCESS
00070         archiveSvc = self.svc("IDataProviderSvc","EventDataArchiveSvc")
00071         if archiveSvc == None:
00072             self.warning("Archive data service not available.")
00073             return FAILURE
00074         else:
00075             baseSvc = self.svc("IService","EventDataArchiveSvc")
00076             self.archiveSvc = iDataSvc( baseSvc.name(), archiveSvc )
00077         return SUCCESS
00078 
00079     def execute(self):
00080         'Subclass should override this method'
00081         self.info("Executing DybPythonAlg:"+self.name())
00082         return SUCCESS
00083         
00084     def finalize(self):
00085         '''Finalize the algorithm.  If sub classes overrides this
00086         method they must call it explicitly like at the end:
00087 
00088         # ... first do my own finalization ...
00089         return DybPythonAlg.finalize(self)
00090         '''
00091         self.msgSvc.release()
00092         self.msgSvc = None
00093         self.archiveSvc = None
00094         status = GaudiAlgo.finalize(self)
00095         return status
00096 
00097     # Define some helpful logging shortcuts
00098     def verbose(self, message):
00099         'Emit message at verbose level'
00100         self.msgSvc.reportMessage(self.name(), VERBOSE, message)
00101         return
00102 
00103     def debug(self, message):
00104         'Emit message at debug level'
00105         self.msgSvc.reportMessage(self.name(), DEBUG, message)
00106         return
00107     
00108     def info(self, message):
00109         'Emit message at info level'
00110         self.msgSvc.reportMessage(self.name(), INFO, message)
00111         return
00112     
00113     def warning(self, message):
00114         'Emit message at warning level'
00115         self.msgSvc.reportMessage(self.name(), WARNING, message)
00116         return
00117     
00118     def error(self, message):
00119         'Emit message at error level'
00120         self.msgSvc.reportMessage(self.name(), ERROR, message)
00121         return
00122     
00123     def fatal(self, message):
00124         'Emit message at fatal level'
00125         self.msgSvc.reportMessage(self.name(), FATAL, message)
00126         return
00127     
00128     def getAES(self, path):
00129         'Return the list of items at the AES path'
00130         if self.archiveSvc == None:
00131             status = self._initializeAES()
00132             if (not status.isSuccess()) or self.archiveSvc == None:
00133                 self.error("Archive data svc not available")
00134                 return None
00135         archiveList = self.archiveSvc[path]
00136         if archiveList == None:
00137             self.error("Path in archive not available: "+path)
00138             return None
00139         dataList = []
00140         for dataObject in irange(archiveList.begin(), archiveList.end()):
00141             dataList.append(dataObject)
00142         return dataList
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:13:00 2011 for DybPython by doxygen 1.4.7