The Gaudi Framework  v36r1 (3e2fb5a8)
EvtColWrite.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
13 """
14 *******************************************************************************
15 * *
16 * Simple example which illustrate the usage of useful *
17 * algorithm base class for writing of EventTag Collections *
18 * *
19 *******************************************************************************
20 """
21 from __future__ import print_function
22 # =============================================================================
23 __author__ = 'Vanya BELYAEV ibelyaev@physics.syr.edu'
24 # =============================================================================
25 
26 import GaudiPython
27 import math
28 
29 Rndm = GaudiPython.gbl.Rndm
30 Numbers = Rndm.Numbers
31 SUCCESS = GaudiPython.SUCCESS
32 
33 from GaudiPython.GaudiAlgs import TupleAlgo
34 
35 # =============================================================================
36 # Simple algorithm which book&fill 3 histograms
37 # =============================================================================
38 
39 
41  """ Simple algorithm which implicitely book&Fill Event Tag collection"""
42 
43  def __init__(self, name='EvtColEx'):
44  """ Constructor """
45  TupleAlgo.__init__(self, name)
46  self.s_nEvt = 0
47  self.s_nRun = 0
48 
49  def execute(self):
50  """ The major method 'execute', it is invoked for each event """
51 
52  self.s_nEvt += 1
53  if 1 == self.s_nEvt % 50:
54  self.s_nRun += 1
55 
56  rSvc = self.randSvc()
57 
58  gauss = Numbers(rSvc, Rndm.Gauss(0.0, 1.0))
59  flat = Numbers(rSvc, Rndm.Flat(-10, 10))
60  expo = Numbers(rSvc, Rndm.Exponential(1.0))
61  breit = Numbers(rSvc, Rndm.BreitWigner(0.0, 1.0))
62  poisson = Numbers(rSvc, Rndm.Poisson(2.0))
63  binom = Numbers(rSvc, Rndm.Binomial(8, 0.25))
64 
65  address = self.get('/Event')
66  address = address.registry().address()
67 
68  # get the event tag collection itself
69  tup = self.evtCol('COL1', 'My trivial N-tuple')
70 
71  tup.column('Address', address)
72 
73  tup.column('evtNum', self.s_nEvt)
74  tup.column('runNum', self.s_nRun)
75 
76  tup.column('gauss', gauss())
77  tup.column('flat', flat())
78  tup.column('expo', expo())
79  tup.column('poisson', int(poisson()))
80  tup.column('binom', int(binom()))
81  tup.column('flag', 0 > gauss())
82 
83  return SUCCESS
84 
85 
86 def _evtcolsvc_(self, name='EvtTupleSvc'):
87  svc = GaudiPython.Helper.service(self._svcloc, name, False)
88  return GaudiPython.iNTupleSvc(name, svc)
89 
90 
91 GaudiPython.AppMgr.evtcolsvc = _evtcolsvc_
92 
93 # =============================================================================
94 # job configuration
95 # =============================================================================
96 
97 
98 def configure(gaudi=None):
99  """ Configuration of the job """
100 
101  if not gaudi:
102  gaudi = GaudiPython.AppMgr()
103 
104  gaudi.HistogramPersistency = "ROOT"
105  gaudi.DLLs += ['GaudiAlg', 'RootHistCnv']
106  gaudi.ExtSvc += ['RndmGenSvc', 'NTupleSvc', 'TagCollectionSvc/EvtTupleSvc']
107 
108  alg = EvtColEx('Fill')
109  gaudi.setAlgorithms([alg])
110 
111  alg.EvtColLUN = 'EVTTAGS'
112  alg.EvtColsProduce = True
113  alg.EvtColsPrint = True
114  alg.NTupleProduce = False
115  alg.HistoProduce = False
116 
117  gaudi.OutStream = ['EvtCollectionStream/TagsWriter']
118  tagsWriter = gaudi.algorithm('TagsWriter')
119  tagsWriter.ItemList = ['/NTUPLES/EVTTAGS/Fill/COL1']
120  tagsWriter.EvtDataSvc = "EvtTupleSvc"
121 
122  evtColSvc = gaudi.evtcolsvc()
123  evtColSvc.defineOutput({
124  'EVTTAGS': 'PFN:EvtTags1.root'
125  },
126  typ='Gaudi::RootCnvSvc')
127  evtColSvc.OutputLevel = 2
128 
129  evtSel = gaudi.evtSel()
130  evtSel.PrintFreq = 1000
131  evtSel.open(['EvtColsEx.dst'])
132 
133  return SUCCESS
134 
135 
136 # =============================================================================
137 # The actual job excution
138 # =============================================================================
139 if '__main__' == __name__:
140  print(__doc__)
141  # configuration (options)
142  from Configurables import GaudiPersistency, FileCatalog, ApplicationMgr
143  GaudiPersistency()
144  ApplicationMgr().ExtSvc.append(
145  FileCatalog(Catalogs=['xmlcatalog_file:EvtColsEx.xml']))
146  # execution
148  configure(gaudi)
149  gaudi.run(10000)
150  gaudi.exit()
151 # =============================================================================
152 # The END
153 # =============================================================================
GaudiPython.GaudiAlgs.TupleAlgo
Definition: GaudiAlgs.py:881
EvtColWrite._evtcolsvc_
def _evtcolsvc_(self, name='EvtTupleSvc')
Definition: EvtColWrite.py:86
EvtColWrite.EvtColEx.execute
def execute(self)
Definition: EvtColWrite.py:49
EvtColWrite.EvtColEx.__init__
def __init__(self, name='EvtColEx')
Definition: EvtColWrite.py:43
GaudiPython.Bindings.AppMgr
Definition: Bindings.py:842
EvtColWrite.EvtColEx.s_nRun
s_nRun
Definition: EvtColWrite.py:47
Rndm::Flat
Parameters for the flat random number generation within boundaries [minimum, maximum].
Definition: RndmGenerators.h:253
EvtColWrite.configure
def configure(gaudi=None)
Definition: EvtColWrite.py:98
Rndm::Gauss
Parameters for the Gauss random number generation.
Definition: RndmGenerators.h:32
Rndm::Numbers
Random number accessor This small class encapsulates the use of the random number generator.
Definition: RndmGenerators.h:359
Rndm::BreitWigner
Parameters for the BreitWigner distributed random number generation.
Definition: RndmGenerators.h:94
HistoUtilsEx.gauss
gauss
Definition: HistoUtilsEx.py:66
EvtColWrite.EvtColEx
Definition: EvtColWrite.py:40
GaudiPython::Helper::service
static IService * service(ISvcLocator *svcloc, const std::string &name, bool createif=false)
Definition: Helpers.h:106
GaudiPython.Bindings.iNTupleSvc
Definition: Bindings.py:745
EvtColWrite.Numbers
Numbers
Definition: EvtColWrite.py:30
EvtColWrite.EvtColEx.s_nEvt
s_nEvt
Definition: EvtColWrite.py:46
Rndm::Exponential
Parameters for the Gauss random number generation.
Definition: RndmGenerators.h:56
Rndm::Poisson
Parameters for the Poisson distributed random number generation with a given mean.
Definition: RndmGenerators.h:209
GaudiPython.GaudiAlgs
Definition: GaudiAlgs.py:1
Rndm::Binomial
Parameters for the Binomial distributed random number generation.
Definition: RndmGenerators.h:230