Functions | |
def | main |
def | recurse_thru_file |
Variables | |
list | saved_argv = sys.argv[:] |
Load classes from ROOT, ensuring it doesn't intercept -h or --help. |
Print information about objects in a ROOT file.
def python::rootplot::rootinfo::main | ( | ) |
Definition at line 87 of file rootinfo.py.
00088 : 00089 parser = argparse.ArgumentParser(description='Print information from an SC2 replay file.') 00090 parser.add_argument('filenames', metavar='filename', type=str, nargs='+', 00091 help="Names of one or more root files") 00092 parser.add_argument('--bincenter', action="store_true", default=False, 00093 help="Get Bin Centers from each bin in each histogram") 00094 parser.add_argument('--classname', action="store_true", default=False, 00095 help="Get type from each object in root file") 00096 parser.add_argument('--contents', action="store_true", default=False, 00097 help="Get Bin Contents from each bin in each histogram") 00098 parser.add_argument('--errors', action="store_true", default=False, 00099 help="Get Bin Errors from each bin in each histogram") 00100 parser.add_argument('--entries', action="store_true", default=False, 00101 help="Get Entries from each histogram") 00102 parser.add_argument('--max', action="store_true", default=False, 00103 help="Get Maximum value from each histogram") 00104 parser.add_argument('--min', action="store_true", default=False, 00105 help="Get Minimum value from each histogram") 00106 parser.add_argument('--name', default=None, 00107 help="Get information only from object with matching name") 00108 parser.add_argument('--overflow', action="store_true", default=False, 00109 help="Get value of overflow bin from each histogram") 00110 parser.add_argument('--underflow', action="store_true", default=False, 00111 help="Get value of underflow bin from each histogram") 00112 arguments = parser.parse_args() 00113 for arg in arguments.filenames: 00114 if arg[-5:] != ".root": 00115 raise TypeError("Arguments must include root file names") 00116 filenames_from_interface = [x for x in arguments.filenames if x[-5:] == ".root"] 00117 if len(filenames_from_interface) == 0: 00118 parser.print_help() 00119 sys.exit(0) 00120 for filename in filenames_from_interface: 00121 if not os.path.exists(filename): 00122 print "%s does not exist." % filename 00123 sys.exit(0) 00124 tfile = TFile(filename, "read") 00125 try: 00126 recurse_thru_file(tfile, arguments) 00127 except IOError, e: 00128 if e.errno != 32: 00129 raise
def python::rootplot::rootinfo::recurse_thru_file | ( | in_tfile, | |
options, | |||
full_path = '/' |
|||
) |
Recursive function to find all contents in a given ROOT file
Definition at line 19 of file rootinfo.py.
00020 : 00021 '''Recursive function to find all contents in a given ROOT file''' 00022 keys = in_tfile.GetDirectory(full_path).GetListOfKeys() 00023 for key in keys: 00024 name = key.GetName() 00025 classname = key.GetClassName() 00026 if 'TDirectory' in classname: 00027 gDirectory.cd(name) 00028 recurse_thru_file(in_tfile, options, '/'.join([full_path,name])) 00029 gDirectory.cd("..") 00030 else: 00031 if options.name and name != options.name: continue 00032 full_name = '/'.join([full_path,name]) 00033 obj = in_tfile.Get(full_name) 00034 if not obj: 00035 continue 00036 simple_name = full_name[2:] 00037 print "%s" % simple_name, 00038 for arg in [x[2:] for x in sys.argv if x.startswith("--")]: 00039 if "classname" == arg: 00040 print "%s" % classname, 00041 if obj.InheritsFrom('TH1'): 00042 if "entries" == arg: 00043 print " %i" % obj.GetEntries(), 00044 if "contents" == arg: 00045 if obj.InheritsFrom('TH2'): 00046 # Print contents as they would look on the 2D graph 00047 # Left to right, top to bottom. Start in upper left corner. 00048 for j in reversed(range(obj.GetNbinsY())): 00049 print 00050 print " %s" % ' '.join( 00051 [str(obj.GetBinContent(i+1, j+1)) for i in range(obj.GetNbinsX())]), 00052 else: 00053 print " %s" % ' '.join( 00054 [str(obj.GetBinContent(i+1)) for i in range(obj.GetNbinsX())]), 00055 if "errors" == arg: 00056 if obj.InheritsFrom('TH2'): 00057 for j in reversed(range(obj.GetNbinsY())): 00058 print 00059 print " %s" % ' '.join( 00060 [str(obj.GetBinError(i+1, j+1)) for i in range(obj.GetNbinsX())]), 00061 else: 00062 print " %s" % ' '.join( 00063 [str(obj.GetBinError(i+1)) for i in range(obj.GetNbinsX())]), 00064 if "bincenter" == arg: 00065 print " %s" % ' '.join( 00066 [str(obj.GetBinCenter(i+1)) for i in range(obj.GetNbinsX())]), 00067 if "max" == arg: 00068 print " %i" % obj.GetMaximum(), 00069 if "min" == arg: 00070 print " %i" % obj.GetMinimum(), 00071 if "overflow" == arg: 00072 print " %i" % obj.GetBinContent(obj.GetNbinsX()), 00073 if "underflow" == arg: 00074 print " %i" % obj.GetBinContent(0), 00075 if obj.InheritsFrom('TGraph'): 00076 if "contents" == arg: 00077 x, y = Double(0), Double(0) 00078 xvals = [] 00079 yvals = [] 00080 for i in range(obj.GetN()): 00081 obj.GetPoint(i, x, y) 00082 xvals.append(copy.copy(x)) 00083 yvals.append(copy.copy(y)) 00084 for point in zip(xvals,yvals): 00085 print " (%d, %d)" % point, 00086 print ""
list python::rootplot::rootinfo::saved_argv = sys.argv[:] |
Load classes from ROOT, ensuring it doesn't intercept -h or --help.
Definition at line 14 of file rootinfo.py.