16 __author__ =
"Sebastien Binet <binet@cern.ch>"
21 from optparse
import OptionParser
23 if __name__ ==
"__main__":
25 parser = OptionParser(
26 usage =
"usage: %prog [-n] nMagnify [-i] input.pool [-o output.pool]"
32 help =
"The number of times the input file will be 'replicated'"
38 help =
"Path to the input POOL file to be 'replicated'/'magnified'"
45 help =
"Path to the output POOL file containing the replicated data"
48 (options, args) = parser.parse_args()
50 if len(args) > 0
and args[0][0] !=
"-":
51 options.nMagnify = args[0]
54 if len(args) > 1
and args[1][0] !=
"-":
55 options.inPoolFile = args[1]
58 if len(args) > 2
and args[2][0] !=
"-":
59 options.outPoolFile = args[2]
62 if not options.nMagnify
or \
63 not options.inPoolFile :
64 str(parser.print_help()
or "ERROR")
68 nMagnify =
int(options.nMagnify)
70 print (
"ERROR: you have to give an integer > 1 for the magnifier !!")
71 str(parser.print_help()
or "ERROR")
75 inPoolFile = os.path.expandvars(os.path.expanduser(options.inPoolFile))
77 if not options.outPoolFile:
78 options.outPoolFile = os.path.join( [
79 os.path.dirname(inPoolFile),
80 "magnified."+os.path.basename(inPoolFile)
83 outPoolFile = os.path.expandvars(os.path.expanduser(options.outPoolFile))
87 print (
"## Magnifying POOL files...")
88 print (
"## - replicator parameter:",options.nMagnify)
89 print (
"## - input: ",inPoolFile)
90 print (
"## - output:",outPoolFile)
94 sys.argv = sys.argv[:1] + [
'-b'] + sys.argv[1:]
95 print (
"## importing ROOT...")
97 print (
"## importing ROOT... [DONE]")
98 import RootUtils.PyROOTFixes
102 print (
"## opening input Pool file...")
103 inPoolFile = ROOT.TFile.Open( inPoolFile,
"READ" )
104 assert( inPoolFile.IsOpen() )
105 print (
"## opening input Pool file... [DONE]")
107 trees = [ k.ReadObj()
for k
in inPoolFile.GetListOfKeys() ]
109 print (
"## creating output Pool file...")
110 outPoolFile = ROOT.TFile.Open( outPoolFile,
"RECREATE" )
111 assert( outPoolFile.IsOpen() )
112 print (
"## creating output Pool file... [DONE]")
114 print (
"## initialize input file trees' branch status...")
115 for tree
in trees: tree.SetBranchStatus(
"*", 0)
117 print (
"## create output trees...")
120 tree.SetBranchStatus(
"*", 1)
121 outTrees.append( tree.CloneTree(0) )
123 print (
"## magnifying...")
124 for m
in range( nMagnify ):
125 if nMagnify<10
or m % (nMagnify/10) == 0:
126 print (
" ... %s" %
str(m).zfill(8))
127 for i
in range(len(trees)):
131 print (
"## magnifying... [DONE]")
133 print (
"## committing output file...")
135 print (
"## committing output file... [DONE]")