2 from __future__
import print_function
7 from optparse
import OptionParser
21 parser = OptionParser(usage=
"Example: ./PDRates.py --runNumber 146644 --PD Mu --perLS")
22 parser.add_option(
"--runNumber", dest=
"RunNumber", help=
"run number", type=
"int", metavar=
"RunNumber")
23 parser.add_option(
"--PD",dest=
"PrimaryDataset",help=
"PD name",metavar=
"PrimaryDataset")
24 parser.add_option(
"--perLS",action=
"store_true",default=
False,dest=
"perLS",help=
"plot the rate vs the LS number",metavar=
"perLS")
25 parser.add_option(
"--logy",action=
"store_true",default=
False,dest=
"logy",help=
"log scale for the y axis",metavar=
"logy")
26 parser.add_option(
"--saveplot",action=
"store_true",default=
False,dest=
"saveplot",help=
"save the plot as a tmp.eps",metavar=
"saveplot")
27 (options, args) = parser.parse_args()
33 dbs_cmd =
""" dbs search --query='find primds.name
34 where run=%d and dataset like */RAW' """ % (Run)
35 rows = commands.getoutput(dbs_cmd)
36 lines = rows.split(
"\n")
38 print(
"\nThe primary datasets for this run are: \n")
45 Datasets.append(line[0])
50 def RateInPD(Run,PrimaryDataset,lsMin,lsMax,printLS=False):
51 dbs_cmd =
""" dbs search --query='find file,lumi,file.numevents, file.size
52 where run=%d and dataset like /%s/*/RAW
53 and lumi >= %d and lumi <= %d
54 and file.status=VALID '""" % (Run, PrimaryDataset,lsMin, lsMax)
55 rows = commands.getoutput(dbs_cmd)
56 lines = rows.split(
"\n")
74 if LumiSections.count(LS) == 0:
75 LumiSections.append(LS)
76 if Files.count(file) == 0:
80 NumberOfLSInFile[file] =1
82 NumberOfLSInFile[file] = NumberOfLSInFile[file]+1
85 Number_of_LS = len(LumiSections)
89 rate = Evts / (Number_of_LS * LS_Length)
91 size_per_event = (Size / Evts) / 1000.
94 print(
"Rate in \t",PrimaryDataset,
"\t is : \t",rate,
" Hz",
" \t size is : \t",size_per_event,
"kB / event ")
98 for (LS,file)
in LSinFile.items():
99 nls = NumberOfLSInFile[file]
100 RatePerLS[LS] = RatePerLS[LS] / nls
101 RatePerLS[LS] = RatePerLS[LS] / LS_Length
107 print(
"lsmin lsmax",lsmin,lsmax)
108 for ls
in range(lsmin,lsmax):
109 if not repr(ls)
in RatePerLS.keys():
111 print(
"Missing LS ",ls)
114 if __name__ ==
"__main__":
116 if not options.RunNumber:
130 print(
"\nRun Number: ",options.RunNumber)
131 if options.PrimaryDataset:
132 Run = options.RunNumber
133 PrimaryDataset = options.PrimaryDataset
135 if not options.perLS:
136 RateInPD(Run,PrimaryDataset,lsMin, lsMax,
False)
140 RateInPD(Run,PrimaryDataset,lsMin, lsMax,
True)
141 RatesTmp = open(
"rates_tmp.txt",
"w")
143 for (LS, rate)
in RatePerLS.items():
144 RatesTmp.write(LS+
"\t"+repr(rate)+
"\n")
154 TempFile = open(
"tmp.gnuplot.txt",
"w")
156 TempFile.write(
"set logscale y \n")
158 TempFile.write(
"set term postscript eps enhanced \n")
159 TempFile.write(
"set output \"tmp.eps\" \n")
160 st_title =
" \"Rates in PrimaryDataset " + PrimaryDataset+
" in Run " + repr(Run)+
"\" "
161 TempFile.write(
"set title " + st_title +
"\n")
162 TempFile.write(
" set pointsize 2. \n")
163 TempFile.write(
" set nokey \n")
164 TempFile.write(
" set xlabel \"LS number\" \n")
165 TempFile.write(
" set ylabel \"Rate (Hz)\" \n")
166 TempFile.write(
" plot \"rates_tmp.txt\" using 1:2 title 'Rate per LS' \n")
167 if not options.saveplot:
168 TempFile.write(
" pause -1")
170 print(
"The plot is saved under tmp.eps")
173 os.system(
"gnuplot tmp.gnuplot.txt")
177 Run = options.RunNumber
180 for PrimaryDataset
in Datasets:
182 RateInPD(Run,PrimaryDataset,lsMin,lsMax)