Пример #1
0
def updatedb(schema,runmap,lumitype):
    '''
    update lumidata set starttime=:rstart,stoptime=:rstop,nls=:nls where runnum=:runnum and data_id=:lumidataid
    '''
    lumidatatableName=''
    if lumitype=='HF':
        lumitableName=nameDealer.lumidataTableName()
    elif lumitype == 'PIXEL':
        lumitableName = nameDealer.pixellumidataTableName()
    else:
        assert False, "ERROR Unknown lumitype '%s'" % lumitype
    t=lumiTime.lumiTime()
    setClause='STARTTIME=:runstarttime,STOPTIME=:runstoptime,NLS=:nls'
    updateCondition='RUNNUM=:runnum AND DATA_ID=:lumidataid'
    inputData=coral.AttributeList()
    inputData.extend('runstarttime','time stamp')
    inputData.extend('runstoptime','time stamp')
    inputData.extend('nls','unsigned int')
    inputData.extend('runnum','unsigned int')
    inputData.extend('lumidataid','unsigned long long')
    db=dbUtil.dbUtil(schema)
    for (run,lumidataid) in runmap.keys():
        [runstarttime,runstoptime,nls]=runmap[(run,lumidataid)]
        runstartT=coral.TimeStamp(runstarttime.year,runstarttime.month,runstarttime.day,runstarttime.hour,runstarttime.minute,runstarttime.second,runstarttime.microsecond*1000)
        runstopT=coral.TimeStamp(runstoptime.year,runstoptime.month,runstoptime.day,runstoptime.hour,runstoptime.minute,runstoptime.second,runstoptime.microsecond*1000)
        inputData['runstarttime'].setData(runstartT)
        inputData['runstoptime'].setData(runstopT)
        inputData['nls'].setData(nls)
        inputData['runnum'].setData(int(run))
        inputData['lumidataid'].setData(int(lumidataid))
        db.singleUpdate(lumitableName,setClause,updateCondition,inputData)
Пример #2
0
def dropTables(schema,tablelist):
    try:
        db=dbUtil.dbUtil(schema)
        for tablename in tablelist:
            if tablename in [nameDealer.luminormTableName(),nameDealer.lumidataTableName(),nameDealer.trgdataTableName(),nameDealer.hltdataTableName()]:
                db.dropTable( nameDealer.idTableName(tablename) )
                db.dropTable( nameDealer.entryTableName(tablename) )
                db.dropTable( nameDealer.revmapTableName(tablename) )            
            if tablename in [nameDealer.trgTableName(),nameDealer.lumisummaryTableName(),nameDealer.lumisummaryv2TableName(),nameDealer.lumidetailTableName(),nameDealer.hltTableName()]:
                db.dropTable( nameDealer.idTableName(tablename) )
            db.dropTable( tablename )
    except :
        raise 
Пример #3
0
def beamForRange(schema,inputRange,withBeamIntensity=False,minIntensity=0.1,tableName=None,branchName=None):
    '''
    input:
           inputRange: {run:[cmsls]} (required)
    output : {runnumber:[(lumicmslnum,cmslsnum,beamenergy,beamstatus,[(ibx,b1,b2)])...](4)}
    '''
    if tableName is None:
        tableName=nameDealer.lumidataTableName()
    if branchName is None:
        branchName='DATA'
    result={}
    for run in inputRange.keys():
        lslist=inputRange[run]
        if lslist is not None and len(lslist)==0:
            result[run]=[]#if no LS is selected for a run
            continue
        lumidataid=dataDML.guessLumiDataIdByRun(schema,run,tableName)
        if lumidataid is None:
            result[run]=None
            continue #run non exist
        lumidata=dataDML.beamInfoById(schema,lumidataid,withBeamIntensity=withBeamIntensity,minIntensity=minIntensity)
        #(runnum,[(lumilsnum(0),cmslsnum(1),beamstatus(2),beamenergy(3),beaminfolist(4)),..])
        result[run]=[]
        perrundata=lumidata[1]
        if not perrundata:
            result[run]=[]
            continue
        for perlsdata in perrundata:
            lumilsnum=perlsdata[0]
            cmslsnum=perlsdata[1]
            if lslist is not None and cmslsnum not in lslist:
                continue
            beamstatus=perlsdata[2]
            beamenergy=perlsdata[3]
            beamintInfolist=[]
            if withBeamIntensity:
                beamintInfolist=perlsdata[4]
            result[run].append((lumilsnum,cmslsnum,beamstatus,beamenergy,beamintInfolist))        
    return result
Пример #4
0
def instLumiForIds(schema,irunlsdict,dataidmap,runsummaryMap,beamstatusfilter=None,timeFilter=None,withBXInfo=False,bxAlgo=None,xingMinLum=None,withBeamIntensity=False,lumitype='HF'):
    '''
    FROM ROOT FILE NO CORRECTION AT ALL 
    input:
           irunlsdict: {run:[cmsls]} 
           dataidmap: {run:(lumiid,trgid,hltid)}
           runsummaryMap: {run:[l1key(0),amodetag(1),egev(2),hltkey(3),fillnum(4),fillscheme(5),starttime(6),stoptime(7)]}
           beamstatus: LS filter on beamstatus (optional)
           timeFilter: (minLSBegTime,maxLSBegTime)
           withBXInfo: get per bunch info (optional)
           bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
           xingMinLum: None means apply no cut
           withBeamIntensity: get beam intensity info (optional)
           lumitype: luminosity measurement source
    output:
           result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),instlumi(5),instlumierr(6),startorbit(7),numorbit(8),(bxidx,bxvalues,bxerrs)(9),(bxidx,b1intensities,b2intensities)(10),fillnum(11)]}}
           
           special meanings:
           {run:None}  None means selected run not in lumiDB, 
           {run:[]} [] means no lumi data for this run in lumiDB
           {run:cmslsnum(1)==0} means either not cmslsnum or iscms but not selected
           instlumi unit in Hz/ub
    '''
    if lumitype not in ['HF','PIXEL']:
        raise ValueError('unknown lumitype '+lumitype)
    lumitableName=''
    lumilstableName=''
    if lumitype=='HF':
        lumitableName=nameDealer.lumidataTableName()
        lumilstableName=nameDealer.lumisummaryv2TableName()
    else:
        lumitableName=nameDealer.pixellumidataTableName()
        lumilstableName=nameDealer.pixellumisummaryv2TableName()
    result={}
    for run in irunlsdict.keys():
    #for run,(lumidataid,trgid,hltid ) in dataidmap.items():
        lslist=irunlsdict[run]
        if lslist is not None and len(lslist)==0:
            result[run]=[]#no lumi data for this run in lumiDB
            continue
        fillnum=runsummaryMap[run][4]
        runstarttimeStr=runsummaryMap[run][6]
        if run not in dataidmap:
            result[run]=[]#no lumi data for this run in lumiDB
            continue
        (lumidataid,trgid,hltid )=dataidmap[run]
        if lumidataid is None: #selected run not in lumiDB
            result[run]=None
            continue
        (lumirunnum,perlsresult)=dataDML.lumiLSById(schema,lumidataid,beamstatus=beamstatusfilter,withBXInfo=withBXInfo,bxAlgo=bxAlgo,withBeamIntensity=withBeamIntensity,tableName=lumilstableName)
        lsresult=[]
        c=lumiTime.lumiTime()
        for lumilsnum in perlsresult.keys():
            perlsdata=perlsresult[lumilsnum]
            cmslsnum=perlsdata[0]
            if lslist is not None and cmslsnum not in lslist: #ls exists but not selected
                cmslsnum=0
            numorbit=perlsdata[6]
            startorbit=perlsdata[7]
            orbittime=c.OrbitToTime(runstarttimeStr,startorbit,begorbit=0,customfm='%m/%d/%y %H:%M:%S')
            if timeFilter:
                if timeFilter[0]:
                    if orbittime<timeFilter[0]: continue
                if timeFilter[1]:
                    if orbittime>timeFilter[1]: continue
            if lumitype=='HF':
                instlumi=perlsdata[1]*1000.0 #HF db avg values are in Hz/mb,change it to Hz/ub
                instlumierr=perlsdata[2]*1000.0
            else:
                instlumi=perlsdata[1] #PIXEL avg values are in Hz/ub, need no conversion
                instlumierr=perlsdata[2]
            beamstatus=perlsdata[4]
            beamenergy=perlsdata[5]
            bxidxlist=[]
            bxvaluelist=[]
            bxerrorlist=[]
            bxdata=None
            beamdata=None
            if withBXInfo:
                bxinfo=perlsdata[8]                
                bxvalueArray=None
                bxerrArray=None
                if bxinfo:
                    bxvalueArray=bxinfo[0]
                    bxerrArray=bxinfo[1]
                    if xingMinLum :
                        for idx,bxval in enumerate(bxvalueArray):
                            if bxval>xingMinLum:
                                bxidxlist.append(idx)
                                bxvaluelist.append(bxval)
                                bxerrorlist.append(bxerrArray[idx])
                    else:
                        bxidxlist=range(0,len(bxvalueArray))
                        bxvaluelist=bxvalueArray.tolist()
                        bxerrorlist=bxerrArray.tolist()
                    del bxvalueArray[:]
                    del bxerrArray[:]
                bxdata=(bxidxlist,bxvaluelist,bxerrorlist)
            if withBeamIntensity:
                beaminfo=perlsdata[9]
                bxindexlist=[]
                b1intensitylist=[]
                b2intensitylist=[]
                if beaminfo[0] and beaminfo[1] and beaminfo[2]:
                    bxindexarray=beaminfo[0]
                    beam1intensityarray=beaminfo[1]
                    beam2intensityarray=beaminfo[2]                    
                    bxindexlist=bxindexarray.tolist()
                    b1intensitylist=beam1intensityarray.tolist()
                    b2intensitylist=beam2intensityarray.tolist()
                    del bxindexarray[:]
                    del beam1intensityarray[:]
                    del beam2intensityarray[:]                    
                beamdata=(bxindexlist,b1intensitylist,b2intensitylist)
            lsresult.append([lumilsnum,cmslsnum,orbittime,beamstatus,beamenergy,instlumi,instlumierr,startorbit,numorbit,bxdata,beamdata,fillnum])         
            del perlsdata[:]
        result[run]=lsresult
    return result
