def queryRR(firstRun, lastRun, groupName): rrurl = "http://runregistry.web.cern.ch/runregistry/" stderr.write( "Querying run registry for range [%d, %d], group name like %s ...\n" % (firstRun, lastRun, groupName)) server = RRApi(rrurl) mycolumns = ['number', 'hltKeyDescription', 'runClassName'] run_data = server.data(workspace='GLOBAL', table='runsummary', template='xml', columns=mycolumns, filter={ 'datasetExists': '= true', 'number': '>= %d and <= %d' % (firstRun, lastRun), 'runClassName': "like '%%%s%%'" % groupName }) ret = {} xml_data = xml.dom.minidom.parseString(run_data) xml_runs = xml_data.documentElement.getElementsByTagName( "RunSummaryRowGlobal") for xml_run in xml_runs: ret[xml_run.getElementsByTagName("number") [0].firstChild.nodeValue] = xml_run.getElementsByTagName( "hltKeyDescription")[0].firstChild.nodeValue return ret
def getRunsNewer(run, minLumis): try: api = RRApi(URL) if api.app == "user": result = api.data(workspace = 'GLOBAL', table = 'runsummary', template = 'json', columns = [ 'number', 'lsCount', 'startTime', 'duration', 'hltkey', 'gtKey', 'l1Menu', 'tscKey', 'triggerMode', 'triggers', 'runClassName', ], query = "{number} > %d and {lsCount} > %d and {triggers} > 0" % (run, minLumis), ) runs = {} for runDict in result : runNo = int(runDict['number']) runDict['date'] = datetime.datetime.strptime(runDict['startTime'], "%a %d-%m-%y %H:%M:%S").date().strftime('%Y%m%d') runs[runNo] = runDict return runs else : print "RunRegistry API 'app' != user, who knows why... :<" except RRApiError, e: print e
def queryRR(firstRun,lastRun,groupName): rrurl = "http://runregistry.web.cern.ch/runregistry/" stderr.write("Querying run registry for range [%d, %d], group name like %s ...\n" % (firstRun, lastRun, groupName)) server = RRApi(rrurl) mycolumns = ['number', 'hltKeyDescription', 'runClassName'] run_data = server.data(workspace = 'GLOBAL', table = 'runsummary', template = 'xml', columns = mycolumns, filter = {'datasetExists': '= true', 'number':'>= %d and <= %d'%(firstRun,lastRun), 'runClassName':"like '%%%s%%'"%groupName}) ret = {} xml_data = xml.dom.minidom.parseString(run_data) xml_runs = xml_data.documentElement.getElementsByTagName("RunSummaryRowGlobal") for xml_run in xml_runs: ret[xml_run.getElementsByTagName("number")[0].firstChild.nodeValue] = xml_run.getElementsByTagName("hltKeyDescription")[0].firstChild.nodeValue return ret
def getRunsNewer(run, minLumis): try: api = RRApi(URL) if api.app == "user": result = api.data( workspace='GLOBAL', table='runsummary', template='json', columns=[ 'number', 'lsCount', 'startTime', 'duration', 'hltkey', 'gtKey', 'l1Menu', 'tscKey', 'triggerMode', 'triggers', 'runClassName', ], query="{number} > %d and {lsCount} > %d and {triggers} > 0" % (run, minLumis), ) runs = {} for runDict in result: runNo = int(runDict['number']) runDict['date'] = datetime.datetime.strptime( runDict['startTime'], "%a %d-%m-%y %H:%M:%S").date().strftime('%Y%m%d') runs[runNo] = runDict return runs else: print "RunRegistry API 'app' != user, who knows why... :<" except RRApiError, e: print e
toDis = 99 Num_noiseB = 99 Num_noiseE = 99 Den_noiseB = 1 Den_noiseE = 1 #Get runs from run registry print "From run registry..." print "Connecting to RunRegistry..." URL = "http://runregistry.web.cern.ch/runregistry/" api = RRApi(URL, debug = True) print api.workspaces() print "from GLOBAL runsummary..." runData = api.data('GLOBAL', 'runsummary', 'json', ['number','duration','initLumi','endLumi','runClassName'], {'datasetExists': '= true', 'number': '= '+str(myrun),'duration': '> '+str(0),'rpcPresent' : 'true'}) for runPair in runData: type_run = runPair["runClassName"] run_duration = runPair["duration"] run_duration = int(run_duration) run_inLumi = runPair["initLumi"] run_enLumi = runPair["endLumi"] h=int(run_duration/3600) min=int((run_duration-h*3600)/60) sec=run_duration - h*3600 - min*60 print "--------------------------" print "Run Class Name ",type_run print "Init Lumi ", run_inLumi, "(check please)" print "End Lumi ", run_enLumi, "(check please)"
def testRunsFromRR(path, outpath): try: # Construct API object api = RRApi(URL, debug = True) #print api.tables('GLOBAL') #print api.columns('GLOBAL', 'runsummary') #coljson = api.columns('GLOBAL', 'runsummary') #for block in coljson: # print block['name'] ##print api.templates('GLOBAL', 'runsummary') ##print api.count('GLOBAL', 'runsummary') # #find out the last run we cleaned up # lastCleanedRun = 0 # for line in reversed(list(open("/home/vis/clearTempArea.log"))): # if ('.root' in line): # myline = line.rstrip() # #print(myline) # #print(myline.rfind('run')) # #print(myline.rfind('_ls')) # lastCleanedRun = myline[myline.rfind('run')+3:myline.rfind('_ls')] # #print(lastCleanedRun) # break #Example queries #print api.data( workspace = 'GLOBAL', table = 'runsummary', template = 'csv', columns = ['number', 'events', 'lsCount', 'duration', 'startTime', 'stopTime', 'datasetExists'], filter = {'startTime': '>= 2015-04-17', 'duration': '>= 300', 'datasetExists': '= true'}, order = ['number asc'] ) #myjson = api.data( workspace = 'GLOBAL', table = 'runsummary', template = 'json', columns = ['number', 'events', 'lsCount', 'duration', 'startTime', 'stopTime', 'datasetExists'], filter = {'startTime': '>= 2015-04-17', 'duration': '>= 300', 'datasetExists': '= true'}, order = ['number asc'] ) #print 'search for runs after '+str(lastCleanedRun)+' of at least '+str(minDuration)+' secs' #print api.data( workspace = 'GLOBAL', table = 'runsummary', template = 'csv', columns = ['number', 'events', 'lsCount', 'duration', 'startTime', 'stopTime', 'datasetExists'], filter = {'number': '> '+lastCleanedRun, 'duration': '>= '+str(minDuration), 'datasetExists': '= true'}, order = ['number asc'] ) #myjson = api.data( workspace = 'GLOBAL', table = 'runsummary', template = 'json', columns = ['number', 'events', 'lsCount', 'duration', 'startTime', 'stopTime', 'datasetExists'], filter = {'number': '> '+lastCleanedRun, 'duration': '>= '+str(minDuration), 'datasetExists': '= true'}, order = ['number asc'] ) # query runs from past N days pastdate = datetime.date.today() - datetime.timedelta(nDaysForQuery) pastdate_str = pastdate.strftime('%Y-%m-%d') print 'search for runs after '+pastdate_str+' of at least '+str(minDuration)+' secs' print api.data( workspace = 'GLOBAL', table = 'runsummary', template = 'csv', columns = ['number', 'events', 'lsCount', 'duration', 'startTime', 'stopTime', 'datasetExists'], filter = {'startTime': '>= '+pastdate_str, 'duration': '>= '+str(minDuration), 'datasetExists': '= true'}, order = ['number asc'] ) myjson = api.data( workspace = 'GLOBAL', table = 'runsummary', template = 'json', columns = ['number', 'events', 'lsCount', 'duration', 'startTime', 'stopTime', 'datasetExists'], filter = {'startTime': '>= '+pastdate_str, 'duration': '>= '+str(minDuration), 'datasetExists': '= true'}, order = ['number asc'] ) #get what time is it now now = time.gmtime() print 'UTC time is '+time.strftime('%a %d-%m-%y %H:%M:%S', time.gmtime()) tsnow = time.mktime(now) nruns = 0. foundruns = 0. nrunsNh = 0. foundrunsNh = 0. for block in myjson: print 'run: '+str(block['number'])+' startTime: '+str(block['startTime']) nruns = nruns+1. strun = time.strptime(block['startTime'], '%a %d-%m-%y %H:%M:%S') tsrun = time.mktime(strun) isRunLastNh = 0 if (tsnow-tsrun < nHours*60*60): nrunsNh = nrunsNh+1. isRunLastNh = 1 print 'run in last '+str(nHours)+' hours!' for f in glob.glob(path): found = str(block['number']) in str(f) if found: print 'found matching file: '+f foundruns = foundruns+1. if (isRunLastNh): foundrunsNh = foundrunsNh+1 break print 'efficiency = %f' % (foundruns/nruns) print 'efficiency last Nh = %f' % ((foundrunsNh/nrunsNh) if nrunsNh>0 else -1) c1 = ROOT.TCanvas() h_eff = ROOT.TH1F("h_eff", "efficiency (>=1 file for runs of >"+str(minDuration)+" sec)", 2, 0, 2) h_eff.GetXaxis().SetBinLabel(1,"all (%i runs)" % nruns) h_eff.GetXaxis().SetBinLabel(2,"last "+str(nHours)+" hours (%i runs)" % nrunsNh) h_eff.SetBinContent(1,(foundruns/nruns)) h_eff.SetBinContent(2,((foundrunsNh/nrunsNh) if nrunsNh>0 else -1)) h_eff.Draw() h_eff.GetYaxis().SetRangeUser(0.,1.1) c1.SaveAs(outpath+"/h_eff-"+outtime+".png") except RRApiError, e: print e