Go to the documentation of this file.00001
00002 import sys,os,commands,re
00003 import xmlrpclib
00004 from CommonMethods import *
00005 try:
00006 import json
00007 except:
00008 try:
00009 import simplejson as json
00010 except:
00011 print "Please set a crab environment in order to get the proper JSON lib"
00012 sys.exit(1)
00013
00014
00015 def getListOfRunsAndLumiFromFile(firstRun=-1,fileName=""):
00016 file = open(fileName);
00017 jsonFile = file.read();
00018 file.close()
00019 jsonList=json.loads(jsonFile);
00020
00021 selected_dcs = {};
00022 for element in jsonList:
00023 selected_dcs[long(element)]=jsonList[element]
00024 return selected_dcs
00025
00026
00027 def getListOfRunsAndLumiFromRR(firstRun=-1,error=""):
00028 RunReg ="https://pccmsdqm04.cern.ch/runregistry"
00029
00030
00031 Group = "Collisions10"
00032
00033
00034 FULLADDRESS=RunReg + "/xmlrpc"
00035
00036
00037 server = xmlrpclib.ServerProxy(FULLADDRESS)
00038
00039 sel_runtable="{groupName} ='" + Group + "' and {runNumber} > " + str(firstRun)
00040
00041 tries = 0;
00042 maxAttempts = 3
00043 while tries<maxAttempts:
00044 try:
00045 run_data = server.DataExporter.export('RUN', 'GLOBAL', 'csv_runs', sel_runtable)
00046 break
00047 except:
00048 tries += 1
00049 print "Trying to get run data. This fails only 2-3 times so don't panic yet...", tries, "/", maxAttempts
00050 time.sleep(1)
00051 print "Exception type: ", sys.exc_info()[0]
00052 if tries==maxAttempts:
00053 error = "Ok, now panic...run registry unaccessible...I'll get the runs from a json file!"
00054 print error;
00055 return {};
00056
00057 listOfRuns=[]
00058 runErrors = {}
00059 for line in run_data.split("\n"):
00060 run=line.split(',')[0]
00061 if run.isdigit():
00062 listOfRuns.append(run)
00063
00064 tries = 0
00065 maxAttempts = 3
00066 firstRun = listOfRuns[len(listOfRuns)-1];
00067 lastRun = listOfRuns[0];
00068 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"
00069 while tries<maxAttempts:
00070 try:
00071 dcs_data = server.DataExporter.export('RUNLUMISECTION', 'GLOBAL', 'json' , sel_dcstable)
00072 break
00073 except:
00074 tries += 1
00075 print "I was able to get the list of runs and now I am trying to access the detector status", tries, "/", maxAttempts
00076 time.sleep(1)
00077 print "Exception type: ", sys.exc_info()[0]
00078
00079 if tries==maxAttempts:
00080 error = "Ok, now panic...run registry unaccessible...I'll get the runs from a json file!"
00081 print error;
00082 return {};
00083
00084 selected_dcs={}
00085 jsonList=json.loads(dcs_data)
00086
00087
00088 for element in listOfRuns:
00089
00090 if element in jsonList:
00091 selected_dcs[long(element)]=jsonList[element]
00092 else:
00093
00094 selected_dcs[long(element)]= [[]]
00095 return selected_dcs
00096
00097
00098 def main():
00099 filesDir = "LatestRuns/Results/";
00100 fileList = ls(filesDir)
00101 listOfRunsAndLumi = {};
00102
00103 if(not listOfRunsAndLumi):
00104 listOfRunsAndLumi = getListOfRunsAndLumiFromFile(-1,"/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions10/7TeV/StreamExpress/Cert_132440-149442_7TeV_StreamExpress_Collisions10_JSON_v3.txt");
00105
00106 runKeys = listOfRunsAndLumi.keys();
00107 runKeys.sort();
00108 runFiles = [];
00109 for fileName in fileList:
00110 regExp = re.search('(\D+)(\d+)_(\d+)_(\d+).txt',fileName);
00111 if(not regExp):
00112 error = "Can't find reg exp";
00113 exit(error);
00114 runFiles.append(long(regExp.group(3)));
00115
00116
00117
00118
00119
00120 runsAndLumisInRR = {};
00121 for run in runKeys:
00122 RRList = [];
00123 for lumiRange in listOfRunsAndLumi[run]:
00124 if lumiRange != []:
00125 for l in range(lumiRange[0],lumiRange[1]+1):
00126 RRList.append(long(l));
00127
00128 runsAndLumisInRR[run] = RRList;
00129
00130 runsAndLumisProcessed = {}
00131 for fileName in fileList:
00132 file = open(filesDir+fileName)
00133 for line in file:
00134 if line.find("Runnumber") != -1:
00135 run = long(line.replace('\n','').split(' ')[1])
00136 elif line.find("LumiRange") != -1:
00137 lumiLine = line.replace('\n','').split(' ')
00138 begLumi = long(lumiLine[1])
00139 endLumi = long(lumiLine[3])
00140 if begLumi != endLumi:
00141 error = "The lumi range is greater than 1 for run " + str(run) + " " + line + " in file: " + runListDir + fileName
00142 exit(error)
00143 else:
00144 if not run in runsAndLumisProcessed:
00145 runsAndLumisProcessed[run] = []
00146 if begLumi in runsAndLumisProcessed[run]:
00147 print "Lumi " + str(begLumi) + " in event " + str(run) + " already exist. This MUST not happen but right now I will ignore this lumi!"
00148 else:
00149 runsAndLumisProcessed[run].append(begLumi)
00150 file.close()
00151
00152
00153 for run in runKeys:
00154 missingLumis = [];
00155 for lumi in runsAndLumisInRR[run]:
00156
00157
00158 if(run not in runFiles):
00159 print "Can't find run", run, "in the files!"
00160 break ;
00161 elif( not lumi in runsAndLumisProcessed[run]):
00162 missingLumis.append(lumi)
00163 if(len(missingLumis) != 0):
00164 print "In run", run, "these lumis are missing ->", missingLumis
00165
00166
00167 if __name__ == "__main__":
00168 main()
00169