9 This module contains set of simple and useful utilities to booking and 10 manipulation with N-Tuples (in the spirit of GaudiTuples<TYPE>) 14 __author__ =
"Vanya BELYAEV ibelyaev@physics.syr.edu" 31 _Tool = cpp.ITupleTool
32 _Deco = cpp.GaudiPython.TupleToolDecorator
42 """ Helper private auxillary utility to get Tool Service """ 43 svc = kwargs.get(
'toolSvc',
None)
45 svc = kwargs.get(
'toolsvc',
None)
47 svc = kwargs.get(
'service',
None)
49 svc = kwargs.get(
'svc',
None)
52 gaudi = kwargs.get(
'gaudi',
None)
55 return gaudi.toolsvc()
61 """ Retrive N-tuple ( book on demand ) """ 62 return _Deco.nTuple(s, *args)
66 _nTuple_. __doc__ +=
"\n" + _Deco.nTuple . __doc__
67 _Tool.nTuple = _nTuple_
68 _Tool.ntuple = _nTuple_
73 def nTuple(dirpath, ID, ID2=None, topdir=None, LUN='FILE1'):
75 Retrieve 'Smart'-N-tuple object. 76 N-tuple is booked on-demand. 79 The logical unit LUN must be configured by N-Tuple Service 81 Retrieve (book-n-demand) N-Tuple using 82 the directory name and the title: 83 >>> t = nTuple ( 'the/path/to/directory' , ## the path to the directory 84 'N-tuple title' , ## the title for N-Tuple 85 LUN = 'FILE1' ) ## logical file unit 87 Retrieve (book-n-demand) N-Tuple using 88 the directory name, literal ID and the title: 89 >>> t = nTuple ( 'the/path/to/directory' , ## the path to the directory 90 'Tuple1' , ## the literal ID for N-Tuple 91 'N-tuple title' , ## the title for N-Tuple 92 LUN = 'FILE1' ) ## logical file unit 94 Retrieve (book-n-demand) N-Tuple using 95 the directory name, numerical ID and the title: 96 >>> t = nTuple ( 'the/path/to/directory' , ## the path to the directory 97 124 , ## the numerical ID for N-Tuple 98 'N-tuple title' , ## the title for N-Tuple 99 LUN = 'FILE1' ) ## logical file unit 106 name =
'Tuple' + LUN +
"/" 113 name = name.replace(
'.',
'_')
114 name = name.replace(
'/',
'_')
115 name = name.replace(
'\\',
'_')
116 name = name.replace(
' ',
'_')
122 t0.NTupleDir = dirpath
123 t0.PropertiesPrint =
False 126 t0.NTupleTopDir = topdir
129 tool = toolSvc.create(
'TupleTool',
135 if t1.NTupleLUN != LUN:
137 if t1.NTupleDir != dirpath:
138 t1.NTupleDir = dirpath
139 if topdir
and (t1.NTupleTopDir != topdir):
140 t1.NTupleTopDir = topdir
144 return tool.nTuple(ID)
146 return tool.nTuple(ID, ID2)
149 nTuple . __doc__ +=
"\n\t help(ITupleTool.nTuple) : \n" \
150 + _Tool.nTuple.__doc__
165 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)
198 AtExit function for GaudiPython.TupleUtils module 201 print 'WARNING: the list of local TupleTools is not empty!' 202 print 'WARNING: please use GaudiPython.TupleUtils.releaseTuples() at the end' 206 atexit.register(_TupleUtils_AtExit_)
209 if "__main__" == __name__:
211 print __doc__, __all__
213 print "\n\n\t", o,
"\n" 214 print sys.modules[__name__].__dict__[o].__doc__
def nTuple(dirpath, ID, ID2=None, topdir=None, LUN='FILE1')
def _TupleUtils_AtExit_()