File indexing completed on 2024-04-06 12:29:04
0001
0002 from __future__ import print_function
0003 import sys,os,subprocess,re
0004 import xmlrpclib
0005 from CommonMethods import *
0006
0007 try:
0008 import json
0009 except:
0010 try:
0011 import simplejson as json
0012 except:
0013 print("Please set a crab environment in order to get the proper JSON lib")
0014 sys.exit(1)
0015
0016
0017 def getUploadedIOVs(tagName,destDB="oracle://cms_orcoff_prod/CMS_COND_31X_BEAMSPOT"):
0018 listIOVCommand = "cmscond_list_iov -c " + destDB + " -P /afs/cern.ch/cms/DB/conddb -t " + tagName
0019 dbError = subprocess.getstatusoutput( listIOVCommand )
0020 if dbError[0] != 0 :
0021 if dbError[1].find("metadata entry \"" + tagName + "\" does not exist") != -1:
0022 exit(dbError[1])
0023 else:
0024 exit("ERROR: Can\'t connect to db because:\n" + dbError[1])
0025
0026
0027 aCommand = listIOVCommand + " | grep DB= | awk \'{print $1}\'"
0028
0029 output = subprocess.getstatusoutput( aCommand )
0030
0031
0032 if output[1] == '':
0033 exit("ERROR: The tag " + tagName + " exists but I can't get the value of the last IOV")
0034
0035 runs = []
0036 for run in output[1].split('\n'):
0037 runs.append(long(run))
0038
0039 return runs
0040
0041
0042 def getListOfRunsAndLumiFromFile(firstRun=-1,fileName=""):
0043 file = open(fileName);
0044 jsonFile = file.read();
0045 file.close()
0046 jsonList=json.loads(jsonFile);
0047
0048 selected_dcs = {};
0049 for element in jsonList:
0050 selected_dcs[long(element)]=jsonList[element]
0051 return selected_dcs
0052
0053
0054 def getListOfRunsAndLumiFromRR(firstRun=-1,error=""):
0055 RunReg ="http://pccmsdqm04.cern.ch/runregistry"
0056
0057
0058 Group = "Collisions10"
0059
0060
0061 FULLADDRESS=RunReg + "/xmlrpc"
0062
0063
0064 server = xmlrpclib.ServerProxy(FULLADDRESS)
0065
0066 sel_runtable="{groupName} ='" + Group + "' and {runNumber} > " + str(firstRun)
0067
0068 tries = 0;
0069 maxAttempts = 3
0070 while tries<maxAttempts:
0071 try:
0072 run_data = server.DataExporter.export('RUN', 'GLOBAL', 'csv_runs', sel_runtable)
0073 break
0074 except:
0075 tries += 1
0076 print("Trying to get run data. This fails only 2-3 times so don't panic yet...", tries, "/", maxAttempts)
0077 time.sleep(1)
0078 print("Exception type: ", sys.exc_info()[0])
0079 if tries==maxAttempts:
0080 error = "Ok, now panic...run registry unaccessible...I'll get the runs from a json file!"
0081 print(error);
0082 return {};
0083
0084 listOfRuns=[]
0085 runErrors = {}
0086 for line in run_data.split("\n"):
0087 run=line.split(',')[0]
0088 if run.isdigit():
0089 listOfRuns.append(run)
0090
0091 tries = 0
0092 maxAttempts = 3
0093 firstRun = listOfRuns[len(listOfRuns)-1];
0094 lastRun = listOfRuns[0];
0095 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"
0096 while tries<maxAttempts:
0097 try:
0098 dcs_data = server.DataExporter.export('RUNLUMISECTION', 'GLOBAL', 'json' , sel_dcstable)
0099 break
0100 except:
0101 tries += 1
0102 print("I was able to get the list of runs and now I am trying to access the detector status", tries, "/", maxAttempts)
0103 time.sleep(1)
0104 print("Exception type: ", sys.exc_info()[0])
0105
0106 if tries==maxAttempts:
0107 error = "Ok, now panic...run registry unaccessible...I'll get the runs from a json file!"
0108 print(error);
0109 return {};
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131 selected_dcs={}
0132 jsonList=json.loads(dcs_data)
0133
0134
0135 for element in listOfRuns:
0136
0137 if element in jsonList:
0138 selected_dcs[long(element)]=jsonList[element]
0139 else:
0140
0141 selected_dcs[long(element)]= [[]]
0142 return selected_dcs
0143
0144
0145 def main():
0146 usage = "USAGE: ./checkPayloads.py (optional tagNumber) (optional \"lumi\") (optional \"z\" (optional destDB)"
0147 printExtra = False
0148 tagNumber = "14"
0149 dbBase = ""
0150 sigmaZ = ""
0151
0152 if len(sys.argv) >= 2:
0153 if not sys.argv[1].isdigit():
0154 exit(usage)
0155 else:
0156 tagNumber = sys.argv[1]
0157 if len(sys.argv) >= 3:
0158 if not sys.argv[2] == "lumi":
0159 exit(usage)
0160 else:
0161 dbBase = "_LumiBased"
0162 if len(sys.argv) >= 4:
0163 if not sys.argv[3] == "z":
0164 exit(usage)
0165 else:
0166 sigmaZ = "_SigmaZ"
0167 destDB = ""
0168 if(len(sys.argv) > 4):
0169 destDB = sys.argv[4]
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192 knownMissingRunList = [132573,132958,133081,133242,133472,133473,136290,138560,138562,139455,140133,140182,142461,142465,142503,142653,143977,148859]
0193 tagName = "BeamSpotObjects_2009" + dbBase + sigmaZ + "_v" + tagNumber + "_offline"
0194 print("Checking payloads for tag " + tagName)
0195 listOfRunsAndLumi = {};
0196
0197 if(not listOfRunsAndLumi):
0198 listOfRunsAndLumi = getListOfRunsAndLumiFromFile(-1,"/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions10/7TeV/StreamExpress/Cert_132440-149442_7TeV_StreamExpress_Collisions10_JSON_v3.txt");
0199 tmpListOfIOVs = []
0200 if(destDB != ""):
0201 tmpListOfIOVs = getUploadedIOVs(tagName,destDB)
0202 else:
0203 tmpListOfIOVs = getUploadedIOVs(tagName)
0204
0205
0206 listOfIOVs = []
0207 if(dbBase == ''):
0208 listOfIOVs = tmpListOfIOVs
0209 else:
0210 for iov in tmpListOfIOVs:
0211 if((iov >> 32) not in listOfIOVs):
0212 listOfIOVs.append(iov >>32)
0213 RRRuns = sorted(listOfRunsAndLumi.keys())
0214 for run in RRRuns:
0215
0216 if run not in listOfIOVs:
0217 extraMsg = ""
0218 if listOfRunsAndLumi[run] == [[]]:
0219 extraMsg = " but it is empty in the RR"
0220 if not printExtra: continue
0221 if run in knownMissingRunList :
0222 extraMsg = " but this run is know to be bad "
0223 if not printExtra: continue
0224 print("Run: " + str(run) + " is missing for DB tag " + tagName + extraMsg)
0225
0226
0227 if __name__ == "__main__":
0228 main()
0229