Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r11 (bdb84f5f)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GaudiPython.TupleUtils Namespace Reference

Functions

def _getToolSvc (**kwargs)
 
def _nTuple_ (s, *args)
 
def nTuple (dirpath, ID, ID2=None, topdir=None, LUN="FILE1")
 
def activeTuples ()
 
def releaseTuples ()
 
def _TupleUtils_AtExit_ ()
 

Variables

string __author__ = "Vanya BELYAEV ibelyaev@physics.syr.edu"
 
tuple __all__
 
 _Tool = cpp.ITupleTool
 
 _Deco = cpp.GaudiPython.TupleToolDecorator
 
list _TOOLS_ = []
 
def ntuple = nTuple
 
def getNTuple = nTuple
 
def getNtuple = nTuple
 
def getntuple = nTuple
 
def getTuple = nTuple
 
def gettuple = nTuple
 

Function Documentation

◆ _getToolSvc()

def GaudiPython.TupleUtils._getToolSvc ( **  kwargs)
private
Helper private auxillary utility to get Tool Service

Definition at line 53 of file TupleUtils.py.

53 def _getToolSvc(**kwargs):
54  """Helper private auxillary utility to get Tool Service"""
55  svc = kwargs.get("toolSvc", None)
56  if not svc:
57  svc = kwargs.get("toolsvc", None)
58  if not svc:
59  svc = kwargs.get("service", None)
60  if not svc:
61  svc = kwargs.get("svc", None)
62  else:
63  return svc # RETURN
64  gaudi = kwargs.get("gaudi", None)
65  if not gaudi:
66  gaudi = AppMgr()
67  return gaudi.toolsvc() # RETURN
68 
69 
70 # =============================================================================
71 # Retrive N-Tuple ( book on demand )

◆ _nTuple_()

def GaudiPython.TupleUtils._nTuple_ (   s,
args 
)
private
Retrive N-tuple ( book on demand )

Definition at line 72 of file TupleUtils.py.

72 def _nTuple_(s, *args):
73  """Retrive N-tuple ( book on demand )"""
74  return _Deco.nTuple(s, *args)
75 
76 
77 # =============================================================================
78 _nTuple_.__doc__ += "\n" + _Deco.nTuple.__doc__
79 _Tool.nTuple = _nTuple_
80 _Tool.ntuple = _nTuple_
81 
82 
83 # =============================================================================
84 # Retrieve (book-on-demand) 'Smart'-N-tuple object.

◆ _TupleUtils_AtExit_()

def GaudiPython.TupleUtils._TupleUtils_AtExit_ ( )
private
AtExit function for GaudiPython.TupleUtils module

Definition at line 208 of file TupleUtils.py.

208 def _TupleUtils_AtExit_():
209  """
210  AtExit function for GaudiPython.TupleUtils module
211  """
212  if activeTuples():
213  print("WARNING: the list of local TupleTools is not empty!")
214  print("WARNING: please use GaudiPython.TupleUtils.releaseTuples() at the end")
215 
216 

◆ activeTuples()

def GaudiPython.TupleUtils.activeTuples ( )
Return the list of active tools

Definition at line 172 of file TupleUtils.py.

172 def activeTuples():
173  """
174  Return the list of active tools
175  """
176  return _TOOLS_
177 
178 
179 # =============================================================================
180 # Release the active tool/tuples
181 
182 

◆ nTuple()

def GaudiPython.TupleUtils.nTuple (   dirpath,
  ID,
  ID2 = None,
  topdir = None,
  LUN = "FILE1" 
)
Retrieve 'Smart'-N-tuple object.
N-tuple is booked on-demand.

Atetntion !!
The logical unit LUN must be configured by N-Tuple Service

Retrieve (book-n-demand) N-Tuple using
the  directory name and the title:
>>> t = nTuple ( 'the/path/to/directory' , ## the path to the directory
                 'N-tuple title'         , ## the title for N-Tuple
                  LUN = 'FILE1'          ) ## logical file unit

Retrieve (book-n-demand) N-Tuple using
the  directory name, literal ID and the title:
>>> t = nTuple ( 'the/path/to/directory' , ## the path to the directory
                 'Tuple1'                , ## the literal ID for N-Tuple
                 'N-tuple title'         , ## the title for N-Tuple
                  LUN = 'FILE1'          ) ## logical file unit

Retrieve (book-n-demand) N-Tuple using
the  directory name, numerical ID and the title:
>>> t = nTuple ( 'the/path/to/directory' , ## the path to the directory
                 124                     , ## the numerical ID for N-Tuple
                 'N-tuple title'         , ## the title for N-Tuple
                  LUN = 'FILE1'          ) ## logical file unit

Definition at line 85 of file TupleUtils.py.

