def addRunToCurrentDataTag(schema,runnum,lumiid,trgid,hltid,lumitype='HF',comment=''): ''' select tagid from tags insert into tagruns(tagid,runnum,lumidataid,trgdataid,hltdataid,creationtime,comment) values(tagid,runnum,lumiid,trgid,hltid,creationtime,comment) ''' if lumitype not in ['HF','PIXEL']: raise ValueError('unknown lumitype '+lumitype) if lumitype=='HF': tagrunstablename=nameDealer.tagRunsTableName() else: tagrunstablename=nameDealer.pixeltagRunsTableName() currenttagid=currentDataTag(schema,lumitype=lumitype)[0] try: db=dbUtil.dbUtil(schema) tabrowDefDict={} tabrowDefDict['TAGID']='unsigned long long' tabrowDefDict['RUNNUM']='unsigned int' tabrowDefDict['LUMIDATAID']='unsigned long long' tabrowDefDict['TRGDATAID']='unsigned long long' tabrowDefDict['HLTDATAID']='unsigned long long' tabrowDefDict['CREATIONTIME']='time stamp' tabrowDefDict['COMMENT']='string' tabrowValueDict={} tabrowValueDict['TAGID']=currenttagid tabrowValueDict['RUNNUM']=runnum tabrowValueDict['LUMIDATAID']=lumiid tabrowValueDict['TRGDATAID']=trgid tabrowValueDict['HLTDATAID']=hltid tabrowValueDict['CREATIONTIME']=coral.TimeStamp() tabrowValueDict['COMMENT']=comment db.insertOneRow( tagrunstablename,tabrowDefDict, tabrowValueDict ) except: raise
def getrunsInCurrentData(schema, minrun=132440, maxrun=500000): ''' get runs in data tables in specified range output: [runnum] select runnum,tagid from tagruns where runnum>=:minrun and runnum<=:maxrun; ''' tmpresult = {} qHandle = schema.newQuery() try: qHandle.addToTableList(nameDealer.tagRunsTableName()) qHandle.addToOutputList('RUNNUM') qHandle.addToOutputList('TAGID') qCondition = coral.AttributeList() qCondition.extend('minrun', 'unsigned int') qCondition.extend('maxrun', 'unsigned int') qCondition['minrun'].setData(minrun) qCondition['maxrun'].setData(maxrun) qResult = coral.AttributeList() qResult.extend('RUNNUM', 'unsigned int') qResult.extend('TAGID', 'unsigned long long') qHandle.defineOutput(qResult) qHandle.setCondition('RUNNUM>=:minrun AND RUNNUM<=:maxrun', qCondition) cursor = qHandle.execute() while cursor.next(): runnum = cursor.currentRow()['RUNNUM'].data() tagid = cursor.currentRow()['TAGID'].data() if runnum not in tmpresult: tmpresult[runnum] = tagid else: if tagid > tmpresult[runnum]: tmpresult[runnum] = tagid del qHandle except: if qHandle: del qHandle raise if tmpresult: return tmpresult.keys() return []
def getrunsInCurrentData(schema,minrun=132440,maxrun=500000): ''' get runs in data tables in specified range output: [runnum] select runnum,tagid from tagruns where runnum>=:minrun and runnum<=:maxrun; ''' tmpresult={} qHandle=schema.newQuery() try: qHandle.addToTableList( nameDealer.tagRunsTableName() ) qHandle.addToOutputList('RUNNUM') qHandle.addToOutputList('TAGID') qCondition=coral.AttributeList() qCondition.extend('minrun','unsigned int') qCondition.extend('maxrun','unsigned int') qCondition['minrun'].setData(minrun) qCondition['maxrun'].setData(maxrun) qResult=coral.AttributeList() qResult.extend('RUNNUM','unsigned int') qResult.extend('TAGID','unsigned long long') qHandle.defineOutput(qResult) qHandle.setCondition('RUNNUM>=:minrun AND RUNNUM<=:maxrun',qCondition) cursor=qHandle.execute() while next(cursor): runnum=cursor.currentRow()['RUNNUM'].data() tagid=cursor.currentRow()['TAGID'].data() if runnum not in tmpresult: tmpresult[runnum]=tagid else: if tagid>tmpresult[runnum]: tmpresult[runnum]=tagid del qHandle except: if qHandle:del qHandle raise if tmpresult:return tmpresult.keys() return []
def dataIdsByTagId(schema,tagid,runlist=None,withcomment=False,lumitype='HF'): ''' select runnum,lumidataid,trgdataid,hltdataid,comment from tagruns where TAGID<=:tagid; 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': tagrunstablename=nameDealer.tagRunsTableName() else: tagrunstablename=nameDealer.pixeltagRunsTableName() result={}#{run:[lumiid,trgid,hltid,comment(optional)]} commentdict={}#{(lumiid,trgid,hltid):[ctimestr,comment]} try: qHandle=schema.newQuery() qHandle.addToTableList(tagrunstablename) qConditionStr='TAGID<=:tagid' qCondition=coral.AttributeList() qCondition.extend('tagid','unsigned long long') qCondition['tagid'].setData(tagid) qResult=coral.AttributeList() qResult.extend('RUNNUM','unsigned int') qResult.extend('LUMIDATAID','unsigned long long') qResult.extend('TRGDATAID','unsigned long long') qResult.extend('HLTDATAID','unsigned long long') if withcomment: qResult.extend('COMMENT','string') qResult.extend('creationtime','string') qHandle.defineOutput(qResult) qHandle.setCondition(qConditionStr,qCondition) qHandle.addToOutputList('RUNNUM') qHandle.addToOutputList('LUMIDATAID') qHandle.addToOutputList('TRGDATAID') qHandle.addToOutputList('HLTDATAID') if withcomment: qHandle.addToOutputList('COMMENT') qHandle.addToOutputList("TO_CHAR(CREATIONTIME,\'MM/DD/YY HH24:MI:SS\')",'creationtime') cursor=qHandle.execute() while next(cursor): runnum=cursor.currentRow()['RUNNUM'].data() if runlist is not None and runnum not in runlist: continue lumidataid=0 if not cursor.currentRow()['LUMIDATAID'].isNull(): lumidataid=cursor.currentRow()['LUMIDATAID'].data() trgdataid=0 if not cursor.currentRow()['TRGDATAID'].isNull(): trgdataid=cursor.currentRow()['TRGDATAID'].data() hltdataid=0 if not cursor.currentRow()['HLTDATAID'].isNull(): hltdataid=cursor.currentRow()['HLTDATAID'].data() if runnum not in result: result[runnum]=[0,0,0] if lumidataid>result[runnum][0]: result[runnum][0]=lumidataid if trgdataid>result[runnum][1]: result[runnum][1]=trgdataid if hltdataid>result[runnum][2]: result[runnum][2]=hltdataid if withcomment: comment='' creationtime='' if not cursor.currentRow()['creationtime'].isNull(): creationtime=cursor.currentRow()['creationtime'].data() if not cursor.currentRow()['COMMENT'].isNull(): comment=cursor.currentRow()['COMMENT'].data() commentdict[(lumidataid,trgdataid,hltdataid)]=(creationtime,comment) del qHandle if withcomment: for run,resultentry in result.items(): lumiid=resultentry[0] trgid=resultentry[1] hltid=resultentry[2] if (lumiid,trgid,hltid) in commentdict: resultentry.append(commentdict[(lumiid,trgid,hltid)]) elif (lumiid,0,0) in commentdict: resultentry.append(commentdict[(lumiid,0,0)]) elif commentdict.has_ley((0,trgid,0)): resultentry.append(commentdict[(0,trgid,0)]) elif commentdict.has_ley((0,0,hltid)): resultentry.append(commentdict[(0,0,hltid)]) else: resultentry.append(()) except: raise return result
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
inputfilename = os.path.abspath(options.inputfile) lumidatafromfile = lumiDataFromfile(inputfilename) sourcesvc = sessionManager.sessionManager(options.sourcestr, authpath=options.authpath, debugON=False) sourcesession = sourcesvc.openSession(isReadOnly=True, cpp2sqltype=[('unsigned int', 'NUMBER(10)'), ('unsigned long long', 'NUMBER(20)')]) sourcesession.transaction().start(True) qHandle = sourcesession.nominalSchema().newQuery() sourcetagid = 0 sourcelumiid = 0 try: qHandle.addToTableList(nameDealer.tagRunsTableName()) qHandle.addToOutputList('TAGID') qHandle.addToOutputList('LUMIDATAID') qCondition = coral.AttributeList() qCondition.extend('runnum', 'unsigned int') qCondition['runnum'].setData(int(options.runnum)) qResult = coral.AttributeList() qResult.extend('TAGID', 'unsigned long long') qResult.extend('LUMIDATAID', 'unsigned long long') qHandle.defineOutput(qResult) qHandle.setCondition('RUNNUM=:runnum', qCondition) cursor = qHandle.execute() while next(cursor): tagid = 0 if not cursor.currentRow()['TAGID'].isNull(): tagid = cursor.currentRow()['TAGID'].data()
parser.add_argument('--debug',dest='debug',action='store_true', help='debug' ) options=parser.parse_args() begLS=int(options.begLS) endLS=int(options.endLS) inputfilename=os.path.abspath(options.inputfile) lumidatafromfile=lumiDataFromfile(inputfilename) sourcesvc=sessionManager.sessionManager(options.sourcestr,authpath=options.authpath,debugON=False) sourcesession=sourcesvc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')]) sourcesession.transaction().start(True) qHandle=sourcesession.nominalSchema().newQuery() sourcetagid=0 sourcelumiid=0 try: qHandle.addToTableList( nameDealer.tagRunsTableName() ) qHandle.addToOutputList('TAGID') qHandle.addToOutputList('LUMIDATAID') qCondition=coral.AttributeList() qCondition.extend('runnum','unsigned int') qCondition['runnum'].setData(int(options.runnum)) qResult=coral.AttributeList() qResult.extend('TAGID','unsigned long long') qResult.extend('LUMIDATAID','unsigned long long') qHandle.defineOutput(qResult) qHandle.setCondition('RUNNUM=:runnum',qCondition) cursor=qHandle.execute() while next(cursor): tagid=0 if not cursor.currentRow()['TAGID'].isNull(): tagid=cursor.currentRow()['TAGID'].data()