The Gaudi Framework  v38r3 (c3fc9673)
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

 __author__
 (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...
 
 __all__
 
 _Tool
 
 _Deco
 
 _TOOLS_
 
 ntuple
 
 getNTuple
 
 getNtuple
 
 getntuple
 
 getTuple
 
 gettuple
 

Function Documentation

◆ _getToolSvc()

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

Definition at line 51 of file TupleUtils.py.

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

◆ _nTuple_()

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

Definition at line 70 of file TupleUtils.py.

70 def _nTuple_(s, *args):
71  """Retrive N-tuple ( book on demand )"""
72  return _Deco.nTuple(s, *args)
73 
74 
75 # =============================================================================
76 _nTuple_.__doc__ += "\n" + _Deco.nTuple.__doc__
77 _Tool.nTuple = _nTuple_
78 _Tool.ntuple = _nTuple_
79 
80 
81 # =============================================================================
82 # 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 206 of file TupleUtils.py.

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

◆ activeTuples()

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

Definition at line 170 of file TupleUtils.py.

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

◆ 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 83 of file TupleUtils.py.

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

◆ 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 181 of file TupleUtils.py.

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

Variable Documentation

◆ __all__

GaudiAlg.TupleUtils.__all__
private

Definition at line 27 of file TupleUtils.py.

◆ __author__

GaudiAlg.TupleUtils.__author__
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
private

Definition at line 42 of file TupleUtils.py.

◆ _Tool

GaudiAlg.TupleUtils._Tool
private

Definition at line 41 of file TupleUtils.py.

◆ _TOOLS_

GaudiAlg.TupleUtils._TOOLS_
private

Definition at line 45 of file TupleUtils.py.

◆ getNTuple

GaudiAlg.TupleUtils.getNTuple

Definition at line 160 of file TupleUtils.py.

◆ getNtuple

GaudiAlg.TupleUtils.getNtuple

Definition at line 161 of file TupleUtils.py.

◆ getntuple

GaudiAlg.TupleUtils.getntuple

Definition at line 162 of file TupleUtils.py.

◆ getTuple

GaudiAlg.TupleUtils.getTuple

Definition at line 163 of file TupleUtils.py.

◆ gettuple

GaudiAlg.TupleUtils.gettuple

Definition at line 164 of file TupleUtils.py.

◆ ntuple

GaudiAlg.TupleUtils.ntuple

Definition at line 159 of file TupleUtils.py.

GaudiAlg.TupleUtils._nTuple_
def _nTuple_(s, *args)
Definition: TupleUtils.py:70
GaudiAlg.TupleUtils.nTuple
def nTuple(dirpath, ID, ID2=None, topdir=None, LUN="FILE1")
Definition: TupleUtils.py:83
GaudiPartProp.Service.AppMgr
AppMgr
Definition: Service.py:41
GaudiAlg.Algs.iAlgTool
iAlgTool
Definition: Algs.py:67
GaudiAlg.TupleUtils.activeTuples
def activeTuples()
Definition: TupleUtils.py:170
GaudiAlg.TupleUtils._getToolSvc
def _getToolSvc(**kwargs)
Definition: TupleUtils.py:51
GaudiPython.Bindings
Definition: Bindings.py:1
GaudiAlg.TupleUtils._TupleUtils_AtExit_
def _TupleUtils_AtExit_()
Definition: TupleUtils.py:206
GaudiAlg.TupleUtils.releaseTuples
def releaseTuples()
Definition: TupleUtils.py:181