CMS 3D CMS Logo

Classes | Functions | Variables

lumiQueryAPI Namespace Reference

Classes

class  ParametersObject
 ==============temporarilly here======### More...

Functions

def allfills
def allruns
 ==============real api=====###
def beamIntensityForRun
def calculateEffective
def calculateTotalRecorded
def calibratedDetailForRunLimitresult
def deliveredLumiForRange
def deliveredLumiForRun
def dumpData
def dumpOverview
def dumpPerLSLumi
def dumpRecordedLumi
def filterDeadtable
def flatten
def getDeadfractions
def hltAllpathByrun
def hltBypathByrun
def hlttrgMappingByrun
def lsBylsLumi
def lslengthsec
def lumidetailAllalgosByrun
def lumidetailByrunByAlgo
def lumisumByrun
def lumisummaryByrun
def lumisummarytrgbitzeroByrun
def mergeXingLumi
def printDeliveredLumi
def printOverviewData
def printPerLSLumi
def printRecordedLumi
def recordedLumiForRange
def recordedLumiForRun
def runsByfillrange
def runsByTimerange
def runsummaryByrun
def setupSession
def splitlistToRangeString
def trgAllbitsByrun
def trgbitzeroByrun
def trgBybitnameByrun
def validation
def xingLuminosityForRun

Variables

tuple allfills = allfills(q)
tuple allruns = allruns(schema,requireLumisummary=True,requireTrg=True,requireHlt=True)
string connectstr = 'oracle://cms_orcoff_prod/cms_lumi_prod'
tuple msg = coral.MessageStream('')
tuple q = schema.newQuery()
tuple schema = session.nominalSchema()
tuple session = svc.connect(connectstr,accessMode=coral.access_ReadOnly)
tuple svc = coral.ConnectionService()

Function Documentation

def lumiQueryAPI::allfills (   queryHandle,
  filtercrazy = True 
)
select distinct fillnum from cmsrunsummary
there are crazy fill numbers. we assume they are not valid runs

Definition at line 1041 of file lumiQueryAPI.py.

01042                                           :
01043     '''select distinct fillnum from cmsrunsummary
01044     there are crazy fill numbers. we assume they are not valid runs
01045     '''
01046     result=[]
01047     queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
01048     queryHandle.addToOutputList('distinct FILLNUM','fillnum')
01049     
01050     if filtercrazy:
01051         queryCondition='FILLNUM>:zero and FILLNUM<:crazybig'
01052         queryBind=coral.AttributeList()
01053         queryBind.extend('zero','unsigned int')
01054         queryBind.extend('crazybig','unsigned int')
01055         queryBind['zero'].setData(int(0))
01056         queryBind['crazybig'].setData(int(29701))
01057         queryHandle.setCondition(queryCondition,queryBind)
01058     queryResult=coral.AttributeList()
01059     queryResult.extend('fillnum','unsigned int')
01060     queryHandle.defineOutput(queryResult)
01061     cursor=queryHandle.execute()
01062     while cursor.next():
01063         result.append(cursor.currentRow()['fillnum'].data())
01064     result.sort()
    return result
def lumiQueryAPI::allruns (   schemaHandle,
  requireRunsummary = True,
  requireLumisummary = False,
  requireTrg = False,
  requireHlt = False 
)

==============real api=====###

find all runs in the DB. By default requires cmsrunsummary table contain the run. The condition can be loosed in situation where db loading failed on certain data portions.

Definition at line 923 of file lumiQueryAPI.py.

00924                                                                                                            :
00925     '''
00926     find all runs in the DB. By default requires cmsrunsummary table contain the run. The condition can be loosed in situation where db loading failed on certain data portions.
00927     '''
00928     if not requireRunsummary and not requireLumiummary and not requireTrg and not requireHlt:
00929         print 'must require at least one table'
00930         raise
00931     runresult=[]
00932     runlist=[]
00933     numdups=0
00934     if requireRunsummary:
00935         numdups=numdups+1
00936         queryHandle=schemaHandle.newQuery()
00937         queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
00938         queryHandle.addToOutputList("RUNNUM","run")
00939         #queryBind=coral.AttributeList()
00940         result=coral.AttributeList()
00941         result.extend("run","unsigned int")
00942         queryHandle.defineOutput(result)
00943         cursor=queryHandle.execute()
00944         while cursor.next():
00945             r=cursor.currentRow()['run'].data()
00946             runlist.append(r)
00947         del queryHandle
00948     if requireLumisummary:
00949         numdups=numdups+1
00950         queryHandle=schemaHandle.newQuery()
00951         queryHandle.addToTableList(nameDealer.lumisummaryTableName())
00952         queryHandle.addToOutputList("distinct RUNNUM","run")
00953         #queryBind=coral.AttributeList()
00954         result=coral.AttributeList()
00955         result.extend("run","unsigned int")
00956         queryHandle.defineOutput(result)
00957         cursor=queryHandle.execute()
00958         while cursor.next():
00959             r=cursor.currentRow()['run'].data()
00960             runlist.append(r)
00961         del queryHandle
00962     if requireTrg:
00963         numdups=numdups+1
00964         queryHandle=schemaHandle.newQuery()
00965         queryHandle.addToTableList(nameDealer.trgTableName())
00966         queryHandle.addToOutputList("distinct RUNNUM","run")
00967         #queryBind=coral.AttributeList()
00968         result=coral.AttributeList()
00969         result.extend("run","unsigned int")
00970         queryHandle.defineOutput(result)
00971         cursor=queryHandle.execute()
00972         while cursor.next():
00973             r=cursor.currentRow()['run'].data()
00974             runlist.append(r)
00975         del queryHandle
00976     if requireHlt:
00977         numdups=numdups+1
00978         queryHandle=schemaHandle.newQuery()
00979         queryHandle.addToTableList(nameDealer.hltTableName())
00980         queryHandle.addToOutputList("distinct RUNNUM","run")
00981         #queryBind=coral.AttributeList()
00982         result=coral.AttributeList()
00983         result.extend("run","unsigned int")
00984         queryHandle.defineOutput(result)
00985         cursor=queryHandle.execute()
00986         while cursor.next():
00987             r=cursor.currentRow()['run'].data()
00988             runlist.append(r)
00989         del queryHandle
00990     dupresult=CommonUtil.count_dups(runlist)
00991     for dup in dupresult:
00992         if dup[1]==numdups:
00993             runresult.append(dup[0])
00994     runresult.sort()
00995     return runresult

def lumiQueryAPI::beamIntensityForRun (   query,
  parameters,
  runnum 
)
select CMSBXINDEXBLOB,BEAMINTENSITYBLOB_1,BEAMINTENSITYBLOB_2 from LUMISUMMARY where runnum=146315 and LUMIVERSION='0001'

output : result {startorbit: [(bxidx,beam1intensity,beam2intensity)]}

Definition at line 1469 of file lumiQueryAPI.py.

01470                                                 :
01471     '''
01472     select CMSBXINDEXBLOB,BEAMINTENSITYBLOB_1,BEAMINTENSITYBLOB_2 from LUMISUMMARY where runnum=146315 and LUMIVERSION='0001'
01473     
01474     output : result {startorbit: [(bxidx,beam1intensity,beam2intensity)]}
01475     '''
01476     result={} #{startorbit:[(bxidx,occlumi,occlumierr,beam1intensity,beam2intensity)]}
01477     
01478     lumisummaryOutput=coral.AttributeList()
01479     lumisummaryOutput.extend('cmslsnum','unsigned int')
01480     lumisummaryOutput.extend('startorbit','unsigned int')
01481     lumisummaryOutput.extend('bxindexblob','blob');
01482     lumisummaryOutput.extend('beamintensityblob1','blob');
01483     lumisummaryOutput.extend('beamintensityblob2','blob');
01484     condition=coral.AttributeList()
01485     condition.extend('runnum','unsigned int')
01486     condition.extend('lumiversion','string')
01487     condition['runnum'].setData(int(runnum))
01488     condition['lumiversion'].setData(parameters.lumiversion)
01489     
01490     query.addToTableList(parameters.lumisummaryname)
01491     query.addToOutputList('CMSLSNUM','cmslsnum')
01492     query.addToOutputList('STARTORBIT','startorbit')
01493     query.addToOutputList('CMSBXINDEXBLOB','bxindexblob')
01494     query.addToOutputList('BEAMINTENSITYBLOB_1','beamintensityblob1')
01495     query.addToOutputList('BEAMINTENSITYBLOB_2','beamintensityblob2')
01496     query.setCondition('RUNNUM=:runnum AND LUMIVERSION=:lumiversion',condition)
01497     query.defineOutput(lumisummaryOutput)
01498     cursor=query.execute()
01499     while cursor.next():
01500         #cmslsnum=cursor.currentRow()['cmslsnum'].data()
01501         startorbit=cursor.currentRow()['startorbit'].data()
01502         bxidx=[]
01503         bb1=[]
01504         bb2=[]
01505         bxindexblob=None
01506         beamintensityblob1=None
01507         beamintensityblob2=None
01508         if not cursor.currentRow()["bxindexblob"].isNull():
01509             bxindexblob=cursor.currentRow()['bxindexblob'].data()
01510             if bxindexblob and bxindexblob.readline()!=None:
01511                 bxidx=CommonUtil.unpackBlobtoArray(bxindexblob,'h')
01512                 if not cursor.currentRow()['beamintensityblob1'].isNull():
01513                     beamintensityblob1=cursor.currentRow()['beamintensityblob1'].data()
01514                     if beamintensityblob1 and beamintensityblob1.readline()!=None:
01515                         bb1=CommonUtil.unpackBlobtoArray(beamintensityblob1,'f')
01516                 if not cursor.currentRow()['beamintensityblob2'].isNull():
01517                     beamintensityblob2=cursor.currentRow()['beamintensityblob2'].data()
01518                     if beamintensityblob2 and beamintensityblob2.readline()!=None:
01519                         bb2=CommonUtil.unpackBlobtoArray(beamintensityblob2,'f')
01520         if not result.has_key(startorbit):
01521             result[startorbit]=[]
01522         for idx,bxidxvalue in enumerate(bxidx):
01523             try:
01524                 b1intensity=bb1[idx]
01525             except IndexError:
01526                 b1intensity=0.0
01527             try:
01528                 b2intensity=bb2[idx]
01529             except IndexError:
01530                 b2intensity=0.0
01531             result[startorbit].append((bxidxvalue,b1intensity,b2intensity))
01532         del bxidx[:]
01533         del bb1[:]
01534         del bb2[:]
01535     return result
    
def lumiQueryAPI::calculateEffective (   trgtable,
  totalrecorded 
)
input: trgtable{hltpath:[l1seed, hltprescale, l1prescale]}, totalrecorded (float)
output:{hltpath, recorded}

Definition at line 445 of file lumiQueryAPI.py.

00446                                                 :
00447     """
00448     input: trgtable{hltpath:[l1seed, hltprescale, l1prescale]}, totalrecorded (float)
00449     output:{hltpath, recorded}
00450     """
00451     #print 'inputtrgtable', trgtable
00452     result = {}
00453     for hltpath, data in trgtable.items():
00454         if len (data) ==  3:
00455             result[hltpath] = totalrecorded/ (data[1]*data[2])
00456         else:
00457             result[hltpath] = 0.0
00458     return result
00459 

def lumiQueryAPI::calculateTotalRecorded (   deadtable)
input: {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]}
output: recordedLumi

Definition at line 410 of file lumiQueryAPI.py.

00411                                       :
00412     """
00413     input: {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]}
00414     output: recordedLumi
00415     """
00416     recordedLumi = 0.0
00417     for myls, d in deadtable.items():
00418         instLumi = d[1]
00419         #deadfrac = float (d[0])/float (d[2]*3564)
00420         #print myls, float (d[2])
00421         if float (d[2]) == 0.0:
00422             deadfrac = 1.0
00423         else:
00424             deadfrac = float (d[0])/(float (d[2])*float (d[-1]))
00425         lstime = lslengthsec (d[3], 3564)
00426         recordedLumi += instLumi* (1.0-deadfrac)*lstime
00427     return recordedLumi
00428 

def lumiQueryAPI::calibratedDetailForRunLimitresult (   query,
  parameters,
  runnum,
  algoname = 'OCC1',
  finecorrection = None 
)
select 
s.cmslsnum,d.bxlumivalue,d.bxlumierror,d.bxlumiquality,d.algoname from LUMIDETAIL d,LUMISUMMARY s where s.runnum=133885 and d.algoname='OCC1' and s.lumisummary_id=d.lumisummary_id order by s.startorbit,s.cmslsnum
result={(startorbit,cmslsnum):[(index,lumivalue,lumierr),]}

Definition at line 1536 of file lumiQueryAPI.py.

01537                                                                                                   :
01538     '''select 
01539     s.cmslsnum,d.bxlumivalue,d.bxlumierror,d.bxlumiquality,d.algoname from LUMIDETAIL d,LUMISUMMARY s where s.runnum=133885 and d.algoname='OCC1' and s.lumisummary_id=d.lumisummary_id order by s.startorbit,s.cmslsnum
01540     result={(startorbit,cmslsnum):[(index,lumivalue,lumierr),]}
01541     '''
01542     result={}
01543     detailOutput=coral.AttributeList()
01544     detailOutput.extend('cmslsnum','unsigned int')
01545     detailOutput.extend('startorbit','unsigned int')
01546     detailOutput.extend('bxlumivalue','blob')
01547     detailOutput.extend('bxlumierror','blob')
01548     detailCondition=coral.AttributeList()
01549     detailCondition.extend('runnum','unsigned int')
01550     detailCondition.extend('algoname','string')
01551     detailCondition['runnum'].setData(runnum)
01552     detailCondition['algoname'].setData(algoname)
01553 
01554     query.addToTableList(parameters.lumisummaryname,'s')
01555     query.addToTableList(parameters.lumidetailname,'d')
01556     query.addToOutputList('s.CMSLSNUM','cmslsnum')
01557     query.addToOutputList('s.STARTORBIT','startorbit')
01558     query.addToOutputList('d.BXLUMIVALUE','bxlumivalue')
01559     query.addToOutputList('d.BXLUMIERROR','bxlumierror')
01560     query.addToOutputList('d.BXLUMIQUALITY','bxlumiquality')
01561     query.setCondition('s.RUNNUM=:runnum and d.ALGONAME=:algoname and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',detailCondition)
01562     query.defineOutput(detailOutput)
01563     cursor=query.execute()
01564     while cursor.next():
01565         cmslsnum=cursor.currentRow()['cmslsnum'].data()
01566         bxlumivalue=cursor.currentRow()['bxlumivalue'].data()
01567         bxlumierror=cursor.currentRow()['bxlumierror'].data()
01568         startorbit=cursor.currentRow()['startorbit'].data()
01569         bxlumivalueArray=array.array('f')
01570         bxlumivalueArray.fromstring(bxlumivalue.readline())
01571         bxlumierrorArray=array.array('f')
01572         bxlumierrorArray.fromstring(bxlumierror.readline())
01573         xingLum=[]
01574         #apply selection criteria
01575         maxlumi=0.0
01576         if len(bxlumivalueArray)!=0:
01577             maxlumi=max(bxlumivalueArray)
01578         avginstlumi=0.0
01579         if len(bxlumivalueArray)!=0:
01580             avginstlumi=sum(bxlumivalueArray)
01581         for index,lum in enumerate(bxlumivalueArray):
01582             lumierror = bxlumierrorArray[index]
01583             if lum<max(parameters.xingMinLum,maxlumi*0.2): 
01584                 continue
01585             mynorm=parameters.normFactor
01586             if finecorrection:
01587                 lum=lumiCorrections.applyfinecorrectionBX(lum,avginstlumi*mynorm,mynorm,finecorrection[0],finecorrection[1],finecorrection[2])
01588                 lumierror=lumiCorrections.applyfinecorrectionBX(lumierror,avginstlumi*mynorm,mynorm,finecorrection[0],finecorrection[1],finecorrection[2])
01589             else:
01590                 lum*=mynorm
01591                 lumierror*=mynorm
01592             xingLum.append( (index,lum,lumierror) )
01593         if len(xingLum)!=0:
01594             result[(startorbit,cmslsnum)]=xingLum
01595     return result
   