85 def nTuple(dirpath, ID, ID2=None, topdir=None, LUN="FILE1"):
86  """
87  Retrieve 'Smart'-N-tuple object.
88  N-tuple is booked on-demand.
89 
90  Atetntion !!
91  The logical unit LUN must be configured by N-Tuple Service
92 
93  Retrieve (book-n-demand) N-Tuple using
94  the directory name and the title:
95  >>> t = nTuple ( 'the/path/to/directory' , ## the path to the directory
96  'N-tuple title' , ## the title for N-Tuple
97  LUN = 'FILE1' ) ## logical file unit
98 
99  Retrieve (book-n-demand) N-Tuple using
100  the directory name, literal ID and the title:
101  >>> t = nTuple ( 'the/path/to/directory' , ## the path to the directory
102  'Tuple1' , ## the literal ID for N-Tuple
103  'N-tuple title' , ## the title for N-Tuple
104  LUN = 'FILE1' ) ## logical file unit
105 
106  Retrieve (book-n-demand) N-Tuple using
107  the directory name, numerical ID and the title:
108  >>> t = nTuple ( 'the/path/to/directory' , ## the path to the directory
109  124 , ## the numerical ID for N-Tuple
110  'N-tuple title' , ## the title for N-Tuple
111  LUN = 'FILE1' ) ## logical file unit
112 
113 
114  """
115  toolSvc = _getToolSvc()
116 
117  # construct the name of the intermediate TupleTool
118  name = "Tuple" + LUN + "/"
119  if topdir:
120  name += topdir
121  name += dirpath
122  name += "_%s" % ID
123  if ID2:
124  name += "_%s" % ID2
125  name = name.replace(".", "_")
126  name = name.replace("/", "_")
127  name = name.replace("\\", "_")
128  name = name.replace(" ", "_")
129 
130  # define tool properties
131  t0 = GaudiPython.iAlgTool("ToolSvc." + name)
132  t0.OutputLevel = 1
133  t0.NTupleLUN = LUN
134  t0.NTupleDir = dirpath
135  t0.PropertiesPrint = False
136  t0.OutputLevel = 4
137  if topdir:
138  t0.NTupleTopDir = topdir
139 
140  # get the tool from Tool service
141  tool = toolSvc.create("TupleTool", name, interface=_Tool)
142 
143  # check the properties and redefine them if needed
144  t1 = GaudiPython.iAlgTool(tool.name(), tool)
145  if t1.NTupleLUN != LUN:
146  t1.NTupleLUN = LUN
147  if t1.NTupleDir != dirpath:
148  t1.NTupleDir = dirpath
149  if topdir and (t1.NTupleTopDir != topdir):
150  t1.NTupleTopDir = topdir
151 
152  _TOOLS_.append(tool)
153  if not ID2:
154  return tool.nTuple(ID) # RETURN
155 
156  return tool.nTuple(ID, ID2) # RETURN
157 
158 
159 nTuple.__doc__ += "\n\t help(ITupleTool.nTuple) : \n" + _Tool.nTuple.__doc__
160 

◆ releaseTuples()

def GaudiPython.TupleUtils.releaseTuples ( )
Release the active tool/tuples
The method needs to be invoked explicitely at the end of the job

Definition at line 183 of file TupleUtils.py.

183 def releaseTuples():
184  """
185  Release the active tool/tuples
186  The method needs to be invoked explicitely at the end of the job
187  """
188  if not _TOOLS_:
189  return
190  from GaudiPython.Bindings import _gaudi
191 
192  if not _gaudi:
193  return
194 
195  toolSvc = _getToolSvc()
196  if toolSvc.isValid():
197  while _TOOLS_:
198  t = _TOOLS_.pop()
199  if not t:
200  continue
201  while 1 < t.refCount():
202  toolSvc._its.releaseTool(t)
203 
204 
205 # =============================================================================
206 
207 

Variable Documentation

◆ __all__

tuple GaudiPython.TupleUtils.__all__
private
Initial value:
1 = (
2  "nTuple", # function to book/retrieve N-tuple
3  "getNTuple", # ditto
4  "getNtuple", # ditto
5  "getntuple", # ditto
6  "gettuple", # ditto
7  "activeTuples", # get the list of all active n-tuples
8  "releaseTuples", # release all actibe N-tuples
9 )

Definition at line 28 of file TupleUtils.py.

◆ __author__

string GaudiPython.TupleUtils.__author__ = "Vanya BELYAEV ibelyaev@physics.syr.edu"
private

Definition at line 26 of file TupleUtils.py.

◆ _Deco

GaudiPython.TupleUtils._Deco = cpp.GaudiPython.TupleToolDecorator
private

Definition at line 44 of file TupleUtils.py.

◆ _Tool

GaudiPython.TupleUtils._Tool = cpp.ITupleTool
private

Definition at line 43 of file TupleUtils.py.

◆ _TOOLS_

list GaudiPython.TupleUtils._TOOLS_ = []
private

Definition at line 47 of file TupleUtils.py.

◆ getNTuple

def GaudiPython.TupleUtils.getNTuple = nTuple

Definition at line 162 of file TupleUtils.py.

◆ getNtuple

def GaudiPython.TupleUtils.getNtuple = nTuple

Definition at line 163 of file TupleUtils.py.

◆ getntuple

def GaudiPython.TupleUtils.getntuple = nTuple

Definition at line 164 of file TupleUtils.py.

◆ getTuple

def GaudiPython.TupleUtils.getTuple = nTuple

Definition at line 165 of file TupleUtils.py.

◆ gettuple

def GaudiPython.TupleUtils.gettuple = nTuple

Definition at line 166 of file TupleUtils.py.

◆ ntuple

def GaudiPython.TupleUtils.ntuple = nTuple

Definition at line 161 of file TupleUtils.py.

GaudiPython.TupleUtils._TupleUtils_AtExit_
def _TupleUtils_AtExit_()
Definition: TupleUtils.py:208
GaudiPython.TupleUtils._nTuple_
def _nTuple_(s, *args)
Definition: TupleUtils.py:72
GaudiPython.Bindings
Definition: Bindings.py:1
GaudiPython.TupleUtils.activeTuples
def activeTuples()
Definition: TupleUtils.py:172
GaudiPython.TupleUtils.nTuple
def nTuple(dirpath, ID, ID2=None, topdir=None, LUN="FILE1")
Definition: TupleUtils.py:85
GaudiPython.TupleUtils._getToolSvc
def _getToolSvc(**kwargs)
Definition: TupleUtils.py:53
GaudiPython.TupleUtils.releaseTuples
def releaseTuples()
Definition: TupleUtils.py:183
GaudiPython.Bindings.iAlgTool
Definition: Bindings.py:490