6 from optparse
import OptionParser
20 parser = OptionParser(usage=
"Example: ./PDRates.py --runNumber 146644 --PD Mu --perLS")
21 parser.add_option(
"--runNumber", dest=
"RunNumber", help=
"run number", type=
"int", metavar=
"RunNumber")
22 parser.add_option(
"--PD",dest=
"PrimaryDataset",help=
"PD name",metavar=
"PrimaryDataset")
23 parser.add_option(
"--perLS",action=
"store_true",default=
False,dest=
"perLS",help=
"plot the rate vs the LS number",metavar=
"perLS")
24 parser.add_option(
"--logy",action=
"store_true",default=
False,dest=
"logy",help=
"log scale for the y axis",metavar=
"logy")
25 parser.add_option(
"--saveplot",action=
"store_true",default=
False,dest=
"saveplot",help=
"save the plot as a tmp.eps",metavar=
"saveplot")
26 (options, args) = parser.parse_args()
32 dbs_cmd =
""" dbs search --query='find primds.name 33 where run=%d and dataset like */RAW' """ % (Run)
34 rows = commands.getoutput(dbs_cmd)
35 lines = rows.split(
"\n")
37 print "\nThe primary datasets for this run are: \n" 44 Datasets.append(line[0])
49 def RateInPD(Run,PrimaryDataset,lsMin,lsMax,printLS=False):
50 dbs_cmd =
""" dbs search --query='find file,lumi,file.numevents, file.size 51 where run=%d and dataset like /%s/*/RAW 52 and lumi >= %d and lumi <= %d 53 and file.status=VALID '""" % (Run, PrimaryDataset,lsMin, lsMax)
54 rows = commands.getoutput(dbs_cmd)
55 lines = rows.split(
"\n")
73 if LumiSections.count(LS) == 0:
74 LumiSections.append(LS)
75 if Files.count(file) == 0:
79 NumberOfLSInFile[file] =1
81 NumberOfLSInFile[file] = NumberOfLSInFile[file]+1
84 Number_of_LS = len(LumiSections)
88 rate = Evts / (Number_of_LS * LS_Length)
90 size_per_event = (Size / Evts) / 1000.
93 print "Rate in \t",PrimaryDataset,
"\t is : \t",rate,
" Hz",
" \t size is : \t",size_per_event,
"kB / event " 97 for (LS,file)
in LSinFile.iteritems():
98 nls = NumberOfLSInFile[file]
99 RatePerLS[LS] = RatePerLS[LS] / nls
100 RatePerLS[LS] = RatePerLS[LS] / LS_Length
106 print "lsmin lsmax",lsmin,lsmax
107 for ls
in range(lsmin,lsmax):
108 if not repr(ls)
in RatePerLS.keys():
110 print "Missing LS ",ls
113 if __name__ ==
"__main__":
115 if not options.RunNumber:
129 print "\nRun Number: ",options.RunNumber
130 if options.PrimaryDataset:
131 Run = options.RunNumber
132 PrimaryDataset = options.PrimaryDataset
134 if not options.perLS:
135 RateInPD(Run,PrimaryDataset,lsMin, lsMax,
False)
139 RateInPD(Run,PrimaryDataset,lsMin, lsMax,
True)
140 RatesTmp = open(
"rates_tmp.txt",
"w")
142 for (LS, rate)
in RatePerLS.iteritems():
143 RatesTmp.write(LS+
"\t"+repr(rate)+
"\n")
153 TempFile = open(
"tmp.gnuplot.txt",
"w")
155 TempFile.write(
"set logscale y \n")
157 TempFile.write(
"set term postscript eps enhanced \n")
158 TempFile.write(
"set output \"tmp.eps\" \n")
159 st_title =
" \"Rates in PrimaryDataset " + PrimaryDataset+
" in Run " + repr(Run)+
"\" " 160 TempFile.write(
"set title " + st_title +
"\n")
161 TempFile.write(
" set pointsize 2. \n")
162 TempFile.write(
" set nokey \n")
163 TempFile.write(
" set xlabel \"LS number\" \n")
164 TempFile.write(
" set ylabel \"Rate (Hz)\" \n")
165 TempFile.write(
" plot \"rates_tmp.txt\" using 1:2 title 'Rate per LS' \n")
166 if not options.saveplot:
167 TempFile.write(
" pause -1")
169 print "The plot is saved under tmp.eps" 172 os.system(
"gnuplot tmp.gnuplot.txt")
176 Run = options.RunNumber
179 for PrimaryDataset
in Datasets:
181 RateInPD(Run,PrimaryDataset,lsMin,lsMax)
def RateInPD(Run, PrimaryDataset, lsMin, lsMax, printLS=False)