16 from __future__
import print_function
18 __author__ =
"Sebastien Binet <binet@cern.ch>"
23 from optparse
import OptionParser
25 if __name__ ==
"__main__":
27 parser = OptionParser(
28 usage =
"usage: %prog [-n] nMagnify [-i] input.pool [-o output.pool]"
34 help =
"The number of times the input file will be 'replicated'"
40 help =
"Path to the input POOL file to be 'replicated'/'magnified'"
47 help =
"Path to the output POOL file containing the replicated data"
50 (options, args) = parser.parse_args()
52 if len(args) > 0
and args[0][0] !=
"-":
53 options.nMagnify = args[0]
56 if len(args) > 1
and args[1][0] !=
"-":
57 options.inPoolFile = args[1]
60 if len(args) > 2
and args[2][0] !=
"-":
61 options.outPoolFile = args[2]
64 if not options.nMagnify
or \
65 not options.inPoolFile :
66 str(parser.print_help()
or "ERROR")
70 nMagnify =
int(options.nMagnify)
72 print (
"ERROR: you have to give an integer > 1 for the magnifier !!")
73 str(parser.print_help()
or "ERROR")
77 inPoolFile = os.path.expandvars(os.path.expanduser(options.inPoolFile))
79 if not options.outPoolFile:
80 options.outPoolFile = os.path.join( [
81 os.path.dirname(inPoolFile),
82 "magnified."+os.path.basename(inPoolFile)
85 outPoolFile = os.path.expandvars(os.path.expanduser(options.outPoolFile))
89 print (
"## Magnifying POOL files...")
90 print (
"## - replicator parameter:",options.nMagnify)
91 print (
"## - input: ",inPoolFile)
92 print (
"## - output:",outPoolFile)
96 sys.argv = sys.argv[:1] + [
'-b'] + sys.argv[1:]
97 print (
"## importing ROOT...")
99 print (
"## importing ROOT... [DONE]")
100 import RootUtils.PyROOTFixes
104 print (
"## opening input Pool file...")
105 inPoolFile = ROOT.TFile.Open( inPoolFile,
"READ" )
106 assert( inPoolFile.IsOpen() )
107 print (
"## opening input Pool file... [DONE]")
109 trees = [ k.ReadObj()
for k
in inPoolFile.GetListOfKeys() ]
111 print (
"## creating output Pool file...")
112 outPoolFile = ROOT.TFile.Open( outPoolFile,
"RECREATE" )
113 assert( outPoolFile.IsOpen() )
114 print (
"## creating output Pool file... [DONE]")
116 print (
"## initialize input file trees' branch status...")
117 for tree
in trees: tree.SetBranchStatus(
"*", 0)
119 print (
"## create output trees...")
122 tree.SetBranchStatus(
"*", 1)
123 outTrees.append( tree.CloneTree(0) )
125 print (
"## magnifying...")
126 for m
in range( nMagnify ):
127 if nMagnify<10
or m % (nMagnify/10) == 0:
128 print (
" ... %s" %
str(m).zfill(8))
129 for i
in range(len(trees)):
133 print (
"## magnifying... [DONE]")
135 print (
"## committing output file...")
137 print (
"## committing output file... [DONE]")