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 ) """
56 return _Deco.nTuple ( s , *args)
59 _nTuple_. __doc__ +=
"\n" + _Deco.nTuple . __doc__
60 _Tool.nTuple = _nTuple_
61 _Tool.ntuple = _nTuple_
66 def nTuple ( dirpath , ID , ID2 = None , topdir = None , LUN = 'FILE1' ) :
68 Retrieve 'Smart'-N-tuple object.
69 N-tuple is booked on-demand.
72 The logical unit LUN must be configured by N-Tuple Service
74 Retrieve (book-n-demand) N-Tuple using
75 the directory name and the title:
76 >>> t = nTuple ( 'the/path/to/directory' , ## the path to the directory
77 'N-tuple title' , ## the title for N-Tuple
78 LUN = 'FILE1' ) ## logical file unit
80 Retrieve (book-n-demand) N-Tuple using
81 the directory name, literal ID and the title:
82 >>> t = nTuple ( 'the/path/to/directory' , ## the path to the directory
83 'Tuple1' , ## the literal ID for N-Tuple
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, numerical ID and the title:
89 >>> t = nTuple ( 'the/path/to/directory' , ## the path to the directory
90 124 , ## the numerical ID for N-Tuple
91 'N-tuple title' , ## the title for N-Tuple
92 LUN = 'FILE1' ) ## logical file unit
96 toolSvc = _getToolSvc ()
99 name =
'Tuple'+LUN+
"/"
100 if topdir : name += topdir
103 if ID2 : name +=
"_%s"%ID2
104 name=name.replace (
'.' ,
'_' )
105 name=name.replace (
'/' ,
'_' )
106 name=name.replace (
'\\' ,
'_' )
107 name=name.replace (
' ' ,
'_' )
113 t0.NTupleDir = dirpath
114 t0.PropertiesPrint =
False
116 if topdir : t0.NTupleTopDir = topdir
119 tool = toolSvc.create (
'TupleTool' ,
125 if t1.NTupleLUN != LUN : t1.NTupleLUN = LUN
126 if t1.NTupleDir != dirpath : t1.NTupleDir = dirpath
127 if topdir
and ( t1.NTupleTopDir != topdir ) :
128 t1.NTupleTopDir = topdir
130 _TOOLS_.append ( tool )
131 if not ID2 :
return tool.nTuple ( ID )
133 return tool.nTuple ( ID , ID2 )
136 nTuple . __doc__ +=
"\n\t help(ITupleTool.nTuple) : \n" \
137 + _Tool.nTuple.__doc__
150 Return the list of active tools
158 Release the active tool/tuples
159 The method needs to be invoked explicitely at the end of the job
161 if not _TOOLS_ :
return
162 print ' %s/%s: release all pending ITupleTools: %s' % ( __file__ ,
166 if not _gaudi :
return
169 if toolSvc.isValid() :
173 while 1 < t.refCount() :
174 toolSvc._its.releaseTool( t )
179 AtExit function for GaudiPython.TupleUtils module
182 print 'WARNING: the list of local TupleTools is not empty!'
183 print 'WARNING: please use GaudiPython.TupleUtils.releaseTuples() at the end'
186 atexit.register ( _TupleUtils_AtExit_ )
189 if "__main__" == __name__ :
191 print __doc__ , __all__
193 print "\n\n\t",o,
"\n"
194 print sys.modules[__name__].__dict__[o].__doc__
def activeTuples
Return the list of active tools.
def releaseTuples
Release the active tool/tuples.
def nTuple
Retrieve (book-on-demand) 'Smart'-N-tuple object.
def _getToolSvc
Helper private auxillary utility to get Tool Service.
def _nTuple_
Retrive N-Tuple ( book on demand )