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

In This Package:

Example.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Template for writing your own algorithm
00004 #
00005 #  Usage:
00006 #   nuwa.py -A 1 Example simulationData.root
00007 
00008 # Load DybPython
00009 from DybPython.DybPythonAlg import DybPythonAlg
00010 from GaudiPython import SUCCESS, FAILURE
00011 from GaudiPython import gbl
00012 
00013 # Make shortcuts to any ROOT classes you want to use
00014 TH1F = gbl.TH1F
00015 
00016 # Make your algorithm
00017 class ExampleAlg(DybPythonAlg):
00018     "Example Python Algorithm"
00019     def __init__(self,name):
00020         DybPythonAlg.__init__(self,name)
00021         # Define Properties and default values here
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         # Initialize services
00031         #  Cable Service: Use for pmt and electronics channel info
00032         # self.cableSvc = self.svc('ICableSvc','StaticCableSvc')
00033 
00034         # Make a histogram
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         # Access current data
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         # Access recent data in archive
00050         readoutArchive = self.getAES("/Event/Readout/ReadoutHeader")
00051         if readoutArchive == None:
00052             self.error("Failed to get recent readout headers")
00053             return FAILURE
00054         # Loop over all readouts in archive, including current readout
00055         for readoutHdr in readoutArchive:
00056             readout = readoutHdr.readout()
00057         # Access current readout (First entry in archive!)
00058         firstHdr = readoutArchive[0]
00059         # This is true: firstHdr == currentHdr
00060         # Loop over previous readouts, not including current readout
00061         for readoutHdr in readoutArchive[1:]:
00062             readout = readoutHdr.readout()
00063 
00064         # Do some calculation...
00065         # ...
00066         # ...
00067         myResult = 3.14
00068         # Add entry to histogram
00069         self.stats["/file1/path/to/MyHist1"].Fill( myResult )
00070 
00071         # Print messages to the job log
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 #####  Job Configuration for nuwa.py ########################################
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     # Set your algorithm Properties here
00100     example.MyProperty = 2
00101     app.addAlgorithm(example)
00102     pass
00103 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:05:58 2011 for DivingIn by doxygen 1.4.7