def main(): """main options for program""" # command line options parser = OptionParser() parser.add_option("--file", "-f", help="ROOT input file", dest="file") parser.add_option("--tree", "-t", help="Tree to parse", dest="treeName") parser.add_option( "--firstN", "-m", help="Display only the first N buckets of the file on the graph", dest="maxBranch" ) parser.add_option( "--display", "-d", dest="display", action="store_true", help="Show interactive matplotlib display" ) parser.add_option( "--top_level", "-b", dest="topLevel", action="store_true", help="Color by only the top level branch" ) parser.add_option("--output_file", "-o", dest="output", help="The name of the output file") parser.add_option("--top_n", "-n", dest="topN", help="Color only the top N branches in the file") parser.add_option( "--eventFilter", "-e", dest="events", help="Plot only up to this event number or this range of events in the display", ) parser.add_option("--list_trees", "-l", dest="list", action="store_true", help="List the available trees in file") parser.add_option("--branch_regex", "-r", dest="branchRegex", help="Regular expression to filter out branches") (options, args) = parser.parse_args() # If now file we have an error if options.file is None: print "File root file is required" parser.print_help() exit(0) if not options.file.upper().endswith(".ROOT"): print "Root file required" exit() try: with open(options.file) as f: pass except IOError as e: print "file does not exits" exit() # if list just list trees and exit if options.list: HCCRootParser.listFileTrees(options.file) exit(0) # require the file name and tree if options.treeName is None: print "Tree Name is required" parser.print_help() exit(-1) numOfBranches = None if options.maxBranch: numOfBranches = int(options.maxBranch) # output file name if options.output != None: outName = options.output else: outName = getName(options.file) # interactive display if options.display: display = True else: display = False if options.topLevel: topLevel = True else: topLevel = False topN = None # color only top ten files if options.topN: topN = int(options.topN) if topN > 30: topN = 30 else: topN = 30 # regular expression if options.branchRegex != None: brex = re.compile(options.branchRegex) else: brex = None # get data data = HCCRootParser.parseFile(options.file, options.treeName, brex, topLevel) if options.events: data = filterByEvents(data, options.events) tenBig = getTenBig(data, topN) if numOfBranches != None: data = truncateData(data, numOfBranches) # no need to make graph if blank data if len(data) == 0: print "No Branches in that tree" exit(0) data = HCCPlot.transformByteToMB(data) # plot if brex != None: colorMap = {} HCCPlot.plotFileLayout(data, display, outName, colorMap, tenBig) else: colorMap = createColorMap(data, False, tenBig) HCCPlot.plotFileLayout(data, display, outName, colorMap, tenBig)
def main(): '''main options for program''' #command line options parser = OptionParser() parser.add_option('--file', '-f', help='ROOT input file',dest='file') parser.add_option('--tree', '-t', help='Tree to parse', dest='treeName') parser.add_option('--firstN', '-m', help='Display only the first N buckets of the file on the graph', dest='maxBranch') parser.add_option('--display', '-d', dest='display', action='store_true' ,help='Show interactive matplotlib display') parser.add_option('--top_level', '-b', dest='topLevel', action='store_true' ,help='Color by only the top level branch') parser.add_option('--output_file','-o', dest = 'output', help='The name of the output file') parser.add_option('--top_n','-n', dest = 'topN' , help='Color only the top N branches in the file') parser.add_option('--eventFilter','-e' ,dest ='events', help='Plot only up to this event number or this range of events in the display') parser.add_option('--list_trees', '-l', dest='list', action='store_true', help='List the available trees in file') parser.add_option('--branch_regex', '-r', dest='branchRegex', help='Regular expression to filter out branches') (options, args)= parser.parse_args() #If now file we have an error if options.file is None: print "File root file is required" parser.print_help() exit(0) if not options.file.upper().endswith('.ROOT'): print 'Root file required' exit() try: with open(options.file) as f: pass except IOError as e: print 'file does not exits' exit() #if list just list trees and exit if(options.list): HCCRootParser.listFileTrees(options.file) exit(0) #require the file name and tree if options.treeName is None: print "Tree Name is required" parser.print_help() exit(-1) numOfBranches = None if options.maxBranch: numOfBranches = int(options.maxBranch) #output file name if options.output != None: outName = options.output else: outName = getName(options.file) #interactive display if options.display: display = True else: display = False if options.topLevel: topLevel = True else: topLevel = False topN = None #color only top ten files if options.topN: topN = int(options.topN) if topN > 30: topN = 30 else: topN = 30 #regular expression if options.branchRegex != None: brex = re.compile(options.branchRegex) else: brex = None print 'parsing data' #get data data = HCCRootParser.parseFile(options.file, options.treeName, brex, topLevel) if options.events: data = filterByEvents(data, options.events) tenBig= getTenBig(data, topN) if (numOfBranches != None): data = truncateData(data, numOfBranches) #no need to make graph if blank data if len(data) == 0: print 'No Branches in that tree' exit(0) data = HCCPlot.transformByteToMB(data) print 'plotting' #plot if brex != None: colorMap = {} HCCPlot.plotFileLayout(data, display, outName, colorMap, tenBig) else: colorMap = createColorMap(data, False, tenBig) HCCPlot.plotFileLayout(data, display, outName, colorMap, tenBig)