2 from __future__
import print_function
3 from builtins
import range
4 import sys,os,commands,re
6 from CommonMethods
import *
11 import simplejson
as json
13 print(
"Please set a crab environment in order to get the proper JSON lib")
18 file = open(fileName);
19 jsonFile = file.read();
21 jsonList=json.loads(jsonFile);
24 for element
in jsonList:
25 selected_dcs[long(element)]=jsonList[element]
30 RunReg =
"http://pccmsdqm04.cern.ch/runregistry"
33 Group =
"Collisions10"
36 FULLADDRESS=RunReg +
"/xmlrpc"
39 server = xmlrpclib.ServerProxy(FULLADDRESS)
41 sel_runtable=
"{groupName} ='" + Group +
"' and {runNumber} > " +
str(firstRun)
45 while tries<maxAttempts:
47 run_data = server.DataExporter.export(
'RUN',
'GLOBAL',
'csv_runs', sel_runtable)
51 print(
"Trying to get run data. This fails only 2-3 times so don't panic yet...", tries,
"/", maxAttempts)
53 print(
"Exception type: ", sys.exc_info()[0])
54 if tries==maxAttempts:
55 error =
"Ok, now panic...run registry unaccessible...I'll get the runs from a json file!"
61 for line
in run_data.split(
"\n"):
62 run=line.split(
',')[0]
64 listOfRuns.append(run)
68 firstRun = listOfRuns[len(listOfRuns)-1];
69 lastRun = listOfRuns[0];
70 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"
71 while tries<maxAttempts:
73 dcs_data = server.DataExporter.export(
'RUNLUMISECTION',
'GLOBAL',
'json' , sel_dcstable)
77 print(
"I was able to get the list of runs and now I am trying to access the detector status", tries,
"/", maxAttempts)
79 print(
"Exception type: ", sys.exc_info()[0])
81 if tries==maxAttempts:
82 error =
"Ok, now panic...run registry unaccessible...I'll get the runs from a json file!"
87 jsonList=json.loads(dcs_data)
90 for element
in listOfRuns:
92 if element
in jsonList:
93 selected_dcs[long(element)]=jsonList[element]
96 selected_dcs[long(element)]= [[]]
101 filesDir =
"LatestRuns/Results/";
102 fileList =
ls(filesDir)
103 listOfRunsAndLumi = {};
105 if(
not listOfRunsAndLumi):
106 listOfRunsAndLumi =
getListOfRunsAndLumiFromFile(-1,
"/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions10/7TeV/StreamExpress/Cert_132440-149442_7TeV_StreamExpress_Collisions10_JSON_v3.txt");
108 runKeys = listOfRunsAndLumi.keys();
111 for fileName
in fileList:
112 regExp = re.search(
'(\D+)(\d+)_(\d+)_(\d+).txt',fileName);
114 error =
"Can't find reg exp";
116 runFiles.append(long(regExp.group(3)));
122 runsAndLumisInRR = {};
125 for lumiRange
in listOfRunsAndLumi[run]:
127 for l
in range(lumiRange[0],lumiRange[1]+1):
128 RRList.append(long(l));
130 runsAndLumisInRR[run] = RRList;
132 runsAndLumisProcessed = {}
133 for fileName
in fileList:
134 file = open(filesDir+fileName)
136 if line.find(
"Runnumber") != -1:
137 run = long(line.replace(
'\n',
'').
split(
' ')[1])
138 elif line.find(
"LumiRange") != -1:
139 lumiLine = line.replace(
'\n',
'').
split(
' ')
140 begLumi = long(lumiLine[1])
141 endLumi = long(lumiLine[3])
142 if begLumi != endLumi:
143 error =
"The lumi range is greater than 1 for run " +
str(run) +
" " + line +
" in file: " + runListDir + fileName
146 if not run
in runsAndLumisProcessed:
147 runsAndLumisProcessed[run] = []
148 if begLumi
in runsAndLumisProcessed[run]:
149 print(
"Lumi " +
str(begLumi) +
" in event " +
str(run) +
" already exist. This MUST not happen but right now I will ignore this lumi!")
151 runsAndLumisProcessed[run].
append(begLumi)
157 for lumi
in runsAndLumisInRR[run]:
160 if(run
not in runFiles):
161 print(
"Can't find run", run,
"in the files!")
163 elif(
not lumi
in runsAndLumisProcessed[run]):
164 missingLumis.append(lumi)
165 if(len(missingLumis) != 0):
166 print(
"In run", run,
"these lumis are missing ->", missingLumis)
169 if __name__ ==
"__main__":