Пример #5
0
def lumiDataFromDB(sourceschema, sourcelumidataid):
    '''
    select nominalegev,ncollidingbunches,starttime,stoptime,nls from lumidata where DATA_ID=:dataid
    select lumilsnum,cmslsnum,beamstatus,beamenergy,numorbit,startorbit,instlumi,cmsbxindexblob,beamintensityblob_1,beamintensityblob_2,bxlumivalue_occ1,bxlumivalue_occ2,bxlumivalue_et,bxlumierror_occ1,bxlumierror_occ2,bxlumierror_et from lumisummaryv2 where data_id=:dataid
    output:(lumirundata,lumilsdata)
           lumirundata=[source,nominalegev,ncollidingbunches,starttime,stoptime,nls]
           lumilsdata={}#{lumilsnum:[cmslsnum,instlumi,instlumierror,instlumiquality,beamstatus,beamenergy,numorbit,startorbit,cmsbxindexblob,beam1intensity,beam2intensity,bxlumivalue_occ1,bxlumierror_occ1,bxlumiquality_occ1,bxlumivalue_occ2,bxlumierror_occ2,bxlumiquality_occ2,bxlumivalue_et,bxlumierror_et,bxlumiquality_et]
    '''
    lumirundata = []
    lumilsdata = {}
    qHandle = sourceschema.newQuery()
    try:
        qHandle.addToTableList(nameDealer.lumidataTableName())
        qHandle.addToOutputList('SOURCE')
        qHandle.addToOutputList('NOMINALEGEV')
        qHandle.addToOutputList('NCOLLIDINGBUNCHES')
        #qHandle.addToOutputList('TO_CHAR(STARTTIME,\'MM/DD/YY HH24:MI:SS\')','starttime')
        #qHandle.addToOutputList('TO_CHAR(STOPTIME,\'MM/DD/YY HH24:MI:SS\')','stoptime')
        qHandle.addToOutputList('STARTTIME')
        qHandle.addToOutputList('STOPTIME')
        qHandle.addToOutputList('NLS')
        qCondition = coral.AttributeList()
        qCondition.extend('lumidataid', 'unsigned long long')
        qCondition['lumidataid'].setData(sourcelumidataid)
        qResult = coral.AttributeList()
        qResult.extend('SOURCE', 'string')
        qResult.extend('NOMINALEGEV', 'float')
        qResult.extend('NCOLLIDINGBUNCHES', 'unsigned int')
        #qResult.extend('starttime','string')
        #qResult.extend('stoptime','string')
        qResult.extend('STARTTIME', 'time stamp')
        qResult.extend('STOPTIME', 'time stamp')
        qResult.extend('NLS', 'unsigned int')
        qHandle.defineOutput(qResult)
        qHandle.setCondition('DATA_ID=:lumidataid', qCondition)
        cursor = qHandle.execute()
        while next(cursor):
            source = cursor.currentRow()['SOURCE'].data()
            nominalegev = cursor.currentRow()['NOMINALEGEV'].data()
            ncollidingbunches = cursor.currentRow()['NCOLLIDINGBUNCHES'].data()
            #starttime=cursor.currentRow()['starttime'].data()
            #stoptime=cursor.currentRow()['stop'].data()
            starttime = cursor.currentRow()['STARTTIME'].data()
            stoptime = cursor.currentRow()['STOPTIME'].data()
            nls = cursor.currentRow()['NLS'].data()
            lumirundata = [
                source, nominalegev, ncollidingbunches, starttime, stoptime,
                nls
            ]
        del qHandle
    except:
        if qHandle: del qHandle
        raise
    qHandle = sourceschema.newQuery()
    try:
        qHandle.addToTableList(nameDealer.lumisummaryv2TableName())
        qHandle.addToOutputList('LUMILSNUM')
        qHandle.addToOutputList('CMSLSNUM')
        qHandle.addToOutputList('INSTLUMI')
        qHandle.addToOutputList('INSTLUMIERROR')
        qHandle.addToOutputList('INSTLUMIQUALITY')
        qHandle.addToOutputList('BEAMSTATUS')
        qHandle.addToOutputList('BEAMENERGY')
        qHandle.addToOutputList('NUMORBIT')
        qHandle.addToOutputList('STARTORBIT')
        qHandle.addToOutputList('CMSBXINDEXBLOB')
        qHandle.addToOutputList('BEAMINTENSITYBLOB_1')
        qHandle.addToOutputList('BEAMINTENSITYBLOB_2')
        qHandle.addToOutputList('BXLUMIVALUE_OCC1')
        qHandle.addToOutputList('BXLUMIERROR_OCC1')
        qHandle.addToOutputList('BXLUMIQUALITY_OCC1')
        qHandle.addToOutputList('BXLUMIVALUE_OCC2')
        qHandle.addToOutputList('BXLUMIERROR_OCC2')
        qHandle.addToOutputList('BXLUMIQUALITY_OCC2')
        qHandle.addToOutputList('BXLUMIVALUE_ET')
        qHandle.addToOutputList('BXLUMIERROR_ET')
        qHandle.addToOutputList('BXLUMIQUALITY_ET')
        qCondition = coral.AttributeList()
        qCondition.extend('lumidataid', 'unsigned long long')
        qCondition['lumidataid'].setData(sourcelumidataid)
        qResult = coral.AttributeList()
        qResult.extend('LUMILSNUM', 'unsigned int')
        qResult.extend('CMSLSNUM', 'unsigned int')
        qResult.extend('INSTLUMI', 'float')
        qResult.extend('INSTLUMIERROR', 'float')
        qResult.extend('INSTLUMIQUALITY', 'short')
        qResult.extend('BEAMSTATUS', 'string')
        qResult.extend('BEAMENERGY', 'float')
        qResult.extend('NUMORBIT', 'unsigned int')
        qResult.extend('STARTORBIT', 'unsigned int')
        qResult.extend('CMSBXINDEXBLOB', 'blob')
        qResult.extend('BEAMINTENSITYBLOB_1', 'blob')
        qResult.extend('BEAMINTENSITYBLOB_2', 'blob')
        qResult.extend('BXLUMIVALUE_OCC1', 'blob')
        qResult.extend('BXLUMIERROR_OCC1', 'blob')
        qResult.extend('BXLUMIQUALITY_OCC1', 'blob')
        qResult.extend('BXLUMIVALUE_OCC2', 'blob')
        qResult.extend('BXLUMIERROR_OCC2', 'blob')
        qResult.extend('BXLUMIQUALITY_OCC2', 'blob')
        qResult.extend('BXLUMIVALUE_ET', 'blob')
        qResult.extend('BXLUMIERROR_ET', 'blob')
        qResult.extend('BXLUMIQUALITY_ET', 'blob')

        qHandle.defineOutput(qResult)
        qHandle.setCondition('DATA_ID=:lumidataid', qCondition)
        cursor = qHandle.execute()
        while next(cursor):
            lumilsnum = cursor.currentRow()['LUMILSNUM'].data()
            cmslsnum = cursor.currentRow()['CMSLSNUM'].data()
            instlumi = cursor.currentRow()['INSTLUMI'].data()
            instlumierror = cursor.currentRow()['INSTLUMIERROR'].data()
            instlumiquality = cursor.currentRow()['INSTLUMIQUALITY'].data()
            beamstatus = cursor.currentRow()['BEAMSTATUS'].data()
            beamenergy = cursor.currentRow()['BEAMENERGY'].data()
            numorbit = cursor.currentRow()['NUMORBIT'].data()
            startorbit = cursor.currentRow()['STARTORBIT'].data()
            cmsbxindexblob = None
            if not cursor.currentRow()['CMSBXINDEXBLOB'].isNull():
                cmsbxindexblob = cursor.currentRow()['CMSBXINDEXBLOB'].data()
            beamintensityblob_1 = None
            if not cursor.currentRow()['BEAMINTENSITYBLOB_1'].isNull():
                beamintensityblob_1 = cursor.currentRow(
                )['BEAMINTENSITYBLOB_1'].data()
            beamintensityblob_2 = None
            if not cursor.currentRow()['BEAMINTENSITYBLOB_2'].isNull():
                beamintensityblob_2 = cursor.currentRow(
                )['BEAMINTENSITYBLOB_2'].data()
            bxlumivalue_occ1 = None
            if not cursor.currentRow()['BXLUMIVALUE_OCC1'].isNull():
                bxlumivalue_occ1 = cursor.currentRow(
                )['BXLUMIVALUE_OCC1'].data()
            bxlumivalue_occ2 = None
            if not cursor.currentRow()['BXLUMIVALUE_OCC2'].isNull():
                bxlumivalue_occ2 = cursor.currentRow(
                )['BXLUMIVALUE_OCC2'].data()
            bxlumivalue_et = None
            if not cursor.currentRow()['BXLUMIVALUE_ET'].isNull():
                bxlumivalue_et = cursor.currentRow()['BXLUMIVALUE_ET'].data()
            bxlumierror_occ1 = None
            if not cursor.currentRow()['BXLUMIERROR_OCC1'].isNull():
                bxlumierror_occ1 = cursor.currentRow(
                )['BXLUMIERROR_OCC1'].data()
            bxlumierror_occ2 = None
            if not cursor.currentRow()['BXLUMIERROR_OCC2'].isNull():
                bxlumierror_occ2 = cursor.currentRow(
                )['BXLUMIERROR_OCC2'].data()
            bxlumierror_et = None
            if not cursor.currentRow()['BXLUMIERROR_ET'].isNull():
                bxlumierror_et = cursor.currentRow()['BXLUMIERROR_ET'].data()
            bxlumiquality_occ1 = None
            if not cursor.currentRow()['BXLUMIQUALITY_OCC1'].isNull():
                bxlumiquality_occ1 = cursor.currentRow(
                )['BXLUMIQUALITY_OCC1'].data()
            bxlumiquality_occ2 = None
            if not cursor.currentRow()['BXLUMIQUALITY_OCC2'].isNull():
                bxlumiquality_occ2 = cursor.currentRow(
                )['BXLUMIQUALITY_OCC2'].data()
            bxlumiquality_et = None
            if not cursor.currentRow()['BXLUMIQUALITY_ET'].isNull():
                bxlumiquality_et = cursor.currentRow(
                )['BXLUMIQUALITY_ET'].data()
            lumilsdata[lumilsnum] = [
                cmslsnum, instlumi, instlumierror, instlumiquality, beamstatus,
                beamenergy, numorbit, startorbit, cmsbxindexblob,
                beamintensityblob_1, beamintensityblob_2, bxlumivalue_occ1,
                bxlumierror_occ1, bxlumiquality_occ1, bxlumivalue_occ2,
                bxlumierror_occ2, bxlumiquality_occ2, bxlumivalue_et,
                bxlumierror_et, bxlumiquality_et
            ]
        del qHandle
    except:
        if qHandle: del qHandle
        raise
    return (lumirundata, lumilsdata)
