2 from __future__
import print_function
3 import sys,os,commands,re
5 from CommonMethods
import *
10 import simplejson
as json
12 print(
"Please set a crab environment in order to get the proper JSON lib")
17 file = open(fileName);
18 jsonFile = file.read();
20 jsonList=json.loads(jsonFile);
23 for element
in jsonList:
24 selected_dcs[long(element)]=jsonList[element]
29 RunReg =
"http://pccmsdqm04.cern.ch/runregistry" 32 Group =
"Collisions10" 35 FULLADDRESS=RunReg +
"/xmlrpc" 38 server = xmlrpclib.ServerProxy(FULLADDRESS)
40 sel_runtable=
"{groupName} ='" + Group +
"' and {runNumber} > " +
str(firstRun)
44 while tries<maxAttempts:
46 run_data = server.DataExporter.export(
'RUN',
'GLOBAL',
'csv_runs', sel_runtable)
50 print(
"Trying to get run data. This fails only 2-3 times so don't panic yet...", tries,
"/", maxAttempts)
52 print(
"Exception type: ", sys.exc_info()[0])
53 if tries==maxAttempts:
54 error =
"Ok, now panic...run registry unaccessible...I'll get the runs from a json file!" 60 for line
in run_data.split(
"\n"):
61 run=line.split(
',')[0]
63 listOfRuns.append(run)
67 firstRun = listOfRuns[len(listOfRuns)-1];
68 lastRun = listOfRuns[0];
69 sel_dcstable=
"{groupName} ='" + Group +
"' and {runNumber} >= " +
str(firstRun) +
" and {runNumber} <= " +
str(lastRun) +
" and {parDcsBpix} = 1 and {parDcsFpix} = 1 and {parDcsTibtid} = 1 and {parDcsTecM} = 1 and {parDcsTecP} = 1 and {parDcsTob} = 1 and {parDcsEbminus} = 1 and {parDcsEbplus} = 1 and {parDcsEeMinus} = 1 and {parDcsEePlus} = 1 and {parDcsEsMinus} = 1 and {parDcsEsPlus} = 1 and {parDcsHbheA} = 1 and {parDcsHbheB} = 1 and {parDcsHbheC} = 1 and {parDcsH0} = 1 and {parDcsHf} = 1" 70 while tries<maxAttempts:
72 dcs_data = server.DataExporter.export(
'RUNLUMISECTION',
'GLOBAL',
'json' , sel_dcstable)
76 print(
"I was able to get the list of runs and now I am trying to access the detector status", tries,
"/", maxAttempts)
78 print(
"Exception type: ", sys.exc_info()[0])
80 if tries==maxAttempts:
81 error =
"Ok, now panic...run registry unaccessible...I'll get the runs from a json file!" 86 jsonList=json.loads(dcs_data)
89 for element
in listOfRuns:
91 if element
in jsonList:
92 selected_dcs[long(element)]=jsonList[element]
95 selected_dcs[long(element)]= [[]]
100 filesDir =
"LatestRuns/Results/";
101 fileList =
ls(filesDir)
102 listOfRunsAndLumi = {};
104 if(
not listOfRunsAndLumi):
105 listOfRunsAndLumi =
getListOfRunsAndLumiFromFile(-1,
"/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions10/7TeV/StreamExpress/Cert_132440-149442_7TeV_StreamExpress_Collisions10_JSON_v3.txt");
107 runKeys = listOfRunsAndLumi.keys();
110 for fileName
in fileList:
111 regExp = re.search(
'(\D+)(\d+)_(\d+)_(\d+).txt',fileName);
113 error =
"Can't find reg exp";
115 runFiles.append(long(regExp.group(3)));
121 runsAndLumisInRR = {};
124 for lumiRange
in listOfRunsAndLumi[run]:
126 for l
in range(lumiRange[0],lumiRange[1]+1):
127 RRList.append(long(l));
129 runsAndLumisInRR[run] = RRList;
131 runsAndLumisProcessed = {}
132 for fileName
in fileList:
133 file = open(filesDir+fileName)
135 if line.find(
"Runnumber") != -1:
136 run = long(line.replace(
'\n',
'').
split(
' ')[1])
137 elif line.find(
"LumiRange") != -1:
138 lumiLine = line.replace(
'\n',
'').
split(
' ')
139 begLumi = long(lumiLine[1])
140 endLumi = long(lumiLine[3])
141 if begLumi != endLumi:
142 error =
"The lumi range is greater than 1 for run " +
str(run) +
" " + line +
" in file: " + runListDir + fileName
145 if not run
in runsAndLumisProcessed:
146 runsAndLumisProcessed[run] = []
147 if begLumi
in runsAndLumisProcessed[run]:
148 print(
"Lumi " +
str(begLumi) +
" in event " +
str(run) +
" already exist. This MUST not happen but right now I will ignore this lumi!")
150 runsAndLumisProcessed[run].
append(begLumi)
156 for lumi
in runsAndLumisInRR[run]:
159 if(run
not in runFiles):
160 print(
"Can't find run", run,
"in the files!")
162 elif(
not lumi
in runsAndLumisProcessed[run]):
163 missingLumis.append(lumi)
164 if(len(missingLumis) != 0):
165 print(
"In run", run,
"these lumis are missing ->", missingLumis)
168 if __name__ ==
"__main__":
def getListOfRunsAndLumiFromFile(firstRun=-1, fileName="")
S & print(S &os, JobReport::InputFile const &f)
def getListOfRunsAndLumiFromRR(firstRun=-1, error="")