9 from __future__
import print_function
10 import xmlrpclib,sys,ConfigParser,os,string,commands,time,re
16 import simplejson
as json
18 print(
"Please use lxplus or set an environment (for example crab) with json lib available")
21 global QF_Req,ls_temp_data,QF_ALL_SYS,EXCEPTION,EXRUN
30 intervals = sorted(intervals, key =
lambda x: x[0])
37 (a,b)=intervals[len(intervals)-1]
41 for (x,y)
in intervals:
43 result.append((curr_min,x-1))
46 result.append((curr_min,max_val))
54 intervals = sorted(intervals, key =
lambda x: x[0])
57 for (x, y)
in intervals[1:]:
67 p = re.compile(
r'<.*?>')
68 newdata=p.sub(
'', data)
69 newdata=newdata.replace(
" ",
"")
73 result= re.sub(
r'\s',
'', data)
77 global QF_Req,ls_temp_data,QF_ALL_SYS,EXCEPTION,EXRUN
81 for line
in ls_temp_data.split(
"\n"):
85 if "%%%BAD LS INFO BEGIN%%%" in line:
86 selectls=line.split(
"%%%BAD LS INFO BEGIN%%%")[1]
87 selectls=selectls.split(
"%%%BAD LS INFO END%%%")[0]
91 for tag
in QF_ALL_SYS:
92 selectls=selectls.replace(tag+
":",
"\n"+tag+
":")
95 for line
in selectls.split(
"\n"):
97 tag=line.split(
":")[0]
98 intervals=line.split(
":")[1]
101 if tag
in QF_Req.keys():
102 if QF_Req[tag]==
"GOOD":
103 for interval
in intervals.split(
","):
104 if "ALL" in interval:
108 strmin=interval.split(
'-')[0]
109 strmax=interval.split(
'-')[1]
115 intervallist.append((lmin,lmax))
131 QF_ALL_SYS=[
"Hcal",
"Track",
"Strip",
"Egam",
"Es",
"Dt",
"Csc",
"Pix",
"Muon",
"Rpc",
"Castor",
"Jmet",
"Ecal",
"L1t",
"Hlt",
"NONE"]
132 QF_ALL_STAT=[
"GOOD",
"BAD",
"EXCL",
"NONE"]
133 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"]
136 CONFIGFILE=
'runreg.cfg' 137 CONFIG = ConfigParser.ConfigParser()
138 print(
'Reading configuration file from ',CONFIGFILE)
139 CONFIG.read(CONFIGFILE)
141 DATASET=CONFIG.get(
'Common',
'Dataset')
142 GROUP=CONFIG.get(
'Common',
'Group')
143 HLTNAMEFILTER=CONFIG.get(
'Common',
'HLTnameFilter')
144 ADDRESS=CONFIG.get(
'Common',
'RunReg')
145 RUNMIN=CONFIG.get(
'Common',
'Runmin')
146 RUNMAX=CONFIG.get(
'Common',
'Runmax')
147 QFLAGS=CONFIG.get(
'Common',
'QFLAGS')
148 BFIELD=CONFIG.get(
'Common',
'BField_thr')
149 LSPARSE=CONFIG.get(
'Common',
'LSCOMMENT')
150 DCSSTAT=CONFIG.get(
'Common',
'DCS')
151 DCSLIST=string.split(DCSSTAT,
',')
153 OUTPUTFILENAME=CONFIG.get(
'Common',
"OutputFileName")
156 if "TRUE" in LSPARSE.upper()
or "1" in LSPARSE.upper()
or "YES" in LSPARSE.upper():
158 elif "FALSE" in LSPARSE.upper()
or "0" in LSPARSE.upper()
or "NO" in LSPARSE.upper():
161 print(
"Error in parsing LSCOMMENT cfg parameter: LSPARSE")
164 QFlist=string.split(QFLAGS,
',')
166 syst=string.split(QF,
":")[0]
167 value=string.split(QF,
":")[1]
168 if syst
not in QF_ALL_SYS
or value
not in QF_ALL_STAT:
169 print(
"QFLAG not valid:",syst,value)
174 if dcs
not in DCS_ALL:
175 print(
"DCS not valid:",dcs)
179 CFGLIST=CONFIG.items(
'Common')
180 JSONFILE=CONFIG.get(
'Common',
'JSONFILE')
183 BFIELD_float=
float(BFIELD)
185 print(
"BFIELD threshold value not understood:",BFIELD)
190 print(
"You asked for the runreg info in the run range:"+RUNMIN+
"-"+RUNMAX)
191 print(
"for dataset: "+DATASET)
192 print(
"with the following quality flags:")
193 for SS
in QF_Req.keys():
194 print(SS, QF_Req[SS])
195 print(
"and with the following DCS status:")
198 print(
"Manual bad LS in comment column:",LSCOMMENT)
202 FULLADDRESS=ADDRESS+
"/xmlrpc" 203 print(
"RunRegistry from: ",FULLADDRESS)
204 server = xmlrpclib.ServerProxy(FULLADDRESS)
207 sel_runtable=
"{groupName} ='"+GROUP+
"' and {runNumber} >= "+RUNMIN+
" and {runNumber} <= "+RUNMAX+
" and {bfield}>"+BFIELD+
" and {datasetName} LIKE '"+DATASET+
"'" 210 sel_dstable=
"{groupName} ='"+GROUP+
"' and {runNumber} >= "+RUNMIN+
" and {runNumber} <= "+RUNMAX+
" and {bfield}>"+BFIELD+
" and {datasetName} LIKE '%Express%'" 212 for key
in QF_Req.keys():
213 if key !=
"NONE" and QF_Req[key]!=
"NONE":
214 sel_runtable+=
" and {cmp"+key+
"} = '"+QF_Req[key]+
"'" 215 sel_dstable+=
" and {cmp"+key+
"} = '"+QF_Req[key]+
"'" 219 sel_dcstable=
"{groupName} ='"+GROUP+
"' and {runNumber} >= "+RUNMIN+
" and {runNumber} <= "+RUNMAX
222 sel_dcstable+=
" and {parDcs"+dcs+
"} = 1" 230 print(
"Accessing run registry....")
231 dcs_data = server.DataExporter.export(
'RUNLUMISECTION',
'GLOBAL',
'json', sel_dcstable)
232 run_data = server.DataExporter.export(
'RUN',
'GLOBAL',
'csv_runs', sel_runtable)
233 ls_temp_data = server.DataExporter.export(
'RUN',
'GLOBAL',
'csv_datasets', sel_dstable)
236 print(
"Something wrong in accessing runregistry, retrying in 3s....")
240 print(
"Run registry unaccessible.....exiting now")
251 selectedRuns = open(OUTPUTFILENAME,
'w')
252 print(
"Saving selected runs to file OUTPUTFILENAME")
253 for line
in run_data.split(
"\n"):
254 run=line.split(
',')[0]
256 hlt=line.split(
',')[9]
257 print(
"for run", run,
"hlt is", hlt)
258 if HLTNAMEFILTER ==
"" or hlt.find(HLTNAMEFILTER):
259 LISTOFRUN.append(run)
260 selectedRuns.write(run+
"\n")
264 jsonlist=json.loads(dcs_data)
267 for element
in jsonlist:
268 if element
in LISTOFRUN:
276 for interval
in manualbad_int:
277 combined.append(interval)
278 for interval
in dcsbad_int:
279 combined.append(interval)
282 selected_dcs[element]=combined
285 selected_dcs[element]=jsonlist[element]
290 if JSONFILE !=
"NONE":
291 lumiSummary = open(JSONFILE,
'w')
292 json.dump(selected_dcs, lumiSummary)
295 print(
"-------------------------------------------")
296 print(
"Json file: ",JSONFILE,
" written.")
300 selectlumi=
"process.source.lumisToProcess = cms.untracked.VLuminosityBlockRange(\n" 302 runs_to_print = sorted(selected_dcs.keys())
303 for run
in runs_to_print:
304 blocks = sorted(selected_dcs[run])
306 for lsrange
in blocks:
307 if lsrange[0] == prevblock[1]+1:
308 print(
"Run: ",run,
"- This lumi starts at ", lsrange[0],
" previous ended at ", prevblock[1]+1,
" so I should merge")
309 prevblock[1] = lsrange[1]
310 ranges[-1] =
"\t'%s:%d-%s:%d',\n" % (run, prevblock[0],
313 ranges.append(
"\t'%s:%d-%s:%d',\n" % (run, lsrange[0],
316 selectlumi +=
"".
join(ranges)
320 print(
"-------------------------------------------")
322 print(
"CFG snippet to select:")
326 print(
"WARNING: Something wrong in manual lumisection selection tag for run: "+
str(EXRUN))
S & print(S &os, JobReport::InputFile const &f)
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)