The Gaudi Framework  v38r1p1 (ae26267b)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GaudiAlg.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"
 (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations # # This software is distributed under the terms of the Apache version 2 licence, # copied verbatim in the file "LICENSE". More...
 
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 GaudiAlg.TupleUtils._getToolSvc ( **  kwargs)
private
Helper private auxillary utility to get Tool Service

Definition at line 52 of file TupleUtils.py.

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

◆ _nTuple_()

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

Definition at line 71 of file TupleUtils.py.

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

◆ _TupleUtils_AtExit_()

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

Definition at line 207 of file TupleUtils.py.

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

◆ activeTuples()

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

Definition at line 171 of file TupleUtils.py.

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

◆ nTuple()

def GaudiAlg.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 84 of file TupleUtils.py.

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

◆ releaseTuples()

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

Definition at line 182 of file TupleUtils.py.

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

Variable Documentation

◆ __all__

tuple GaudiAlg.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 27 of file TupleUtils.py.

◆ __author__

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

(c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations # # This software is distributed under the terms of the Apache version 2 licence, # copied verbatim in the file "LICENSE".

# # In applying this licence, CERN does not waive the privileges and immunities # granted to it by virtue of its status as an Intergovernmental Organization # or submit itself to any jurisdiction. #


This module contains set of simple and useful utilities to booking and manipulation with N-Tuples (in the spirit of GaudiTuples<TYPE>)

Author
Vanya BELYAEV ibely.nosp@m.aev@.nosp@m.physi.nosp@m.cs.s.nosp@m.yr.ed.nosp@m.u

@date 2007-08-04

Definition at line 25 of file TupleUtils.py.

◆ _Deco

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

Definition at line 43 of file TupleUtils.py.

◆ _Tool

GaudiAlg.TupleUtils._Tool = cpp.ITupleTool
private

Definition at line 42 of file TupleUtils.py.

◆ _TOOLS_

list GaudiAlg.TupleUtils._TOOLS_ = []
private

Definition at line 46 of file TupleUtils.py.

◆ getNTuple

def GaudiAlg.TupleUtils.getNTuple = nTuple

Definition at line 161 of file TupleUtils.py.

◆ getNtuple

def GaudiAlg.TupleUtils.getNtuple = nTuple

Definition at line 162 of file TupleUtils.py.

◆ getntuple

def GaudiAlg.TupleUtils.getntuple = nTuple

Definition at line 163 of file TupleUtils.py.

◆ getTuple

def GaudiAlg.TupleUtils.getTuple = nTuple

Definition at line 164 of file TupleUtils.py.

◆ gettuple

def GaudiAlg.TupleUtils.gettuple = nTuple

Definition at line 165 of file TupleUtils.py.

◆ ntuple

def GaudiAlg.TupleUtils.ntuple = nTuple

Definition at line 160 of file TupleUtils.py.

GaudiAlg.TupleUtils._nTuple_
def _nTuple_(s, *args)
Definition: TupleUtils.py:71
GaudiAlg.TupleUtils.nTuple
def nTuple(dirpath, ID, ID2=None, topdir=None, LUN="FILE1")
Definition: TupleUtils.py:84
GaudiPartProp.Service.AppMgr
AppMgr
Definition: Service.py:40
GaudiAlg.Algs.iAlgTool
iAlgTool
Definition: Algs.py:67
GaudiAlg.TupleUtils.activeTuples
def activeTuples()
Definition: TupleUtils.py:171
GaudiAlg.TupleUtils._getToolSvc
def _getToolSvc(**kwargs)
Definition: TupleUtils.py:52
GaudiPython.Bindings
Definition: Bindings.py:1
GaudiAlg.TupleUtils._TupleUtils_AtExit_
def _TupleUtils_AtExit_()
Definition: TupleUtils.py:207
GaudiAlg.TupleUtils.releaseTuples
def releaseTuples()
Definition: TupleUtils.py:182