The Gaudi Framework  v32r2 (46d42edc)
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 42 of file TupleUtils.py.

42 def _getToolSvc(**kwargs):
43  """ Helper private auxillary utility to get Tool Service """
44  svc = kwargs.get('toolSvc', None)
45  if not svc:
46  svc = kwargs.get('toolsvc', None)
47  if not svc:
48  svc = kwargs.get('service', None)
49  if not svc:
50  svc = kwargs.get('svc', None)
51  else:
52  return svc # RETURN
53  gaudi = kwargs.get('gaudi', None)
54  if not gaudi:
55  gaudi = AppMgr()
56  return gaudi.toolsvc() # RETURN
57 
58 
59 # =============================================================================
60 # Retrive N-Tuple ( book on demand )
def _getToolSvc(**kwargs)
Definition: TupleUtils.py:42

◆ _nTuple_()

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

Definition at line 61 of file TupleUtils.py.

61 def _nTuple_(s, *args):
62  """ Retrive N-tuple ( book on demand ) """
63  return _Deco.nTuple(s, *args)
64 
65 
66 # =============================================================================
67 _nTuple_.__doc__ += "\n" + _Deco.nTuple.__doc__
68 _Tool.nTuple = _nTuple_
69 _Tool.ntuple = _nTuple_
70 
71 
72 # =============================================================================
73 # Retrieve (book-on-demand) 'Smart'-N-tuple object.
def _nTuple_(s, *args)
Definition: TupleUtils.py:61

◆ _TupleUtils_AtExit_()

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

Definition at line 197 of file TupleUtils.py.

197 def _TupleUtils_AtExit_():
198  """
199  AtExit function for GaudiPython.TupleUtils module
200  """
201  if activeTuples():
202  print('WARNING: the list of local TupleTools is not empty!')
203  print(
204  'WARNING: please use GaudiPython.TupleUtils.releaseTuples() at the end'
205  )
206 
207 

◆ activeTuples()

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

Definition at line 162 of file TupleUtils.py.

162 def activeTuples():
163  """
164  Return the list of active tools
165  """
166  return _TOOLS_
167 
168 
169 # =============================================================================
170 # Release the active tool/tuples
171 
172 

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

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

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

173 def releaseTuples():
174  """
175  Release the active tool/tuples
176  The method needs to be invoked explicitely at the end of the job
177  """
178  if not _TOOLS_:
179  return
180  from GaudiPython.Bindings import _gaudi
181  if not _gaudi:
182  return
183 
184  toolSvc = _getToolSvc()
185  if toolSvc.isValid():
186  while _TOOLS_:
187  t = _TOOLS_.pop()
188  if not t:
189  continue
190  while 1 < t.refCount():
191  toolSvc._its.releaseTool(t)
192 
193 
194 # =============================================================================
195 
196 
def _getToolSvc(**kwargs)
Definition: TupleUtils.py:42

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

◆ __author__

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

Definition at line 15 of file TupleUtils.py.

◆ _Deco

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

Definition at line 33 of file TupleUtils.py.

◆ _Tool

GaudiPython.TupleUtils._Tool = cpp.ITupleTool
private

Definition at line 32 of file TupleUtils.py.

◆ _TOOLS_

list GaudiPython.TupleUtils._TOOLS_ = []
private

Definition at line 36 of file TupleUtils.py.

◆ getNTuple

def GaudiPython.TupleUtils.getNTuple = nTuple

Definition at line 152 of file TupleUtils.py.

◆ getNtuple

def GaudiPython.TupleUtils.getNtuple = nTuple

Definition at line 153 of file TupleUtils.py.

◆ getntuple

def GaudiPython.TupleUtils.getntuple = nTuple

Definition at line 154 of file TupleUtils.py.

◆ getTuple

def GaudiPython.TupleUtils.getTuple = nTuple

Definition at line 155 of file TupleUtils.py.

◆ gettuple

def GaudiPython.TupleUtils.gettuple = nTuple

Definition at line 156 of file TupleUtils.py.

◆ ntuple

def GaudiPython.TupleUtils.ntuple = nTuple

Definition at line 151 of file TupleUtils.py.