def lumiQueryAPI::deliveredLumiForRange (   dbsession,
  parameters,
  inputRange,
  finecorrections = None 
)
Takes either single run as a string or dictionary of run ranges

Definition at line 82 of file lumiQueryAPI.py.

00083                                                                                  :
00084     '''Takes either single run as a string or dictionary of run ranges'''
00085     lumidata = []
00086     runs=[]
00087     if isinstance(inputRange, str):
00088         runs.append(int(inputRange))
00089     else:
00090         runs=inputRange.runs()
00091     for r in sorted(runs):
00092         if parameters.verbose:
00093             print "run", run
00094         c=None
00095         if finecorrections:
00096             c=finecorrections[r]
00097         lumidata.append( deliveredLumiForRun (dbsession, parameters,r,finecorrections=c) )       
00098     return lumidata

def lumiQueryAPI::deliveredLumiForRun (   dbsession,
  parameters,
  runnum,
  finecorrections = None 
)
select sum (INSTLUMI), count (INSTLUMI) from lumisummary where runnum = 124025 and lumiversion = '0001';
select INSTLUMI,NUMORBIT  from lumisummary where runnum = 124025 and lumiversion = '0001'
query result unit E27cm^-2 (= 1 / mb)

optional corrections=None/(constfactor,afterglowfactor,nonlinearfactor)

Definition at line 158 of file lumiQueryAPI.py.

00158                                                                               :    
00159     """
00160     select sum (INSTLUMI), count (INSTLUMI) from lumisummary where runnum = 124025 and lumiversion = '0001';
00161     select INSTLUMI,NUMORBIT  from lumisummary where runnum = 124025 and lumiversion = '0001'
00162     query result unit E27cm^-2 (= 1 / mb)
00163 
00164     optional corrections=None/(constfactor,afterglowfactor,nonlinearfactor)
00165     """    
00166     #if parameters.verbose:
00167     #    print 'deliveredLumiForRun : norm : ', parameters.norm, ' : run : ', runnum
00168     #output ['run', 'totalls', 'delivered', 'beammode']
00169     delivered = 0.0
00170     totalls = 0
00171     try:
00172         conditionstring="RUNNUM = :runnum AND LUMIVERSION = :lumiversion"
00173         dbsession.transaction().start (True)
00174         schema = dbsession.nominalSchema()
00175         query = schema.tableHandle (nameDealer.lumisummaryTableName()).newQuery()
00176         query.addToOutputList("INSTLUMI",'instlumi')
00177         query.addToOutputList ("NUMORBIT", "norbits")
00178         queryBind = coral.AttributeList()
00179         queryBind.extend ("runnum", "unsigned int")
00180         queryBind.extend ("lumiversion", "string")
00181         queryBind["runnum"].setData (int (runnum))
00182         queryBind["lumiversion"].setData (parameters.lumiversion)
00183         #print parameters.beammode
00184         if len(parameters.beammode)!=0:
00185             conditionstring=conditionstring+' and BEAMSTATUS=:beamstatus'
00186             queryBind.extend('beamstatus','string')
00187             queryBind['beamstatus'].setData(parameters.beammode)
00188         result = coral.AttributeList()
00189         result.extend ("instlumi", "float")
00190         result.extend ("norbits", "unsigned int")
00191         query.defineOutput (result)
00192         query.setCondition (conditionstring,queryBind)
00193         cursor = query.execute()
00194         while cursor.next():
00195             instlumi = cursor.currentRow()['instlumi'].data()
00196             norbits = cursor.currentRow()['norbits'].data()
00197             if finecorrections is not None:
00198                 instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
00199             if instlumi is not None and norbits is not None:
00200                 lstime = lslengthsec(norbits, parameters.NBX)
00201                 delivered=delivered+instlumi*parameters.norm*lstime
00202                 totalls+=1
00203         del query
00204         dbsession.transaction().commit()
00205         lumidata = []
00206         if delivered == 0.0:
00207             lumidata = [str (runnum), 'N/A', 'N/A', 'N/A']
00208         else:
00209             lumidata = [str (runnum), str (totalls), '%.3f'%delivered, parameters.beammode]
00210         return lumidata
00211     except Exception, e:
00212         print str (e)
00213         dbsession.transaction().rollback()
00214         del dbsession
00215 
def lumiQueryAPI::dumpData (   lumidata,
  filename 
)
input params: lumidata [{'fieldname':value}]
              filename csvname

Definition at line 401 of file lumiQueryAPI.py.

Referenced by HcalDbXml::dumpObject(), and CastorDbXml::dumpObject().

00402                                  :
00403     """
00404     input params: lumidata [{'fieldname':value}]
00405                   filename csvname
00406     """
00407     
00408     r = csvReporter.csvReporter(filename)
00409     r.writeRows(lumidata)

def lumiQueryAPI::dumpOverview (   delivered,
  recorded,
  hltpath = '' 
)

Definition at line 751 of file lumiQueryAPI.py.

00752                                                     :
00753     #toprowlabels = ['run', 'delivered', 'recorded', 'hltpath']
00754     datatable = []
00755     for runidx, deliveredrowdata in enumerate (delivered):
00756         rowdata = []
00757         rowdata += [deliveredrowdata[0], deliveredrowdata[2]]
00758         if deliveredrowdata[1] == 'N/A': #run does not exist
00759             rowdata += ['N/A', 'N/A']
00760             datatable.append (rowdata)
00761             continue
00762         recordedLumi = calculateTotalRecorded (recorded[runidx][2])
00763         lumiinPaths = calculateEffective (recorded[runidx][1], recordedLumi)
00764         if hltpath != '' and hltpath != 'all':
00765             if lumiinPaths.has_key (hltpath):
00766                 rowdata += [recordedLumi, lumiinPaths[hltpath]]
00767             else:
00768                 rowdata += [recordedLumi, 'N/A']
00769         else:
00770             rowdata += [recordedLumi, recordedLumi]
00771         datatable.append (rowdata)
00772     return datatable
00773 

def lumiQueryAPI::dumpPerLSLumi (   lumidata)

Definition at line 514 of file lumiQueryAPI.py.

00515                             :
00516     datatodump = []
00517     for perrundata in lumidata:
00518         runnumber = perrundata[0]
00519         deadtable = perrundata[2]
00520         lumiresult = lsBylsLumi (deadtable)
00521         for lsnum, dataperls in lumiresult.items():
00522             rowdata = []
00523             if len (dataperls) == 0:
00524                 rowdata += [str (runnumber), str (lsnum), 'N/A', 'N/A']
00525             else:
00526                 rowdata += [str (runnumber), str (lsnum), dataperls[0], dataperls[1]]
00527             if len (dataperls) > 2:
00528                 rowdata.extend ( flatten (dataperls[2:]) )
00529             datatodump.append (rowdata)
00530     return datatodump
00531 

def lumiQueryAPI::dumpRecordedLumi (   lumidata,
  hltpath = '' 
)

Definition at line 641 of file lumiQueryAPI.py.

00642                                              :
00643     #labels = ['Run', 'HLT path', 'Recorded']
00644     datatodump = []
00645     for dataperRun in lumidata:
00646         runnum = dataperRun[0]
00647         if len (dataperRun[1]) == 0:
00648             rowdata = []
00649             rowdata += [str (runnum)]+2*['N/A']
00650             datatodump.append (rowdata)
00651             continue
00652         perlsdata = dataperRun[2]
00653         recordedLumi = 0.0
00654         #norbits = perlsdata.values()[0][3]
00655         recordedLumi = calculateTotalRecorded (perlsdata)
00656         trgdict = dataperRun[1]
00657         effective = calculateEffective (trgdict, recordedLumi)
00658         if trgdict.has_key (hltpath) and effective.has_key (hltpath):
00659             rowdata = []
00660             l1bit = trgdict[hltpath][0]
00661             if len (trgdict[hltpath]) !=  3:
00662                 rowdata += [str (runnum), hltpath, 'N/A']
00663             else:
00664                 hltprescale = trgdict[hltpath][1]
00665                 l1prescale = trgdict[hltpath][2]
00666                 rowdata += [str (runnum), hltpath, effective[hltpath]]
00667             datatodump.append (rowdata)
00668             continue
00669         
00670         for trg, trgdata in trgdict.items():
00671             #print trg, trgdata
00672             rowdata = []                    
00673             rowdata += [str (runnum)]
00674             l1bit = trgdata[0]
00675             if len (trgdata) == 3:
00676                 rowdata += [trg, effective[trg]]
00677             else:
00678                 rowdata += [trg, 'N/A']
00679             datatodump.append (rowdata)
00680     return datatodump
00681 

def lumiQueryAPI::filterDeadtable (   inTable,
  lslist 
)

Definition at line 383 of file lumiQueryAPI.py.

00384                                      :
00385     result = {}
00386     if lslist is None:
00387         return inTable
00388     if len (lslist) == 0: #if request no ls, then return nothing
00389         return result
00390     for existingLS in inTable.keys():
00391         if existingLS in lslist:
00392             result[existingLS] = inTable[existingLS]
00393     return result
00394 

def lumiQueryAPI::flatten (   obj)
Given nested lists or tuples, returns a single flattened list

Definition at line 864 of file lumiQueryAPI.py.

00865                  :
00866     '''Given nested lists or tuples, returns a single flattened list'''
00867     result = []
00868     for piece in obj:
00869         if hasattr (piece, '__iter__') and not isinstance (piece, basestring):
00870             result.extend( flatten (piece) )
00871         else:
00872             result.append (piece)
00873     return result    
00874 

def lumiQueryAPI::getDeadfractions (   deadtable)
inputtable: {lsnum:[deadtime, instlumi, bit_0, norbits,bit_0_prescale]}
output: {lsnum:deadfraction}

Definition at line 460 of file lumiQueryAPI.py.

00461                                 :
00462     """
00463     inputtable: {lsnum:[deadtime, instlumi, bit_0, norbits,bit_0_prescale]}
00464     output: {lsnum:deadfraction}
00465     """
00466     result = {}
00467     for myls, d in deadtable.items():
00468         #deadfrac = float (d[0])/ (float (d[2])*float (3564))
00469         if float (d[2]) == 0.0: ##no beam
00470             deadfrac = -1.0
00471         else:
00472             deadfrac = float (d[0])/ (float (d[2])*float(d[-1]))
00473         result[myls] = deadfrac
00474     return result

def lumiQueryAPI::hltAllpathByrun (   queryHandle,
  runnum 
)
select cmslsnum,inputcount,acceptcount,prescale,pathname from hlt where runnum=:runnum
this can be changed to blob query later
output: {cmslsnum:{pathname:[inputcount,acceptcount,prescale]}}

Definition at line 1429 of file lumiQueryAPI.py.

01430                                        :
01431     '''
01432     select cmslsnum,inputcount,acceptcount,prescale,pathname from hlt where runnum=:runnum
01433     this can be changed to blob query later
01434     output: {cmslsnum:{pathname:[inputcount,acceptcount,prescale]}}
01435     '''
01436     result={}
01437     queryHandle.addToTableList(nameDealer.hltTableName())
01438     queryCondition=coral.AttributeList()
01439     queryCondition.extend('runnum','unsigned int')
01440     queryCondition['runnum'].setData(int(runnum))
01441     queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
01442     queryHandle.addToOutputList('INPUTCOUNT','inputcount')
01443     queryHandle.addToOutputList('ACCEPTCOUNT','acceptcount')
01444     queryHandle.addToOutputList('PRESCALE','prescale')
01445     queryHandle.addToOutputList('PATHNAME','pathname')
01446     queryHandle.setCondition('RUNNUM=:runnum',queryCondition)
01447     queryResult=coral.AttributeList()
01448     queryResult.extend('cmslsnum','unsigned int')
01449     queryResult.extend('inputcount','unsigned int')
01450     queryResult.extend('acceptcount','unsigned int')
01451     queryResult.extend('prescale','unsigned int')
01452     queryResult.extend('pathname','string')
01453     queryHandle.defineOutput(queryResult)
01454     cursor=queryHandle.execute()
01455     while cursor.next():
01456         cmslsnum=cursor.currentRow()['cmslsnum'].data()
01457         inputcount=cursor.currentRow()['inputcount'].data()
01458         acceptcount=cursor.currentRow()['acceptcount'].data()
01459         prescale=cursor.currentRow()['prescale'].data()
01460         pathname=cursor.currentRow()['pathname'].data()
01461         if not result.has_key(cmslsnum):
01462             dataperLS={}
01463             dataperLS[pathname]=[inputcount,acceptcount,prescale]
01464             result[cmslsnum]=dataperLS
01465         else:
01466             result[cmslsnum][pathname]=[inputcount,acceptcount,prescale]
01467     return result
01468 

def lumiQueryAPI::hltBypathByrun (   queryHandle,
  runnum,
  hltpath 
)
select cmslsnum,inputcount,acceptcount,prescale from hlt where runnum=:runnum and pathname=:pathname
output: {cmslsnum:[inputcount,acceptcount,prescale]}

Definition at line 1396 of file lumiQueryAPI.py.

01397                                               :
01398     '''
01399     select cmslsnum,inputcount,acceptcount,prescale from hlt where runnum=:runnum and pathname=:pathname
01400     output: {cmslsnum:[inputcount,acceptcount,prescale]}
01401     '''
01402     result={}
01403     queryHandle.addToTableList(nameDealer.hltTableName())
01404     queryCondition=coral.AttributeList()
01405     queryCondition.extend('runnum','unsigned int')
01406     queryCondition.extend('pathname','string')
01407     queryCondition['runnum'].setData(int(runnum))
01408     queryCondition['pathname'].setData(hltpath)
01409     queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
01410     queryHandle.addToOutputList('INPUTCOUNT','inputcount')
01411     queryHandle.addToOutputList('ACCEPTCOUNT','acceptcount')
01412     queryHandle.addToOutputList('PRESCALE','prescale')
01413     queryHandle.setCondition('RUNNUM=:runnum and PATHNAME=:pathname',queryCondition)
01414     queryResult=coral.AttributeList()
01415     queryResult.extend('cmslsnum','unsigned int')
01416     queryResult.extend('inputcount','unsigned int')
01417     queryResult.extend('acceptcount','unsigned int')
01418     queryResult.extend('prescale','unsigned int')
01419     queryHandle.defineOutput(queryResult)
01420     cursor=queryHandle.execute()
01421     while cursor.next():
01422         cmslsnum=cursor.currentRow()['cmslsnum'].data()
01423         inputcount=cursor.currentRow()['inputcount'].data()
01424         acceptcount=cursor.currentRow()['acceptcount'].data()
01425         prescale=cursor.currentRow()['prescale'].data()
01426         if not result.has_key(cmslsnum):
01427             result[cmslsnum]=[inputcount,acceptcount,prescale]
01428     return result

