-
Notifications
You must be signed in to change notification settings - Fork 0
/
hlt_MostContributingPaths.py
92 lines (77 loc) · 3.44 KB
/
hlt_MostContributingPaths.py
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
###################################################################################################
# Daniel Aguilar #
# dalejandro_acdc@yahoo.com #
# June 16, 2018 #
# This script shows a file with a sorted list of the paths with most contribution of time #
# in a interval specified #
# Ex: python hlt_MostContributingPaths.py fileDQM.root 305670 lowerLimit upperLimit #
###################################################################################################
import os,sys
import subprocess
import string, re
import fileinput
import commands
import operator
from time import gmtime, localtime, strftime
#README Change the path to your root directory
#sys.path.append(r'C:\root_v5.34.34\bin')
from ROOT import gPad, gROOT, TCanvas, TH1F, TFile, TLegend, gStyle,gDirectory
import io
#just a debug flag
DEBUG = False
class Duplet:
def __init__(self, path, weight):
self.path=path
self.weight=weight
def usage():
if (DEBUG):
print "This is the usage function"
print '\n'
print 'Usage: '+sys.argv[0]+' <file> <run> <lowerLimit> <upperLimit>'
print 'e.g.: '+sys.argv[0]+' \n'
def getPathOrderByIntegral(file,run,lowerLimit,upperLimit):
pathList = []
process = "TIMING"
tfile = TFile(file)
dirname = "DQMData/Run %s/HLT/Run summary/TimerService/process %s paths" % (run, process)
gDirectory.cd(dirname)
for everyPath in gDirectory.GetListOfKeys():
if everyPath.GetName().startswith("path "):
hist=tfile.Get(dirname+"/"+everyPath.GetName()+"/path time_real")
pathList.append(Duplet(everyPath.GetName(),hist.Integral(lowerLimit/5,upperLimit/5)))
pathList=sorted(pathList,key=lambda duplet: duplet.weight, reverse=True)
return pathList
def wirte_csv(pathList,file,lowerLimit,upperLimit):
f = io.open(unicode("MostContributingPaths_"+file.split('_')[1].strip(".csv"))+unicode("from")+unicode(lowerLimit+"to"+upperLimit+".csv"),'w',encoding='utf8')
f.write(unicode("Path name,Weight"+"\n"))
for eachPathDuplet in pathList:
f.write(unicode(eachPathDuplet.path+","))
f.write(unicode(eachPathDuplet.weight))
f.write(unicode("\n"))
def main():
#check the number of parameter
if len(sys.argv) < 5:
usage()
return 1
infile = sys.argv[1]
run = sys.argv[2]
lowerLimit = sys.argv[3]
upperLimit = sys.argv[4]
#check if input files exist
if not(os.path.isfile(infile)):
print infile+" does not exist. Please check."
sys.exit(1)
intLowerLimit =int(lowerLimit)
intUpperLimit =int(upperLimit)
#check the ranges of the limits
if not(intLowerLimit>=0 and intUpperLimit<=1000 and intLowerLimit<=intUpperLimit):
print " Out of range limits. Please check."
sys.exit(1)
#check the value of the limits
if not(intLowerLimit%5==0 and intUpperLimit%5==0):
print " The limits must be a multiple of 5."
sys.exit(1)
#getPathOrderByIntegral and print in a csv file
wirte_csv(getPathOrderByIntegral(infile,run,intLowerLimit,intUpperLimit),infile,lowerLimit,upperLimit)
if __name__ =='__main__':
sys.exit(main())