The Gaudi Framework  v36r9p1 (5c15b2bb)
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 # =============================================================================
24 __author__ = "Vanya BELYAEV ibelyaev@physics.syr.edu"
25 # =============================================================================
26 
27 import math
28 
29 import GaudiPython
30 
31 Rndm = GaudiPython.gbl.Rndm
32 Numbers = Rndm.Numbers
33 SUCCESS = GaudiPython.SUCCESS
34 
35 from GaudiPython.GaudiAlgs import TupleAlgo
36 
37 # =============================================================================
38 # Simple algorithm which book&fill 3 histograms
39 # =============================================================================
40 
41 
43  """Simple algorithm which implicitely book&Fill Event Tag collection"""
44 
45  def __init__(self, name="EvtColEx"):
46  """Constructor"""
47  TupleAlgo.__init__(self, name)
48  self.s_nEvt = 0
49  self.s_nRun = 0
50 
51  def execute(self):
52  """The major method 'execute', it is invoked for each event"""
53 
54  self.s_nEvt += 1
55  if 1 == self.s_nEvt % 50:
56  self.s_nRun += 1
57 
58  rSvc = self.randSvc()
59 
60  gauss = Numbers(rSvc, Rndm.Gauss(0.0, 1.0))
61  flat = Numbers(rSvc, Rndm.Flat(-10, 10))
62  expo = Numbers(rSvc, Rndm.Exponential(1.0))
63  breit = Numbers(rSvc, Rndm.BreitWigner(0.0, 1.0))
64  poisson = Numbers(rSvc, Rndm.Poisson(2.0))
65  binom = Numbers(rSvc, Rndm.Binomial(8, 0.25))
66 
67  address = self.get("/Event")
68  address = address.registry().address()
69 
70  # get the event tag collection itself
71  tup = self.evtCol("COL1", "My trivial N-tuple")
72 
73  tup.column("Address", address)
74 
75  tup.column("evtNum", self.s_nEvt)
76  tup.column("runNum", self.s_nRun)
77 
78  tup.column("gauss", gauss())
79  tup.column("flat", flat())
80  tup.column("expo", expo())
81  tup.column("poisson", int(poisson()))
82  tup.column("binom", int(binom()))
83  tup.column("flag", 0 > gauss())
84 
85  return SUCCESS
86 
87 
88 def _evtcolsvc_(self, name="EvtTupleSvc"):
89  svc = GaudiPython.Helper.service(self._svcloc, name, False)
90  return GaudiPython.iNTupleSvc(name, svc)
91 
92 
93 GaudiPython.AppMgr.evtcolsvc = _evtcolsvc_
94 
95 # =============================================================================
96 # job configuration
97 # =============================================================================
98 
99 
100 def configure(gaudi=None):
101  """Configuration of the job"""
102 
103  if not gaudi:
104  gaudi = GaudiPython.AppMgr()
105 
106  gaudi.HistogramPersistency = "ROOT"
107  gaudi.DLLs += ["GaudiAlg", "RootHistCnv"]
108  gaudi.ExtSvc += ["RndmGenSvc", "NTupleSvc", "TagCollectionSvc/EvtTupleSvc"]
109 
110  alg = EvtColEx("Fill")
111  gaudi.setAlgorithms([alg])
112 
113  alg.EvtColLUN = "EVTTAGS"
114  alg.EvtColsProduce = True
115  alg.EvtColsPrint = True
116  alg.NTupleProduce = False
117  alg.HistoProduce = False
118 
119  gaudi.OutStream = ["EvtCollectionStream/TagsWriter"]
120  tagsWriter = gaudi.algorithm("TagsWriter")
121  tagsWriter.ItemList = ["/NTUPLES/EVTTAGS/Fill/COL1"]
122  tagsWriter.EvtDataSvc = "EvtTupleSvc"
123 
124  evtColSvc = gaudi.evtcolsvc()
125  evtColSvc.defineOutput({"EVTTAGS": "PFN:EvtTags1.root"}, typ="Gaudi::RootCnvSvc")
126  evtColSvc.OutputLevel = 2
127 
128  evtSel = gaudi.evtSel()
129  evtSel.PrintFreq = 1000
130  evtSel.open(["EvtColsEx.dst"])
131 
132  return SUCCESS
133 
134 
135 # =============================================================================
136 # The actual job excution
137 # =============================================================================
138 if "__main__" == __name__:
139  print(__doc__)
140  # configuration (options)
141  from Configurables import ApplicationMgr, FileCatalog, GaudiPersistency
142 
143  GaudiPersistency()
144  ApplicationMgr().ExtSvc.append(
145  FileCatalog(Catalogs=["xmlcatalog_file:EvtColsEx.xml"])
146  )
147  # execution
149  configure(gaudi)
150  gaudi.run(10000)
151  gaudi.exit()
152 # =============================================================================
153 # The END
154 # =============================================================================
GaudiPython.GaudiAlgs.TupleAlgo
Definition: GaudiAlgs.py:882
EvtColWrite.EvtColEx.execute
def execute(self)
Definition: EvtColWrite.py:51
EvtColWrite._evtcolsvc_
def _evtcolsvc_(self, name="EvtTupleSvc")
Definition: EvtColWrite.py:88
GaudiPython.Bindings.AppMgr
Definition: Bindings.py:873
EvtColWrite.EvtColEx.s_nRun
s_nRun
Definition: EvtColWrite.py:49
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:100
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
EvtColWrite.EvtColEx.__init__
def __init__(self, name="EvtColEx")
Definition: EvtColWrite.py:45
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:42
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:772
EvtColWrite.Numbers
Numbers
Definition: EvtColWrite.py:32
EvtColWrite.EvtColEx.s_nEvt
s_nEvt
Definition: EvtColWrite.py:48
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