19 This module contains set of simple and useful utilities to booking and
20 manipulation with N-Tuples (in the spirit of GaudiTuples<TYPE>)
23 from __future__
import print_function
25 __author__ =
"Vanya BELYAEV ibelyaev@physics.syr.edu"
42 _Tool = cpp.ITupleTool
43 _Deco = cpp.GaudiPython.TupleToolDecorator
53 """ Helper private auxillary utility to get Tool Service """
54 svc = kwargs.get(
'toolSvc',
None)
56 svc = kwargs.get(
'toolsvc',
None)
58 svc = kwargs.get(
'service',
None)
60 svc = kwargs.get(
'svc',
None)
63 gaudi = kwargs.get(
'gaudi',
None)
66 return gaudi.toolsvc()
72 """ Retrive N-tuple ( book on demand ) """
73 return _Deco.nTuple(s, *args)
77 _nTuple_.__doc__ +=
"\n" + _Deco.nTuple.__doc__
78 _Tool.nTuple = _nTuple_
79 _Tool.ntuple = _nTuple_
84 def nTuple(dirpath, ID, ID2=None, topdir=None, LUN='FILE1'):
86 Retrieve 'Smart'-N-tuple object.
87 N-tuple is booked on-demand.
90 The logical unit LUN must be configured by N-Tuple Service
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
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
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
117 name =
'Tuple' + LUN +
"/"
124 name = name.replace(
'.',
'_')
125 name = name.replace(
'/',
'_')
126 name = name.replace(
'\\',
'_')
127 name = name.replace(
' ',
'_')
133 t0.NTupleDir = dirpath
134 t0.PropertiesPrint =
False
137 t0.NTupleTopDir = topdir
140 tool = toolSvc.create(
'TupleTool', name, interface=_Tool)
144 if t1.NTupleLUN != LUN:
146 if t1.NTupleDir != dirpath:
147 t1.NTupleDir = dirpath
148 if topdir
and (t1.NTupleTopDir != topdir):
149 t1.NTupleTopDir = topdir
153 return tool.nTuple(ID)
155 return tool.nTuple(ID, ID2)
158 nTuple . __doc__ +=
"\n\t help(ITupleTool.nTuple) : \n" \
159 + _Tool.nTuple.__doc__
174 Return the list of active tools
185 Release the active tool/tuples
186 The method needs to be invoked explicitely at the end of the job
195 if toolSvc.isValid():
200 while 1 < t.refCount():
201 toolSvc._its.releaseTool(t)
209 AtExit function for GaudiPython.TupleUtils module
212 print(
'WARNING: the list of local TupleTools is not empty!')
214 'WARNING: please use GaudiPython.TupleUtils.releaseTuples() at the end'
219 atexit.register(_TupleUtils_AtExit_)
222 if "__main__" == __name__:
224 print(__doc__, __all__)
226 print(
"\n\n\t", o,
"\n")
227 print(sys.modules[__name__].__dict__[o].__doc__)