def lumiQueryAPI::hlttrgMappingByrun (   queryHandle,
  runnum 
)
select m.hltpathname,m.l1seed from cmsrunsummary r,trghltmap m where r.runnum=:runnum and m.hltkey=r.hltkey
output: {hltpath:l1seed}

Definition at line 1678 of file lumiQueryAPI.py.

01679                                           :
01680     '''
01681     select m.hltpathname,m.l1seed from cmsrunsummary r,trghltmap m where r.runnum=:runnum and m.hltkey=r.hltkey
01682     output: {hltpath:l1seed}
01683     '''
01684     result={}
01685     queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName(),'r')
01686     queryHandle.addToTableList(nameDealer.trghltMapTableName(),'m')
01687     queryCondition=coral.AttributeList()
01688     queryCondition.extend('runnum','unsigned int')
01689     queryCondition['runnum'].setData(int(runnum))
01690     queryHandle.addToOutputList('m.HLTPATHNAME','hltpathname')
01691     queryHandle.addToOutputList('m.L1SEED','l1seed')
01692     queryHandle.setCondition('r.RUNNUM=:runnum and m.HLTKEY=r.HLTKEY',queryCondition)
01693     queryResult=coral.AttributeList()
01694     queryResult.extend('hltpathname','string')
01695     queryResult.extend('l1seed','string')
01696     queryHandle.defineOutput(queryResult)
01697     cursor=queryHandle.execute()
01698     while cursor.next():
01699         hltpathname=cursor.currentRow()['hltpathname'].data()
01700         l1seed=cursor.currentRow()['l1seed'].data()
01701         if not result.has_key(hltpathname):
01702             result[hltpathname]=l1seed
01703     return result

def lumiQueryAPI::lsBylsLumi (   deadtable)
input: {lsnum:[deadtime, instlumi, bit_0, norbits,prescale...]}
output: {lsnum:[instlumi, recordedlumi...]}

Definition at line 60 of file lumiQueryAPI.py.

00061                           :
00062     """
00063     input: {lsnum:[deadtime, instlumi, bit_0, norbits,prescale...]}
00064     output: {lsnum:[instlumi, recordedlumi...]}
00065     """
00066     result = {}
00067     for myls, deadArray in deadtable.items():
00068         lstime = lslengthsec (deadArray[3], 3564)
00069         instlumi = deadArray[1] * lstime
00070         if float( deadArray[2] ) ==  0.0:
00071             deadfrac = 1.0
00072         else:
00073             deadfrac = float (deadArray[0]) / (float (deadArray[2])*float(deadArray[4]))
00074         recordedLumi = instlumi * (1.0 - deadfrac)
00075         myLsList = [instlumi, recordedLumi]
00076         #print myls,instlumi,recordedLumi,lstime,deadfrac
00077         if len (deadArray) > 5:
00078             myLsList.extend (deadArray[5:])
00079         result[myls] = myLsList
00080     return result
00081 

def lumiQueryAPI::lslengthsec (   numorbit,
  numbx 
)

Definition at line 55 of file lumiQueryAPI.py.

00056                                  :
00057     #print numorbit, numbx
00058     l = numorbit * numbx * 25.0e-09
00059     return l

def lumiQueryAPI::lumidetailAllalgosByrun (   queryHandle,
  runnum 
)
select s.cmslsnum,d.bxlumivalue,d.bxlumierror,d.bxlumiquality,d.algoname,s.startorbit from LUMIDETAIL d,LUMISUMMARY s where s.runnum=:runnumber and s.lumisummary_id=d.lumisummary_id order by s.startorbit,d.algoname
output: {algoname:{cmslsnum:[bxlumivalue,bxlumierror,bxlumiquality,startorbit]}}

Definition at line 1634 of file lumiQueryAPI.py.

01635                                                :
01636     '''
01637     select s.cmslsnum,d.bxlumivalue,d.bxlumierror,d.bxlumiquality,d.algoname,s.startorbit from LUMIDETAIL d,LUMISUMMARY s where s.runnum=:runnumber and s.lumisummary_id=d.lumisummary_id order by s.startorbit,d.algoname
01638     output: {algoname:{cmslsnum:[bxlumivalue,bxlumierror,bxlumiquality,startorbit]}}
01639     '''
01640     result={}
01641     queryHandle.addToTableList(nameDealer.lumidetailTableName(),'d')
01642     queryHandle.addToTableList(nameDealer.lumisummaryTableName(),'s')
01643     queryCondition=coral.AttributeList()
01644     queryCondition.extend('runnum','unsigned int')
01645     queryCondition['runnum'].setData(int(runnum))
01646     queryHandle.addToOutputList('s.CMSLSNUM','cmslsnum')
01647     queryHandle.addToOutputList('d.BXLUMIVALUE','bxlumivalue')
01648     queryHandle.addToOutputList('d.BXLUMIERROR','bxlumierror')
01649     queryHandle.addToOutputList('d.BXLUMIQUALITY','bxlumiquality')
01650     queryHandle.addToOutputList('d.ALGONAME','algoname')
01651     queryHandle.addToOutputList('s.STARTORBIT','startorbit')
01652     queryHandle.setCondition('s.RUNNUM=:runnum and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',queryCondition)
01653     queryResult=coral.AttributeList()
01654     queryResult.extend('cmslsnum','unsigned int')
01655     queryResult.extend('bxlumivalue','blob')
01656     queryResult.extend('bxlumierror','blob')
01657     queryResult.extend('bxlumiquality','blob')
01658     queryResult.extend('algoname','string')
01659     queryResult.extend('startorbit','unsigned int')    
01660     queryHandle.addToOrderList('startorbit')
01661     queryHandle.addToOrderList('algoname')
01662     queryHandle.defineOutput(queryResult)
01663     cursor=queryHandle.execute()
01664     while cursor.next():
01665         cmslsnum=cursor.currentRow()['cmslsnum'].data()
01666         bxlumivalue=cursor.currentRow()['bxlumivalue'].data()
01667         bxlumierror=cursor.currentRow()['bxlumierror'].data()
01668         bxlumiquality=cursor.currentRow()['bxlumiquality'].data()
01669         algoname=cursor.currentRow()['algoname'].data()
01670         startorbit=cursor.currentRow()['startorbit'].data()
01671         if not result.has_key(algoname):
01672             dataPerAlgo={}
01673             dataPerAlgo[cmslsnum]=[bxlumivalue,bxlumierror,bxlumiquality,startorbit]
01674             result[algoname]=dataPerAlgo
01675         else:
01676             result[algoname][cmslsnum]=[bxlumivalue,bxlumierror,bxlumiquality,startorbit]           
01677     return result

def lumiQueryAPI::lumidetailByrunByAlgo (   queryHandle,
  runnum,
  algoname = 'OCC1' 
)
select s.cmslsnum,d.bxlumivalue,d.bxlumierror,d.bxlumiquality,s.startorbit from LUMIDETAIL d,LUMISUMMARY s where s.runnum=:runnum and d.algoname=:algoname and s.lumisummary_id=d.lumisummary_id order by s.startorbit
output: [[cmslsnum,bxlumivalue,bxlumierror,bxlumiquality,startorbit]]
since the output is ordered by time, it has to be in seq list format

Definition at line 1596 of file lumiQueryAPI.py.

01597                                                              :
01598     '''
01599     select s.cmslsnum,d.bxlumivalue,d.bxlumierror,d.bxlumiquality,s.startorbit from LUMIDETAIL d,LUMISUMMARY s where s.runnum=:runnum and d.algoname=:algoname and s.lumisummary_id=d.lumisummary_id order by s.startorbit
01600     output: [[cmslsnum,bxlumivalue,bxlumierror,bxlumiquality,startorbit]]
01601     since the output is ordered by time, it has to be in seq list format
01602     '''
01603     result=[]
01604     queryHandle.addToTableList(nameDealer.lumidetailTableName(),'d')
01605     queryHandle.addToTableList(nameDealer.lumisummaryTableName(),'s')
01606     queryCondition=coral.AttributeList()
01607     queryCondition.extend('runnum','unsigned int')
01608     queryCondition.extend('algoname','string')
01609     queryCondition['runnum'].setData(int(runnum))
01610     queryCondition['algoname'].setData(algoname)
01611     queryHandle.addToOutputList('s.CMSLSNUM','cmslsnum')
01612     queryHandle.addToOutputList('d.BXLUMIVALUE','bxlumivalue')
01613     queryHandle.addToOutputList('d.BXLUMIERROR','bxlumierror')
01614     queryHandle.addToOutputList('d.BXLUMIQUALITY','bxlumiquality')
01615     queryHandle.addToOutputList('s.STARTORBIT','startorbit')
01616     queryHandle.setCondition('s.runnum=:runnum and d.algoname=:algoname and s.lumisummary_id=d.lumisummary_id',queryCondition)
01617     queryResult=coral.AttributeList()
01618     queryResult.extend('cmslsnum','unsigned int')
01619     queryResult.extend('bxlumivalue','blob')
01620     queryResult.extend('bxlumierror','blob')
01621     queryResult.extend('bxlumiquality','blob')
01622     queryResult.extend('startorbit','unsigned int')    
01623     queryHandle.addToOrderList('s.STARTORBIT')
01624     queryHandle.defineOutput(queryResult)
01625     cursor=queryHandle.execute()
01626     while cursor.next():
01627         cmslsnum=cursor.currentRow()['cmslsnum'].data()
01628         bxlumivalue=cursor.currentRow()['bxlumivalue'].data()
01629         bxlumierror=cursor.currentRow()['bxlumierror'].data()
01630         bxlumiquality=cursor.currentRow()['bxlumiquality'].data()
01631         startorbit=cursor.currentRow()['startorbit'].data()
01632         result.append([cmslsnum,bxlumivalue,bxlumierror,bxlumiquality,startorbit])
01633     return result

def lumiQueryAPI::lumisumByrun (   queryHandle,
  runnum,
  lumiversion,
  beamstatus = None,
  beamenergy = None,
  beamenergyfluctuation = 0.09,
  finecorrections = None 
)
beamenergy unit : GeV
beamenergyfluctuation : fraction allowed to fluctuate around beamenergy value
select instlumi from lumisummary where runnum=:runnum and lumiversion=:lumiversion
output: float sum(instlumi)
Note: the output is the raw result, need to apply LS length in time(sec)

Definition at line 1160 of file lumiQueryAPI.py.

01161                                                                                                                                 :
01162     '''
01163     beamenergy unit : GeV
01164     beamenergyfluctuation : fraction allowed to fluctuate around beamenergy value
01165     select instlumi from lumisummary where runnum=:runnum and lumiversion=:lumiversion
01166     output: float sum(instlumi)
01167     Note: the output is the raw result, need to apply LS length in time(sec)
01168     '''
01169     result=[]
01170     queryHandle.addToTableList(nameDealer.lumisummaryTableName())
01171     queryCondition=coral.AttributeList()
01172     queryCondition.extend('runnum','unsigned int')
01173     queryCondition.extend('lumiversion','string')
01174     
01175     queryCondition['runnum'].setData(int(runnum))
01176     queryCondition['lumiversion'].setData(lumiversion)
01177     queryHandle.addToOutputList('INSTLUMI','instlumi')
01178     conditionstring='RUNNUM=:runnum and LUMIVERSION=:lumiversion'
01179     if beamstatus and len(beamstatus)!=0:
01180         conditionstring=conditionstring+' and BEAMSTATUS=:beamstatus'
01181         queryCondition.extend('beamstatus','string')
01182         queryCondition['beamstatus'].setData(beamstatus)
01183     if beamenergy and beamenergy!=0.0:
01184         minBeamenergy=float(beamenergy*(1.0-beamenergyfluctuation))
01185         maxBeamenergy=float(beamenergy*(1.0+beamenergyfluctuation))
01186         conditionstring=conditionstring+' and BEAMENERGY>:minBeamenergy and BEAMENERGY<:maxBeamenergy'
01187         queryCondition.extend('minBeamenergy','float')
01188         queryCondition.extend('maxBeamenergy','float')
01189         queryCondition['minBeamenergy'].setData(float(minBeamenergy))
01190         queryCondition['maxBeamenergy'].setData(float(maxBeamenergy))
01191     queryHandle.setCondition(conditionstring,queryCondition)
01192     queryResult=coral.AttributeList()
01193     queryResult.extend('instlumi','float')
01194     queryHandle.defineOutput(queryResult)
01195     cursor=queryHandle.execute()
01196     while cursor.next():
01197         instlumi=cursor.currentRow()['instlumi'].data()
01198         if instlumi:
01199             if finecorrections:
01200                 instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
01201             result.append(instlumi)
01202     if result:
01203         return sum(result)
01204     else:
01205         return 0.0

def lumiQueryAPI::lumisummaryByrun (   queryHandle,
  runnum,
  lumiversion,
  beamstatus = None,
  beamenergy = None,
  beamenergyfluctuation = 0.09,
  finecorrections = None 
)
one can impose beamstatus, beamenergy selections at the SQL query level or process them later from the general result
select cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenery from lumisummary where runnum=:runnum and lumiversion=:lumiversion order by startorbit;
output: [[cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenergy,cmsalive]]
Note: the non-cmsalive LS are included in the result

Definition at line 1101 of file lumiQueryAPI.py.

