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
26 __author__ =
"Vanya BELYAEV ibelyaev@physics.syr.edu"
43 _Tool = cpp.ITupleTool
44 _Deco = cpp.GaudiPython.TupleToolDecorator
54 """Helper private auxillary utility to get Tool Service"""
55 svc = kwargs.get(
"toolSvc",
None)
57 svc = kwargs.get(
"toolsvc",
None)
59 svc = kwargs.get(
"service",
None)
61 svc = kwargs.get(
"svc",
None)
64 gaudi = kwargs.get(
"gaudi",
None)
67 return gaudi.toolsvc()
73 """Retrive N-tuple ( book on demand )"""
74 return _Deco.nTuple(s, *args)
78 _nTuple_.__doc__ +=
"\n" + _Deco.nTuple.__doc__
79 _Tool.nTuple = _nTuple_
80 _Tool.ntuple = _nTuple_
85 def nTuple(dirpath, ID, ID2=None, topdir=None, LUN="FILE1"):
87 Retrieve 'Smart'-N-tuple object.
88 N-tuple is booked on-demand.
91 The logical unit LUN must be configured by N-Tuple Service
93 Retrieve (book-n-demand) N-Tuple using
94 the directory name and the title:
95 >>> t = nTuple ( 'the/path/to/directory' , ## the path to the directory
96 'N-tuple title' , ## the title for N-Tuple
97 LUN = 'FILE1' ) ## logical file unit
99 Retrieve (book-n-demand) N-Tuple using
100 the directory name, literal ID and the title:
101 >>> t = nTuple ( 'the/path/to/directory' , ## the path to the directory
102 'Tuple1' , ## the literal ID for N-Tuple
103 'N-tuple title' , ## the title for N-Tuple
104 LUN = 'FILE1' ) ## logical file unit
106 Retrieve (book-n-demand) N-Tuple using
107 the directory name, numerical ID and the title:
108 >>> t = nTuple ( 'the/path/to/directory' , ## the path to the directory
109 124 , ## the numerical ID for N-Tuple
110 'N-tuple title' , ## the title for N-Tuple
111 LUN = 'FILE1' ) ## logical file unit
118 name =
"Tuple" + LUN +
"/"
125 name = name.replace(
".",
"_")
126 name = name.replace(
"/",
"_")
127 name = name.replace(
"\\",
"_")
128 name = name.replace(
" ",
"_")
134 t0.NTupleDir = dirpath
135 t0.PropertiesPrint =
False
138 t0.NTupleTopDir = topdir
141 tool = toolSvc.create(
"TupleTool", name, interface=_Tool)
145 if t1.NTupleLUN != LUN:
147 if t1.NTupleDir != dirpath:
148 t1.NTupleDir = dirpath
149 if topdir
and (t1.NTupleTopDir != topdir):
150 t1.NTupleTopDir = topdir
154 return tool.nTuple(ID)
156 return tool.nTuple(ID, ID2)
159 nTuple.__doc__ +=
"\n\t help(ITupleTool.nTuple) : \n" + _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
196 if toolSvc.isValid():
201 while 1 < t.refCount():
202 toolSvc._its.releaseTool(t)
210 AtExit function for GaudiPython.TupleUtils module
213 print(
"WARNING: the list of local TupleTools is not empty!")
214 print(
"WARNING: please use GaudiPython.TupleUtils.releaseTuples() at the end")
219 atexit.register(_TupleUtils_AtExit_)
222 if "__main__" == __name__:
225 print(__doc__, __all__)
227 print(
"\n\n\t", o,
"\n")
228 print(sys.modules[__name__].__dict__[o].__doc__)