Пример #6
0
    hfdataidmap = revisionDML.dataIdsByTagId(destsession.nominalSchema(),
                                             hf_tagid, [int(options.runnum)],
                                             withcomment=False,
                                             lumitype='HF')
    destsession.transaction().commit()
    print('dest hfdataidmap ', hfdataidmap)

    if int(options.runnum) in hfdataidmap:
        print('existing old hf data in destdb of run ', options.runnum,
              hfdataidmap[int(options.runnum)])
        destsession.transaction().start(False)
        [destlumidataid, desttrgdataid,
         desthltdataid] = hfdataidmap[int(options.runnum)]
        (lumirevid, lumientryid, lumidataid) = dataDML.addLumiRunDataToBranch(
            destsession.nominalSchema(), int(options.runnum), rundat,
            branchinfo, nameDealer.lumidataTableName())
        dataDML.bulkInsertLumiLSSummary(destsession, int(options.runnum),
                                        lumidataid, lsdat,
                                        nameDealer.lumisummaryv2TableName())
        destsession.transaction().commit()
        destsession.transaction().start(False)
        revisionDML.addRunToCurrentDataTag(destsession.nominalSchema(),
                                           int(options.runnum),
                                           lumidataid,
                                           desttrgdataid,
                                           desthltdataid,
                                           lumitype='HF',
                                           comment=options.comment)
        destsession.transaction().commit()
    else:
        print('non-existing old hf data in destdb of run ',
Пример #7
0
 session.transaction().start(False)
 tables = lumidbDDL.createTables(schema)
 trunkinfo = createBranch(schema, 'TRUNK', None, comment='main')
 #print trunkinfo
 datainfo = createBranch(schema, 'DATA', 'TRUNK', comment='hold data')
 #print datainfo
 norminfo = createBranch(schema,
                         'NORM',
                         'TRUNK',
                         comment='hold normalization factor')
 #print norminfo
 (branchid, branchparent) = branchInfoByName(schema, 'DATA')
 databranchinfo = (branchid, 'DATA')
 print(databranchinfo)
 for runnum in [1200, 1211, 1222, 1233, 1345, 1222, 1200]:
     lumientryid = entryInBranch(schema, nameDealer.lumidataTableName(),
                                 str(runnum), 'DATA')
     trgentryid = entryInBranch(schema, nameDealer.trgdataTableName(),
                                str(runnum), 'DATA')
     hltentryid = entryInBranch(schema, nameDealer.hltdataTableName(),
                                str(runnum), 'DATA')
     if lumientryid is None:
         (revision_id, entry_id,
          data_id) = bookNewEntry(schema, nameDealer.lumidataTableName())
         entryinfo = (revision_id, entry_id, str(runnum), data_id)
         addEntry(schema, nameDealer.lumidataTableName(), entryinfo,
                  databranchinfo)
         #add data here
     else:
         revisioninfo = bookNewRevision(schema,
                                        nameDealer.lumidataTableName())
Пример #8
0
 destsession.transaction().start(False)
 (lumibranchid,lumibranchparent)=revisionDML.branchInfoByName(destsession.nominalSchema(),'DATA')
 branchinfo=(lumibranchid,'DATA')
 print('branchinfo ',branchinfo)
 
 (hf_tagid,hf_tagname)=revisionDML.currentDataTag(destsession.nominalSchema(),lumitype='HF')
 print('(hf_tagid,hf_tagname) ',(hf_tagid,hf_tagname))
 hfdataidmap=revisionDML.dataIdsByTagId(destsession.nominalSchema(),hf_tagid,[int(options.runnum)],withcomment=False,lumitype='HF')
 destsession.transaction().commit()
 print('dest hfdataidmap ',hfdataidmap)
 
 if int(options.runnum) in hfdataidmap:
     print('existing old hf data in destdb of run ',options.runnum,hfdataidmap[int(options.runnum)])
     destsession.transaction().start(False)
     [destlumidataid,desttrgdataid,desthltdataid]=hfdataidmap[int(options.runnum)]
     (lumirevid,lumientryid,lumidataid)=dataDML.addLumiRunDataToBranch(destsession.nominalSchema(),int(options.runnum),rundat,branchinfo,nameDealer.lumidataTableName())
     dataDML.bulkInsertLumiLSSummary(destsession,int(options.runnum),lumidataid,lsdat,nameDealer.lumisummaryv2TableName())
     destsession.transaction().commit()
     destsession.transaction().start(False)
     revisionDML.addRunToCurrentDataTag(destsession.nominalSchema(),int(options.runnum),lumidataid,desttrgdataid,desthltdataid,lumitype='HF',comment=options.comment)
     destsession.transaction().commit()
 else:
     print('non-existing old hf data in destdb of run ',int(options.runnum))
     destsession.transaction().start(False)
     (lumirevid,lumientryid,lumidataid)=dataDML.addLumiRunDataToBranch(destsession.nominalSchema(),int(options.runnum),rundat,branchinfo,nameDealer.lumidataTableName())
     print((lumirevid,lumientryid,lumidataid))
     dataDML.bulkInsertLumiLSSummary(destsession,int(options.runnum),lumidataid,lsdat,nameDealer.lumisummaryv2TableName())
     destsession.transaction().commit()
     destsession.transaction().start(False)
     revisionDML.addRunToCurrentDataTag(destsession.nominalSchema(),int(options.runnum),lumidataid,0,0,lumitype='HF',comment=options.comment)
     destsession.transaction().commit()
Пример #9
0
                        help='run number')
    parser.add_argument('--debug',
                        dest='debug',
                        action='store_true',
                        help='debug')

    options = parser.parse_args()
    svc = sessionManager.sessionManager(options.connect,
                                        authpath=options.authpath,
                                        debugON=options.debug)
    session = svc.openSession(isReadOnly=True,
                              cpp2sqltype=[('unsigned int', 'NUMBER(10)'),
                                           ('unsigned long long', 'NUMBER(20)')
                                           ])
    session.transaction().start(True)
    lumiIdInDATA = dataDML.guessLumiDataIdByRunInBranch(
        session.nominalSchema(),
        options.runnum,
        nameDealer.lumidataTableName(),
        branchName='DATA')
    print(lumiIdInDATA)
    lumiIdInPIXELLUMI = dataDML.guessLumiDataIdByRunInBranch(
        session.nominalSchema(),
        options.runnum,
        nameDealer.lumidataTableName(),
        branchName='PIXELLUMI')
    print(lumiIdInPIXELLUMI)
    session.transaction().commit()
    del session
    del svc
Пример #10
0
def lumiDataFromDB(sourceschema,sourcelumidataid):
    '''
    select nominalegev,ncollidingbunches,starttime,stoptime,nls from lumidata where DATA_ID=:dataid
    select lumilsnum,cmslsnum,beamstatus,beamenergy,numorbit,startorbit,instlumi,cmsbxindexblob,beamintensityblob_1,beamintensityblob_2,bxlumivalue_occ1,bxlumivalue_occ2,bxlumivalue_et,bxlumierror_occ1,bxlumierror_occ2,bxlumierror_et from lumisummaryv2 where data_id=:dataid
    output:(lumirundata,lumilsdata)
           lumirundata=[source,nominalegev,ncollidingbunches,starttime,stoptime,nls]
           lumilsdata={}#{lumilsnum:[cmslsnum,instlumi,instlumierror,instlumiquality,beamstatus,beamenergy,numorbit,startorbit,cmsbxindexblob,beam1intensity,beam2intensity,bxlumivalue_occ1,bxlumierror_occ1,bxlumiquality_occ1,bxlumivalue_occ2,bxlumierror_occ2,bxlumiquality_occ2,bxlumivalue_et,bxlumierror_et,bxlumiquality_et]
    '''
    lumirundata=[]
    lumilsdata={}
    qHandle=sourceschema.newQuery()
    try:
        qHandle.addToTableList( nameDealer.lumidataTableName() )
        qHandle.addToOutputList('SOURCE')
        qHandle.addToOutputList('NOMINALEGEV')
        qHandle.addToOutputList('NCOLLIDINGBUNCHES')
        #qHandle.addToOutputList('TO_CHAR(STARTTIME,\'MM/DD/YY HH24:MI:SS\')','starttime')
        #qHandle.addToOutputList('TO_CHAR(STOPTIME,\'MM/DD/YY HH24:MI:SS\')','stoptime')
        qHandle.addToOutputList('STARTTIME')
        qHandle.addToOutputList('STOPTIME')
        qHandle.addToOutputList('NLS')
        qCondition=coral.AttributeList()
        qCondition.extend('lumidataid','unsigned long long')
        qCondition['lumidataid'].setData(sourcelumidataid)
        qResult=coral.AttributeList()
        qResult.extend('SOURCE','string')
        qResult.extend('NOMINALEGEV','float')
        qResult.extend('NCOLLIDINGBUNCHES','unsigned int')
        #qResult.extend('starttime','string')
        #qResult.extend('stoptime','string')
        qResult.extend('STARTTIME','time stamp')
        qResult.extend('STOPTIME','time stamp')
        qResult.extend('NLS','unsigned int')
        qHandle.defineOutput(qResult)
        qHandle.setCondition('DATA_ID=:lumidataid',qCondition)
        cursor=qHandle.execute()
        while next(cursor):
            source=cursor.currentRow()['SOURCE'].data()
            nominalegev=cursor.currentRow()['NOMINALEGEV'].data()
            ncollidingbunches=cursor.currentRow()['NCOLLIDINGBUNCHES'].data()
            #starttime=cursor.currentRow()['starttime'].data()
            #stoptime=cursor.currentRow()['stop'].data()
            starttime=cursor.currentRow()['STARTTIME'].data()
            stoptime=cursor.currentRow()['STOPTIME'].data()
            nls=cursor.currentRow()['NLS'].data()
            lumirundata=[source,nominalegev,ncollidingbunches,starttime,stoptime,nls]
        del qHandle
    except:
        if qHandle:del qHandle
        raise
    qHandle=sourceschema.newQuery()
    try:
        qHandle.addToTableList( nameDealer.lumisummaryv2TableName() )
        qHandle.addToOutputList('LUMILSNUM')
        qHandle.addToOutputList('CMSLSNUM')
        qHandle.addToOutputList('INSTLUMI')
        qHandle.addToOutputList('INSTLUMIERROR')
        qHandle.addToOutputList('INSTLUMIQUALITY')
        qHandle.addToOutputList('BEAMSTATUS')
        qHandle.addToOutputList('BEAMENERGY')
        qHandle.addToOutputList('NUMORBIT')
        qHandle.addToOutputList('STARTORBIT')
        qHandle.addToOutputList('CMSBXINDEXBLOB')
        qHandle.addToOutputList('BEAMINTENSITYBLOB_1')
        qHandle.addToOutputList('BEAMINTENSITYBLOB_2')
        qHandle.addToOutputList('BXLUMIVALUE_OCC1')
        qHandle.addToOutputList('BXLUMIERROR_OCC1')
        qHandle.addToOutputList('BXLUMIQUALITY_OCC1')
        qHandle.addToOutputList('BXLUMIVALUE_OCC2')
        qHandle.addToOutputList('BXLUMIERROR_OCC2')
        qHandle.addToOutputList('BXLUMIQUALITY_OCC2')
        qHandle.addToOutputList('BXLUMIVALUE_ET')
        qHandle.addToOutputList('BXLUMIERROR_ET')
        qHandle.addToOutputList('BXLUMIQUALITY_ET')
        qCondition=coral.AttributeList()
        qCondition.extend('lumidataid','unsigned long long')
        qCondition['lumidataid'].setData(sourcelumidataid)
        qResult=coral.AttributeList()
        qResult.extend('LUMILSNUM','unsigned int')
        qResult.extend('CMSLSNUM','unsigned int')
        qResult.extend('INSTLUMI','float')
        qResult.extend('INSTLUMIERROR','float')
        qResult.extend('INSTLUMIQUALITY','short')
        qResult.extend('BEAMSTATUS','string')
        qResult.extend('BEAMENERGY','float')
        qResult.extend('NUMORBIT','unsigned int')
        qResult.extend('STARTORBIT','unsigned int')
        qResult.extend('CMSBXINDEXBLOB','blob')
        qResult.extend('BEAMINTENSITYBLOB_1','blob')
        qResult.extend('BEAMINTENSITYBLOB_2','blob')
        qResult.extend('BXLUMIVALUE_OCC1','blob')
        qResult.extend('BXLUMIERROR_OCC1','blob')
        qResult.extend('BXLUMIQUALITY_OCC1','blob')        
        qResult.extend('BXLUMIVALUE_OCC2','blob')
        qResult.extend('BXLUMIERROR_OCC2','blob')
        qResult.extend('BXLUMIQUALITY_OCC2','blob')
        qResult.extend('BXLUMIVALUE_ET','blob')
        qResult.extend('BXLUMIERROR_ET','blob')
        qResult.extend('BXLUMIQUALITY_ET','blob')
        
        qHandle.defineOutput(qResult)
        qHandle.setCondition('DATA_ID=:lumidataid',qCondition)
        cursor=qHandle.execute()
        while next(cursor):
            lumilsnum=cursor.currentRow()['LUMILSNUM'].data()
            cmslsnum=cursor.currentRow()['CMSLSNUM'].data()
            instlumi=cursor.currentRow()['INSTLUMI'].data()
            instlumierror=cursor.currentRow()['INSTLUMIERROR'].data()
            instlumiquality=cursor.currentRow()['INSTLUMIQUALITY'].data()
            beamstatus=cursor.currentRow()['BEAMSTATUS'].data()
            beamenergy=cursor.currentRow()['BEAMENERGY'].data()
            numorbit=cursor.currentRow()['NUMORBIT'].data()
            startorbit=cursor.currentRow()['STARTORBIT'].data()
            cmsbxindexblob=None
            if not cursor.currentRow()['CMSBXINDEXBLOB'].isNull():
                cmsbxindexblob=cursor.currentRow()['CMSBXINDEXBLOB'].data()
            beamintensityblob_1=None
            if not cursor.currentRow()['BEAMINTENSITYBLOB_1'].isNull():
                beamintensityblob_1=cursor.currentRow()['BEAMINTENSITYBLOB_1'].data()
            beamintensityblob_2=None
            if not cursor.currentRow()['BEAMINTENSITYBLOB_2'].isNull():
                beamintensityblob_2=cursor.currentRow()['BEAMINTENSITYBLOB_2'].data()
            bxlumivalue_occ1=None
            if not cursor.currentRow()['BXLUMIVALUE_OCC1'].isNull():
                bxlumivalue_occ1=cursor.currentRow()['BXLUMIVALUE_OCC1'].data()
            bxlumivalue_occ2=None
            if not cursor.currentRow()['BXLUMIVALUE_OCC2'].isNull():
                bxlumivalue_occ2=cursor.currentRow()['BXLUMIVALUE_OCC2'].data()
            bxlumivalue_et=None
            if not cursor.currentRow()['BXLUMIVALUE_ET'].isNull():
                bxlumivalue_et=cursor.currentRow()['BXLUMIVALUE_ET'].data()
            bxlumierror_occ1=None
            if not cursor.currentRow()['BXLUMIERROR_OCC1'].isNull():
                bxlumierror_occ1=cursor.currentRow()['BXLUMIERROR_OCC1'].data()
            bxlumierror_occ2=None
            if not cursor.currentRow()['BXLUMIERROR_OCC2'].isNull():
                bxlumierror_occ2=cursor.currentRow()['BXLUMIERROR_OCC2'].data()
            bxlumierror_et=None
            if not cursor.currentRow()['BXLUMIERROR_ET'].isNull():
                bxlumierror_et=cursor.currentRow()['BXLUMIERROR_ET'].data()
            bxlumiquality_occ1=None
            if not cursor.currentRow()['BXLUMIQUALITY_OCC1'].isNull():
                bxlumiquality_occ1=cursor.currentRow()['BXLUMIQUALITY_OCC1'].data()
            bxlumiquality_occ2=None
            if not cursor.currentRow()['BXLUMIQUALITY_OCC2'].isNull():
                bxlumiquality_occ2=cursor.currentRow()['BXLUMIQUALITY_OCC2'].data()
            bxlumiquality_et=None
            if not cursor.currentRow()['BXLUMIQUALITY_ET'].isNull():
                bxlumiquality_et=cursor.currentRow()['BXLUMIQUALITY_ET'].data()
            lumilsdata[lumilsnum]=[cmslsnum,instlumi,instlumierror,instlumiquality,beamstatus,beamenergy,numorbit,startorbit,cmsbxindexblob,beamintensityblob_1,beamintensityblob_2,bxlumivalue_occ1,bxlumierror_occ1,bxlumiquality_occ1,bxlumivalue_occ2,bxlumierror_occ2,bxlumiquality_occ2,bxlumivalue_et,bxlumierror_et,bxlumiquality_et]
        del qHandle
    except:
        if qHandle:del qHandle
        raise
    return (lumirundata,lumilsdata)
