CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/RecoVertex/BeamSpotProducer/scripts/checkPayloads.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import sys,os,commands,re
00003 import xmlrpclib
00004 from CommonMethods import *
00005 
00006 try: # FUTURE: Python 2.6, prior to 2.6 requires simplejson
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     #print aCommand
00028     output = commands.getstatusoutput( aCommand )
00029             
00030     #WARNING when we pass to lumi IOV this should be long long
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     #RunReg  = "http://localhost:40010/runregistry"
00056     #Dataset=%Online%
00057     Group   = "Collisions10"
00058 
00059     # get handler to RR XML-RPC server
00060     FULLADDRESS=RunReg + "/xmlrpc"
00061     #print "RunRegistry from: ",FULLADDRESS
00062     #firstRun = 153000
00063     server = xmlrpclib.ServerProxy(FULLADDRESS)
00064     #sel_runtable="{groupName} ='" + Group + "' and {runNumber} > " + str(firstRun) + " and {datasetName} LIKE '" + Dataset + "'"
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     #This is the original and shold work in the furture as soon as the server will be moved to a more powerfull PC
00111     #while tries<maxAttempts:
00112     #    try:
00113     #        run_data = server.DataExporter.export('RUN'           , 'GLOBAL', 'csv_runs', sel_runtable)
00114     #        dcs_data = server.DataExporter.export('RUNLUMISECTION', 'GLOBAL', 'json'    , sel_dcstable)
00115     #        #print run_data
00116     #        #print dcs_data
00117     #        break
00118     #    except:
00119     #        print "Something wrong in accessing runregistry, retrying in 5s...."
00120     #        tries += 1
00121     #        time.sleep(2)
00122     #        print "Exception type: ", sys.exc_info()[0]
00123     #
00124     #    if tries==maxAttempts:
00125     #        error = "Run registry unaccessible.....exiting now"
00126     #        sys.exit(error)
00127                 
00128                 
00129                         
00130     selected_dcs={}
00131     jsonList=json.loads(dcs_data)
00132     
00133     #for element in jsonList:
00134     for element in listOfRuns:
00135         #if element in listOfRuns:
00136         if element in jsonList:
00137             selected_dcs[long(element)]=jsonList[element]
00138         else:
00139             #print "WARNING: Run " + element + " is a collision10 run with 0 lumis in Run Registry!"
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     #132573 Beam lost immediately
00170     #132958 Bad strips
00171     #133081 Bad pixels bad strips
00172     #133242 Bad strips
00173     #133472 Bad strips
00174     #133473 Only 20 lumisection, run duration 00:00:03:00 
00175     #133509 Should be good!!!!!!!!!!
00176     #136290 Bad Pixels bad strips
00177     #138560 Bad pixels bad strips
00178     #138562 Bad HLT bad L1T, need to rescale the Jet Triggers
00179     #139363 NOT in the bad list but only 15 lumis and stopped for DAQ problems
00180     #139455 Bad Pixels and Strips and stopped because of HCAL trigger rate too high
00181     #140133 Beams dumped
00182     #140182 No pixel and Strips with few entries
00183     #141865 Pixel are bad but Strips work. Run is acceptable but need relaxed cuts since there are no pixels. BeamWidth measurement is bad 80um compared to 40um
00184     #142461 Run crashed immediately due to PIX, stable beams since LS1
00185     #142465 PostCollsions10, beams lost, HCAl DQM partly working
00186     #142503 Bad pixels bad strips
00187     #142653 Strips not in data taking
00188     #143977 No Beam Strips and Pixels bad
00189     #148859 Strips and Pixels HV off waiting for beam 
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     #listOfRunsAndLumi = getListOfRunsAndLumiFromRR(-1);
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         #print listOfRunsAndLumiFromRR[run]
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 " #+ runErrors[run]
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