ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tools
PyUtils
bin
magnifyPoolFile.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
3
# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4
5
# @file: magnifyPoolFile.py
6
# @purpose: produce a new POOL file with N times the content of an input one.
7
# @author: Sebastien Binet <binet@cern.ch>
8
# @date: May 2007
9
#
10
# @example:
11
#
12
# magnifyPoolFile.py 1000 aod.pool
13
# magnifyPoolFile.py 1000 aod.pool my.magnified.aod.pool
14
#
15
16
__author__ =
"Sebastien Binet <binet@cern.ch>"
17
18
import
sys
19
import
os
20
21
from
optparse
import
OptionParser
22
23
if
__name__ ==
"__main__"
:
24
25
parser = OptionParser(
26
usage =
"usage: %prog [-n] nMagnify [-i] input.pool [-o output.pool]"
27
)
28
29
parser.add_option(
30
"-n"
,
31
dest =
"nMagnify"
,
32
help =
"The number of times the input file will be 'replicated'"
33
)
34
parser.add_option(
35
"-i"
,
36
"--input"
,
37
dest =
"inPoolFile"
,
38
help =
"Path to the input POOL file to be 'replicated'/'magnified'"
39
)
40
parser.add_option(
41
"-o"
,
42
"--output"
,
43
dest =
"outPoolFile"
,
44
default =
None
,
45
help =
"Path to the output POOL file containing the replicated data"
46
)
47
48
(options, args) = parser.parse_args()
49
50
if
len(args) > 0
and
args[0][0] !=
"-"
:
51
options.nMagnify = args[0]
52
pass
53
54
if
len(args) > 1
and
args[1][0] !=
"-"
:
55
options.inPoolFile = args[1]
56
pass
57
58
if
len(args) > 2
and
args[2][0] !=
"-"
:
59
options.outPoolFile = args[2]
60
pass
61
62
if
not
options.nMagnify
or
\
63
not
options.inPoolFile :
64
str(parser.print_help()
or
"ERROR"
)
65
sys.exit(1)
66
pass
67
68
nMagnify = int(options.nMagnify)
69
if
nMagnify <= 1:
70
print
(
"ERROR: you have to give an integer > 1 for the magnifier !!"
)
71
str(parser.print_help()
or
"ERROR"
)
72
sys.exit(1)
73
pass
74
75
inPoolFile = os.path.expandvars(os.path.expanduser(options.inPoolFile))
76
77
if
not
options.outPoolFile:
78
options.outPoolFile = os.path.join( [
79
os.path.dirname(inPoolFile),
80
"magnified."
+os.path.basename(inPoolFile)
81
] )
82
83
outPoolFile = os.path.expandvars(os.path.expanduser(options.outPoolFile))
84
85
86
print
(
"#"
*80)
87
print
(
"## Magnifying POOL files..."
)
88
print
(
"## - replicator parameter:"
,options.nMagnify)
89
print
(
"## - input: "
,inPoolFile)
90
print
(
"## - output:"
,outPoolFile)
91
print
(
"##"
)
92
93
oldArgs = sys.argv
94
sys.argv = sys.argv[:1] + [
'-b'
] + sys.argv[1:]
95
print
(
"## importing ROOT..."
)
96
import
ROOT
97
print
(
"## importing ROOT... [DONE]"
)
98
import
RootUtils.PyROOTFixes
# noqa: F401
99
100
sys.argv = oldArgs
101
102
print
(
"## opening input Pool file..."
)
103
inPoolFile = ROOT.TFile.Open( inPoolFile,
"READ"
)
104
assert( inPoolFile.IsOpen() )
105
print
(
"## opening input Pool file... [DONE]"
)
106
107
trees = [ k.ReadObj()
for
k
in
inPoolFile.GetListOfKeys() ]
108
109
print
(
"## creating output Pool file..."
)
110
outPoolFile = ROOT.TFile.Open( outPoolFile,
"RECREATE"
)
111
assert( outPoolFile.IsOpen() )
112
print
(
"## creating output Pool file... [DONE]"
)
113
114
print
(
"## initialize input file trees' branch status..."
)
115
for
tree
in
trees: tree.SetBranchStatus(
"*"
, 0)
116
117
print
(
"## create output trees..."
)
118
outTrees = [ ]
119
for
tree
in
trees:
120
tree.SetBranchStatus(
"*"
, 1)
121
outTrees.append( tree.CloneTree(0) )
122
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)):
128
for
j
in
range(trees[i].
GetEntries
()):
129
trees[i].GetEntry(j)
130
outTrees[i].Fill()
131
print
(
"## magnifying... [DONE]"
)
132
133
print
(
"## committing output file..."
)
134
outPoolFile.Write()
135
print
(
"## committing output file... [DONE]"
)
136
137
inPoolFile.Close()
138
del inPoolFile
139
140
outPoolFile.Close()
141
del outPoolFile
142
143
print
(
"## Bye."
)
144
sys.exit(0)
145
GetEntries
TGraphErrors * GetEntries(TH2F *histo)
Definition
TRTCalib_makeplots.cxx:4025
Generated on
for ATLAS Offline Software by
1.17.0