Пример #11
0
 destsession.transaction().start(False)
 (lumibranchid,lumibranchparent)=revisionDML.branchInfoByName(destsession.nominalSchema(),'DATA')
 branchinfo=(lumibranchid,'DATA')
 print('branchinfo ',branchinfo)
 
 (hf_tagid,hf_tagname)=revisionDML.currentDataTag(destsession.nominalSchema(),lumitype='HF')
 print('(hf_tagid,hf_tagname) ',(hf_tagid,hf_tagname))
 hfdataidmap=revisionDML.dataIdsByTagId(destsession.nominalSchema(),hf_tagid,[int(options.runnum)],withcomment=False,lumitype='HF')
 destsession.transaction().commit()
 print('dest hfdataidmap ',hfdataidmap)
 
 if int(options.runnum) in hfdataidmap:
     print('existing old hf data in destdb of run ',options.runnum,hfdataidmap[int(options.runnum)])
     destsession.transaction().start(False)
     [destlumidataid,desttrgdataid,desthltdataid]=hfdataidmap[int(options.runnum)]
     (lumirevid,lumientryid,lumidataid)=dataDML.addLumiRunDataToBranch(destsession.nominalSchema(),int(options.runnum),rundat,branchinfo,nameDealer.lumidataTableName())
     dataDML.bulkInsertLumiLSSummary(destsession,int(options.runnum),lumidataid,lsdat,nameDealer.lumisummaryv2TableName())
     destsession.transaction().commit()
     destsession.transaction().start(False)
     revisionDML.addRunToCurrentDataTag(destsession.nominalSchema(),int(options.runnum),lumidataid,desttrgdataid,desthltdataid,lumitype='HF',comment=options.comment)
     destsession.transaction().commit()
 else:
     print('non-existing old hf data in destdb of run ',int(options.runnum))
     destsession.transaction().start(False)
     (lumirevid,lumientryid,lumidataid)=dataDML.addLumiRunDataToBranch(destsession.nominalSchema(),int(options.runnum),rundat,branchinfo,nameDealer.lumidataTableName())
     print((lumirevid,lumientryid,lumidataid))
     dataDML.bulkInsertLumiLSSummary(destsession,int(options.runnum),lumidataid,lsdat,nameDealer.lumisummaryv2TableName())
     destsession.transaction().commit()
     destsession.transaction().start(False)
     revisionDML.addRunToCurrentDataTag(destsession.nominalSchema(),int(options.runnum),lumidataid,0,0,lumitype='HF',comment=options.comment)
     destsession.transaction().commit()
Пример #12
0
    parser.add_argument('-c',dest='connect',action='store',
                        required=True,
                        help='connect string to lumiDB (required)',
                        )
    parser.add_argument('-P',dest='authpath',action='store',
                        required=True,
                        help='path to authentication file (required)'
                        )
    parser.add_argument('-r',dest='runnum',action='store',
                        type=int,
                        required=True,
                        help='run number'
                        )
    parser.add_argument('--debug',dest='debug',action='store_true',
                        help='debug'
                        )
    
    options=parser.parse_args()
    svc=sessionManager.sessionManager(options.connect,
                                      authpath=options.authpath,
                                      debugON=options.debug)
    session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
    session.transaction().start(True)
    lumiIdInDATA=dataDML.guessLumiDataIdByRunInBranch(session.nominalSchema(),options.runnum,nameDealer.lumidataTableName(),branchName='DATA')
    print lumiIdInDATA
    lumiIdInPIXELLUMI=dataDML.guessLumiDataIdByRunInBranch(session.nominalSchema(),options.runnum,nameDealer.lumidataTableName(),branchName='PIXELLUMI')
    print lumiIdInPIXELLUMI
    session.transaction().commit()
    del session
    del svc
