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