9 import xmlrpclib,sys,ConfigParser,os,string,commands,time,re
15 import simplejson
as json
17 print "Please use lxplus or set an environment (for example crab) with json lib available" 20 global QF_Req,ls_temp_data,QF_ALL_SYS,EXCEPTION,EXRUN
29 intervals = sorted(intervals, key =
lambda x: x[0])
36 (a,b)=intervals[len(intervals)-1]
40 for (x,y)
in intervals:
42 result.append((curr_min,x-1))
45 result.append((curr_min,max_val))
53 intervals = sorted(intervals, key =
lambda x: x[0])
56 for (x, y)
in intervals[1:]:
66 p = re.compile(
r'<.*?>')
67 newdata=p.sub(
'', data)
68 newdata=newdata.replace(
" ",
"")
72 result= re.sub(
r'\s',
'', data)
76 global QF_Req,ls_temp_data,QF_ALL_SYS,EXCEPTION,EXRUN
80 for line
in ls_temp_data.split(
"\n"):
84 if "%%%BAD LS INFO BEGIN%%%" in line:
85 selectls=line.split(
"%%%BAD LS INFO BEGIN%%%")[1]
86 selectls=selectls.split(
"%%%BAD LS INFO END%%%")[0]
90 for tag
in QF_ALL_SYS:
91 selectls=selectls.replace(tag+
":",
"\n"+tag+
":")
94 for line
in selectls.split(
"\n"):
96 tag=line.split(
":")[0]
97 intervals=line.split(
":")[1]
100 if tag
in QF_Req.keys():
101 if QF_Req[tag]==
"GOOD":
102 for interval
in intervals.split(
","):
103 if "ALL" in interval:
107 strmin=interval.split(
'-')[0]
108 strmax=interval.split(
'-')[1]
114 intervallist.append((lmin,lmax))
130 QF_ALL_SYS=[
"Hcal",
"Track",
"Strip",
"Egam",
"Es",
"Dt",
"Csc",
"Pix",
"Muon",
"Rpc",
"Castor",
"Jmet",
"Ecal",
"L1t",
"Hlt",
"NONE"]
131 QF_ALL_STAT=[
"GOOD",
"BAD",
"EXCL",
"NONE"]
132 DCS_ALL=[
'Bpix',
'Fpix',
'Tibtid',
'TecM',
'TecP',
'Tob',
'Ebminus',
'Ebplus',
'EeMinus',
'EePlus',
'EsMinus',
'EsPlus',
'HbheA',
'HbheB',
'HbheC',
'H0',
'Hf',
'Dtminus',
'Dtplus',
'Dt0',
'CscMinus',
'CscPlus',
'Rpc',
'Castor',
"NONE"]
135 CONFIGFILE=
'runreg.cfg' 136 CONFIG = ConfigParser.ConfigParser()
137 print 'Reading configuration file from ',CONFIGFILE
138 CONFIG.read(CONFIGFILE)
140 DATASET=CONFIG.get(
'Common',
'Dataset')
141 GROUP=CONFIG.get(
'Common',
'Group')
142 HLTNAMEFILTER=CONFIG.get(
'Common',
'HLTnameFilter')
143 ADDRESS=CONFIG.get(
'Common',
'RunReg')
144 RUNMIN=CONFIG.get(
'Common',
'Runmin')
145 RUNMAX=CONFIG.get(
'Common',
'Runmax')
146 QFLAGS=CONFIG.get(
'Common',
'QFLAGS')
147 BFIELD=CONFIG.get(
'Common',
'BField_thr')
148 LSPARSE=CONFIG.get(
'Common',
'LSCOMMENT')
149 DCSSTAT=CONFIG.get(
'Common',
'DCS')
150 DCSLIST=string.split(DCSSTAT,
',')
152 OUTPUTFILENAME=CONFIG.get(
'Common',
"OutputFileName")
155 if "TRUE" in LSPARSE.upper()
or "1" in LSPARSE.upper()
or "YES" in LSPARSE.upper():
157 elif "FALSE" in LSPARSE.upper()
or "0" in LSPARSE.upper()
or "NO" in LSPARSE.upper():
160 print "Error in parsing LSCOMMENT cfg parameter: LSPARSE" 163 QFlist=string.split(QFLAGS,
',')
165 syst=string.split(QF,
":")[0]
166 value=string.split(QF,
":")[1]
167 if syst
not in QF_ALL_SYS
or value
not in QF_ALL_STAT:
168 print "QFLAG not valid:",syst,value
173 if dcs
not in DCS_ALL:
174 print "DCS not valid:",dcs
178 CFGLIST=CONFIG.items(
'Common')
179 JSONFILE=CONFIG.get(
'Common',
'JSONFILE')
182 BFIELD_float=
float(BFIELD)
184 print "BFIELD threshold value not understood:",BFIELD
189 print "You asked for the runreg info in the run range:"+RUNMIN+
"-"+RUNMAX
190 print "for dataset: "+DATASET
191 print "with the following quality flags:" 192 for SS
in QF_Req.keys():
194 print "and with the following DCS status:" 197 print "Manual bad LS in comment column:",LSCOMMENT
201 FULLADDRESS=ADDRESS+
"/xmlrpc" 202 print "RunRegistry from: ",FULLADDRESS
203 server = xmlrpclib.ServerProxy(FULLADDRESS)
206 sel_runtable=
"{groupName} ='"+GROUP+
"' and {runNumber} >= "+RUNMIN+
" and {runNumber} <= "+RUNMAX+
" and {bfield}>"+BFIELD+
" and {datasetName} LIKE '"+DATASET+
"'" 209 sel_dstable=
"{groupName} ='"+GROUP+
"' and {runNumber} >= "+RUNMIN+
" and {runNumber} <= "+RUNMAX+
" and {bfield}>"+BFIELD+
" and {datasetName} LIKE '%Express%'" 211 for key
in QF_Req.keys():
212 if key !=
"NONE" and QF_Req[key]!=
"NONE":
213 sel_runtable+=
" and {cmp"+key+
"} = '"+QF_Req[key]+
"'" 214 sel_dstable+=
" and {cmp"+key+
"} = '"+QF_Req[key]+
"'" 218 sel_dcstable=
"{groupName} ='"+GROUP+
"' and {runNumber} >= "+RUNMIN+
" and {runNumber} <= "+RUNMAX
221 sel_dcstable+=
" and {parDcs"+dcs+
"} = 1" 229 print "Accessing run registry...." 230 dcs_data = server.DataExporter.export(
'RUNLUMISECTION',
'GLOBAL',
'json', sel_dcstable)
231 run_data = server.DataExporter.export(
'RUN',
'GLOBAL',
'csv_runs', sel_runtable)
232 ls_temp_data = server.DataExporter.export(
'RUN',
'GLOBAL',
'csv_datasets', sel_dstable)
235 print "Something wrong in accessing runregistry, retrying in 3s...." 239 print "Run registry unaccessible.....exiting now" 250 selectedRuns = open(OUTPUTFILENAME,
'w')
251 print "Saving selected runs to file OUTPUTFILENAME" 252 for line
in run_data.split(
"\n"):
253 run=line.split(
',')[0]
255 hlt=line.split(
',')[9]
256 print "for run", run,
"hlt is", hlt
257 if HLTNAMEFILTER ==
"" or hlt.find(HLTNAMEFILTER):
258 LISTOFRUN.append(run)
259 selectedRuns.write(run+
"\n")
263 jsonlist=json.loads(dcs_data)
266 for element
in jsonlist:
267 if element
in LISTOFRUN:
275 for interval
in manualbad_int:
276 combined.append(interval)
277 for interval
in dcsbad_int:
278 combined.append(interval)
281 selected_dcs[element]=combined
284 selected_dcs[element]=jsonlist[element]
289 if JSONFILE !=
"NONE":
290 lumiSummary = open(JSONFILE,
'w')
291 json.dump(selected_dcs, lumiSummary)
294 print "-------------------------------------------" 295 print "Json file: ",JSONFILE,
" written." 299 selectlumi=
"process.source.lumisToProcess = cms.untracked.VLuminosityBlockRange(\n" 301 runs_to_print = sorted(selected_dcs.keys())
302 for run
in runs_to_print:
303 blocks = sorted(selected_dcs[run])
305 for lsrange
in blocks:
306 if lsrange[0] == prevblock[1]+1:
307 print "Run: ",run,
"- This lumi starts at ", lsrange[0],
" previous ended at ", prevblock[1]+1,
" so I should merge" 308 prevblock[1] = lsrange[1]
309 ranges[-1] =
"\t'%s:%d-%s:%d',\n" % (run, prevblock[0],
312 ranges.append(
"\t'%s:%d-%s:%d',\n" % (run, lsrange[0],
315 selectlumi +=
"".
join(ranges)
319 print "-------------------------------------------" 321 print "CFG snippet to select:" 325 print "WARNING: Something wrong in manual lumisection selection tag for run: "+
str(EXRUN)
def invert_intervals(intervals, min_val=1, max_val=9999)
def merge_intervals(intervals)
static std::string join(char **cmd)
def remove_extra_spaces(data)
def remove_html_tags(data)