Пример #1
0
def getDataTagId(schema,tagname,lumitype='HF'):
    '''
    select tagid from tags where tagname=:tagname
    '''
    if lumitype not in ['HF','PIXEL']:
        raise ValueError('unknown lumitype '+lumitype)
    if lumitype=='HF':
        tagstablename=nameDealer.tagsTableName()
    else:
        tagstablename=nameDealer.pixeltagsTableName()        
    tagid=None
    try:
        qHandle=schema.newQuery()
        qHandle.addToTableList( tagstablename )
        qConditionStr='TAGNAME=:tagname'
        qCondition=coral.AttributeList()
        qCondition.extend('tagname','string')
        qCondition['tagname'].setData(tagname)
        qHandle.addToOutputList('TAGID')
        qResult=coral.AttributeList()        
        qResult.extend('TAGID','unsigned long long')
        qHandle.defineOutput(qResult)
        qHandle.setCondition(qConditionStr,qCondition)
        cursor=qHandle.execute()
        while next(cursor):
            if not cursor.currentRow()['TAGID'].isNull():
                tagid=cursor.currentRow()['TAGID'].data()
        del qHandle
    except:
        raise
    return tagid
Пример #2
0
def currentDataTag(schema,lumitype='HF'):
    '''
    select tagid,tagname from tags
    output:(tagid,tagname)
    '''
    if lumitype not in ['HF','PIXEL']:
        raise ValueError('unknown lumitype '+lumitype)
    if lumitype=='HF':
        tagstablename=nameDealer.tagsTableName()
    else:
        tagstablename=nameDealer.pixeltagsTableName()
    tagmap={}
    try:
        qHandle=schema.newQuery()
        qHandle.addToTableList( tagstablename )
        qHandle.addToOutputList('TAGID')
        qHandle.addToOutputList('TAGNAME')
        qResult=coral.AttributeList()
        qResult.extend('TAGID','unsigned long long')
        qResult.extend('TAGNAME','string')
        qHandle.defineOutput(qResult)
        cursor=qHandle.execute()
        currenttagid=0
        while next(cursor):
            tagid=cursor.currentRow()['TAGID'].data()
            tagname=cursor.currentRow()['TAGNAME'].data()
            tagmap[tagid]=tagname
        del qHandle
        if len(tagmap)!=0:
            currenttagid=max(tagmap.keys())
        if currenttagid==0:
            raise 'currentDataTag: no tag available'
        return (currenttagid,tagmap[currenttagid])
    except:
        raise
Пример #3
0
def createDataTag(schema,tagname,lumitype='HF'):
    '''
    insert into tags(tagname,tagid,creationtime) values()
    output:
        tagname,tagid,creationtime
    '''
    if lumitype not in ['HF','PIXEL']:
        raise ValueError('unknown lumitype '+lumitype)
    if lumitype=='HF':
        tagstablename=nameDealer.tagsTableName()
    else:
        tagstablename=nameDealer.pixeltagsTableName()
    try:
        iddealer=idDealer.idDealer(schema)
        tagid=iddealer.generateNextIDForTable( tagstablename )
        db=dbUtil.dbUtil(schema)
        tabrowDefDict={}
        tabrowDefDict['TAGNAME']='string'
        tabrowDefDict['TAGID']='unsigned long long'
        tabrowDefDict['CREATIONTIME']='time stamp'
        tabrowValueDict={}
        tabrowValueDict['TAGNAME']=tagname
        tabrowValueDict['TAGID']=tagid
        creationtime=coral.TimeStamp()
        tabrowValueDict['CREATIONTIME']=creationtime
        db.insertOneRow(tagstablename,tabrowDefDict, tabrowValueDict )
        return (tagname,tagid,creationtime)
    except:
        raise
def dataIdsByTagName(schema,
                     tagname,
                     runlist=None,
                     withcomment=False,
                     lumitype='HF'):
    '''
    select tagid from tags where tagname=:tagname
    input:
        runlist: select run list, if None, all
    output:
        {run:(lumidataid,trgdataid,hltdataid,(creationtime,comment)}
    '''
    if lumitype not in ['HF', 'PIXEL']:
        raise ValueError('unknown lumitype ' + lumitype)
    if lumitype == 'HF':
        tagstablename = nameDealer.tagsTableName()
    else:
        tagstablename = nameDealer.pixeltagsTableName()
    tagid = None
    try:
        qHandle = schema.newQuery()
        qHandle.addToTableList(tagstablename)
        qConditionStr = 'TAGNAME=:tagname'
        qCondition = coral.AttributeList()
        qCondition.extend('tagname', 'string')
        qCondition['tagname'].setData(tagname)
        qHandle.addToOutputList('TAGID')
        qResult = coral.AttributeList()
        qResult.extend('TAGID', 'unsigned long long')
        qHandle.defineOutput(qResult)
        qHandle.setCondition(qConditionStr, qCondition)
        cursor = qHandle.execute()
        while cursor.next():
            if not cursor.currentRow()['TAGID'].isNull():
                tagid = cursor.currentRow()['TAGID'].data()
        del qHandle
    except:
        raise
    if tagid is None:
        return {}
    return dataIdsByTagId(schema,
                          tagid,
                          runlist=runlist,
                          withcomment=withcomment,
                          lumitype=lumitype)