Пример #13
0
def effectiveLumiForRange(schema,inputRange,hltpathname=None,hltpathpattern=None,amodetag=None,beamstatus=None,egev=None,withBXInfo=False,xingMinLum=0.0,bxAlgo=None,withBeamIntensity=False,norm=None,finecorrections=None,driftcorrections=None,usecorrectionv2=False,lumitype='HF',branchName=None):
    '''
    input:
           inputRange  {run:[cmsls]} (required)
           hltpathname: selected hltpathname
           hltpathpattern: regex select hltpaths           
           amodetag: amodetag for  picking norm(optional)
           egev: beamenergy for picking norm(optional)
           withBXInfo: get per bunch info (optional)
           bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
           xingMinLum: cut on bx lumi value (optional)
           withBeamIntensity: get beam intensity info (optional)
           normname: norm factor name to use (optional)
           branchName: data version
    output:
    result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),recordedlumi(6),calibratedlumierror(7),{hltpath:[l1name,l1prescale,hltprescale,efflumi]},bxdata,beamdata,fillnum]}
           lumi unit: 1/ub
    '''
    if lumitype not in ['HF','PIXEL']:
        raise ValueError('unknown lumitype '+lumitype)
    if branchName is None:
        branchName='DATA'
    lumitableName=''
    lumilstableName=''
    if lumitype=='HF':
        lumitableName=nameDealer.lumidataTableName()
        lumilstableName=nameDealer.lumisummaryv2TableName()
    else:
        lumitableName=nameDealer.pixellumidataTableName()
        lumilstableName=nameDealer.pixellumisummaryv2TableName()
    numbx=3564
    result = {}
    normval=None
    perbunchnormval=None
    if norm:
        normval=_getnorm(schema,norm)
        perbunchnormval=float(normval)/float(1000)
    elif amodetag and egev:
        normval=_decidenormFromContext(schema,amodetag,egev)
        perbunchnormval=float(normval)/float(1000)
    c=lumiTime.lumiTime()
    lumip=lumiParameters.ParametersObject()
    for run in inputRange.keys():
        lslist=inputRange[run]
        if lslist is not None and len(lslist)==0:#no selected ls, do nothing for this run
            result[run]=[]
            continue
        cmsrunsummary=dataDML.runsummary(schema,run)
        if len(cmsrunsummary)==0:#non existing run
            result[run]=None
            continue
        startTimeStr=cmsrunsummary[6]
        fillnum=cmsrunsummary[4]
        lumidataid=None
        trgdataid=None
        hltdataid=None
        lumidataid=dataDML.guessLumiDataIdByRun(schema,run,lumitableName)
        trgdataid=dataDML.guessTrgDataIdByRun(schema,run)
        hltdataid=dataDML.guessHltDataIdByRun(schema,run)
        if lumidataid is None or trgdataid is None or hltdataid is None:
            result[run]=None
            continue
        (lumirunnum,lumidata)=dataDML.lumiLSById(schema,lumidataid,beamstatus,tableName=lumilstableName)
        (trgrunnum,trgdata)=dataDML.trgLSById(schema,trgdataid,withPrescale=True)
        (hltrunnum,hltdata)=dataDML.hltLSById(schema,hltdataid,hltpathname=hltpathname,hltpathpattern=hltpathpattern)
        hlttrgmap=dataDML.hlttrgMappingByrun(schema,run)
        if not normval:#if norm cannot be decided , look for it according to context per run
            normval=_decidenormForRun(schema,run)
            perbunchnormval=float(normval)/float(1000)
        if not normval:#still not found? resort to global default (should never come here)
            normval=6370
            perbunchnormval=6.37
            print '[Warning] using default normalization '+str(normval)

        perrunresult=[]
        for lumilsnum,perlsdata in lumidata.items():
            cmslsnum=perlsdata[0]            
            triggeredls=perlsdata[0] 
            if lslist is not None and cmslsnum not in lslist:
                #cmslsnum=0
                triggeredls=0
                recordedlumi=0.0
            instlumi=perlsdata[1]
            instlumierror=perlsdata[2]
            avglumi=instlumi*normval
            calibratedlumi=avglumi 
            if lumitype=='HF' and finecorrections and finecorrections[run]:
                if usecorrectionv2:
                    if driftcorrections and driftcorrections[run]:
                        calibratedlumi=lumiCorrections.applyfinecorrectionV2(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],driftcorrections[run])
                    else:
                        calibratedlumi=lumiCorrections.applyfinecorrectionV2(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],1.0)
                else:
                    calibratedlumi=lumiCorrections.applyfinecorrection(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2])
            if lumitype=='PIXEL' and finecorrections is not None:
                calibratedlumi=finecorrections[run]*avglumi
            calibratedlumierror=instlumierror*normval
            bstatus=perlsdata[4]
            begev=perlsdata[5]
            numorbit=perlsdata[6]
            startorbit=perlsdata[7]
            timestamp=c.OrbitToTime(startTimeStr,startorbit,0)
            lslen=lumip.lslengthsec()
            deliveredlumi=calibratedlumi*lslen
            recordedlumi=0.0
            trgprescalemap={}#trgprescalemap for this ls
            efflumidict={}
            if triggeredls!=0:
                if not trgdata.has_key(cmslsnum):
                    #triggeredls=0 #if no trigger, set back to non-cms-active ls
                    recordedlumi=0.0 # no trigger->nobeam recordedlumi=None
                else:
                    deadcount=trgdata[cmslsnum][0] ##subject to change !!
                    bitzerocount=trgdata[cmslsnum][1]
                    bitzeroprescale=trgdata[cmslsnum][2]
                    deadfrac=trgdata[cmslsnum][3]
                    if deadfrac<0 or deadfrac>1.0:
                        deadfrac=1.0
                    #if float(bitzerocount)*float(bitzeroprescale)==0.0:
                    #    deadfrac=1.0
                    #else:
                    #    deadfrac=float(deadcount)/(float(bitzerocount)*float(bitzeroprescale))
                    #if deadfrac>1.0:
                    #    deadfrac=1.0  #artificial correction in case of deadfrac>1
                    recordedlumi=deliveredlumi*(1.0-deadfrac)
                    l1bitinfo=trgdata[cmslsnum][4]
                    if l1bitinfo:
                        for thisbitinfo in l1bitinfo:
                            thisbitname=thisbitinfo[0]
                            thisbitprescale=thisbitinfo[2]
                            #trgprescalemap['"'+thisbitname+'"']=thisbitprescale#note:need to double quote bit name!
                            trgprescalemap['"'+thisbitname+'"']=thisbitprescale

                    del trgdata[cmslsnum][:]
                if hltdata.has_key(cmslsnum):                
                    hltpathdata=hltdata[cmslsnum]
                    #print 'hltpathdata ',hltpathdata
                    for pathidx,thispathinfo in enumerate(hltpathdata):
                        efflumi=0.0                    
                        thispathname=thispathinfo[0]
                        thisprescale=thispathinfo[1]
                        thisl1seed=None
                        l1bitname=None
                        l1prescale=None
                        try:
                            thisl1seed=hlttrgmap[thispathname]
                        except KeyError:
                            thisl1seed=None
                            # print 'hltpath, l1seed, hltprescale ',thispathname,thisl1seed,thisprescale
                        if thisl1seed:                            
                            try:
                                l1bitname=hltTrgSeedMapper.findUniqueSeed(thispathname,thisl1seed)
                                if l1bitname :
                                    l1prescale=trgprescalemap[l1bitname]#need to match double quoted string!
                                else:
                                    l1prescale=None
                            except KeyError:
                                l1prescale=None                           
                        if l1prescale and thisprescale :#normal both prescaled
                            efflumi=recordedlumi/(float(l1prescale)*float(thisprescale))
                            efflumidict[thispathname]=[l1bitname,l1prescale,thisprescale,efflumi]
                        elif l1prescale and thisprescale==0: #hltpath in menu but masked
                            efflumi=0.0
                            efflumidict[thispathname]=[l1bitname,l1prescale,thisprescale,efflumi]
                        else:
                            efflumi=0.0
                            efflumidict[thispathname]=[None,0,thisprescale,efflumi]
                
            bxvaluelist=[]
            bxerrorlist=[]
            bxdata=None
            beamdata=None
            if withBXInfo:
                bxinfo=lumidata[8]
                bxvalueArray=None
                bxerrArray=None
                if bxinfo:
                    bxvalueArray=bxinfo[0]
                    bxerrArray=bxinfo[1]
                    for idx,bxval in enumerate(bxvalueArray):
                        if finecorrections and finecorrections[run]:
                            if usecorrectionv2:
                                if driftcorrections and driftcorrections[run]:
                                    mybxval=lumiCorrections.applyfinecorrectionBXV2(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],driftcorrections[run])
                                else:
                                    mybxval=lumiCorrections.applyfinecorrectionBXV2(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],1.0)
                            else:
                                mybxval=lumiCorrections.applyfinecorrectionBX(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2])
                        else:
                            mybxval=bxval*perbunchnormval
                        if mybxval>xingMinLum:
                            bxidxlist.append(idx)
                            bxvaluelist.append(bxval)
                            bxerrorlist.append(bxerrArray[idx])
                    del bxvalueArray[:]
                    del bxerrArray[:]
                bxdata=(bxidxlist,bxvaluelist,bxerrorlist)    
            if withBeamIntensity:
                beaminfo=perlsdata[9]
                bxindexlist=[]
                b1intensitylist=[]
                b2intensitylist=[]
                if beaminfo:
                    bxindexarray=beaminfo[0]
                    beam1intensityarray=beaminfo[1]
                    beam2intensityarray=beaminfo[2]                    
                    bxindexlist=bxindexarray.tolist()
                    b1intensitylist=beam1intensityarray.tolist()
                    b2intensitylist=beam2intensityarray.tolist()
                    del bxindexarray[:]
                    del beam1intensityarray[:]
                    del beam2intensityarray[:]
                beamdata=(bxindexlist,b1intensitylist,b2intensitylist)
#            print cmslsnum,deliveredlumi,recordedlumi,efflumidict
            perrunresult.append([lumilsnum,triggeredls,timestamp,bstatus,begev,deliveredlumi,recordedlumi,calibratedlumierror,efflumidict,bxdata,beamdata,fillnum])
            del perlsdata[:]
        result[run]=perrunresult
    #print result
    return result
Пример #14
0
def lumiForRange(schema,inputRange,beamstatus=None,amodetag=None,egev=None,withBXInfo=False,bxAlgo=None,xingMinLum=0.0,withBeamIntensity=False,norm=None,datatag='DATA',finecorrections=None,driftcorrections=None,usecorrectionv2=False,lumitype='HF',branchName=None):
    '''
    delivered/recorded lumi
    input:
           inputRange  {run:[cmsls]} (required)
           beamstatus: LS filter on beamstatus (optional)
           amodetag: amodetag for  picking norm(optional)
           egev: beamenergy for picking norm(optional)
           withBXInfo: get per bunch info (optional)
           bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
           xingMinLum: cut on bx lumi value (optional)
           withBeamIntensity: get beam intensity info (optional)
           normname: norm factor name to use (optional)
           branchName: data version
    output:
           result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),recordedlumi(6),calibratedlumierror(7),(bxidx,bxvalues,bxerrs)(8),(bxidx,b1intensities,b2intensities)(9),fillnum(10)]}
           lumi unit: 1/ub
    '''
    if lumitype not in ['HF','PIXEL']:
        raise ValueError('unknown lumitype '+lumitype)
    #if branchName is None:
    #    branchName='DATA'
    lumip=lumiParameters.ParametersObject()
    lumitableName=''
    lumilstableName=''
    if lumitype=='HF':
        lumitableName=nameDealer.lumidataTableName()
        lumilstableName=nameDealer.lumisummaryv2TableName()
    else:
        lumitableName=nameDealer.pixellumidataTableName()
        lumilstableName=nameDealer.pixellumisummaryv2TableName()
    numbx=lumip.NBX
    result = {}
    normval=None
    perbunchnormval=None
    if norm:
        normval=_getnorm(schema,norm)
        perbunchnormval=float(normval)/float(1000)
    elif amodetag and egev:
        normval=_decidenormFromContext(schema,amodetag,egev)
        perbunchnormval=float(normval)/float(1000)
    c=lumiTime.lumiTime()
    for run in inputRange.keys():#loop over run
        lslist=inputRange[run]
        if lslist is not None and len(lslist)==0:#no selected ls, do nothing for this run
            result[run]=[]
            continue
        cmsrunsummary=dataDML.runsummary(schema,run)
        if len(cmsrunsummary)==0:#non existing run
            result[run]=None
            continue
        startTimeStr=cmsrunsummary[6]
        fillnum=cmsrunsummary[4]
        lumidataid=None
        trgdataid=None
        lumidataid=dataDML.guessLumiDataIdByRun(schema,run,lumitableName)
        if lumidataid is None :
            result[run]=None
            continue
        trgdataid=dataDML.guessTrgDataIdByRun(schema,run)
        (lumirunnum,lumidata)=dataDML.lumiLSById(schema,lumidataid,beamstatus=beamstatus,withBXInfo=withBXInfo,bxAlgo=bxAlgo,withBeamIntensity=withBeamIntensity,tableName=lumilstableName)
        if trgdataid is None :
            trgdata={}
        else:
            (trgrunnum,trgdata)=dataDML.trgLSById(schema,trgdataid)
            
        if not normval:#if norm cannot be decided , look for it according to context per run
            normval=_decidenormForRun(schema,run)
            perbunchnormval=float(normval)/float(1000)
        if not normval:#still not found? resort to global default (should never come here)
            normval=6370
            perbunchnormval=6.37
            print '[Warning] using default normalization '+str(normval)
        
        perrunresult=[]
        for lumilsnum,perlsdata in lumidata.items():
            cmslsnum=perlsdata[0]
            triggeredls=perlsdata[0]
            if lslist is not None and cmslsnum not in lslist:
                #cmslsnum=0
                triggeredls=0
                recordedlumi=0.0
            instlumi=perlsdata[1]
            instlumierror=perlsdata[2]
            avglumi=instlumi*normval
            calibratedlumi=avglumi
            if lumitype=='HF' and finecorrections and finecorrections[run]:
                if usecorrectionv2:
                    if driftcorrections and driftcorrections[run]:
                        calibratedlumi=lumiCorrections.applyfinecorrectionV2(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],driftcorrections[run])
                    else:
                        calibratedlumi=lumiCorrections.applyfinecorrectionV2(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],1.0)
                else:
                    calibratedlumi=lumiCorrections.applyfinecorrection(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2])
            if lumitype=='PIXEL' and finecorrections is not None:
                calibratedlumi=finecorrections[run]*avglumi
            calibratedlumierror=instlumierror*normval
            bstatus=perlsdata[4]
            begev=perlsdata[5]
            numorbit=perlsdata[6]
            startorbit=perlsdata[7]
            timestamp=c.OrbitToTime(startTimeStr,startorbit,0)
            lslen=lumip.lslengthsec()
            deliveredlumi=calibratedlumi*lslen
            recordedlumi=0.0
            if triggeredls!=0:
                if not trgdata.has_key(cmslsnum):                    
                   # triggeredls=0 #if no trigger, set back to non-cms-active ls
                    recordedlumi=0.0 # no trigger->nobeam recordedlumi=None
                else:
                    deadcount=trgdata[cmslsnum][0] ##subject to change !!
                    bitzerocount=trgdata[cmslsnum][1]
                    bitzeroprescale=trgdata[cmslsnum][2]
                    deadfrac=trgdata[cmslsnum][3]
                    if deadfrac<0 or deadfrac>1.0:
                        deadfrac=1.0
                    #if float(bitzerocount)*float(bitzeroprescale)==0.0:
                    #    deadfrac=1.0
                    #else:
                    #    deadfrac=float(deadcount)/(float(bitzerocount)*float(bitzeroprescale))
                    #if deadfrac>1.0:
                    #    deadfrac=1.0  #artificial correction in case of deadfrac>1
                    recordedlumi=deliveredlumi*(1.0-deadfrac)
                    del trgdata[cmslsnum][:]
            bxdata=None
            if withBXInfo:
                bxinfo=perlsdata[8]
                bxvalueArray=None
                bxerrArray=None
                bxidxlist=[]
                bxvaluelist=[]
                bxerrorlist=[]
                if bxinfo:
                    bxvalueArray=bxinfo[0]
                    bxerrArray=bxinfo[1]
                    #if cmslsnum==1:
                    #    print 'bxvalueArray ',bxvalueArray
                    for idx,bxval in enumerate(bxvalueArray):                    
                        if finecorrections and finecorrections[run]:
                            if usecorrectionv2:
                                if driftcorrections and driftcorrections[run]:
                                    mybxval=lumiCorrections.applyfinecorrectionBXV2(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],driftcorrections[run])
                                else:
                                    mybxval=lumiCorrections.applyfinecorrectionBXV2(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],1.0)
                            else:
                                mybxval=lumiCorrections.applyfinecorrectionBX(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2])
                        else:
                            mybxval=bxval*perbunchnormval
                        if mybxval>xingMinLum:
                            bxidxlist.append(idx)
                            bxvaluelist.append(mybxval)
                            bxerrorlist.append(bxerrArray[idx]*perbunchnormval)#no correciton on errors
                    del bxvalueArray[:]
                    del bxerrArray[:]
                bxdata=(bxidxlist,bxvaluelist,bxerrorlist)
            beamdata=None
            if withBeamIntensity:
                beaminfo=perlsdata[9]
                bxindexlist=[]
                b1intensitylist=[]
                b2intensitylist=[]                
                if beaminfo:
                    bxindexarray=beaminfo[0]
                    beam1intensityarray=beaminfo[1]
                    beam2intensityarray=beaminfo[2]                    
                    bxindexlist=bxindexarray.tolist()
                    b1intensitylist=beam1intensityarray.tolist()
                    b2intensitylist=beam2intensityarray.tolist()
                    del bxindexarray[:]
                    del beam1intensityarray[:]
                    del beam2intensityarray[:]
                beamdata=(bxindexlist,b1intensitylist,b2intensitylist)
            perrunresult.append([lumilsnum,triggeredls,timestamp,bstatus,begev,deliveredlumi,recordedlumi,calibratedlumierror,bxdata,beamdata,fillnum])
            del perlsdata[:]
        result[run]=perrunresult    
    return result
