2 from __future__
import print_function
7 from optparse
import OptionParser
22 parser = OptionParser(usage=
"Example: ./PDRates.py --runNumber 146644 --PD Mu --perLS")
23 parser.add_option(
"--runNumber", dest=
"RunNumber", help=
"run number", type=
"int", metavar=
"RunNumber")
24 parser.add_option(
"--PD",dest=
"PrimaryDataset",help=
"PD name",metavar=
"PrimaryDataset")
25 parser.add_option(
"--perLS",action=
"store_true",default=
False,dest=
"perLS",help=
"plot the rate vs the LS number",metavar=
"perLS")
26 parser.add_option(
"--logy",action=
"store_true",default=
False,dest=
"logy",help=
"log scale for the y axis",metavar=
"logy")
27 parser.add_option(
"--saveplot",action=
"store_true",default=
False,dest=
"saveplot",help=
"save the plot as a tmp.eps",metavar=
"saveplot")
28 (options, args) = parser.parse_args()
34 dbs_cmd =
""" dbs search --query='find primds.name
35 where run=%d and dataset like */RAW' """ % (Run)
36 rows = commands.getoutput(dbs_cmd)
37 lines = rows.split(
"\n")
39 print(
"\nThe primary datasets for this run are: \n")
46 Datasets.append(line[0])
51 def RateInPD(Run,PrimaryDataset,lsMin,lsMax,printLS=False):
52 dbs_cmd =
""" dbs search --query='find file,lumi,file.numevents, file.size
53 where run=%d and dataset like /%s/*/RAW
54 and lumi >= %d and lumi <= %d
55 and file.status=VALID '""" % (Run, PrimaryDataset,lsMin, lsMax)
56 rows = commands.getoutput(dbs_cmd)
57 lines = rows.split(
"\n")
75 if LumiSections.count(LS) == 0:
76 LumiSections.append(LS)
77 if Files.count(file) == 0:
81 NumberOfLSInFile[file] =1
83 NumberOfLSInFile[file] = NumberOfLSInFile[file]+1
86 Number_of_LS = len(LumiSections)
90 rate = Evts / (Number_of_LS * LS_Length)
92 size_per_event = (Size / Evts) / 1000.
95 print(
"Rate in \t",PrimaryDataset,
"\t is : \t",rate,
" Hz",
" \t size is : \t",size_per_event,
"kB / event ")
99 for (LS,file)
in six.iteritems(LSinFile):
100 nls = NumberOfLSInFile[file]
101 RatePerLS[LS] = RatePerLS[LS] / nls
102 RatePerLS[LS] = RatePerLS[LS] / LS_Length
108 print(
"lsmin lsmax",lsmin,lsmax)
109 for ls
in range(lsmin,lsmax):
110 if not repr(ls)
in RatePerLS.keys():
112 print(
"Missing LS ",ls)
115 if __name__ ==
"__main__":
117 if not options.RunNumber:
131 print(
"\nRun Number: ",options.RunNumber)
132 if options.PrimaryDataset:
133 Run = options.RunNumber
134 PrimaryDataset = options.PrimaryDataset
136 if not options.perLS:
137 RateInPD(Run,PrimaryDataset,lsMin, lsMax,
False)
141 RateInPD(Run,PrimaryDataset,lsMin, lsMax,
True)
142 RatesTmp = open(
"rates_tmp.txt",
"w")
144 for (LS, rate)
in six.iteritems(RatePerLS):
145 RatesTmp.write(LS+
"\t"+repr(rate)+
"\n")
155 TempFile = open(
"tmp.gnuplot.txt",
"w")
157 TempFile.write(
"set logscale y \n")
159 TempFile.write(
"set term postscript eps enhanced \n")
160 TempFile.write(
"set output \"tmp.eps\" \n")
161 st_title =
" \"Rates in PrimaryDataset " + PrimaryDataset+
" in Run " + repr(Run)+
"\" "
162 TempFile.write(
"set title " + st_title +
"\n")
163 TempFile.write(
" set pointsize 2. \n")
164 TempFile.write(
" set nokey \n")
165 TempFile.write(
" set xlabel \"LS number\" \n")
166 TempFile.write(
" set ylabel \"Rate (Hz)\" \n")
167 TempFile.write(
" plot \"rates_tmp.txt\" using 1:2 title 'Rate per LS' \n")
168 if not options.saveplot:
169 TempFile.write(
" pause -1")
171 print(
"The plot is saved under tmp.eps")
174 os.system(
"gnuplot tmp.gnuplot.txt")
178 Run = options.RunNumber
181 for PrimaryDataset
in Datasets:
183 RateInPD(Run,PrimaryDataset,lsMin,lsMax)