Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r7 (7f57a304)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Aida2RootEx.py
Go to the documentation of this file.
1 #!/usr/bin/env python2.7
2 
19 " Simple example to illustrate the usage of aida2root converter "
20 from __future__ import print_function
21 
22 # =============================================================================
23 __author__ = "Vanya BELYAEV ibelyaev@phys.syr.edu"
24 # =============================================================================
25 import os
26 import sys
27 
28 import ROOT
29 
30 if "-b" in sys.argv:
31  # Force batch mode
32  ROOT.gROOT.SetBatch(True)
33 
34 from GaudiPython.GaudiAlgs import SUCCESS, HistoAlgo, aida2root
35 
36 # list of booked histograms
37 paths = (
38  "HistoEx/ 1D histo ",
39  "HistoEx/ 2D histo ",
40  "HistoEx/ 3D histo ",
41  "HistoEx1/ 1D histo ",
42  "HistoEx1/ 2D histo ",
43  "HistoEx1/ 3D histo ",
44  "HistoEx2/ x vs y ",
45  "HistoEx2/ x vs y+3x ",
46  "HistoEx2/ x vs y-3x ",
47  "HistoEx2/ x vs y (profile)",
48  "HistoEx2/ x vs y+3x (profile)",
49  "HistoEx2/ x vs y-3x (profile)",
50 )
51 
52 # =============================================================================
53 # @class Aida2RootEx1
54 # Simple algorithm which used aida2root utility
55 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
56 # @date 2007-01-24
57 
58 
60  # Standard Constructor
61  def __init__(self, name="Aida2RootEx1"):
62  """Standard Constructor"""
63  HistoAlgo.__init__(self, name)
64 
65  # the main execution method
66  def execute(self):
67  "The main execution method"
68 
69  # list of booked histograms
70  for path in paths:
71  self.Print("AIDA object: '%s'" % path)
72  # get AIDA pointer
73  aida = self.histoSvc(path)
74  if not aida:
75  return self.Error("Invalid AIDA at '%s'" % path)
76  # explicitly convert to ROOT
77  root = aida2root(aida)
78  if not root:
79  return self.Error("Invalid conversion to ROOT '%s'" % path)
80  # use the native ROOT printout
81  root.Print()
82 
83  return SUCCESS
84 
85 
86 # =============================================================================
87 
88 # =============================================================================
89 # @class Aida2RootEx2
90 # Simple algorithm which uses aida2root utility
91 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
92 # @date 2007-01-24
93 
94 
96  # Standard Constructor
97  def __init__(self, name="Aida2RootEx2"):
98  """Standard Constructor"""
99  HistoAlgo.__init__(self, name)
100 
101  # the main execution method
102  def execute(self):
103  "The main execution method"
104 
105  # get the service itself
106  s = self.histoSvc()
107 
108  for path in paths:
109  self.Print("AIDA object: '%s'" % path)
110  root = s.getAsROOT(path)
111  if not root:
112  return self.Error("Invalid conversion to ROOT '%s'" % path)
113  # use the native ROOT printout
114  root.Print()
115 
116  return SUCCESS
117 
118 
119 # =============================================================================
120 
121 
122 # =============================================================================
123 # The main configuration method
124 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
125 # @date 2007-01-24
126 def configure(gaudi=None):
127  """the main configuration method"""
128 
129  if not gaudi:
130  from GaudiPython.Bindings import AppMgr
131 
132  gaudi = AppMgr()
133 
134  # reuse the previous example
135  import HistoEx2
136 
137  HistoEx2.configure(gaudi)
138 
139  # create the algorithms
140  alg1 = Aida2RootEx1()
141  alg2 = Aida2RootEx2()
142  # append them to the list of Top-Level algorithms
143  gaudi.addAlgorithm(alg1)
144  gaudi.addAlgorithm(alg2)
145 
146  return SUCCESS
147 
148 
149 # =============================================================================
150 # The third way to convert AIDA histograms into ROOT
151 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
152 # @date 2007-01-24
153 def useScript(histos):
154  "the third way to convert AIDA histograms into ROOT"
155 
156  from GaudiPython.Bindings import AppMgr
157 
158  g = AppMgr()
159 
160  hsvc = g.histsvc()
161 
162  i = 0
163  for histo in histos:
164  root = hsvc.getAsROOT(histo)
165  if not root:
166  print("ERROR in access the histogram '%s' " % histo)
167  continue
168  canvas = ROOT.TCanvas("canvas_%d" % i, histo, 250, 250)
169  root.Draw()
170  name = histo.replace("/", "_")
171  name = name.replace("\\", "_")
172  name = name.replace('"', "_")
173  name = name.replace("'", "_")
174  name = name.replace("'", "_")
175  name = name.replace(" ", "_")
176  name = name.replace(os.sep, "_") + ".png"
177  if os.path.exists(name):
178  # strictly speaking, it is not needed, but avoids a message on the stderr
179  os.remove(name)
180  canvas.Print(name)
181  print("The file name is '%s'" % name)
182  i += 1
183 
184 
185 # =============================================================================
186 
187 # =============================================================================
188 # The actual job execution
189 # =============================================================================
190 if "__main__" == __name__:
191  print(__doc__, __author__)
192 
193  from GaudiPython.Bindings import AppMgr
194 
195  gaudi = AppMgr()
196  configure(gaudi)
197  gaudi.run(5)
198 
199  # use the scripts
200  useScript(paths)
201 
202 # =============================================================================
203 # The END
204 # =============================================================================
Aida2RootEx.Aida2RootEx1.__init__
def __init__(self, name="Aida2RootEx1")
Definition: Aida2RootEx.py:61
GaudiPython.GaudiAlgs.HistoAlgo
Definition: GaudiAlgs.py:768
Aida2RootEx.configure
def configure(gaudi=None)
Definition: Aida2RootEx.py:126
GaudiPython.Bindings.AppMgr
Definition: Bindings.py:873
Aida2RootEx.Aida2RootEx1.execute
def execute(self)
Definition: Aida2RootEx.py:66
Aida2RootEx.Aida2RootEx2
Definition: Aida2RootEx.py:95
GaudiPython.Bindings
Definition: Bindings.py:1
Aida2RootEx.Aida2RootEx2.execute
def execute(self)
Definition: Aida2RootEx.py:102
HistoEx2.configure
def configure(gaudi=None)
Definition: HistoEx2.py:67
Aida2RootEx.Aida2RootEx1
Definition: Aida2RootEx.py:59
Aida2RootEx.useScript
def useScript(histos)
Definition: Aida2RootEx.py:153
GaudiMP.GMPBase.aida2root
aida2root
Definition: GMPBase.py:84
Aida2RootEx.Aida2RootEx2.__init__
def __init__(self, name="Aida2RootEx2")
Definition: Aida2RootEx.py:97
GaudiPython.GaudiAlgs
Definition: GaudiAlgs.py:1