Пример #15
0
def instLumiForRange(schema,inputRange,beamstatusfilter=None,withBXInfo=False,bxAlgo=None,xingMinLum=0.0,withBeamIntensity=False,lumitype='HF',branchName=None):
    '''
    DIRECTLY FROM ROOT FIME NO CORRECTION AT ALL 
    lumi raw data. beofore normalization and time integral
    input:
           inputRange  {run:[cmsls]} (required)
           beamstatus: LS filter on beamstatus (optional)
           withBXInfo: get per bunch info (optional)
           bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
           xingMinLum: cut on bx lumi value (optional)
           withBeamIntensity: get beam intensity info (optional)
           branchName: data version
    output:
           result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),instlumi(5),instlumierr(6),startorbit(7),numorbit(8),(bxidx,bxvalues,bxerrs)(9),(bxidx,b1intensities,b2intensities)(10),fillnum(11)]}}
           lumi unit: HZ/ub
    '''
    if lumitype not in ['HF','PIXEL']:
        raise ValueError('unknown lumitype '+lumitype)
    lumitableName=''
    lumilstableName=''
    if lumitype=='HF':
        lumitableName=nameDealer.lumidataTableName()
        lumilstableName=nameDealer.lumisummaryv2TableName()
    else:
        lumitableName=nameDealer.pixellumidataTableName()
        lumilstableName=nameDealer.pixellumisummaryv2TableName()
        
    result={}
    for run in inputRange.keys():
        lslist=inputRange[run]
        if lslist is not None and len(lslist)==0:
            result[run]=[]#if no LS is selected for a run
            continue
        runsummary=dataDML.runsummary(schema,run)
        if len(runsummary)==0:#if run not found in runsummary
            result[run]=None
            continue
        fillnum=runsummary[4]
        runstarttimeStr=runsummary[6]
        lumidataid=dataDML.guessLumiDataIdByRun(schema,run,lumitableName)
        if lumidataid is None: #if run not found in lumidata
            result[run]=None
            continue
        (lumirunnum,perlsresult)=dataDML.lumiLSById(schema,lumidataid,beamstatusfilter,withBXInfo=withBXInfo,bxAlgo=bxAlgo,withBeamIntensity=withBeamIntensity,tableName=lumilstableName)
        lsresult=[]
        c=lumiTime.lumiTime()
        for lumilsnum in perlsresult.keys():
            perlsdata=perlsresult[lumilsnum]
            cmslsnum=perlsdata[0]
            if lslist is not None and lumilsnum not in lslist:
                cmslsnum=0
            numorbit=perlsdata[6]
            startorbit=perlsdata[7]
            orbittime=c.OrbitToTime(runstarttimeStr,startorbit,0)
            instlumi=perlsdata[1]
            instlumierr=perlsdata[2]
            beamstatus=perlsdata[4]
            beamenergy=perlsdata[5]
            bxidxlist=[]
            bxvaluelist=[]
            bxerrorlist=[]
            bxdata=None
            beamdata=None
            if withBXInfo:
                bxinfo=perlsdata[8]                
                bxvalueArray=None
                bxerrArray=None
                if bxinfo:
                    bxvalueArray=bxinfo[0]
                    bxerrArray=bxinfo[1]
                    for idx,bxval in enumerate(bxvalueArray):
                        if bxval>xingMinLum:
                            bxidxlist.append(idx)
                            bxvaluelist.append(bxval)
                            bxerrorlist.append(bxerrArray[idx])
                    del bxvalueArray[:]
                    del bxerrArray[:]
                bxdata=(bxidxlist,bxvaluelist,bxerrorlist)
            if withBeamIntensity:
                beaminfo=perlsdata[9]
                bxindexlist=[]
                b1intensitylist=[]
                b2intensitylist=[]
                if beaminfo[0] and beaminfo[1] and beaminfo[2]:
                    bxindexarray=beaminfo[0]
                    beam1intensityarray=beaminfo[1]
                    beam2intensityarray=beaminfo[2]                    
                    bxindexlist=bxindexarray.tolist()
                    b1intensitylist=beam1intensityarray.tolist()
                    b2intensitylist=beam2intensityarray.tolist()
                    del bxindexarray[:]
                    del beam1intensityarray[:]
                    del beam2intensityarray[:]                    
                beamdata=(bxindexlist,b1intensitylist,b2intensitylist)
            lsresult.append([lumilsnum,cmslsnum,orbittime,beamstatus,beamenergy,instlumi,instlumierr,startorbit,numorbit,bxdata,beamdata,fillnum])         
            del perlsdata[:]
        result[run]=lsresult
    return result