01102                                                                                                                                     :
01103     '''
01104     one can impose beamstatus, beamenergy selections at the SQL query level or process them later from the general result
01105     select cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenery from lumisummary where runnum=:runnum and lumiversion=:lumiversion order by startorbit;
01106     output: [[cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenergy,cmsalive]]
01107     Note: the non-cmsalive LS are included in the result
01108     '''
01109     result=[]
01110     queryHandle.addToTableList(nameDealer.lumisummaryTableName())
01111     queryCondition=coral.AttributeList()
01112     queryCondition.extend('runnum','unsigned int')
01113     queryCondition.extend('lumiversion','string')
01114     conditionstring='RUNNUM=:runnum and LUMIVERSION=:lumiversion'
01115     queryCondition['runnum'].setData(int(runnum))
01116     queryCondition['lumiversion'].setData(lumiversion)
01117     queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
01118     queryHandle.addToOutputList('INSTLUMI','instlumi')
01119     queryHandle.addToOutputList('NUMORBIT','numorbit')
01120     queryHandle.addToOutputList('STARTORBIT','startorbit')
01121     queryHandle.addToOutputList('BEAMSTATUS','beamstatus')
01122     queryHandle.addToOutputList('BEAMENERGY','beamenergy')
01123     queryHandle.addToOutputList('CMSALIVE','cmsalive')
01124     if beamstatus and len(beamstatus)!=0:
01125         conditionstring=conditionstring+' and BEAMSTATUS=:beamstatus'
01126         queryCondition.extend('beamstatus','string')
01127         queryCondition['beamstatus'].setData(beamstatus)
01128     if beamenergy:
01129         minBeamenergy=float(beamenergy*(1.0-beamenergyfluctuation))
01130         maxBeamenergy=float(beamenergy*(1.0+beamenergyfluctuation))
01131         conditionstring=conditionstring+' and BEAMENERGY>:minBeamenergy and BEAMENERGY<:maxBeamenergy'
01132         queryCondition.extend('minBeamenergy','float')
01133         queryCondition.extend('maxBeamenergy','float')
01134         queryCondition['minBeamenergy'].setData(float(minBeamenergy))
01135         queryCondition['maxBeamenergy'].setData(float(maxBeamenergy))
01136     queryResult=coral.AttributeList()
01137     queryResult.extend('cmslsnum','unsigned int')
01138     queryResult.extend('instlumi','float')
01139     queryResult.extend('numorbit','unsigned int')
01140     queryResult.extend('startorbit','unsigned int')
01141     queryResult.extend('beamstatus','string')
01142     queryResult.extend('beamenergy','float')
01143     queryResult.extend('cmsalive','unsigned int')
01144     queryHandle.defineOutput(queryResult)
01145     queryHandle.setCondition(conditionstring,queryCondition)
01146     queryHandle.addToOrderList('startorbit')
01147     cursor=queryHandle.execute()
01148     while cursor.next():
01149         cmslsnum=cursor.currentRow()['cmslsnum'].data()
01150         instlumi=cursor.currentRow()['instlumi'].data()
01151         if finecorrections:
01152             instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
01153         numorbit=cursor.currentRow()['numorbit'].data()
01154         startorbit=cursor.currentRow()['startorbit'].data()
01155         beamstatus=cursor.currentRow()['beamstatus'].data()
01156         beamenergy=cursor.currentRow()['beamenergy'].data()
01157         cmsalive=cursor.currentRow()['cmsalive'].data()
01158         result.append([cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenergy,cmsalive])
01159     return result

def lumiQueryAPI::lumisummarytrgbitzeroByrun (   queryHandle,
  runnum,
  lumiversion,
  beamstatus = None,
  beamenergy = None,
  beamenergyfluctuation = 0.09,
  finecorrections = None 
)
select l.cmslsnum,l.instlumi,l.numorbit,l.startorbit,l.beamstatus,l.beamenery,t.trgcount,t.deadtime,t.bitname,t.prescale from trg t,lumisummary l where t.bitnum=:bitnum and l.runnum=:runnum and l.lumiversion=:lumiversion and l.runnum=t.runnum and t.cmslsnum=l.cmslsnum; 
Everything you ever need to know about bitzero and avg luminosity. Since we do not know if joint query is better of sperate, support both.
output: {cmslsnum:[instlumi,numorbit,startorbit,beamstatus,beamenergy,bitzerocount,deadtime,bitname,prescale]}
Note: only cmsalive LS are included in the result. Therefore, this function cannot be used for calculating delivered!

Definition at line 1242 of file lumiQueryAPI.py.

01243                                                                                                                                               :
01244     '''
01245     select l.cmslsnum,l.instlumi,l.numorbit,l.startorbit,l.beamstatus,l.beamenery,t.trgcount,t.deadtime,t.bitname,t.prescale from trg t,lumisummary l where t.bitnum=:bitnum and l.runnum=:runnum and l.lumiversion=:lumiversion and l.runnum=t.runnum and t.cmslsnum=l.cmslsnum; 
01246     Everything you ever need to know about bitzero and avg luminosity. Since we do not know if joint query is better of sperate, support both.
01247     output: {cmslsnum:[instlumi,numorbit,startorbit,beamstatus,beamenergy,bitzerocount,deadtime,bitname,prescale]}
01248     Note: only cmsalive LS are included in the result. Therefore, this function cannot be used for calculating delivered!
01249     '''
01250     result={}
01251     queryHandle.addToTableList(nameDealer.trgTableName(),'t')
01252     queryHandle.addToTableList(nameDealer.lumisummaryTableName(),'l')
01253     queryCondition=coral.AttributeList()
01254     queryCondition.extend('bitnum','unsigned int')
01255     queryCondition.extend('runnum','unsigned int')
01256     queryCondition.extend('lumiversion','string')
01257     queryCondition['bitnum'].setData(int(0))        
01258     queryCondition['runnum'].setData(int(runnum))
01259     queryCondition['lumiversion'].setData(lumiversion)
01260     
01261     queryHandle.addToOutputList('l.CMSLSNUM','cmslsnum')
01262     queryHandle.addToOutputList('l.INSTLUMI','instlumi')
01263     queryHandle.addToOutputList('l.NUMORBIT','numorbit')
01264     queryHandle.addToOutputList('l.STARTORBIT','startorbit')
01265     queryHandle.addToOutputList('l.BEAMSTATUS','beamstatus')
01266     queryHandle.addToOutputList('l.BEAMENERGY','beamenergy')
01267     queryHandle.addToOutputList('t.TRGCOUNT','trgcount')
01268     queryHandle.addToOutputList('t.DEADTIME','deadtime')
01269     queryHandle.addToOutputList('t.BITNAME','bitname')
01270     queryHandle.addToOutputList('t.PRESCALE','prescale')
01271     conditionstring='t.BITNUM=:bitnum and l.RUNNUM=:runnum and l.LUMIVERSION=:lumiversion and l.RUNNUM=t.RUNNUM and t.CMSLSNUM=l.CMSLSNUM'
01272     if beamstatus and len(beamstatus)!=0:
01273         conditionstring=conditionstring+' and l.BEAMSTATUS=:beamstatus'
01274         queryCondition.extend('beamstatus','string')
01275         queryCondition['beamstatus'].setData(beamstatus)
01276     if beamenergy and beamenergy!=0.0:
01277         minBeamenergy=float(beamenergy*(1-beamenergyfluctuation))
01278         maxBeamenergy=float(beamenergy*(1+beamenergyfluctuation))
01279         conditionstring=conditionstring+' and l.BEAMENERGY>:minBeamenergy and l.BEAMENERGY<:maxBeamenergy'
01280         queryCondition.extend('minBeamenergy','float')
01281         queryCondition.extend('maxBeamenergy','float')
01282         queryCondition['minBeamenergy'].setData(float(minBeamenergy))
01283         queryCondition['maxBeamenergy'].setData(float(maxBeamenergy))
01284     queryHandle.setCondition(conditionstring,queryCondition)
01285     queryResult=coral.AttributeList()
01286     queryResult.extend('cmslsnum','unsigned int')
01287     queryResult.extend('instlumi','float')
01288     queryResult.extend('numorbit','unsigned int')
01289     queryResult.extend('startorbit','unsigned int')
01290     queryResult.extend('beamstatus','string')
01291     queryResult.extend('beamenergy','float')  
01292     queryResult.extend('trgcount','unsigned int')
01293     queryResult.extend('deadtime','unsigned int')
01294     queryResult.extend('bitname','string')
01295     queryResult.extend('prescale','unsigned int')
01296     queryHandle.defineOutput(queryResult)
01297     cursor=queryHandle.execute()
01298     while cursor.next():
01299         cmslsnum=cursor.currentRow()['cmslsnum'].data()
01300         instlumi=cursor.currentRow()['instlumi'].data()
01301         if finecorrections:
01302             instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
01303         numorbit=cursor.currentRow()['numorbit'].data()
01304         startorbit=cursor.currentRow()['startorbit'].data()
01305         beamstatus=cursor.currentRow()['beamstatus'].data()
01306         beamenergy=cursor.currentRow()['beamenergy'].data()
01307         trgcount=cursor.currentRow()['trgcount'].data()
01308         deadtime=cursor.currentRow()['deadtime'].data()
01309         bitname=cursor.currentRow()['bitname'].data()
01310         prescale=cursor.currentRow()['prescale'].data()
01311         if not result.has_key(cmslsnum):
01312             result[cmslsnum]=[instlumi,numorbit,startorbit,beamstatus,beamenergy,trgcount,deadtime,bitname,prescale]
01313     return result

def lumiQueryAPI::mergeXingLumi (   triplet,
  xingLumiDict 
)
Given general xing information and a xingLumiDict, the xing
luminosity information is merged with the general information

Definition at line 875 of file lumiQueryAPI.py.

00876                                          :
00877     '''Given general xing information and a xingLumiDict, the xing
00878     luminosity information is merged with the general information'''
00879     runNumber = triplet[0]
00880     deadTable = triplet[2]
00881     for lumi, lumiList in deadTable.iteritems():
00882         key = ( int(runNumber), int(lumi) )
00883         xingLumiValues = xingLumiDict.get (key)
00884         if xingLumiValues:
00885             lumiList.append( flatten (xingLumiValues) )
00886 

def lumiQueryAPI::printDeliveredLumi (   lumidata,
  mode 
)

Definition at line 395 of file lumiQueryAPI.py.

00396                                        :
00397     labels = [ ('Run', 'Delivered LS', 'Delivered'+u' (/\u03bcb)'.encode ('utf-8'), 'Beam Mode')]
00398     print tablePrinter.indent (labels+lumidata, hasHeader = True, separateRows = False,
00399                                prefix = '| ', postfix = ' |', justify = 'right',
00400                                delim = ' | ', wrapfunc = lambda x: wrap_onspace (x, 20) )

def lumiQueryAPI::printOverviewData (   delivered,
  recorded,
  hltpath = '' 
)

Definition at line 682 of file lumiQueryAPI.py.

