9 This module contains set of simple and useful utilities to booking and 10 manipulation with N-Tuples (in the spirit of GaudiTuples<TYPE>) 13 from __future__
import print_function
15 __author__ =
"Vanya BELYAEV ibelyaev@physics.syr.edu" 32 _Tool = cpp.ITupleTool
33 _Deco = cpp.GaudiPython.TupleToolDecorator
43 """ Helper private auxillary utility to get Tool Service """ 44 svc = kwargs.get(
'toolSvc',
None)
46 svc = kwargs.get(
'toolsvc',
None)
48 svc = kwargs.get(
'service',
None)
50 svc = kwargs.get(
'svc',
None)
53 gaudi = kwargs.get(
'gaudi',
None)
56 return gaudi.toolsvc()
62 """ Retrive N-tuple ( book on demand ) """ 63 return _Deco.nTuple(s, *args)
67 _nTuple_.__doc__ +=
"\n" + _Deco.nTuple.__doc__
68 _Tool.nTuple = _nTuple_
69 _Tool.ntuple = _nTuple_
74 def nTuple(dirpath, ID, ID2=None, topdir=None, LUN='FILE1'):
76 Retrieve 'Smart'-N-tuple object. 77 N-tuple is booked on-demand. 80 The logical unit LUN must be configured by N-Tuple Service 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 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 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 107 name =
'Tuple' + LUN +
"/" 114 name = name.replace(
'.',
'_')
115 name = name.replace(
'/',
'_')
116 name = name.replace(
'\\',
'_')
117 name = name.replace(
' ',
'_')
123 t0.NTupleDir = dirpath
124 t0.PropertiesPrint =
False 127 t0.NTupleTopDir = topdir
130 tool = toolSvc.create(
'TupleTool', name, interface=_Tool)
134 if t1.NTupleLUN != LUN:
136 if t1.NTupleDir != dirpath:
137 t1.NTupleDir = dirpath
138 if topdir
and (t1.NTupleTopDir != topdir):
139 t1.NTupleTopDir = topdir
143 return tool.nTuple(ID)
145 return tool.nTuple(ID, ID2)
148 nTuple . __doc__ +=
"\n\t help(ITupleTool.nTuple) : \n" \
149 + _Tool.nTuple.__doc__
164 Return the list of active tools 175 Release the active tool/tuples 176 The method needs to be invoked explicitely at the end of the job 185 if toolSvc.isValid():
190 while 1 < t.refCount():
191 toolSvc._its.releaseTool(t)
199 AtExit function for GaudiPython.TupleUtils module 202 print(
'WARNING: the list of local TupleTools is not empty!')
204 'WARNING: please use GaudiPython.TupleUtils.releaseTuples() at the end' 209 atexit.register(_TupleUtils_AtExit_)
212 if "__main__" == __name__:
214 print(__doc__, __all__)
216 print(
"\n\n\t", o,
"\n")
217 print(sys.modules[__name__].__dict__[o].__doc__)
def _getToolSvc(**kwargs)
def nTuple(dirpath, ID, ID2=None, topdir=None, LUN='FILE1')
def _TupleUtils_AtExit_()