Пример #16
0
def createTables(schema):
    '''
    create new tables if not exist
    revisions,revisions_id,luminorms,luminorms_entries,luminorms_entries_id,fillscheme
    '''
    try:
        created=[]
        db=dbUtil.dbUtil(schema)
        if not schema.existsTable(nameDealer.fillschemeTableName()):
            print('creating fillscheme table')
            fillschemeTab=coral.TableDescription()
            fillschemeTab.setName( nameDealer.fillschemeTableName() )
            fillschemeTab.insertColumn( 'FILLSCHEME_ID','unsigned long long' )
            fillschemeTab.insertColumn( 'FILLSCHEMEPATTERN','string',128,False )
            fillschemeTab.insertColumn( 'CORRECTIONFACTOR','float' )
            fillschemeTab.setPrimaryKey( 'FILLSCHEME_ID' )
            db.createTable(fillschemeTab,withIdTable=True)
            created.append( nameDealer.fillschemeTableName() )
            
        if not schema.existsTable(nameDealer.revisionTableName()):
            print('creating revisions table')
            revisionsTab=coral.TableDescription()
            revisionsTab.setName( nameDealer.revisionTableName() )
            revisionsTab.insertColumn( 'REVISION_ID','unsigned long long')
            revisionsTab.insertColumn( 'BRANCH_ID','unsigned long long')
            revisionsTab.insertColumn( 'NAME', 'string',56,False)
            revisionsTab.insertColumn( 'BRANCH_NAME', 'string',56,False)
            revisionsTab.insertColumn( 'COMMENT', 'string',1024,False)
            revisionsTab.insertColumn( 'CTIME', 'time stamp',6)
            revisionsTab.setPrimaryKey( 'REVISION_ID' )
            revisionsTab.setUniqueConstraint(('NAME'))
            db.createTable(revisionsTab,withIdTable=True)
            created.append(nameDealer.revisionTableName())
            
        if not schema.existsTable(nameDealer.luminormTableName()):
            print('creating luminorms table')
            luminormsTab=coral.TableDescription()
            luminormsTab.setName( nameDealer.luminormTableName() )
            luminormsTab.insertColumn( 'DATA_ID','unsigned long long')
            luminormsTab.insertColumn( 'ENTRY_ID','unsigned long long')
            luminormsTab.insertColumn( 'ENTRY_NAME','string',56,False)
            luminormsTab.insertColumn( 'AMODETAG', 'string',28,False)
            luminormsTab.insertColumn( 'NORM_1', 'float')
            luminormsTab.insertColumn( 'EGEV_1', 'unsigned int')
            luminormsTab.insertColumn( 'NORM_2', 'float')
            luminormsTab.insertColumn( 'EGEV_2', 'unsigned int')
            luminormsTab.setPrimaryKey( 'DATA_ID' )
            db.createTable(luminormsTab,withIdTable=True,withEntryTables=True,withRevMapTable=True)
            created.append(nameDealer.luminormTableName())
  
        if not schema.existsTable(nameDealer.lumidataTableName()):
            print('creating lumidata table')
            lumidataTab=coral.TableDescription()
            lumidataTab.setName( nameDealer.lumidataTableName() )
            lumidataTab.insertColumn( 'DATA_ID','unsigned long long')
            lumidataTab.insertColumn( 'ENTRY_ID','unsigned long long')
            lumidataTab.insertColumn( 'ENTRY_NAME','string',56,False)
            lumidataTab.insertColumn( 'SOURCE', 'string',128,False)
            lumidataTab.insertColumn( 'RUNNUM', 'unsigned int')
            lumidataTab.insertColumn( 'NOMINALEGEV', 'float')
            lumidataTab.setPrimaryKey( 'DATA_ID' )
            db.createTable(lumidataTab,withIdTable=True,withEntryTables=True,withRevMapTable=True)
            created.append(nameDealer.lumidataTableName())

        if not schema.existsTable(nameDealer.lumisummaryv2TableName() ):
            print('creating lumisummaryv2 table')
            summary=coral.TableDescription()
            summary.setName( nameDealer.lumisummaryv2TableName() )
            summary.insertColumn('DATA_ID','unsigned long long')
            summary.insertColumn('RUNNUM','unsigned int')
            summary.insertColumn('LUMILSNUM','unsigned int')
            summary.insertColumn('CMSLSNUM','unsigned int')
            summary.insertColumn('INSTLUMI','float')
            summary.insertColumn('INSTLUMIERROR','float')
            summary.insertColumn('INSTLUMIQUALITY','short')
            summary.insertColumn('BEAMSTATUS','string',28,False)
            summary.insertColumn('BEAMENERGY','float')
            summary.insertColumn('NUMORBIT','unsigned int')
            summary.insertColumn('STARTORBIT','unsigned int')
            summary.insertColumn('CMSBXINDEXBLOB','blob')
            summary.insertColumn('BEAMINTENSITYBLOB_1','blob')
            summary.insertColumn('BEAMINTENSITYBLOB_2','blob')
            summary.insertColumn('BXLUMIVALUE_OCC1','blob')
            summary.insertColumn('BXLUMIVALUE_OCC2','blob')
            summary.insertColumn('BXLUMIVALUE_ET','blob')
            summary.insertColumn('BXLUMIERROR_OCC1','blob')
            summary.insertColumn('BXLUMIERROR_OCC2','blob')
            summary.insertColumn('BXLUMIERROR_ET','blob')
            summary.insertColumn('BXLUMIQUALITY_OCC1','blob')
            summary.insertColumn('BXLUMIQUALITY_OCC2','blob')
            summary.insertColumn('BXLUMIQUALITY_ET','blob')
            summary.setPrimaryKey(('DATA_ID','LUMILSNUM'))
            db.createTable(summary,withIdTable=False)            
            created.append(nameDealer.lumisummaryv2TableName())
            
        #
        # This table exists in the old schema
        #
        if not schema.existsTable(nameDealer.cmsrunsummaryTableName()):
            print('creating cmsrunsummary table')
            cmsrunsummary=coral.TableDescription()
            cmsrunsummary.setName( nameDealer.cmsrunsummaryTableName() )
            cmsrunsummary.insertColumn('RUNNUM','unsigned int')
            cmsrunsummary.insertColumn('HLTKEY','string',128,False)
            cmsrunsummary.insertColumn('L1KEY','string',128,False)
            cmsrunsummary.insertColumn('FILLNUM','unsigned int')
            cmsrunsummary.insertColumn('SEQUENCE','string',56,False)
            cmsrunsummary.insertColumn('STARTTIME','time stamp',6)
            cmsrunsummary.insertColumn('STOPTIME','time stamp',6)
            cmsrunsummary.insertColumn('EGEV','unsigned int')
            cmsrunsummary.insertColumn('AMODETAG','string',28,False)
            cmsrunsummary.insertColumn('FILLSCHEME','string',128,False)
            cmsrunsummary.insertColumn('NCOLLIDINGBUNCHES','usigned int')
            cmsrunsummary.setPrimaryKey('RUNNUM')
            db.createTable(cmsrunsummary,withIdTable=False)
            created.append(nameDealer.cmsrunsummaryTableName())
        #
        #  This table exists in the old schema
        #
        if not schema.existsTable(nameDealer.trghltMapTableName()):
            print('creating trghltmap table')
            trghlt=coral.TableDescription()
            trghlt.setName( nameDealer.trghltMapTableName() )
            trghlt.insertColumn( 'HLTKEY','string',128,False )
            trghlt.insertColumn( 'HLTPATHNAME','string',256,False )
            trghlt.insertColumn( 'L1SEED','string' ,1024,False)
            trghlt.setNotNullConstraint('HLTKEY',True)
            trghlt.setNotNullConstraint('HLTPATHNAME',True)
            trghlt.setNotNullConstraint('L1SEED',True)
            db.createTable(trghlt,withIdTable=False)
            created.append(nameDealer.trghltMapTableName())      
        if not schema.existsTable(nameDealer.trgdataTableName()):
            print('creating trgdata table')
            trgdataTab=coral.TableDescription()
            trgdataTab.setName( nameDealer.trgdataTableName() )
            trgdataTab.insertColumn( 'DATA_ID','unsigned long long')
            trgdataTab.insertColumn( 'ENTRY_ID','unsigned long long')
            trgdataTab.insertColumn( 'ENTRY_NAME','string',56,False)
            trgdataTab.insertColumn( 'SOURCE', 'string',128,False)
            trgdataTab.insertColumn( 'RUNNUM', 'unsigned int')
            trgdataTab.insertColumn( 'BITZERONAME', 'string',56,False)
            trgdataTab.insertColumn( 'BITNAMECLOB', 'string',6000)
            trgdataTab.setPrimaryKey( 'DATA_ID' )
            db.createTable(trgdataTab,withIdTable=True,withEntryTables=True,withRevMapTable=True)
            created.append(nameDealer.trgdataTableName())
        if not schema.existsTable(nameDealer.lstrgTableName()):
            print('creating lstrg table')
            lstrgTab=coral.TableDescription()
            lstrgTab.setName( nameDealer.lstrgTableName() )
            lstrgTab.insertColumn( 'DATA_ID','unsigned long long')
            lstrgTab.insertColumn( 'RUNNUM', 'unsigned int')
            lstrgTab.insertColumn( 'CMSLSNUM', 'unsigned int')
            lstrgTab.insertColumn( 'DEADTIMECOUNT', 'unsigned long long')
            lstrgTab.insertColumn( 'BITZEROCOUNT', 'unsigned int')
            lstrgTab.insertColumn( 'BITZEROPRESCALE', 'unsigned int')
            lstrgTab.insertColumn( 'DEADFRAC', 'float')
            lstrgTab.insertColumn( 'PRESCALEBLOB', 'blob')
            lstrgTab.insertColumn( 'TRGCOUNTBLOB', 'blob')
            lstrgTab.setPrimaryKey( ('DATA_ID','CMSLSNUM') )
            db.createTable(lstrgTab,withIdTable=False)            
            created.append( nameDealer.lstrgTableName() )

        if not schema.existsTable(nameDealer.hltdataTableName()):
            print('creating hltdata table')
            hltdataTab=coral.TableDescription()
            hltdataTab.setName( nameDealer.hltdataTableName() )
            hltdataTab.insertColumn( 'DATA_ID','unsigned long long')
            hltdataTab.insertColumn( 'ENTRY_ID','unsigned long long')
            hltdataTab.insertColumn( 'ENTRY_NAME','string',56,False)
            hltdataTab.insertColumn( 'RUNNUM', 'unsigned int')
            hltdataTab.insertColumn( 'SOURCE', 'string',128,False)
            hltdataTab.insertColumn( 'NPATH', 'unsigned int')
            hltdataTab.insertColumn( 'PATHNAMECLOB', 'string',6000)
            hltdataTab.setPrimaryKey( 'DATA_ID' )
            db.createTable(hltdataTab,withIdTable=True,withEntryTables=True,withRevMapTable=True)
            created.append(nameDealer.hltTableName())
            
        if not schema.existsTable(nameDealer.lshltTableName()):
            print('creating lshlt table')
            lshltTab=coral.TableDescription()
            lshltTab.setName( nameDealer.lshltTableName() )
            lshltTab.insertColumn( 'DATA_ID','unsigned long long')
            lshltTab.insertColumn( 'RUNNUM', 'unsigned int')
            lshltTab.insertColumn( 'CMSLSNUM', 'unsigned int')
            lshltTab.insertColumn( 'PRESCALEBLOB', 'blob')
            lshltTab.insertColumn( 'HLTCOUNTBLOB', 'blob')
            lshltTab.insertColumn( 'HLTACCEPTBLOB', 'blob')
            db.createTable(lshltTab,withIdTable=False)
            lshltTab.setPrimaryKey( ('DATA_ID','CMSLSNUM') )
            created.append(nameDealer.lshltTableName())          

            
        if not schema.existsTable(nameDealer.lumivalidationTableName()):
            print('creating lumivalidation  table')
            lumivalidation=coral.TableDescription()
            lumivalidation.setName( nameDealer.lumivalidationTableName() )
            lumivalidation.insertColumn( 'RUNNUM','unsigned int' )
            lumivalidation.insertColumn( 'CMSLSNUM','unsigned int' )
            lumivalidation.insertColumn( 'FLAG','string',28,False )
            lumivalidation.insertColumn( 'COMMENT','string',1024,False )
            lumivalidation.setPrimaryKey( ('RUNNUM','CMSLSNUM') )
            lumivalidation.setNotNullConstraint('FLAG',True)
            db.createTable(lumivalidation,withIdTable=False)
            created.append(nameDealer.lumivalidationTableName())
        return created
    except :
        raise 
