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
40 """ Helper private auxillary utility to get Tool Service """ 41 svc = kwargs.get (
'toolSvc' ,
None )
42 if not svc : svc = kwargs.get (
'toolsvc' ,
None )
43 if not svc : svc = kwargs.get (
'service' ,
None )
44 if not svc : svc = kwargs.get (
'svc' ,
None )
46 gaudi = kwargs.get (
'gaudi' ,
None )
47 if not gaudi : gaudi =
AppMgr()
48 return gaudi.toolsvc()
54 """ Retrive N-tuple ( book on demand ) """ 55 return _Deco.nTuple ( s , *args)
58 _nTuple_. __doc__ +=
"\n" + _Deco.nTuple . __doc__
59 _Tool.nTuple = _nTuple_
60 _Tool.ntuple = _nTuple_
65 def nTuple ( dirpath , ID , ID2 = None , topdir = None , LUN = 'FILE1' ) :
67 Retrieve 'Smart'-N-tuple object. 68 N-tuple is booked on-demand. 71 The logical unit LUN must be configured by N-Tuple Service 73 Retrieve (book-n-demand) N-Tuple using 74 the directory name and the title: 75 >>> t = nTuple ( 'the/path/to/directory' , ## the path to the directory 76 'N-tuple title' , ## the title for N-Tuple 77 LUN = 'FILE1' ) ## logical file unit 79 Retrieve (book-n-demand) N-Tuple using 80 the directory name, literal ID and the title: 81 >>> t = nTuple ( 'the/path/to/directory' , ## the path to the directory 82 'Tuple1' , ## the literal ID for N-Tuple 83 'N-tuple title' , ## the title for N-Tuple 84 LUN = 'FILE1' ) ## logical file unit 86 Retrieve (book-n-demand) N-Tuple using 87 the directory name, numerical ID and the title: 88 >>> t = nTuple ( 'the/path/to/directory' , ## the path to the directory 89 124 , ## the numerical ID for N-Tuple 90 'N-tuple title' , ## the title for N-Tuple 91 LUN = 'FILE1' ) ## logical file unit 95 toolSvc = _getToolSvc ()
98 name =
'Tuple'+LUN+
"/" 99 if topdir : name += topdir
102 if ID2 : name +=
"_%s"%ID2
103 name=name.replace (
'.' ,
'_' )
104 name=name.replace (
'/' ,
'_' )
105 name=name.replace (
'\\' ,
'_' )
106 name=name.replace (
' ' ,
'_' )
112 t0.NTupleDir = dirpath
113 t0.PropertiesPrint =
False 115 if topdir : t0.NTupleTopDir = topdir
118 tool = toolSvc.create (
'TupleTool' ,
124 if t1.NTupleLUN != LUN : t1.NTupleLUN = LUN
125 if t1.NTupleDir != dirpath : t1.NTupleDir = dirpath
126 if topdir
and ( t1.NTupleTopDir != topdir ) :
127 t1.NTupleTopDir = topdir
129 _TOOLS_.append ( tool )
130 if not ID2 :
return tool.nTuple ( ID )
132 return tool.nTuple ( ID , ID2 )
135 nTuple . __doc__ +=
"\n\t help(ITupleTool.nTuple) : \n" \
136 + _Tool.nTuple.__doc__
149 Return the list of active tools 157 Release the active tool/tuples 158 The method needs to be invoked explicitely at the end of the job 160 if not _TOOLS_ :
return 162 if not _gaudi :
return 165 if toolSvc.isValid() :
169 while 1 < t.refCount() :
170 toolSvc._its.releaseTool( t )
175 AtExit function for GaudiPython.TupleUtils module 178 print 'WARNING: the list of local TupleTools is not empty!' 179 print 'WARNING: please use GaudiPython.TupleUtils.releaseTuples() at the end' 182 atexit.register ( _TupleUtils_AtExit_ )
185 if "__main__" == __name__ :
187 print __doc__ , __all__
189 print "\n\n\t",o,
"\n" 190 print sys.modules[__name__].__dict__[o].__doc__
def releaseTuples()
Release the active tool/tuples.
def activeTuples()
Return the list of active tools.
def _getToolSvc(kwargs)
Helper private auxillary utility to get Tool Service.
def nTuple(dirpath, ID, ID2=None, topdir=None, LUN='FILE1')
Retrieve (book-on-demand) 'Smart'-N-tuple object.
def _TupleUtils_AtExit_()
def _nTuple_(s, args)
Retrive N-Tuple ( book on demand )