Go to the documentation of this file.00001
00002 import sys,os,commands,re
00003 import xmlrpclib
00004 from CommonMethods import *
00005
00006 try:
00007 import json
00008 except:
00009 try:
00010 import simplejson as json
00011 except:
00012 print "Please set a crab environment in order to get the proper JSON lib"
00013 sys.exit(1)
00014
00015
00016 def getUploadedIOVs(tagName,destDB="oracle://cms_orcoff_prod/CMS_COND_31X_BEAMSPOT"):
00017 listIOVCommand = "cmscond_list_iov -c " + destDB + " -P /afs/cern.ch/cms/DB/conddb -t " + tagName
00018 dbError = commands.getstatusoutput( listIOVCommand )
00019 if dbError[0] != 0 :
00020 if dbError[1].find("metadata entry \"" + tagName + "\" does not exist") != -1:
00021 exit(dbError[1])
00022 else:
00023 exit("ERROR: Can\'t connect to db because:\n" + dbError[1])
00024
00025
00026 aCommand = listIOVCommand + " | grep DB= | awk \'{print $1}\'"
00027
00028 output = commands.getstatusoutput( aCommand )
00029
00030
00031 if output[1] == '':
00032 exit("ERROR: The tag " + tagName + " exists but I can't get the value of the last IOV")
00033
00034 runs = []
00035 for run in output[1].split('\n'):
00036 runs.append(long(run))
00037
00038 return runs
00039
00040
00041 def getListOfRunsAndLumiFromFile(firstRun=-1,fileName=""):
00042 file = open(fileName);
00043 jsonFile = file.read();
00044 file.close()
00045 jsonList=json.loads(jsonFile);
00046
00047 selected_dcs = {};
00048 for element in jsonList:
00049 selected_dcs[long(element)]=jsonList[element]
00050 return selected_dcs
00051
00052
00053 def getListOfRunsAndLumiFromRR(firstRun=-1,error=""):
00054 RunReg ="http://pccmsdqm04.cern.ch/runregistry"
00055
00056
00057 Group = "Collisions10"
00058
00059
00060 FULLADDRESS=RunReg + "/xmlrpc"
00061
00062
00063 server = xmlrpclib.ServerProxy(FULLADDRESS)
00064
00065 sel_runtable="{groupName} ='" + Group + "' and {runNumber} > " + str(firstRun)
00066
00067 tries = 0;
00068 maxAttempts = 3
00069 while tries<maxAttempts:
00070 try:
00071 run_data = server.DataExporter.export('RUN', 'GLOBAL', 'csv_runs', sel_runtable)
00072 break
00073 except:
00074 tries += 1
00075 print "Trying to get run data. This fails only 2-3 times so don't panic yet...", tries, "/", maxAttempts
00076 time.sleep(1)
00077 print "Exception type: ", sys.exc_info()[0]
00078 if tries==maxAttempts:
00079 error = "Ok, now panic...run registry unaccessible...I'll get the runs from a json file!"
00080 print error;
00081 return {};
00082
00083 listOfRuns=[]
00084 runErrors = {}
00085 for line in run_data.split("\n"):
00086 run=line.split(',')[0]
00087 if run.isdigit():
00088 listOfRuns.append(run)
00089
00090 tries = 0
00091 maxAttempts = 3
00092 firstRun = listOfRuns[len(listOfRuns)-1];
00093 lastRun = listOfRuns[0];
00094 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"
00095 while tries<maxAttempts:
00096 try:
00097 dcs_data = server.DataExporter.export('RUNLUMISECTION', 'GLOBAL', 'json' , sel_dcstable)
00098 break
00099 except:
00100 tries += 1
00101 print "I was able to get the list of runs and now I am trying to access the detector status", tries, "/", maxAttempts
00102 time.sleep(1)
00103 print "Exception type: ", sys.exc_info()[0]
00104
00105 if tries==maxAttempts:
00106 error = "Ok, now panic...run registry unaccessible...I'll get the runs from a json file!"
00107 print error;
00108 return {};
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 selected_dcs={}
00131 jsonList=json.loads(dcs_data)
00132
00133
00134 for element in listOfRuns:
00135
00136 if element in jsonList:
00137 selected_dcs[long(element)]=jsonList[element]
00138 else:
00139
00140 selected_dcs[long(element)]= [[]]
00141 return selected_dcs
00142
00143
00144 def main():
00145 usage = "USAGE: ./checkPayloads.py (optional tagNumber) (optional \"lumi\") (optional \"z\" (optional destDB)"
00146 printExtra = False
00147 tagNumber = "14"
00148 dbBase = ""
00149 sigmaZ = ""
00150
00151 if len(sys.argv) >= 2:
00152 if not sys.argv[1].isdigit():
00153 exit(usage)
00154 else:
00155 tagNumber = sys.argv[1]
00156 if len(sys.argv) >= 3:
00157 if not sys.argv[2] == "lumi":
00158 exit(usage)
00159 else:
00160 dbBase = "_LumiBased"
00161 if len(sys.argv) >= 4:
00162 if not sys.argv[3] == "z":
00163 exit(usage)
00164 else:
00165 sigmaZ = "_SigmaZ"
00166 destDB = ""
00167 if(len(sys.argv) > 4):
00168 destDB = sys.argv[4]
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 knownMissingRunList = [132573,132958,133081,133242,133472,133473,136290,138560,138562,139455,140133,140182,142461,142465,142503,142653,143977,148859]
00192 tagName = "BeamSpotObjects_2009" + dbBase + sigmaZ + "_v" + tagNumber + "_offline"
00193 print "Checking payloads for tag " + tagName
00194 listOfRunsAndLumi = {};
00195
00196 if(not listOfRunsAndLumi):
00197 listOfRunsAndLumi = getListOfRunsAndLumiFromFile(-1,"/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions10/7TeV/StreamExpress/Cert_132440-149442_7TeV_StreamExpress_Collisions10_JSON_v3.txt");
00198 tmpListOfIOVs = []
00199 if(destDB != ""):
00200 tmpListOfIOVs = getUploadedIOVs(tagName,destDB)
00201 else:
00202 tmpListOfIOVs = getUploadedIOVs(tagName)
00203
00204
00205 listOfIOVs = []
00206 if(dbBase == ''):
00207 listOfIOVs = tmpListOfIOVs
00208 else:
00209 for iov in tmpListOfIOVs:
00210 if((iov >> 32) not in listOfIOVs):
00211 listOfIOVs.append(iov >>32)
00212 RRRuns = listOfRunsAndLumi.keys()
00213 RRRuns.sort()
00214 for run in RRRuns:
00215
00216 if run not in listOfIOVs:
00217 extraMsg = ""
00218 if listOfRunsAndLumi[run] == [[]]:
00219 extraMsg = " but it is empty in the RR"
00220 if not printExtra: continue
00221 if run in knownMissingRunList :
00222 extraMsg = " but this run is know to be bad "
00223 if not printExtra: continue
00224 print "Run: " + str(run) + " is missing for DB tag " + tagName + extraMsg
00225
00226
00227 if __name__ == "__main__":
00228 main()
00229