Пример #17
0
 svc=sessionManager.sessionManager(myconstr,debugON=False)
 session=svc.openSession(isReadOnly=False,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
 schema=session.nominalSchema()
 session.transaction().start(False)
 tables=lumidbDDL.createTables(schema)
 trunkinfo=createBranch(schema,'TRUNK',None,comment='main')
 #print trunkinfo
 datainfo=createBranch(schema,'DATA','TRUNK',comment='hold data')
 #print datainfo
 norminfo=createBranch(schema,'NORM','TRUNK',comment='hold normalization factor')
 #print norminfo
 (branchid,branchparent)=branchInfoByName(schema,'DATA')
 databranchinfo=(branchid,'DATA')
 print databranchinfo
 for runnum in [1200,1211,1222,1233,1345,1222,1200]:
     lumientryid=entryInBranch(schema,nameDealer.lumidataTableName(),str(runnum),'DATA')
     trgentryid=entryInBranch(schema,nameDealer.trgdataTableName(),str(runnum),'DATA')
     hltentryid=entryInBranch(schema,nameDealer.hltdataTableName(),str(runnum),'DATA')
     if lumientryid is None:
         (revision_id,entry_id,data_id)=bookNewEntry( schema,nameDealer.lumidataTableName() )
         entryinfo=(revision_id,entry_id,str(runnum),data_id)
         addEntry(schema,nameDealer.lumidataTableName(),entryinfo,databranchinfo)
         #add data here
     else:
         revisioninfo=bookNewRevision( schema,nameDealer.lumidataTableName() )
         addRevision(schema,nameDealer.lumidataTableName(),revisioninfo,databranchinfo)
         #add data here
     if trgentryid is None:
         (revision_id,entry_id,data_id)=bookNewEntry( schema,nameDealer.trgdataTableName() )
         entryinfo=(revision_id,entry_id,str(runnum),data_id)
         addEntry(schema,nameDealer.trgdataTableName(),entryinfo,databranchinfo)
Пример #18
0
def createTables(schema):
    '''
    create new tables if not exist
    revisions,revisions_id,luminorms,luminorms_entries,luminorms_entries_id,fillscheme
    '''
    try:
        created = []
        db = dbUtil.dbUtil(schema)
        if not schema.existsTable(nameDealer.fillschemeTableName()):
            print('creating fillscheme table')
            fillschemeTab = coral.TableDescription()
            fillschemeTab.setName(nameDealer.fillschemeTableName())
            fillschemeTab.insertColumn('FILLSCHEME_ID', 'unsigned long long')
            fillschemeTab.insertColumn('FILLSCHEMEPATTERN', 'string', 128,
                                       False)
            fillschemeTab.insertColumn('CORRECTIONFACTOR', 'float')
            fillschemeTab.setPrimaryKey('FILLSCHEME_ID')
            db.createTable(fillschemeTab, withIdTable=True)
            created.append(nameDealer.fillschemeTableName())

        if not schema.existsTable(nameDealer.revisionTableName()):
            print('creating revisions table')
            revisionsTab = coral.TableDescription()
            revisionsTab.setName(nameDealer.revisionTableName())
            revisionsTab.insertColumn('REVISION_ID', 'unsigned long long')
            revisionsTab.insertColumn('BRANCH_ID', 'unsigned long long')
            revisionsTab.insertColumn('NAME', 'string', 56, False)
            revisionsTab.insertColumn('BRANCH_NAME', 'string', 56, False)
            revisionsTab.insertColumn('COMMENT', 'string', 1024, False)
            revisionsTab.insertColumn('CTIME', 'time stamp', 6)
            revisionsTab.setPrimaryKey('REVISION_ID')
            revisionsTab.setUniqueConstraint(('NAME'))
            db.createTable(revisionsTab, withIdTable=True)
            created.append(nameDealer.revisionTableName())

        if not schema.existsTable(nameDealer.luminormTableName()):
            print('creating luminorms table')
            luminormsTab = coral.TableDescription()
            luminormsTab.setName(nameDealer.luminormTableName())
            luminormsTab.insertColumn('DATA_ID', 'unsigned long long')
            luminormsTab.insertColumn('ENTRY_ID', 'unsigned long long')
            luminormsTab.insertColumn('ENTRY_NAME', 'string', 56, False)
            luminormsTab.insertColumn('AMODETAG', 'string', 28, False)
            luminormsTab.insertColumn('NORM_1', 'float')
            luminormsTab.insertColumn('EGEV_1', 'unsigned int')
            luminormsTab.insertColumn('NORM_2', 'float')
            luminormsTab.insertColumn('EGEV_2', 'unsigned int')
            luminormsTab.setPrimaryKey('DATA_ID')
            db.createTable(luminormsTab,
                           withIdTable=True,
                           withEntryTables=True,
                           withRevMapTable=True)
            created.append(nameDealer.luminormTableName())

        if not schema.existsTable(nameDealer.lumidataTableName()):
            print('creating lumidata table')
            lumidataTab = coral.TableDescription()
            lumidataTab.setName(nameDealer.lumidataTableName())
            lumidataTab.insertColumn('DATA_ID', 'unsigned long long')
            lumidataTab.insertColumn('ENTRY_ID', 'unsigned long long')
            lumidataTab.insertColumn('ENTRY_NAME', 'string', 56, False)
            lumidataTab.insertColumn('SOURCE', 'string', 128, False)
            lumidataTab.insertColumn('RUNNUM', 'unsigned int')
            lumidataTab.insertColumn('NOMINALEGEV', 'float')
            lumidataTab.setPrimaryKey('DATA_ID')
            db.createTable(lumidataTab,
                           withIdTable=True,
                           withEntryTables=True,
                           withRevMapTable=True)
            created.append(nameDealer.lumidataTableName())

        if not schema.existsTable(nameDealer.lumisummaryv2TableName()):
            print('creating lumisummaryv2 table')
            summary = coral.TableDescription()
            summary.setName(nameDealer.lumisummaryv2TableName())
            summary.insertColumn('DATA_ID', 'unsigned long long')
            summary.insertColumn('RUNNUM', 'unsigned int')
            summary.insertColumn('LUMILSNUM', 'unsigned int')
            summary.insertColumn('CMSLSNUM', 'unsigned int')
            summary.insertColumn('INSTLUMI', 'float')
            summary.insertColumn('INSTLUMIERROR', 'float')
            summary.insertColumn('INSTLUMIQUALITY', 'short')
            summary.insertColumn('BEAMSTATUS', 'string', 28, False)
            summary.insertColumn('BEAMENERGY', 'float')
            summary.insertColumn('NUMORBIT', 'unsigned int')
            summary.insertColumn('STARTORBIT', 'unsigned int')
            summary.insertColumn('CMSBXINDEXBLOB', 'blob')
            summary.insertColumn('BEAMINTENSITYBLOB_1', 'blob')
            summary.insertColumn('BEAMINTENSITYBLOB_2', 'blob')
            summary.insertColumn('BXLUMIVALUE_OCC1', 'blob')
            summary.insertColumn('BXLUMIVALUE_OCC2', 'blob')
            summary.insertColumn('BXLUMIVALUE_ET', 'blob')
            summary.insertColumn('BXLUMIERROR_OCC1', 'blob')
            summary.insertColumn('BXLUMIERROR_OCC2', 'blob')
            summary.insertColumn('BXLUMIERROR_ET', 'blob')
            summary.insertColumn('BXLUMIQUALITY_OCC1', 'blob')
            summary.insertColumn('BXLUMIQUALITY_OCC2', 'blob')
            summary.insertColumn('BXLUMIQUALITY_ET', 'blob')
            summary.setPrimaryKey(('DATA_ID', 'LUMILSNUM'))
            db.createTable(summary, withIdTable=False)
            created.append(nameDealer.lumisummaryv2TableName())

        #
        # This table exists in the old schema
        #
        if not schema.existsTable(nameDealer.cmsrunsummaryTableName()):
            print('creating cmsrunsummary table')
            cmsrunsummary = coral.TableDescription()
            cmsrunsummary.setName(nameDealer.cmsrunsummaryTableName())
            cmsrunsummary.insertColumn('RUNNUM', 'unsigned int')
            cmsrunsummary.insertColumn('HLTKEY', 'string', 128, False)
            cmsrunsummary.insertColumn('L1KEY', 'string', 128, False)
            cmsrunsummary.insertColumn('FILLNUM', 'unsigned int')
            cmsrunsummary.insertColumn('SEQUENCE', 'string', 56, False)
            cmsrunsummary.insertColumn('STARTTIME', 'time stamp', 6)
            cmsrunsummary.insertColumn('STOPTIME', 'time stamp', 6)
            cmsrunsummary.insertColumn('EGEV', 'unsigned int')
            cmsrunsummary.insertColumn('AMODETAG', 'string', 28, False)
            cmsrunsummary.insertColumn('FILLSCHEME', 'string', 128, False)
            cmsrunsummary.insertColumn('NCOLLIDINGBUNCHES', 'usigned int')
            cmsrunsummary.setPrimaryKey('RUNNUM')
            db.createTable(cmsrunsummary, withIdTable=False)
            created.append(nameDealer.cmsrunsummaryTableName())
        #
        #  This table exists in the old schema
        #
        if not schema.existsTable(nameDealer.trghltMapTableName()):
            print('creating trghltmap table')
            trghlt = coral.TableDescription()
            trghlt.setName(nameDealer.trghltMapTableName())
            trghlt.insertColumn('HLTKEY', 'string', 128, False)
            trghlt.insertColumn('HLTPATHNAME', 'string', 256, False)
            trghlt.insertColumn('L1SEED', 'string', 1024, False)
            trghlt.setNotNullConstraint('HLTKEY', True)
            trghlt.setNotNullConstraint('HLTPATHNAME', True)
            trghlt.setNotNullConstraint('L1SEED', True)
            db.createTable(trghlt, withIdTable=False)
            created.append(nameDealer.trghltMapTableName())
        if not schema.existsTable(nameDealer.trgdataTableName()):
            print('creating trgdata table')
            trgdataTab = coral.TableDescription()
            trgdataTab.setName(nameDealer.trgdataTableName())
            trgdataTab.insertColumn('DATA_ID', 'unsigned long long')
            trgdataTab.insertColumn('ENTRY_ID', 'unsigned long long')
            trgdataTab.insertColumn('ENTRY_NAME', 'string', 56, False)
            trgdataTab.insertColumn('SOURCE', 'string', 128, False)
            trgdataTab.insertColumn('RUNNUM', 'unsigned int')
            trgdataTab.insertColumn('BITZERONAME', 'string', 56, False)
            trgdataTab.insertColumn('BITNAMECLOB', 'string', 6000)
            trgdataTab.setPrimaryKey('DATA_ID')
            db.createTable(trgdataTab,
                           withIdTable=True,
                           withEntryTables=True,
                           withRevMapTable=True)
            created.append(nameDealer.trgdataTableName())
        if not schema.existsTable(nameDealer.lstrgTableName()):
            print('creating lstrg table')
            lstrgTab = coral.TableDescription()
            lstrgTab.setName(nameDealer.lstrgTableName())
            lstrgTab.insertColumn('DATA_ID', 'unsigned long long')
            lstrgTab.insertColumn('RUNNUM', 'unsigned int')
            lstrgTab.insertColumn('CMSLSNUM', 'unsigned int')
            lstrgTab.insertColumn('DEADTIMECOUNT', 'unsigned long long')
            lstrgTab.insertColumn('BITZEROCOUNT', 'unsigned int')
            lstrgTab.insertColumn('BITZEROPRESCALE', 'unsigned int')
            lstrgTab.insertColumn('DEADFRAC', 'float')
            lstrgTab.insertColumn('PRESCALEBLOB', 'blob')
            lstrgTab.insertColumn('TRGCOUNTBLOB', 'blob')
            lstrgTab.setPrimaryKey(('DATA_ID', 'CMSLSNUM'))
            db.createTable(lstrgTab, withIdTable=False)
            created.append(nameDealer.lstrgTableName())

        if not schema.existsTable(nameDealer.hltdataTableName()):
            print('creating hltdata table')
            hltdataTab = coral.TableDescription()
            hltdataTab.setName(nameDealer.hltdataTableName())
            hltdataTab.insertColumn('DATA_ID', 'unsigned long long')
            hltdataTab.insertColumn('ENTRY_ID', 'unsigned long long')
            hltdataTab.insertColumn('ENTRY_NAME', 'string', 56, False)
            hltdataTab.insertColumn('RUNNUM', 'unsigned int')
            hltdataTab.insertColumn('SOURCE', 'string', 128, False)
            hltdataTab.insertColumn('NPATH', 'unsigned int')
            hltdataTab.insertColumn('PATHNAMECLOB', 'string', 6000)
            hltdataTab.setPrimaryKey('DATA_ID')
            db.createTable(hltdataTab,
                           withIdTable=True,
                           withEntryTables=True,
                           withRevMapTable=True)
            created.append(nameDealer.hltTableName())

        if not schema.existsTable(nameDealer.lshltTableName()):
            print('creating lshlt table')
            lshltTab = coral.TableDescription()
            lshltTab.setName(nameDealer.lshltTableName())
            lshltTab.insertColumn('DATA_ID', 'unsigned long long')
            lshltTab.insertColumn('RUNNUM', 'unsigned int')
            lshltTab.insertColumn('CMSLSNUM', 'unsigned int')
            lshltTab.insertColumn('PRESCALEBLOB', 'blob')
            lshltTab.insertColumn('HLTCOUNTBLOB', 'blob')
            lshltTab.insertColumn('HLTACCEPTBLOB', 'blob')
            db.createTable(lshltTab, withIdTable=False)
            lshltTab.setPrimaryKey(('DATA_ID', 'CMSLSNUM'))
            created.append(nameDealer.lshltTableName())

        if not schema.existsTable(nameDealer.lumivalidationTableName()):
            print('creating lumivalidation  table')
            lumivalidation = coral.TableDescription()
            lumivalidation.setName(nameDealer.lumivalidationTableName())
            lumivalidation.insertColumn('RUNNUM', 'unsigned int')
            lumivalidation.insertColumn('CMSLSNUM', 'unsigned int')
            lumivalidation.insertColumn('FLAG', 'string', 28, False)
            lumivalidation.insertColumn('COMMENT', 'string', 1024, False)
            lumivalidation.setPrimaryKey(('RUNNUM', 'CMSLSNUM'))
            lumivalidation.setNotNullConstraint('FLAG', True)
            db.createTable(lumivalidation, withIdTable=False)
            created.append(nameDealer.lumivalidationTableName())
        return created
    except:
        raise