-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshowoptions
executable file
·92 lines (77 loc) · 2.86 KB
/
showoptions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
#
# Display the contents of an Options ntuple within a ROOT file.
# 06-Dec-2022 WGS
import sys
from ROOT import TFile, gDirectory
debug = False
# Look at the arguments.
if ( len(sys.argv) < 2 ):
print (sys.argv[0]," needs at least one argument: the name of the ROOT file with an Options nutple")
sys.exit(1)
# Open the file.
fileName = sys.argv[1]
try:
myfile = TFile( fileName )
except OSError as error:
print (error)
sys.exit(1)
# If there is a second argument, it's the name of the ntuple
# that contains the options.
ntupleName = 'Options'
if ( len(sys.argv) > 2 ):
ntupleName = sys.argv[2]
# Retrieve the Options ntuple.
optionsNtuple = gDirectory.Get( ntupleName )
# Number of rows in the ntuple.
try:
entries = optionsNtuple.GetEntriesFast()
except AttributeError as error:
print ("There is no ntuple with the name",ntupleName,"in file",fileName)
sys.exit(1)
if (debug):
print ("number of options = ",entries)
# How we'll format the output. The "{:N.N}" format assures
# that the column width will be exactly N characters, truncating
# any strings that are longer than that.
# Use different formats for string, int, and double values.
outputstring = "{:3.3} {:24.24} {:>18.18} {:30.30} {:15.15}"
outputint = "{:3.3} {:24.24} {:18} {:30.30} {:15.15}"
outputdouble = "{:3.3} {:24.24} {:18.15} {:30.30} {:15.15}"
outputunderline = "{:*^3} {:*^24} {:*^18} {:*^30} {:*^15}"
# Print a table heading
print (outputunderline.format("","","","",""))
print (outputstring.format("Abb","Name","Value","Description","Source"))
print (outputunderline.format("","","","",""))
# For each row in the ntuple:
for jentry in range( entries ):
# Copy next entry into memory and verify.
nb = optionsNtuple.GetEntry( jentry )
if nb <= 0:
continue
try:
name = optionsNtuple.OptionName
value = optionsNtuple.OptionValue
otype = optionsNtuple.OptionType
brief = optionsNtuple.OptionBrief
desc = optionsNtuple.OptionDesc
source = optionsNtuple.OptionSource
except AttributeError as error:
print ("ntuple",ntupleName,"in file",fileName,"is not a complete options ntuple")
sys.exit(1)
# Display the numeric and boolean values in a more "natural" format.
if ( otype == 'integer' ):
ivalue = int(value)
print (outputint.format(brief,name,ivalue,desc,source))
elif ( otype == 'double' ):
fvalue = float(value)
print (outputdouble.format(brief,name,fvalue,desc,source))
elif ( otype == 'flag' or otype == 'boolean'):
bvalue = 'False'
if ( value == '1' ):
bvalue = 'True'
print (outputstring.format(brief,name,bvalue,desc,source))
else:
print (outputstring.format(brief,name,value,desc,source))
# Write a "bottom of table" delimiter.
print (outputunderline.format("","","","",""))