| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Test.py
Go to the documentation of this file.
1 import math
2 import sys
3 #----------Patch to force loading .so with RTDL_GLOBAL
4 if sys.platform == 'linux2' : sys.setdlopenflags(0x100|0x2)
5
6 import gaudimodule as gaudi
7 g = gaudi.AppMgr()
8 g.JobOptionsType = 'NONE'
9 g.EvtSel = "NONE"
10
11 g.config()
12 print '**************GaudiPython Job has been configured*************'
13
14 g.DLLs = ['GaudiAlg', 'GaudiIntrospection']
15 g.ExtSvc = ['IntrospectionSvc']
16
17 g.service('IntrospectionSvc').Dictionaries = ['TestDict']
18
19 g.DLLs += ['Test']
20
21 seq1 = g.algorithm('seq1')
22 seq1.members = ['HelloWorld', 'WriteAlg' ]
23
24 g.topAlg += ['Sequencer/seq1']
25
26 g.initialize()
27 print '**************GaudiPython Job has been initialized*************'
28 g.run(2)
29 print '**************GaudiPython Job has been run ********************'
30
31
32 evt = gaudi.DataSvc(g.service('EventDataSvc'))
33 header = evt['/Event']
34 print '***The event header is: ', header.values()
35 tracks = evt['/Event/MyTracks']
36 print '***I got ', len(tracks), ' tracks'
37
38 his = gaudi.HistoSvc(g.service('HistogramDataSvc'))
39 h1 = his.book('h1', 'histogram title 1D', 10, 0, 10)
40 print '***Created 1D histogram'
41 print h1
42 h2 = his.book('h2', 'histogram title 1D', 10, 0, 10, 20, 0, 10)
43 print '***Created 2D histogram'
44 print h2
45
46 print '**************Histograms Tested ********************'
47
48
49 #---------------User Algorithm----------------------------------------------
50 class PhysAnalAlg(gaudi.PyAlgorithm):
51 def initialize(self):
52 self.evt = gaudi.DataSvc(g.service('EventDataSvc'))
53 self.his = gaudi.HistoSvc(g.service('HistogramDataSvc'))
54 print 'Initializing User Analysis...'
55 self.h1 = self.his.book('myhisto1', 'Histogram 1D for tests', 20, 0., 40.)
56 self.h2 = self.his.book('myhisto2', 'Histogram 2D for test2', 20, 0., 40., 20, 0., 10.)
57 print '....User Analysis Initialized'
58 return 1
59 def execute(self):
60 tks = self.evt.object('MyTracks')
61 print 'MyTracks collection contains ' + `len(tks)` + ' Tracks'
62 for t in tks :
63 self.h1.fill( math.sqrt(t.px*t.px + t.py*t.py + t.pz*t.pz), 1)
64 self.h2.fill( t.px, t.py )
65 return 1
66 def finalize(self):
67 print 'Finalizing User Analysis...'
68 print self.h1
69 print self.h1.entries()
70 print self.h2
71 print '....User Analysis Finalized'
72 return 1
73
74 print '**************Testing Python Algorithms ********************'
75 phyanalalg = PhysAnalAlg('PythonAlgorithm')
76 g.topAlg = g.topAlg + [ 'PythonAlgorithm' ]
77 g.run(100)
78 g.exit()
79
80
81
82
83
84
85
86
87
Test.PhysAnalAlg.execute
def execute(self)
Definition: Test.py:59
Test.PhysAnalAlg.h1
h1
Definition: Test.py:55
Test.PhysAnalAlg.evt
evt
Definition: Test.py:52
Test.PhysAnalAlg.finalize
def finalize(self)
Definition: Test.py:66
Test.PhysAnalAlg.his
his
Definition: Test.py:53
Test.PhysAnalAlg
Definition: Test.py:50
Test.PhysAnalAlg.initialize
def initialize(self)
Definition: Test.py:51
Test.PhysAnalAlg.h2
h2
Definition: Test.py:56