00683                                                          :
00684     if len (hltpath) == 0 or hltpath == 'all':
00685         toprowlabels = [ ('Run', 'Delivered LS', 'Delivered'+u' (/\u03bcb)'.encode ('utf-8'), 'Selected LS', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8') )]
00686         lastrowlabels = [ ('Delivered LS', 'Delivered'+u' (/\u03bcb)'.encode ('utf-8'), 'Selected LS', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8') ) ]
00687     else:
00688         toprowlabels = [ ('Run', 'Delivered LS', 'Delivered'+u' (/\u03bcb)'.encode ('utf-8'), 'Selected LS', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'), 'Effective'+u' (/\u03bcb) '.encode ('utf-8')+hltpath )]
00689         lastrowlabels = [ ('Delivered LS', 'Delivered'+u' (/\u03bcb)'.encode ('utf-8'), 'Selected LS', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'), 'Effective '+u' (/\u03bcb) '.encode ('utf-8')+hltpath)]
00690     datatable = []
00691     totaldata = []
00692     totalDeliveredLS = 0
00693     totalSelectedLS = 0
00694     totalDelivered = 0.0
00695     totalRecorded = 0.0
00696     totalRecordedInPath = 0.0
00697     totaltable = []
00698     for runidx, deliveredrowdata in enumerate (delivered):
00699         rowdata = []
00700         rowdata += [deliveredrowdata[0], deliveredrowdata[1], deliveredrowdata[2]]
00701         if deliveredrowdata[1] == 'N/A': #run does not exist
00702             if  hltpath != '' and hltpath != 'all':
00703                 rowdata += ['N/A', 'N/A', 'N/A']
00704             else:
00705                 rowdata += ['N/A', 'N/A']
00706             datatable.append (rowdata)
00707             continue
00708         totalDeliveredLS += int (deliveredrowdata[1])
00709         totalDelivered += float (deliveredrowdata[2])
00710         selectedls = recorded[runidx][2].keys()
00711         #print 'runidx ', runidx, deliveredrowdata
00712         #print 'selectedls ', selectedls
00713         if len (selectedls) == 0:
00714             selectedlsStr = '[]'
00715             recordedLumi = 0
00716             if  hltpath != '' and hltpath != 'all':
00717                 rowdata += [selectedlsStr, 'N/A', 'N/A']
00718             else:
00719                 rowdata += [selectedlsStr, 'N/A']
00720         else:
00721             selectedlsStr = splitlistToRangeString (selectedls)
00722             recordedLumi = calculateTotalRecorded (recorded[runidx][2])
00723             lumiinPaths = calculateEffective (recorded[runidx][1], recordedLumi)
00724             if hltpath != '' and hltpath != 'all':
00725                 if lumiinPaths.has_key (hltpath):
00726                     rowdata += [selectedlsStr, '%.3f'% (recordedLumi), '%.3f'% (lumiinPaths[hltpath])]
00727                     totalRecordedInPath += lumiinPaths[hltpath]
00728                 else:
00729                     rowdata += [selectedlsStr, '%.3f'% (recordedLumi), 'N/A']
00730             else:
00731                 #rowdata += [selectedlsStr, '%.3f'% (recordedLumi), '%.3f'% (recordedLumi)]
00732                 rowdata += [selectedlsStr, '%.3f'% (recordedLumi)]
00733         totalSelectedLS += len (selectedls)
00734         totalRecorded += recordedLumi
00735         datatable.append (rowdata)
00736 
00737     if hltpath != '' and hltpath != 'all':
00738         totaltable = [[str (totalDeliveredLS), '%.3f'% (totalDelivered), str (totalSelectedLS),
00739                        '%.3f'% (totalRecorded), '%.3f'% (totalRecordedInPath)]]
00740     else:
00741         totaltable = [[str (totalDeliveredLS), '%.3f'% (totalDelivered), str (totalSelectedLS),
00742                        '%.3f'% (totalRecorded)]]
00743     print tablePrinter.indent (toprowlabels+datatable, hasHeader = True, separateRows = False, prefix = '| ',
00744                                postfix = ' |', justify = 'right', delim = ' | ',
00745                                wrapfunc = lambda x: wrap_onspace (x, 20))
00746     print ' ==  =  Total : '
00747     print tablePrinter.indent (lastrowlabels+totaltable, hasHeader = True, separateRows = False, prefix = '| ',
00748                                postfix = ' |', justify = 'right', delim = ' | ',
00749                                wrapfunc = lambda x: wrap_onspace (x, 20))
00750 

def lumiQueryAPI::printPerLSLumi (   lumidata,
  isVerbose = False 
)
input lumidata  [['runnumber', 'trgtable{}', 'deadtable{}']]
deadtable {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]}

Definition at line 475 of file lumiQueryAPI.py.

00476                                                 :
00477     '''
00478     input lumidata  [['runnumber', 'trgtable{}', 'deadtable{}']]
00479     deadtable {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]}
00480     '''
00481     datatoprint = []
00482     totalrow = []
00483     labels = [ ('Run', 'LS', 'Delivered', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'))]
00484     lastrowlabels = [ ('Selected LS', 'Delivered'+u' (/\u03bcb)'.encode ('utf-8'), 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'))]
00485     totalDeliveredLS = 0
00486     totalSelectedLS = 0
00487     totalDelivered = 0.0
00488     totalRecorded = 0.0
00489     
00490     for perrundata in lumidata:
00491         runnumber = perrundata[0]
00492         deadtable = perrundata[2]
00493         lumiresult = lsBylsLumi (deadtable)
00494         totalSelectedLS = totalSelectedLS+len (deadtable)
00495         for lsnum, dataperls in lumiresult.items():
00496             rowdata = []
00497             if len (dataperls) == 0:
00498                 rowdata  +=  [str (runnumber), str (lsnum), 'N/A', 'N/A']
00499             else:
00500                 rowdata  +=  [str (runnumber), str (lsnum), '%.3f' % (dataperls[0]), '%.3f' % (dataperls[1])]
00501                 totalDelivered = totalDelivered+dataperls[0]
00502                 totalRecorded = totalRecorded+dataperls[1]
00503             datatoprint.append (rowdata)
00504     totalrow.append ([str (totalSelectedLS), '%.3f'% (totalDelivered), '%.3f'% (totalRecorded)])
00505     print ' ==  = '
00506     print tablePrinter.indent (labels+datatoprint, hasHeader = True, separateRows = False, prefix = '| ',
00507                                postfix = ' |', justify = 'right', delim = ' | ',
00508                                wrapfunc = lambda x: wrap_onspace_strict (x, 22))
00509     print ' ==  =  Total : '
00510     print tablePrinter.indent (lastrowlabels+totalrow, hasHeader = True, separateRows = False, prefix = '| ',
00511                                postfix = ' |', justify = 'right', delim = ' | ',
00512                                wrapfunc = lambda x: wrap_onspace (x, 20))    
00513 
    
def lumiQueryAPI::printRecordedLumi (   lumidata,
  isVerbose = False,
  hltpath = '' 
)

Definition at line 532 of file lumiQueryAPI.py.

00533                                                                  :
00534     datatoprint = []
00535     totalrow = []
00536     labels = [ ('Run', 'HLT path', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'))]
00537     lastrowlabels = [ ('Selected LS', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'))]
00538     if len (hltpath) != 0 and hltpath != 'all':
00539         lastrowlabels = [ ('Selected LS', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'),
00540                            'Effective '+u' (/\u03bcb) '.encode ('utf-8')+hltpath)]
00541     if isVerbose:
00542         labels = [ ('Run', 'HLT-path', 'L1-bit', 'L1-presc', 'HLT-presc', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'))]
00543     totalSelectedLS = 0
00544     totalRecorded = 0.0
00545     totalRecordedInPath = 0.0
00546     
00547     for dataperRun in lumidata:
00548         runnum = dataperRun[0]
00549         if len (dataperRun[1]) == 0:
00550             rowdata = []
00551             rowdata += [str (runnum)]+2*['N/A']
00552             datatoprint.append (rowdata)
00553             continue
00554         perlsdata = dataperRun[2]
00555         totalSelectedLS = totalSelectedLS+len (perlsdata)
00556         recordedLumi = 0.0
00557         #norbits = perlsdata.values()[0][3]
00558         recordedLumi = calculateTotalRecorded (perlsdata)
00559         totalRecorded = totalRecorded+recordedLumi
00560         trgdict = dataperRun[1]
00561         effective = calculateEffective (trgdict, recordedLumi)
00562         if trgdict.has_key (hltpath) and effective.has_key (hltpath):
00563             rowdata = []
00564             l1bit = trgdict[hltpath][0]
00565             if len (trgdict[hltpath]) !=  3:
00566                 if not isVerbose:
00567                     rowdata += [str (runnum), hltpath, 'N/A']
00568                 else:
00569                     rowdata += [str (runnum), hltpath, l1bit, 'N/A', 'N/A', 'N/A']
00570             else:
00571                 if not isVerbose:
00572                     rowdata += [str (runnum), hltpath, '%.3f'% (effective[hltpath])]
00573                 else:
00574                     hltprescale = trgdict[hltpath][1]
00575                     l1prescale = trgdict[hltpath][2]
00576                     rowdata += [str (runnum), hltpath, l1bit, str (l1prescale), str (hltprescale),
00577                                 '%.3f'% (effective[hltpath])]
00578                 totalRecordedInPath = totalRecordedInPath+effective[hltpath]
00579             datatoprint.append (rowdata)
00580             continue
00581         
00582         for trg, trgdata in trgdict.items():
00583             #print trg, trgdata
00584             rowdata = []                    
00585             if trg == trgdict.keys()[0]:
00586                 rowdata += [str (runnum)]
00587             else:
00588                 rowdata += ['']
00589             l1bit = trgdata[0]
00590             if len (trgdata) == 3:
00591                 if not isVerbose:
00592                     rowdata += [trg, '%.3f'% (effective[trg])]
00593                 else:
00594                     hltprescale = trgdata[1]
00595                     l1prescale = trgdata[2]
00596                     rowdata += [trg, l1bit, str (l1prescale), str (hltprescale), '%.3f'% (effective[trg])]
00597             else:
00598                 if not isVerbose:
00599                     rowdata += [trg, 'N/A']
00600                 else:
00601                     rowdata += [trg, l1bit, 'N/A', 'N/A', '%.3f'% (effective[trg])]
00602             datatoprint.append (rowdata)
00603     #print datatoprint
00604     print ' ==  = '
00605     print tablePrinter.indent (labels+datatoprint, hasHeader = True, separateRows = False, prefix = '| ',
00606                                postfix = ' |', justify = 'right', delim = ' | ',
00607                                wrapfunc = lambda x: wrap_onspace_strict (x, 22))
00608 
00609     if len (hltpath) != 0 and hltpath != 'all':
00610         totalrow.append ([str (totalSelectedLS), '%.3f'% (totalRecorded), '%.3f'% (totalRecordedInPath)])
00611     else:
00612         totalrow.append ([str (totalSelectedLS), '%.3f'% (totalRecorded)])
00613     print ' ==  =  Total : '
00614     print tablePrinter.indent (lastrowlabels+totalrow, hasHeader = True, separateRows = False, prefix = '| ',
00615                                postfix = ' |', justify = 'right', delim = ' | ',
00616                                wrapfunc = lambda x: wrap_onspace (x, 20))    
00617     if isVerbose:
00618         deadtoprint = []
00619         deadtimelabels = [ ('Run', 'Lumi section : Dead fraction')]
00620 
00621         for dataperRun in lumidata:
00622             runnum = dataperRun[0]
00623             if len (dataperRun[1]) == 0:
00624                 deadtoprint.append ([str (runnum), 'N/A'])
00625                 continue
00626             perlsdata = dataperRun[2]
00627             #print 'perlsdata 2 : ', perlsdata
00628             deadT = getDeadfractions (perlsdata)
00629             t = ''
00630             for myls, de in deadT.items():
00631                 if de<0:
00632                     t += str (myls)+':nobeam '
00633                 else:
00634                     t += str (myls)+':'+'%.5f'% (de)+' '
00635             deadtoprint.append ([str (runnum), t])
00636         print ' ==  = '
00637         print tablePrinter.indent (deadtimelabels+deadtoprint, hasHeader = True, separateRows = True, prefix = '| ',
00638                                    postfix = ' |', justify = 'right', delim = ' | ',
00639                                    wrapfunc = lambda x: wrap_onspace (x, 80))
00640 

def lumiQueryAPI::recordedLumiForRange (   dbsession,
  parameters,
  inputRange,
  finecorrections = None 
)
Takes either single run as a string or dictionary of run ranges

Definition at line 99 of file lumiQueryAPI.py.

00100                                                                                  :
00101     '''Takes either single run as a string or dictionary of run ranges'''
00102     lumidata = []
00103     if isinstance(inputRange,str):
00104         run=int(inputRange)
00105         if finecorrections and finecorrections[run]:
00106             lumiDataPiece = recordedLumiForRun (dbsession, parameters,inputRange,lslist=None,finecorrections=finecorrections[run])
00107         else:
00108             lumiDataPiece = recordedLumiForRun(dbsession, parameters,run)
00109         if parameters.lumiXing:            
00110             # get the xing information for the run
00111             if  finecorrections and finecorrections[run]:
00112                 xingLumiDict = xingLuminosityForRun (dbsession, inputRange,
00113                                                      parameters,finecorrections=finecorrections[run])
00114             else:
00115                 xingLumiDict = xingLuminosityForRun (dbsession, inputRange,
00116                                                      parameters)
00117             mergeXingLumi (lumiDataPiece, xingLumiDict)
00118         lumidata.append (lumiDataPiece)
00119     else:
00120         # we want to collapse the lists so that every run is considered once.
00121         runLsDict = {}
00122         maxLumiSectionDict = {}
00123         for (run, lslist) in sorted (inputRange.runsandls().items() ):
00124             if(len(lslist)!=0):
00125                 maxLumiSectionDict[run] = max ( max (lslist),
00126                                            maxLumiSectionDict.get(run,0) )
00127             runLsDict.setdefault (run, []).append (lslist)
00128         for run, metaLsList in sorted (runLsDict.iteritems()):
00129             if parameters.verbose:
00130                 print "run", run
00131             runLumiData = []
00132             for lslist in metaLsList:
00133                 if finecorrections and finecorrections[run]:
00134                     runLumiData.append( recordedLumiForRun (dbsession, parameters,run,lslist=lslist,finecorrections=finecorrections[run]) )
00135                     
00136                 else:
00137                     runLumiData.append( recordedLumiForRun (dbsession, parameters,run,lslist=lslist) )
00138             if parameters.lumiXing:
00139                 # get the xing information once for the whole run
00140                 if finecorrections and finecorrections[run]:
00141                     xingLumiDict = xingLuminosityForRun (dbsession, run,
00142                                                          parameters,
00143                                                          maxLumiSection = \
00144                                                          maxLumiSectionDict[run],
00145                                                          finecorrections=finecorrections[run])
00146                 else:
00147                     xingLumiDict = xingLuminosityForRun (dbsession, run,
00148                                                          parameters,
00149                                                          maxLumiSection = \
00150                                                          maxLumiSectionDict[run])
00151                 # merge it with every piece of lumi data for this run
00152                 for lumiDataPiece in runLumiData:
00153                     mergeXingLumi (lumiDataPiece, xingLumiDict)
00154                     lumidata.append (lumiDataPiece)
00155             else:
00156                 lumidata.extend( runLumiData )
00157     return lumidata

def lumiQueryAPI::recordedLumiForRun (   dbsession,
  parameters,
  runnum,
  lslist = None,
  finecorrections = None 
)
lslist = [] means take none in the db
lslist = None means to take all in the db
output: ['runnumber', 'trgtable{}', 'deadtable{}']

Definition at line 216 of file lumiQueryAPI.py.

00217                                                                                         :
00218     """
00219     lslist = [] means take none in the db
00220     lslist = None means to take all in the db
00221     output: ['runnumber', 'trgtable{}', 'deadtable{}']
00222     """
00223     recorded = 0.0
00224     lumidata = [] #[runnumber, trgtable, deadtable]
00225     trgtable = {} #{hltpath:[l1seed, hltprescale, l1prescale]}
00226     deadtable = {} #{lsnum:[deadtime, instlumi, bit_0, norbits,bitzero_prescale]}
00227     lumidata.append (runnum)
00228     lumidata.append (trgtable)
00229     lumidata.append (deadtable)
00230     collectedseeds = [] #[ (hltpath, l1seed)]
00231     conditionstring='trghltmap.HLTKEY = cmsrunsummary.HLTKEY AND cmsrunsummary.RUNNUM = :runnumber'
00232     try:
00233         dbsession.transaction().start (True)
00234         schema = dbsession.nominalSchema()
00235         query = schema.newQuery()
00236         query.addToTableList (nameDealer.cmsrunsummaryTableName(), 'cmsrunsummary')
00237         query.addToTableList (nameDealer.trghltMapTableName(), 'trghltmap')#small table first
00238         queryCondition = coral.AttributeList()
00239         queryCondition.extend ("runnumber", "unsigned int")
00240         queryCondition["runnumber"].setData (int (runnum))
00241         query.setCondition (conditionstring,queryCondition)
00242         query.addToOutputList ("trghltmap.HLTPATHNAME", "hltpathname")
00243         query.addToOutputList ("trghltmap.L1SEED", "l1seed")
00244         result = coral.AttributeList()
00245         result.extend ("hltpathname", "string")
00246         result.extend ("l1seed", "string")
00247         query.defineOutput (result)
00248         cursor = query.execute()
00249         while cursor.next():
00250             hltpathname = cursor.currentRow()["hltpathname"].data()
00251             l1seed = cursor.currentRow()["l1seed"].data()
00252             collectedseeds.append ( (hltpathname, l1seed))
00253         #print 'collectedseeds ', collectedseeds
00254         del query
00255         dbsession.transaction().commit()
00256         #loop over hltpath
00257         for (hname, sname) in collectedseeds:
00258             l1bitname = hltTrgSeedMapper.findUniqueSeed (hname, sname)
00259             #print 'found unque seed ', hname, l1bitname
00260             if l1bitname:
00261                 lumidata[1][hname] = []
00262                 lumidata[1][hname].append (l1bitname.replace ('\"', ''))
00263         dbsession.transaction().start (True)
00264         schema = dbsession.nominalSchema()
00265         hltprescQuery = schema.tableHandle (nameDealer.hltTableName()).newQuery()
00266         hltprescQuery.addToOutputList ("PATHNAME", "hltpath")
00267         hltprescQuery.addToOutputList ("PRESCALE", "hltprescale")
00268         hltprescCondition = coral.AttributeList()
00269         hltprescCondition.extend ('runnumber', 'unsigned int')
00270         hltprescCondition.extend ('cmslsnum', 'unsigned int')
00271         hltprescCondition.extend ('inf', 'unsigned int')
00272         hltprescResult = coral.AttributeList()
00273         hltprescResult.extend ('hltpath', 'string')
00274         hltprescResult.extend ('hltprescale', 'unsigned int')
00275         hltprescQuery.defineOutput (hltprescResult)
00276         hltprescCondition['runnumber'].setData (int (runnum))
00277         hltprescCondition['cmslsnum'].setData (1)
00278         hltprescCondition['inf'].setData (0)
00279         hltprescQuery.setCondition ("RUNNUM = :runnumber and CMSLSNUM = :cmslsnum and PRESCALE != :inf",hltprescCondition)
00280         cursor = hltprescQuery.execute()
00281         while cursor.next():
00282             hltpath = cursor.currentRow()['hltpath'].data()
00283             hltprescale = cursor.currentRow()['hltprescale'].data()
00284             if lumidata[1].has_key (hltpath):
00285                 lumidata[1][hltpath].append (hltprescale)
00286                 
00287         cursor.close()
00288         del hltprescQuery
00289         dbsession.transaction().commit()      
00290         dbsession.transaction().start (True)
00291         schema = dbsession.nominalSchema()
00292         query = schema.newQuery()
00293         query.addToTableList (nameDealer.trgTableName(), 'trg')
00294         query.addToTableList (nameDealer.lumisummaryTableName(), 'lumisummary')#small table first--right-most
00295         queryCondition = coral.AttributeList()
00296         queryCondition.extend ("runnumber", "unsigned int")
00297         queryCondition.extend ("lumiversion", "string")
00298         queryCondition["runnumber"].setData (int (runnum))
00299         queryCondition["lumiversion"].setData (parameters.lumiversion)
00300         conditionstring='lumisummary.RUNNUM =:runnumber and lumisummary.LUMIVERSION =:lumiversion AND lumisummary.CMSLSNUM=trg.CMSLSNUM and lumisummary.RUNNUM=trg.RUNNUM'
00301         if len(parameters.beammode)!=0:
00302             conditionstring=conditionstring+' and lumisummary.BEAMSTATUS=:beamstatus'
00303             queryCondition.extend('beamstatus','string')
00304             queryCondition['beamstatus'].setData(parameters.beammode)
00305         query.setCondition(conditionstring,queryCondition)
00306         query.addToOutputList ("lumisummary.CMSLSNUM", "cmsls")
00307         query.addToOutputList ("lumisummary.INSTLUMI", "instlumi")
00308         query.addToOutputList ("lumisummary.NUMORBIT", "norbits")
00309         query.addToOutputList ("trg.TRGCOUNT",         "trgcount")
00310         query.addToOutputList ("trg.BITNAME",          "bitname")
00311         query.addToOutputList ("trg.DEADTIME",         "trgdeadtime")
00312         query.addToOutputList ("trg.PRESCALE",         "trgprescale")
00313         query.addToOutputList ("trg.BITNUM",           "trgbitnum")
00314         
00315         result = coral.AttributeList()
00316         result.extend ("cmsls",       "unsigned int")
00317         result.extend ("instlumi",    "float")
00318         result.extend ("norbits",     "unsigned int")
00319         result.extend ("trgcount",    "unsigned int")
00320         result.extend ("bitname",     "string")
00321         result.extend ("trgdeadtime", "unsigned long long")
00322         result.extend ("trgprescale", "unsigned int")
00323         result.extend ("trgbitnum",   "unsigned int")
00324         trgprescalemap = {}
00325         query.defineOutput (result)
00326         cursor = query.execute()
00327         while cursor.next():
00328             cmsls       = cursor.currentRow()["cmsls"].data()
00329             instlumi    = cursor.currentRow()["instlumi"].data()*parameters.norm
00330             if finecorrections:
00331                 instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
00332             norbits     = cursor.currentRow()["norbits"].data()
00333             trgcount    = cursor.currentRow()["trgcount"].data()
00334             trgbitname  = cursor.currentRow()["bitname"].data()
00335             trgdeadtime = cursor.currentRow()["trgdeadtime"].data()
00336             trgprescale = cursor.currentRow()["trgprescale"].data()
00337             trgbitnum   = cursor.currentRow()["trgbitnum"].data()
00338             if cmsls == 1:
00339                 if not trgprescalemap.has_key (trgbitname):
00340                     trgprescalemap[trgbitname] = trgprescale
00341             if trgbitnum == 0:
00342                 if not deadtable.has_key (cmsls):
00343                     deadtable[cmsls] = []
00344                     deadtable[cmsls].append (trgdeadtime)
00345                     deadtable[cmsls].append (instlumi)
00346                     deadtable[cmsls].append (trgcount)
00347                     deadtable[cmsls].append (norbits)
00348                     deadtable[cmsls].append (trgprescale)
00349         cursor.close()
00350         del query
00351         dbsession.transaction().commit()
00352         
00353         #
00354         #consolidate results
00355         #
00356         #trgtable
00357         #print 'trgprescalemap', trgprescalemap
00358         #print lumidata[1]
00359         for hpath, trgdataseq in lumidata[1].items():   
00360             bitn = trgdataseq[0]
00361             if trgprescalemap.has_key (bitn) and len (trgdataseq) == 2:
00362                 lumidata[1][hpath].append (trgprescalemap[bitn])                
00363         #filter selected cmsls
00364         lumidata[2] = filterDeadtable (deadtable, lslist)
00365         if not parameters.noWarnings:
00366             if len(lumidata[2])!=0:
00367                 for lumi, deaddata in lumidata[2].items():
00368                     if deaddata[1] == 0.0 and deaddata[2]!=0 and deaddata[0]!=0:
00369                         print '[Warning] : run %s :ls %d has 0 instlumi but trigger has data' % (runnum, lumi)
00370                     if (deaddata[2] == 0 or deaddata[0] == 0) and deaddata[1]!=0.0:
00371                         print '[Warning] : run %s :ls %d has 0 dead counts or 0 zerobias bit counts, but inst!=0' % (runnum, lumi)
00372         #print 'lumidata[2] ', lumidata[2]
00373     except Exception, e:
00374         print str (e)
00375         dbsession.transaction().rollback()
00376         del dbsession
00377     #print 'before return lumidata ', lumidata
00378     ## if parameters.lumiXing:
00379     ##     xingLumiDict =  xingLuminosityForRun (dbsession, runnum, parameters)
00380     ##     mergeXingLumi (lumidata, xingLumiDict)
00381     return lumidata
00382 

def lumiQueryAPI::runsByfillrange (   queryHandle,
  minFill,
  maxFill 
)
find all runs in the fill range inclusive
select runnum,fillnum from cmsrunsummary where fillnum>=:minFill and fillnum<=:maxFill
output: fillDict={fillnum:[runlist]}

Definition at line 1704 of file lumiQueryAPI.py.

01705                                                 :
01706     '''
01707     find all runs in the fill range inclusive
01708     select runnum,fillnum from cmsrunsummary where fillnum>=:minFill and fillnum<=:maxFill
01709     output: fillDict={fillnum:[runlist]}
01710     '''
01711     result={}
01712     queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
01713     queryCondition=coral.AttributeList()
01714     queryCondition.extend('minFill','unsigned int')
01715     queryCondition.extend('maxFill','unsigned int')
01716     queryCondition['minFill'].setData(int(minFill))
01717     queryCondition['maxFill'].setData(int(maxFill))
01718     queryHandle.addToOutputList('RUNNUM','runnum')
01719     queryHandle.addToOutputList('FILLNUM','fillnum')
01720     queryHandle.setCondition('FILLNUM>=:minFill and FILLNUM<=:maxFill',queryCondition)
01721     queryResult=coral.AttributeList()
01722     queryResult.extend('runnum','unsigned int')
01723     queryResult.extend('fillnum','unsigned int')
01724     queryHandle.defineOutput(queryResult)
01725     cursor=queryHandle.execute()
01726     while cursor.next():
01727         runnum=cursor.currentRow()['runnum'].data()
01728         fillnum=cursor.currentRow()['fillnum'].data()
01729         if not result.has_key(fillnum):
01730             result[fillnum]=[runnum]
01731         else:
01732             result[fillnum].append(runnum)
01733     return result

def lumiQueryAPI::runsByTimerange (   queryHandle,
  minTime,
  maxTime 
)
find all runs in the time range inclusive
the selected run must have started after minTime and finished by maxTime
select runnum,to_char(startTime),to_char(stopTime) from cmsrunsummary where startTime>=timestamp(minTime) and stopTime<=timestamp(maxTime);
input: minTime,maxTime in python obj datetime.datetime
output: {runnum:[starttime,stoptime]} return in python obj datetime.datetime

Definition at line 1734 of file lumiQueryAPI.py.

01735                                                 :
01736     '''
01737     find all runs in the time range inclusive
01738     the selected run must have started after minTime and finished by maxTime
01739     select runnum,to_char(startTime),to_char(stopTime) from cmsrunsummary where startTime>=timestamp(minTime) and stopTime<=timestamp(maxTime);
01740     input: minTime,maxTime in python obj datetime.datetime
01741     output: {runnum:[starttime,stoptime]} return in python obj datetime.datetime
01742     '''
01743     t=lumiTime.lumiTime()
01744     result={}
01745     coralminTime=coral.TimeStamp(minTime.year,minTime.month,minTime.day,minTime.hour,minTime.minute,minTime.second,0)
01746     coralmaxTime=coral.TimeStamp(maxTime.year,maxTime.month,maxTime.day,maxTime.hour,maxTime.minute,maxTime.second,0)
01747     queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
01748     queryCondition=coral.AttributeList()
01749     queryCondition.extend('minTime','time stamp')
01750     queryCondition.extend('maxTime','time stamp')
01751     queryCondition['minTime'].setData(coralminTime)
01752     queryCondition['maxTime'].setData(coralmaxTime)
01753     queryHandle.addToOutputList('RUNNUM','runnum')
01754     queryHandle.addToOutputList('TO_CHAR(STARTTIME,\''+t.coraltimefm+'\')','starttime')
01755     queryHandle.addToOutputList('TO_CHAR(STOPTIME,\''+t.coraltimefm+'\')','stoptime')
01756     queryHandle.setCondition('STARTTIME>=:minTime and STOPTIME<=:maxTime',queryCondition)
01757     queryResult=coral.AttributeList()
01758     queryResult.extend('runnum','unsigned int')
01759     queryResult.extend('starttime','string')
01760     queryResult.extend('stoptime','string')
01761     queryHandle.defineOutput(queryResult)
01762     cursor=queryHandle.execute()
01763     while cursor.next():
01764         runnum=cursor.currentRow()['runnum'].data()
01765         starttimeStr=cursor.currentRow()['starttime'].data()
01766         stoptimeStr=cursor.currentRow()['stoptime'].data()
01767         if not result.has_key(runnum):
01768             result[runnum]=[t.StrToDatetime(starttimeStr),t.StrToDatetime(stoptimeStr)]
01769     return result
    
def lumiQueryAPI::runsummaryByrun (   queryHandle,
  runnum 
)
select fillnum,sequence,hltkey,to_char(starttime),to_char(stoptime) from cmsrunsummary where runnum=:runnum
output: [fillnum,sequence,hltkey,starttime,stoptime]

Definition at line 1065 of file lumiQueryAPI.py.

01066                                        :
01067     '''
01068     select fillnum,sequence,hltkey,to_char(starttime),to_char(stoptime) from cmsrunsummary where runnum=:runnum
01069     output: [fillnum,sequence,hltkey,starttime,stoptime]
01070     '''
01071     t=lumiTime.lumiTime()
01072     result=[]
01073     queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
01074     queryCondition=coral.AttributeList()
01075     queryCondition.extend('runnum','unsigned int')
01076     queryCondition['runnum'].setData(int(runnum))
01077     queryHandle.addToOutputList('FILLNUM','fillnum')
01078     queryHandle.addToOutputList('SEQUENCE','sequence')
01079     queryHandle.addToOutputList('HLTKEY','hltkey')
01080     queryHandle.addToOutputList('to_char(STARTTIME,\''+t.coraltimefm+'\')','starttime')
01081     queryHandle.addToOutputList('to_char(STOPTIME,\''+t.coraltimefm+'\')','stoptime')
01082     queryHandle.setCondition('RUNNUM=:runnum',queryCondition)
01083     queryResult=coral.AttributeList()
01084     queryResult.extend('fillnum','unsigned int')
01085     queryResult.extend('sequence','string')
01086     queryResult.extend('hltkey','string')
01087     queryResult.extend('starttime','string')
01088     queryResult.extend('stoptime','string')
01089     queryHandle.defineOutput(queryResult)
01090     cursor=queryHandle.execute()
01091     while cursor.next():
01092         result.append(cursor.currentRow()['fillnum'].data())
01093         result.append(cursor.currentRow()['sequence'].data())
01094         result.append(cursor.currentRow()['hltkey'].data())
01095         result.append(cursor.currentRow()['starttime'].data())
01096         result.append(cursor.currentRow()['stoptime'].data())
01097     #if len(result)!=5:
01098     #    print 'wrong runsummary result'
01099     #    raise
01100     return result

def lumiQueryAPI::setupSession (   connectString,
  siteconfpath,
  parameters,
  debug = False 
)
returns database session

Definition at line 887 of file lumiQueryAPI.py.

00888                                                                          :
00889     '''returns database session'''
00890     connectparser = connectstrParser.connectstrParser (connectString)
00891     connectparser.parse()
00892     usedefaultfrontierconfig = False
00893     cacheconfigpath = ''
00894     if connectparser.needsitelocalinfo():
00895         if not siteconfpath:
00896             cacheconfigpath = os.environ['CMS_PATH']
00897             if cacheconfigpath:
00898                 cacheconfigpath = os.path.join (cacheconfigpath, 'SITECONF', 'local', 'JobConfig', 'site-local-config.xml')
00899             else:
00900                 usedefaultfrontierconfig = True
00901         else:
00902             cacheconfigpath = siteconfpath
00903             cacheconfigpath = os.path.join (cacheconfigpath, 'site-local-config.xml')
00904         ccp = cacheconfigParser.cacheconfigParser()
00905         if usedefaultfrontierconfig:
00906             ccp.parseString (parameters.defaultfrontierConfigString)
00907         else:
00908             ccp.parse (cacheconfigpath)
00909         connectString = connectparser.fullfrontierStr (connectparser.schemaname(), ccp.parameterdict())
00910     svc = coral.ConnectionService()
00911     if debug :
00912         msg = coral.MessageStream ('')
00913         msg.setMsgVerbosity (coral.message_Level_Debug)
00914         parameters.verbose = True
00915     session = svc.connect (connectString, accessMode = coral.access_ReadOnly)
00916     session.typeConverter().setCppTypeForSqlType ("unsigned int", "NUMBER (10)")
00917     session.typeConverter().setCppTypeForSqlType ("unsigned long long", "NUMBER (20)")
00918     return session, svc
00919 
00920 

def lumiQueryAPI::splitlistToRangeString (   inPut)

Definition at line 429 of file lumiQueryAPI.py.

00430                                   :
00431     result = []
00432     first = inPut[0]
00433     last = inPut[0]
00434     result.append ([inPut[0]])
00435     counter = 0
00436     for i in inPut[1:]:
00437         if i == last+1:
00438             result[counter].append (i)
00439         else:
00440             counter += 1
00441             result.append ([i])
00442         last = i
00443     return ', '.join (['['+str (min (x))+'-'+str (max (x))+']' for x in result])
00444 

def lumiQueryAPI::trgAllbitsByrun (   queryHandle,
  runnum 
)
all you ever want to know about trigger
select cmslsnum,trgcount,deadtime,bitnum,bitname,prescale from trg where runnum=:runnum order by  bitnum,cmslsnum
this can be changed to blob query later
output: {cmslsnum:{bitname:[bitnum,trgcount,deadtime,prescale]}}

Definition at line 1350 of file lumiQueryAPI.py.

01351                                        :
01352     '''
01353     all you ever want to know about trigger
01354     select cmslsnum,trgcount,deadtime,bitnum,bitname,prescale from trg where runnum=:runnum order by  bitnum,cmslsnum
01355     this can be changed to blob query later
01356     output: {cmslsnum:{bitname:[bitnum,trgcount,deadtime,prescale]}}
01357     '''
01358     result={}
01359     queryHandle.addToTableList(nameDealer.trgTableName())
01360     queryCondition=coral.AttributeList()
01361     queryCondition.extend('runnum','unsigned int')
01362     queryCondition['runnum'].setData(int(runnum))
01363     queryHandle.addToOutputList('cmslsnum')
01364     queryHandle.addToOutputList('trgcount')
01365     queryHandle.addToOutputList('deadtime')
01366     queryHandle.addToOutputList('bitnum')
01367     queryHandle.addToOutputList('bitname')
01368     queryHandle.addToOutputList('prescale')
01369     queryHandle.setCondition('runnum=:runnum',queryCondition)
01370     queryResult=coral.AttributeList()
01371     queryResult.extend('cmslsnum','unsigned int')
01372     queryResult.extend('trgcount','unsigned int')
01373     queryResult.extend('deadtime','unsigned long long')
01374     queryResult.extend('bitnum','unsigned int')
01375     queryResult.extend('bitname','string')
01376     queryResult.extend('prescale','unsigned int')
01377     queryHandle.defineOutput(queryResult)
01378     queryHandle.addToOrderList('bitnum')
01379     queryHandle.addToOrderList('cmslsnum')
01380     cursor=queryHandle.execute()
01381     while cursor.next():
01382         cmslsnum=cursor.currentRow()['cmslsnum'].data()
01383         trgcount=cursor.currentRow()['trgcount'].data()
01384         deadtime=cursor.currentRow()['deadtime'].data()
01385         bitnum=cursor.currentRow()['bitnum'].data()
01386         bitname=cursor.currentRow()['bitname'].data()
01387         prescale=cursor.currentRow()['prescale'].data()
01388         if not result.has_key(cmslsnum):
01389             dataperLS={}
01390             dataperLS[bitname]=[bitnum,trgcount,deadtime,prescale]
01391             result[cmslsnum]=dataperLS
01392         else:
01393             result[cmslsnum][bitname]=[bitnum,trgcount,deadtime,prescale]
01394     return result
01395 

def lumiQueryAPI::trgbitzeroByrun (   queryHandle,
  runnum 
)
select cmslsnum,trgcount,deadtime,bitname,prescale from trg where runnum=:runnum and bitnum=0;
output: {cmslsnum:[trgcount,deadtime,bitname,prescale]}

Definition at line 1206 of file lumiQueryAPI.py.

01207                                        :
01208     '''
01209     select cmslsnum,trgcount,deadtime,bitname,prescale from trg where runnum=:runnum and bitnum=0;
01210     output: {cmslsnum:[trgcount,deadtime,bitname,prescale]}
01211     '''
01212     result={}
01213     queryHandle.addToTableList(nameDealer.trgTableName())
01214     queryCondition=coral.AttributeList()
01215     queryCondition.extend('runnum','unsigned int')
01216     queryCondition.extend('bitnum','unsigned int')
01217     queryCondition['runnum'].setData(int(runnum))
01218     queryCondition['bitnum'].setData(int(0))
01219     queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
01220     queryHandle.addToOutputList('TRGCOUNT','trgcount')
01221     queryHandle.addToOutputList('DEADTIME','deadtime')
01222     queryHandle.addToOutputList('BITNAME','bitname')
01223     queryHandle.addToOutputList('PRESCALE','prescale')
01224     queryHandle.setCondition('RUNNUM=:runnum and BITNUM=:bitnum',queryCondition)
01225     queryResult=coral.AttributeList()
01226     queryResult.extend('cmslsnum','unsigned int')
01227     queryResult.extend('trgcount','unsigned int')
01228     queryResult.extend('deadtime','unsigned int')
01229     queryResult.extend('bitname','string')
01230     queryResult.extend('prescale','unsigned int')
01231     queryHandle.defineOutput(queryResult)
01232     cursor=queryHandle.execute()
01233     while cursor.next():
01234         cmslsnum=cursor.currentRow()['cmslsnum'].data()
01235         trgcount=cursor.currentRow()['trgcount'].data()
01236         deadtime=cursor.currentRow()['deadtime'].data()
01237         bitname=cursor.currentRow()['bitname'].data()
01238         prescale=cursor.currentRow()['prescale'].data()
01239         if not result.has_key(cmslsnum):
01240             result[cmslsnum]=[trgcount,deadtime,bitname,prescale]
01241     return result

def lumiQueryAPI::trgBybitnameByrun (   queryHandle,
  runnum,
  bitname 
)
select cmslsnum,trgcount,deadtime,bitnum,prescale from trg where runnum=:runnum and bitname=:bitname;
output: {cmslsnum:[trgcount,deadtime,bitnum,prescale]}

Definition at line 1314 of file lumiQueryAPI.py.

01315                                                  :
01316     '''
01317     select cmslsnum,trgcount,deadtime,bitnum,prescale from trg where runnum=:runnum and bitname=:bitname;
01318     output: {cmslsnum:[trgcount,deadtime,bitnum,prescale]}
01319     '''
01320     result={}
01321     queryHandle.addToTableList(nameDealer.trgTableName())
01322     queryCondition=coral.AttributeList()
01323     queryCondition.extend('runnum','unsigned int')
01324     queryCondition.extend('bitname','string')
01325     queryCondition['runnum'].setData(int(runnum))
01326     queryCondition['bitname'].setData(bitname)        
01327     queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
01328     queryHandle.addToOutputList('TRGCOUNT','trgcount')
01329     queryHandle.addToOutputList('DEADTIME','deadtime')
01330     queryHandle.addToOutputList('BITNUM','bitnum')
01331     queryHandle.addToOutputList('PRESCALE','prescale')
01332     queryHandle.setCondition('RUNNUM=:runnum and BITNAME=:bitname',queryCondition)
01333     queryResult=coral.AttributeList()
01334     queryResult.extend('cmslsnum','unsigned int')
01335     queryResult.extend('trgcount','unsigned int')
01336     queryResult.extend('deadtime','unsigned long long')
01337     queryResult.extend('bitnum','unsigned int')
01338     queryResult.extend('prescale','unsigned int')
01339     queryHandle.defineOutput(queryResult)
01340     cursor=queryHandle.execute()
01341     while cursor.next():
01342         cmslsnum=cursor.currentRow()['cmslsnum'].data()
01343         trgcount=cursor.currentRow()['trgcount'].data()
01344         deadtime=cursor.currentRow()['deadtime'].data()
01345         bitnum=cursor.currentRow()['bitnum'].data()
01346         prescale=cursor.currentRow()['prescale'].data()
01347         if not result.has_key(cmslsnum):
01348             result[cmslsnum]=[trgcount,deadtime,bitnum,prescale]
01349     return result

def lumiQueryAPI::validation (   queryHandle,
  run = None,
  cmsls = None 
)
retrieve validation data per run or all
input: run. if not run, retrive all; if cmslsnum selection list pesent, filter out unselected result
output: {run:[[cmslsnum,status,comment]]}

Definition at line 996 of file lumiQueryAPI.py.

00997                                                :
00998     '''retrieve validation data per run or all
00999     input: run. if not run, retrive all; if cmslsnum selection list pesent, filter out unselected result
01000     output: {run:[[cmslsnum,status,comment]]}
01001     '''
01002     result={}
01003     queryHandle.addToTableList(nameDealer.lumivalidationTableName())
01004     queryHandle.addToOutputList('RUNNUM','runnum')
01005     queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
01006     queryHandle.addToOutputList('FLAG','flag')
01007     queryHandle.addToOutputList('COMMENT','comment')
01008     if run:
01009         queryCondition='RUNNUM=:runnum'
01010         queryBind=coral.AttributeList()
01011         queryBind.extend('runnum','unsigned int')
01012         queryBind['runnum'].setData(run)
01013         queryHandle.setCondition(queryCondition,queryBind)
01014     queryResult=coral.AttributeList()
01015     queryResult.extend('runnum','unsigned int')
01016     queryResult.extend('cmslsnum','unsigned int')
01017     queryResult.extend('flag','string')
01018     queryResult.extend('comment','string')
01019     queryHandle.defineOutput(queryResult)
01020     cursor=queryHandle.execute()
01021     while cursor.next():
01022         runnum=cursor.currentRow()['runnum'].data()
01023         if not result.has_key(runnum):
01024             result[runnum]=[]
01025         cmslsnum=cursor.currentRow()['cmslsnum'].data()
01026         flag=cursor.currentRow()['flag'].data()
01027         comment=cursor.currentRow()['comment'].data()
01028         result[runnum].append([cmslsnum,flag,comment])
01029     if run and cmsls and len(cmsls)!=0:
01030         selectedresult={}
01031         for runnum,perrundata in result.items():
01032             for lsdata in perrundata:
01033                 if lsdata[0] not in cmsls:
01034                     continue
01035                 if not selectedresult.has_key(runnum):
01036                     selectedresult[runnum]=[]
01037                 selectedresult[runnum].append(lsdata)
01038         return selectedresult
01039     else:
01040         return result
    
def lumiQueryAPI::xingLuminosityForRun (   dbsession,
  runnum,
  parameters,
  lumiXingDict = {},
  maxLumiSection = None,
  finecorrections = None 
)
Given a run number and a minimum xing luminosity value,
returns a dictionary (keyed by (run, lumi section)) where the
value is a list of tuples of (xingID, xingLum).

- For all xing luminosities, simply set minLumValue to 0.

- If you want one dictionary for several runs, pass it in to
  "lumiXingDict"

select 
s.cmslsnum, d.bxlumivalue, d.bxlumierror, d.bxlumiquality, d.algoname from LUMIDETAIL d, LUMISUMMARY s where s.runnum = 133885 and d.algoname = 'OCC1' and s.lumisummary_id = d.lumisummary_id order by s.startorbit, s.cmslsnum

Definition at line 774 of file lumiQueryAPI.py.

00774                                                                         {},
00775                           maxLumiSection = None, finecorrections=None):
00776     '''Given a run number and a minimum xing luminosity value,
00777     returns a dictionary (keyed by (run, lumi section)) where the
00778     value is a list of tuples of (xingID, xingLum).
00779 
00780     - For all xing luminosities, simply set minLumValue to 0.
00781 
00782     - If you want one dictionary for several runs, pass it in to
00783       "lumiXingDict"
00784 
00785     select 
00786     s.cmslsnum, d.bxlumivalue, d.bxlumierror, d.bxlumiquality, d.algoname from LUMIDETAIL d, LUMISUMMARY s where s.runnum = 133885 and d.algoname = 'OCC1' and s.lumisummary_id = d.lumisummary_id order by s.startorbit, s.cmslsnum
00787     '''
00788     try:
00789         runnum = int (runnum)
00790         dbsession.transaction().start (True)
00791         schema = dbsession.schema (parameters.lumischema)
00792         if not schema:
00793             raise 'cannot connect to schema ', parameters.lumischema
00794         detailOutput = coral.AttributeList()
00795         detailOutput.extend ('startorbit',    'unsigned int')
00796         detailOutput.extend ('cmslsnum',      'unsigned int')
00797         detailOutput.extend ('bxlumivalue',   'blob')
00798         detailOutput.extend ('bxlumierror',   'blob')
00799         detailOutput.extend ('bxlumiquality', 'blob')
00800         detailOutput.extend ('algoname',      'string')
00801         detailCondition = coral.AttributeList()
00802         detailCondition.extend ('runnum',   'unsigned int')
00803         detailCondition.extend ('algoname', 'string')
00804         detailCondition['runnum'].setData (runnum)
00805         detailCondition['algoname'].setData ('OCC1')
00806         query = schema.newQuery()
00807         query.addToTableList(nameDealer.lumisummaryTableName(), 's')
00808         query.addToTableList(nameDealer.lumidetailTableName(),  'd')
00809         query.addToOutputList ('s.STARTORBIT',    'startorbit')
00810         query.addToOutputList ('s.CMSLSNUM',      'cmslsnum')
00811         query.addToOutputList ('d.BXLUMIVALUE',   'bxlumivalue')
00812         query.addToOutputList ('d.BXLUMIERROR',   'bxlumierror')
00813         query.addToOutputList ('d.BXLUMIQUALITY', 'bxlumiquality')
00814         query.addToOutputList ('d.ALGONAME',      'algoname')
00815         query.setCondition ('s.RUNNUM =:runnum and d.ALGONAME =:algoname and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',detailCondition)
00816         query.addToOrderList ('s.CMSLSNUM')
00817         query.defineOutput (detailOutput)
00818         cursor = query.execute()
00819         count = 0
00820         while cursor.next():
00821             ## ## Note: If you are going to break out of this loop early,
00822             ## ## make sure you call cursor.close():
00823             ## 
00824             ## if count > 20 :
00825             ##     cursor.close()
00826             ##     break
00827             ## count  +=  1
00828             cmslsnum    = cursor.currentRow()['cmslsnum'].data()
00829             algoname    = cursor.currentRow()['algoname'].data()
00830             bxlumivalue = cursor.currentRow()['bxlumivalue'].data()
00831             startorbit  = cursor.currentRow()['startorbit'].data()
00832             
00833             if maxLumiSection and maxLumiSection < cmslsnum:
00834                 cursor.close()
00835                 break
00836             
00837             xingArray = array.array ('f')
00838             xingArray.fromstring( bxlumivalue.readline() )
00839             numPrinted = 0
00840             xingLum = []
00841             avginstlumi=0.0
00842             if len(xingArray)!=0:
00843                 avginstlumi=sum(xingArray)
00844             for index, lum in enumerate (xingArray):
00845                 mynorm=parameters.normFactor
00846                 if finecorrections:
00847                     lum=lumiCorrections.applyfinecorrectionBX(lum,avginstlumi*mynorm,mynorm,finecorrections[0],finecorrections[1],finecorrections[2])
00848                 else:
00849                     lum*=mynorm
00850                 if lum < parameters.xingMinLum:
00851                     continue
00852                 xingLum.append( (index, lum) )
00853             lumiXingDict[ (runnum, cmslsnum) ] = xingLum
00854         del query
00855         dbsession.transaction().commit()
00856         return lumiXingDict      
00857     except Exception, e:
00858         print str (e)
00859         print "whoops"
00860         dbsession.transaction().rollback()
00861         del dbsession
00862 
00863 

Variable Documentation

Definition at line 1840 of file lumiQueryAPI.py.

tuple lumiQueryAPI::allruns = allruns(schema,requireLumisummary=True,requireTrg=True,requireHlt=True)

Definition at line 1782 of file lumiQueryAPI.py.

string lumiQueryAPI::connectstr = 'oracle://cms_orcoff_prod/cms_lumi_prod'

Definition at line 1776 of file lumiQueryAPI.py.

Referenced by spf::SherpackFetcher::FnFileGet().

tuple lumiQueryAPI::msg = coral.MessageStream('')

Definition at line 1771 of file lumiQueryAPI.py.

Referenced by stor::DQMTopLevelFolder::addDQMEvent(), stor::EventDistributor::addEventToRelevantQueues(), FWGUIEventDataAdder::addNewItem(), stor::I2OChain::addToChain(), stor::RunMonitorCollection::alarmErrorEvents(), stor::RunMonitorCollection::alarmUnwantedEvents(), DDXMLElement::appendText(), edm::service::ELdestination::changeFile(), stor::FileHandler::checkAdler32(), stor::utils::checkDirectory(), stor::FileHandler::checkFileSizeMatch(), smproxy::DataRetrieverMonitorCollection::checkForCorruptedEvents(), stor::ResourceMonitorCollection::checkNumberOfCopyWorkers(), stor::ResourceMonitorCollection::checkNumberOfInjectWorkers(), stor::ResourceMonitorCollection::checkSataDisks(), edm::service::ELdestination::clearSummary(), evf::StateMachine::commandCallback(), evf::BU::configuring(), evf::rb_statemachine::Configuring::connectToBUandSM(), evf::Vulture::control(), evf::FWEPWrapper::createAndSendScalersMessage(), evf::SMProxy::createFragmentChain(), cond::DecodingKey::createFromInputFile(), evf::EPStateMachine::createFSMReplyMsg(), DDI::Specific::createPartSelections(), cond::RelationalAuthenticationService::RelationalAuthenticationService::credentials(), evf::FUResourceTable::discardDataEvent(), evf::FUResourceTable::discardDataEventWhileHalting(), evf::FUResourceTable::discardDqmEvent(), evf::FUResourceTable::discardDqmEventWhileHalting(), stor::detail::EventMsgData::do_adler32Checksum(), stor::detail::InitMsgData::do_adler32Checksum(), stor::detail::DQMEventMsgData::do_adler32Checksum(), stor::detail::ChainData::do_dqmKey(), stor::detail::DQMEventMsgData::do_dqmKey(), stor::detail::EventMsgData::do_droppedEventsCount(), stor::detail::ChainData::do_droppedEventsCount(), stor::detail::ErrorEventMsgData::do_eventNumber(), stor::detail::EventMsgData::do_eventNumber(), stor::detail::ChainData::do_eventNumber(), stor::detail::ChainData::do_hltTriggerBits(), stor::detail::EventMsgData::do_hltTriggerBits(), stor::detail::EventMsgData::do_hltTriggerCount(), stor::detail::ChainData::do_hltTriggerCount(), stor::detail::ChainData::do_hltTriggerNames(), stor::detail::InitMsgData::do_hltTriggerNames(), stor::detail::InitMsgData::do_hltTriggerSelections(), stor::detail::ChainData::do_hltTriggerSelections(), stor::detail::ChainData::do_l1TriggerNames(), stor::detail::InitMsgData::do_l1TriggerNames(), stor::detail::DQMEventMsgData::do_lumiSection(), stor::detail::ErrorEventMsgData::do_lumiSection(), stor::detail::ChainData::do_lumiSection(), stor::detail::EventMsgData::do_lumiSection(), stor::detail::ChainData::do_nExpectedEPs(), stor::detail::InitMsgData::do_outputModuleId(), stor::detail::EventMsgData::do_outputModuleId(), stor::detail::ChainData::do_outputModuleId(), stor::detail::InitMsgData::do_outputModuleLabel(), stor::detail::ChainData::do_outputModuleLabel(), stor::detail::DQMEventMsgData::do_runNumber(), stor::detail::ErrorEventMsgData::do_runNumber(), stor::detail::EventMsgData::do_runNumber(), stor::detail::ChainData::do_runNumber(), stor::detail::ChainData::do_setDroppedEventsCount(), stor::detail::DQMEventMsgData::do_topFolderName(), stor::detail::ChainData::do_topFolderName(), evf::MasterQueue::drain(), stor::I2OChain::droppedEventsCount(), edm::JobReport::dumpFiles(), stor::ResourceMonitorCollection::emitDiskAlarm(), evf::BU::enabling(), HLTScalersClient::endLuminosityBlock(), DDLMap::errorOut(), RPCConst::etaFromTowerNum(), stor::DataSenderMonitorCollection::faultyEventsAlarm(), xmas2dqm::wse::XmasToDQM::fireEvent(), dqm::StateMachine::fireEvent(), cond::DecodingKey::flush(), edm::service::ELdestination::flush(), evf::iDie::fsmCallback(), evf::BU::fsmCallback(), evf::FUEventProcessor::fsmCallback(), DDXMLElement::get(), DDXMLElement::getDDName(), EcalCondDBInterface::getEcalLogicID(), stor::InitMsgCollection::getElementForOutputModuleLabel(), cond::getLoginName(), DDXMLElement::getText(), evf::BU::halting(), evf::FUResourceBroker::handleFSMSoapMessage(), stor::StorageManager::handleFSMSoapMessage(), smproxy::SMProxyServer::handleFSMSoapMessage(), evf::BU::I2O_BU_ALLOCATE_Callback(), evf::BU::I2O_BU_DISCARD_Callback(), evf::FUResourceBroker::I2O_EVM_LUMISECTION_Callback(), stor::DataSenderMonitorCollection::ignoredDiscardAlarm(), cond::CredentialStore::importForPrincipal(), triggerExpression::HLTReader::init(), cond::DecodingKey::init(), evf::FUResourceQueue::initialize(), evf::FUResourceTable::initialize(), cond::CredentialStore::installAdmin(), RPCConst::iptFromPt(), stor::FileHandler::makeFileReadOnly(), ora::ContainerSchema::mapping(), MuonDDDConstants::MuonDDDConstants(), DQMNet::onPeerData(), FWFileEntry::openFile(), stor::DbFileHandler::openFile(), evf::ParameterSetRetriever::ParameterSetRetriever(), QualityTester::performTests(), evf::CurlPoster::post(), evf::FUResourceTable::postEndOfLumiSection(), egHLT::TrigCodes::TrigBitSetMap::printCodes(), DDLVector::processElement(), DDLTrapezoid::processElement(), DDLCompositeMaterial::processElement(), DDLRotationAndReflection::processElement(), DDLTubs::processElement(), DDLAlgoPosPart::processElement(), DDLPolyGenerator::processElement(), DDLRotationByAxis::processOne(), RPCConst::ptFromIpt(), cond::SQLReport::putOnFile(), cond::FileReader::read(), readRemote(), evf::FUEventProcessor::receiving(), RecoProducerFP420::RecoProducerFP420(), DQMNet::releaseFromWait(), CmsShowMainBase::reloadConfiguration(), cond::CredentialStore::removeConnection(), cond::CredentialStore::removePrincipal(), stor::FileHandler::renameFile(), edm::JobReport::reportAnalysisFile(), edm::JobReport::reportError(), edm::JobReport::reportFallbackAttempt(), stor::StreamsMonitorCollection::StreamRecord::reportLumiSectionInfo(), edm::JobReport::reportMemoryInfo(), edm::JobReport::reportMessageInfo(), edm::JobReport::reportPerformanceForModule(), edm::JobReport::reportPerformanceSummary(), edm::JobReport::reportPSetHash(), edm::JobReport::reportRandomStateFile(), edm::JobReport::reportSkippedEvent(), edm::JobReport::reportSkippedFile(), DQMNet::requestObjectData(), stor::Operations::safeEntryAction(), smproxy::State< Configuring, AllOk >::safeEntryAction(), smproxy::State< Configuring, AllOk >::safeExitAction(), stor::Operations::safeExitAction(), DCCTBBlockPrototype::seeIfIsPossibleToIncrement(), evf::BUProxy::sendAllocate(), evf::SMProxy::sendDataEvent(), evf::BUProxy::sendDiscard(), stor::DiscardManager::sendDiscardMessage(), stor::FUProxy::sendDiscardMsg(), evf::SMProxy::sendDqmEvent(), evf::SMProxy::sendErrorEvent(), evf::BU::sending(), evf::SMProxy::sendInitMessage(), WebInterface::sendMessage(), DQMImplNet< DQMNet::Object >::sendObjectListToPeers(), CmsShowMainBase::sendVersionInfo(), edm::StreamerOutputModuleBase::serializeEvent(), stor::I2OChain::setDroppedEventsCount(), cond::CredentialStore::setPermission(), Tm::setToString(), cond::CredentialStore::setUpForService(), TrackingRecHit::sharesInput(), evf::FUResourceTable::shutDownClients(), evf::BU::startBuildingWorkLoop(), evf::rb_statemachine::SharedResources::startDiscardWorkLoop(), evf::BU::startMonitoringWorkLoop(), evf::FWEPWrapper::startMonitoringWorkLoop(), evf::rb_statemachine::SharedResources::startMonitoringWorkLoop(), evf::Vulture::startProwling(), evf::FUEventProcessor::startReceivingLoop(), evf::FUEventProcessor::startReceivingMonitorLoop(), evf::FUEventProcessor::startScalersWorkLoop(), evf::rb_statemachine::SMEventScheduler::startSchedulerWorkloop(), evf::rb_statemachine::SharedResources::startSendDataWorkLoop(), evf::rb_statemachine::SharedResources::startSendDqmWorkLoop(), evf::BU::startSendingWorkLoop(), evf::FUEventProcessor::startSignalMonitorWorkLoop(), evf::FUEventProcessor::startSummarizeWorkLoop(), evf::FUEventProcessor::startSupervisorLoop(), evf::rb_statemachine::SharedResources::startWatchingWorkLoop(), stor::FragmentProcessor::startWorkLoop(), stor::StatisticsReporter::startWorkLoop(), stor::DQMEventProcessor::startWorkLoop(), stor::DiskWriter::startWorkLoop(), smproxy::StatisticsReporter::startWorkLoop(), evf::BU::stopping(), evf::FUEventProcessor::stopSlavesAndAcknowledge(), evf::FUEventProcessor::subWeb(), edm::service::ELdestination::summarization(), edm::service::ELdestination::summary(), stor::EventDistributor::tagCompleteEventForQueues(), stor::I2OChain::tagForDQMEventConsumer(), stor::I2OChain::tagForEventConsumer(), stor::I2OChain::tagForStream(), DDXMLElement::throwError(), evf::iDie::timeExpired(), stor::ResourceMonitorCollection::DiskUsage::toString(), cond::CredentialStore::unsetPermission(), edm::StreamerOutputModuleBase::write(), FRDEventOutputModule< Consumer >::write(), stor::FileHandler::writeEvent(), stor::DiskWriter::writeEventToStreams(), and edm::JobReport::JobReportImpl::writeGeneratorInfo().

tuple lumiQueryAPI::q = schema.newQuery()

Definition at line 1839 of file lumiQueryAPI.py.

Referenced by PhotonValidator::analyze(), JetAnaPythia< Jet >::analyze(), TrackParameterAnalyzer::analyze(), HLTScalers::analyze(), CaloRecHitMetaCollection::at(), AlignmentTrackSelector::basicCuts(), HcalPulseShapes::beginRun(), PhysicsTools::AtomicId::build(), CandCombinerBase< OutputCollection, CandPtr >::combine(), AnalyticalCurvilinearJacobian::computeFullJacobian(), Conv4HitsReco::ConversionCandidate(), VVIObjDetails::cosint(), TtFullLepKinSolver::cubic(), TwoBodyDecayModel::curvilinearToCartesianJacobian(), PhysicsTools::VarProcessor::deriv(), lhef::domToLines(), EEQuadrant(), lhef::LHEReader::XMLHandler::endElement(), ConfigurationDBHandler::endElement(), LMFSeqDat::fetchByRunNumber(), TrackAnalyzer::fillHistosForState(), PrimaryVertexAnalyzer4PU::fillTrackHistos(), edm::ParameterSet::fromString(), GammaFunctionGenerator::gammaFrac(), lumi::idDealer::generateNextIDForTable(), EvtPlaneProducer::GenPlane::getAngle(), TiXmlBase::GetEntity(), lumi::idDealer::getIDforTable(), MonitorElement::getQReport(), PrimaryVertexAnalyzer4PU::getSimTrkParameters(), pftools::CaloEllipse::getTheta(), L1MuGMTSortRankUnit::getVeryLowQualityLevel(), gen::Herwig6Instance::give(), ConversionFastHelix::helixStateAtVertex(), FastHelix::helixStateAtVertex(), HLTDeDxFilter::hltFilter(), GflashTrajectory::initializeTrajectory(), SeedFromConsecutiveHitsStraightLineCreator::initialKinematic(), RoadSearchTrackCandidateMakerAlgorithm::initialTrajectory(), JacobianCartesianToCurvilinear::JacobianCartesianToCurvilinear(), JacobianCartesianToLocal::JacobianCartesianToLocal(), JacobianCurvilinearToCartesian::JacobianCurvilinearToCartesian(), JacobianLocalToCartesian::JacobianLocalToCartesian(), JetBProbabilityComputer::jetProbability(), reco::TrackProbabilityTagInfo::jetProbability(), JetProbabilityComputer::jetProbability(), SteppingHelixPropagator::makeAtomStep(), match(), L1MuGMTMerger::merge_rank(), MergeRootfile(), NtpProducer< C >::NtpProducer(), edm::Guid::operator=(), edm::Guid::operator==(), HcalPacker::pack(), trigger::TriggerObject::particle(), RawParticle::PDGcharge(), CastorNominalCoderTemplate::process(), HcalNominalCoderTemplate::process(), HcalBeamMonitor::processEvent(), TtSemiEvtSolutionMaker::produce(), L3MuonCandidateProducer::produce(), L2MuonCandidateProducer::produce(), TtHadEvtSolutionMaker::produce(), NtpProducer< C >::produce(), FFTJetPileupProcessor::produce(), L3MuonCandidateProducerFromMuons::produce(), Herwig6Hadronizer::pythiaStatusCode(), reco::TrackBase::quality(), reco::Conversion::quality(), GSUtilities::quantile(), SusyPostProcessor::QuantilePlots(), RealQuadEquation::RealQuadEquation(), HcalCableMapper::record(), L1MuDTEtaProcessor::runEtaTrackFinder(), CustomPDGParser::s_charge(), MuScleFit::selGlobalMuon(), MuScleFitMuonSelector::selGlobalMuon(), BPhysicsOniaDQM::selGlobalMuon(), RawParticle::setCharge(), ObjectValidator::setEBRecHitCollection(), ObjectValidator::setEcalChannelStatus(), ObjectValidator::setEcalSeverityLevelAlgo(), ObjectValidator::setEERecHitCollection(), ObjectValidator::setHcalChannelQuality(), ObjectValidator::setHcalSeverityLevelComputer(), pat::HardEventHypothesis::setQuality(), CSCCorrelatedLCTDigi::setQuality(), reco::Conversion::setQuality(), reco::TrackBase::setQuality(), GenEventInfoProduct::setScales(), VVIObjDetails::sincosint(), VVIObjDetails::sinint(), HelixExtrapolatorToLine2Order::solve3rdOrder(), L1MuGMTSortRankUnit::sort_rank(), L1MuGMTLFMergeRankEtaQLUT::SpecificLookup(), L1MuGMTLFSortRankPtQLUT::SpecificLookup(), L1MuGMTLFMergeRankPtQLUT::SpecificLookup(), L1MuGMTLFSortRankEtaQLUT::SpecificLookup(), L1MuGMTLFMergeRankEtaQLUT::SpecificLookup_flag(), L1MuGMTLFMergeRankEtaQLUT::SpecificLookup_rank_etaq(), L1MuGMTLFSortRankEtaQLUT::SpecificLookup_rank_etaq(), L1MuGMTLFSortRankPtQLUT::SpecificLookup_rank_ptq(), L1MuGMTLFMergeRankPtQLUT::SpecificLookup_rank_ptq(), L1MuGMTLFSortRankEtaQLUT::SpecificLookup_vlq(), TauValidation::spinEffectsZ(), PhysicsTools::split(), ConversionFastHelix::straightLineStateAtVertex(), FastHelix::straightLineStateAtVertex(), TiXmlBase::StringEqual(), edm::service::ELoutput::summarization(), edm::ELlog4cplus::summarization(), edm::service::ELfwkJobReport::summarization(), L1MuGMTLFMergeRankEtaQLUT::TheLookupFunction(), L1MuGMTLFSortRankPtQLUT::TheLookupFunction(), L1MuonPixelTrackFitter::valInversePt(), SiStripClusterInfo::variance(), VVIObj::VVIObj(), and DCULVRVoltagesDat::writeArrayDB().

tuple lumiQueryAPI::schema = session.nominalSchema()

Definition at line 1781 of file lumiQueryAPI.py.

tuple lumiQueryAPI::session = svc.connect(connectstr,accessMode=coral.access_ReadOnly)

Definition at line 1777 of file lumiQueryAPI.py.

tuple lumiQueryAPI::svc = coral.ConnectionService()

Definition at line 1775 of file lumiQueryAPI.py.