Пример #5
0
def dataIdsByTagName(schema,tagname,runlist=None,withcomment=False,lumitype='HF'):
    '''
    select tagid from tags where tagname=:tagname
    input:
        runlist: select run list, if None, all
    output:
        {run:(lumidataid,trgdataid,hltdataid,(creationtime,comment)}
    '''
    if lumitype not in ['HF','PIXEL']:
        raise ValueError('unknown lumitype '+lumitype)
    if lumitype=='HF':
        tagstablename=nameDealer.tagsTableName()
    else:
        tagstablename=nameDealer.pixeltagsTableName()        
    tagid=None
    try:
        qHandle=schema.newQuery()
        qHandle.addToTableList( tagstablename )
        qConditionStr='TAGNAME=:tagname'
        qCondition=coral.AttributeList()
        qCondition.extend('tagname','string')
        qCondition['tagname'].setData(tagname)
        qHandle.addToOutputList('TAGID')
        qResult=coral.AttributeList()        
        qResult.extend('TAGID','unsigned long long')
        qHandle.defineOutput(qResult)
        qHandle.setCondition(qConditionStr,qCondition)
        cursor=qHandle.execute()
        while next(cursor):
            if not cursor.currentRow()['TAGID'].isNull():
                tagid=cursor.currentRow()['TAGID'].data()
        del qHandle
    except:
        raise
    if tagid is None:
        return {}
    return dataIdsByTagId(schema,tagid,runlist=runlist,withcomment=withcomment,lumitype=lumitype)
Пример #6
0
def dataTagInfo(schema,tagname,runlist=None,lumitype='HF'):
    '''
    select tagid from tags where tagname=:tagname
    select runnum,comment from tagruns where tagid<=:tagid
    input:
        runlist: select run list, if None, all
    output:
       {tagid:(name,minrun,maxrun,creationtime)}
    '''
    if lumitype not in ['HF','PIXEL']:
        raise ValueError('unknown lumitype '+lumitype)
    if lumitype=='HF':
        tagstablename=nameDealer.tagsTableName()
        tagrunstablename=nameDealer.tagRunsTableName()
    else:
        tagstablename=nameDealer.pixeltagsTableName()
        tagrunstablename=nameDealer.pixeltagRunsTableName()
    tagmap={}#{tagid:[tagname,minrun,maxrun,creationtime]}
    try:
        qHandle=schema.newQuery()
        qHandle.addToTableList( tagstablename )
        qCondition=coral.AttributeList()
        qHandle.addToOutputList('TAGNAME')
        qHandle.addToOutputList('TAGID')
        qHandle.addToOutputList("TO_CHAR(CREATIONTIME,\'MM/DD/YY HH24:MI:SS\')",'creationtime')
        qResult=coral.AttributeList()        
        qResult.extend('TAGNAME','string')
        qResult.extend('TAGID','unsigned long long')
        qResult.extend('creationtime','string')
        qHandle.defineOutput(qResult)
        cursor=qHandle.execute()
        while next(cursor):
            tagname=cursor.currentRow()['TAGNAME'].data()
            tagid=cursor.currentRow()['TAGID'].data()
            creationtime=cursor.currentRow()['creationtime'].data()
            tagmap[tagid]=[tagname,0,0,creationtime]
        del qHandle
        
        tagids=tagmap.keys()
        allruns=set()
        for tagid in tagids:
            qConditionStr='TAGID<=:tagid'
            qCondition=coral.AttributeList()
            qCondition.extend('tagid','unsigned long long')
            qCondition['tagid'].setData(tagid)
            qHandle=schema.newQuery()
            qHandle.addToTableList(tagrunstablename)
            qResult=coral.AttributeList()
            qResult.extend('RUNNUM','unsigned int')
            qHandle.defineOutput(qResult)
            qHandle.setCondition(qConditionStr,qCondition)
            qHandle.addToOutputList('RUNNUM')
            cursor=qHandle.execute()
            while next(cursor):
                rnum=cursor.currentRow()['RUNNUM'].data()
                if runlist is not None and rnum not in runlist:
                    continue
                allruns.add(rnum)
            minrun=0
            maxrun=0
            if len(allruns)!=0:
                minrun=min(allruns)
                maxrun=max(allruns)
            tagmap[tagid][1]=minrun
            if len(tagmap)>1 and tagid!=max(tagids):
                tagmap[tagid][2]=maxrun   
    except:
        raise
    return tagmap