00001
00002
00003
00004
00005
00006
00007
00008
00009 from DybPython.DybPythonAlg import DybPythonAlg
00010 from GaudiPython import SUCCESS, FAILURE
00011 from GaudiPython import gbl
00012
00013
00014 TH1F = gbl.TH1F
00015
00016
00017 class ExampleAlg(DybPythonAlg):
00018 "Example Python Algorithm"
00019 def __init__(self,name):
00020 DybPythonAlg.__init__(self,name)
00021
00022 self.MyProperty = 1
00023 return
00024
00025 def initialize(self):
00026 status = DybPythonAlg.initialize(self)
00027 if status.isFailure(): return status
00028 self.info("initializing")
00029
00030
00031
00032
00033
00034
00035 self.stats["/file1/path/to/MyHist1"] = TH1F("MyHist1","Test Histogram",
00036 100,0.0,10.0)
00037 return SUCCESS
00038
00039 def execute(self):
00040 self.info("executing")
00041
00042
00043 evt = self.evtSvc()
00044 currentHdr = evt["/Event/Readout/ReadoutHeader"]
00045 if currentHdr == None:
00046 self.error("Failed to get current readout header")
00047 return FAILURE
00048
00049
00050 readoutArchive = self.getAES("/Event/Readout/ReadoutHeader")
00051 if readoutArchive == None:
00052 self.error("Failed to get recent readout headers")
00053 return FAILURE
00054
00055 for readoutHdr in readoutArchive:
00056 readout = readoutHdr.readout()
00057
00058 firstHdr = readoutArchive[0]
00059
00060
00061 for readoutHdr in readoutArchive[1:]:
00062 readout = readoutHdr.readout()
00063
00064
00065
00066
00067 myResult = 3.14
00068
00069 self.stats["/file1/path/to/MyHist1"].Fill( myResult )
00070
00071
00072 self.error("an error message")
00073 self.warning("a warning")
00074 self.info("some information")
00075 self.debug("some extra debugging information")
00076 self.verbose("too much information")
00077 return SUCCESS
00078
00079 def finalize(self):
00080 self.info("finalizing")
00081 status = DybPythonAlg.finalize(self)
00082 return status
00083
00084
00085
00086
00087 def configure():
00088 from StatisticsSvc.StatisticsSvcConf import StatisticsSvc
00089 statsSvc = StatisticsSvc()
00090 statsSvc.Output ={"file1":"readoutResult.root"}
00091 return
00092
00093 def run(app):
00094 '''
00095 Configure and add an algorithm to job
00096 '''
00097 app.ExtSvc += ["StaticCableSvc", "StatisticsSvc"]
00098 example = ExampleAlg("MyExample")
00099
00100 example.MyProperty = 2
00101 app.addAlgorithm(example)
00102 pass
00103