18def exploreTree(inputFile, dumpSummary=False, underflowThreshold=0.1, overflowThreshold=0.1, maxRanges=5, skipRanges=-1):
19 ''' @brief Explore ROOT Tree to find tables with histograms to be saved in csv
20
21 Per each found directory TableConstructor object is created.
22 Expected directory tree:
23 rootDir
24 table1Dir
25 entry1Dir
26 hist1
27 hist2
28 ...
29 entry2Dir
30 hist1
31 ...
32 table2Dir
33 ...
34 walltimeHist
35
36 @param[in] inputFile ROOT.TFile object with histograms
37 '''
38
39 processingWarnings = []
40 rangeCounter = 0
41 rangesToSkip = skipRanges
42 for timeRange in inputFile.GetListOfKeys():
43 if timeRange.GetName() != "metadata" and rangesToSkip > 0:
44 rangesToSkip-=1
45 log.debug("Skipping range {0}".format(timeRange.GetName()))
46 continue
47
48 if maxRanges > 0 and rangeCounter >= maxRanges:
49 log.info("{0} ranges were processed - exiting the postprocessing".format(rangeCounter))
50 break
51
52 rangeObj = timeRange.ReadObj()
53 if not rangeObj.IsA().InheritsFrom(ROOT.TDirectory.Class()): continue
54
55 walltime = getWalltime(inputFile, timeRange.GetName())
56
57 for table in rangeObj.GetListOfKeys():
58 tableObj = table.ReadObj()
59 if not tableObj.IsA().InheritsFrom(ROOT.TDirectory.Class()): continue
60 log.info("Processing Table %s", table.GetName())
61
62 try:
63 className = table.GetName() + "_TableConstructor"
64 exec("from TrigCostAnalysis." + className + " import " + className)
65 t = eval(className + "(tableObj, underflowThreshold, overflowThreshold)")
66
67 if table.GetName() == "Chain_HLT" or table.GetName() == "Chain_Algorithm_HLT":
68 t.totalTime = getAlgorithmTotalTime(inputFile, rangeObj.GetName())
69
70 if table.GetName() == "Global_HLT":
71 t.lbLength = walltime
72
73 if table.GetName() == "Algorithm_HLT":
74 t.dumpSummary = dumpSummary
75
76 fileName = getFileName(table.GetName(), timeRange.GetName())
77 histPrefix = getHistogramPrefix(table.GetName(), timeRange.GetName())
78
79 t.fillTable(histPrefix)
80 t.normalizeColumns(walltime)
81 t.saveToFile(fileName)
82
83 processingWarnings += t.getWarningMsgs()
84
85 except (ValueError):
86 log.error("Processing of table {0} failed!".format(table.GetName()))
87 return []
88 except (NameError, ImportError):
89 log.warning("Class {0} not defined - directory {1} will not be processed"
90 .format(table.GetName()+"_TableConstructor", table.GetName()))
91
92 rangeCounter += 1
93 log.debug("Range {0} was processed".format(timeRange.GetName()))
94
95
96 summary = createOverflowSummary(processingWarnings)
97 summary["Summary"] += ["Underflow threshold: {0}".format(underflowThreshold), "Overflow threshold: {0}".format(overflowThreshold)]
98 return processingWarnings + [summary]
99
100