| # Gaudi Framework, version v21r7 |

Home |  | Generated: 22 Jan 2010

# Test.py

Go to the documentation of this file.

    00001 import math
    00002 import sys
    00003 #----------Patch to force loading .so with RTDL_GLOBAL
    00004 if sys.platform == 'linux2' : sys.setdlopenflags(0x100|0x2)
    00005
    00006 import gaudimodule as gaudi
    00007 g = gaudi.AppMgr()
    00008 g.JobOptionsType = 'NONE'
    00009 g.EvtSel  = "NONE"
    00010
    00011 g.config()
    00012 print '**************GaudiPython Job has been configured*************'
    00013
    00014 g.DLLs   =   ['GaudiAlg', 'GaudiIntrospection']
    00015 g.ExtSvc =   ['IntrospectionSvc']
    00016
    00017 g.service('IntrospectionSvc').Dictionaries = ['TestDict']
    00018
    00019 g.DLLs   +=  ['Test']
    00020
    00021 seq1 = g.algorithm('seq1')
    00022 seq1.members = ['HelloWorld', 'WriteAlg' ]
    00023
    00024 g.topAlg +=  ['Sequencer/seq1']
    00025
    00026 g.initialize()
    00027 print '**************GaudiPython Job has been initialized*************'
    00028 g.run(2)
    00029 print '**************GaudiPython Job has been run ********************'
    00030
    00031
    00032 evt    = gaudi.DataSvc(g.service('EventDataSvc'))
    00033 header = evt['/Event']
    00034 print '***The event header is: ', header.values()
    00035 tracks = evt['/Event/MyTracks']
    00036 print '***I got ', len(tracks), ' tracks'
    00037
    00038 his    = gaudi.HistoSvc(g.service('HistogramDataSvc'))
    00039 h1 = his.book('h1', 'histogram title 1D', 10, 0, 10)
    00040 print '***Created 1D histogram'
    00041 print h1
    00042 h2 = his.book('h2', 'histogram title 1D', 10, 0, 10, 20, 0, 10)
    00043 print '***Created 2D histogram'
    00044 print h2
    00045
    00046 print '**************Histograms Tested ********************'
    00047
    00048
    00049 #---------------User Algorithm----------------------------------------------
    00050 class PhysAnalAlg(gaudi.PyAlgorithm):
    00051   def initialize(self):
    00052     self.evt = gaudi.DataSvc(g.service('EventDataSvc'))
    00053     self.his = gaudi.HistoSvc(g.service('HistogramDataSvc'))
    00054     print 'Initializing User Analysis...'
    00055     self.h1 = self.his.book('myhisto1', 'Histogram 1D for tests', 20, 0., 40.)
    00056     self.h2 = self.his.book('myhisto2', 'Histogram 2D for test2', 20, 0., 40., 20, 0., 10.)
    00057     print '....User Analysis Initialized'
    00058     return 1
    00059   def execute(self):
    00060     tks = self.evt.object('MyTracks')
    00061     print 'MyTracks collection contains '  + `len(tks)` + ' Tracks'
    00062     for t in tks :
    00063       self.h1.fill( math.sqrt(t.px*t.px + t.py*t.py + t.pz*t.pz), 1)
    00064       self.h2.fill( t.px, t.py )
    00065     return 1
    00066   def finalize(self):
    00067     print 'Finalizing User Analysis...'
    00068     print self.h1
    00069     print self.h1.entries()
    00070     print self.h2
    00071     print '....User Analysis Finalized'
    00072     return 1
    00073
    00074 print '**************Testing Python Algorithms ********************'
    00075 phyanalalg = PhysAnalAlg('PythonAlgorithm')
    00076 g.topAlg = g.topAlg + [ 'PythonAlgorithm' ]
    00077 g.run(100)
    00078 g.exit()
    00079
    00080
    00081
    00082
    00083
    00084
    00085
    00086
    00087