def addindb(session, datatag, normtag, lumidata, bulksize): ''' input : [fill,run,lumils,cmsls,lstime,beamstatus,beamenergy,delivered,recorded,avgpu] ''' hfresultDefDict = [('RUNNUM', 'unsigned int'), ('LS', 'unsigned int'), ('CMSLS', 'unsigned int'), ('FILLNUM', 'unsigned int'), ('TIME', 'time stamp'), ('BEAM_STATUS', 'string'), ('ENERGY', 'unsigned int'), ('DELIVERED', 'float'), ('RECORDED', 'float'), ('AVG_PU', 'float'), ('DATA_VERSION', 'string'), ('NORM_VERSION', 'string'), ('INSERT_TIME', 'time stamp')] committedrows = 0 nrows = 0 bulkvalues = [] lute = lumiTime.lumiTime() try: for datum in lumidata: [ fillnum, runnum, lumils, cmsls, lstime_char, beamstatus, beamenergy, delivered, recorded, avgpu ] = datum inserttime = coral.TimeStamp() lstime = lute.StrToDatetime(lstime_char, customfm='%m/%d/%y %H:%M:%S') corallstime = coral.TimeStamp(lstime.year, lstime.month, lstime.day, lstime.hour, lstime.minute, lstime.second, 0) bulkvalues.append([('RUNNUM', runnum), ('LS', lumils), ('CMSLS', cmsls), ('FILLNUM', fillnum), ('TIME', corallstime), ('BEAM_STATUS', beamstatus), ('ENERGY', beamenergy), ('DELIVERED', delivered), ('RECORDED', recorded), ('AVG_PU', avgpu), ('DATA_VERSION', datatag), ('NORM_VERSION', normtag), ('INSERT_TIME', inserttime)]) nrows += 1 committedrows += 1 if nrows == bulksize: print 'committing trg in LS chunck ', nrows db = dbUtil.dbUtil(session.nominalSchema()) session.transaction().start(False) db.bulkInsert('HFLUMIRESULT', hfresultDefDict, bulkvalues) session.transaction().commit() nrows = 0 bulkvalues = [] elif committedrows == len(lumidata): print 'committing at the end ' db = dbUtil.dbUtil(session.nominalSchema()) session.transaction().start(False) db.bulkInsert('HFLUMIRESULT', hfresultDefDict, bulkvalues) session.transaction().commit() except: print 'error in addindb' raise
def runsummary(schema,amodetag,egev): ''' input: output:[l1key,amodetag,egev,hltkey,fillnum,sequence,starttime,stoptime] ''' o=['collisioncollision','PROTPHYS',3500,'/cdaq/physics/firstCollisions10/v2.0/HLT_7TeV/V5',1005,'GLOBAL-RUN'] starttime=coral.TimeStamp(2010,11,1,0,0,0,0) stoptime=coral.TimeStamp(2010,11,1,11,0,0,0) o.append(starttime) o.append(stoptime) return o
def generateLumiRundata(filename,runsummaryData,runlist): ''' input: runsummaryData {runnum: (datasource(0),nominalegev(1),ncollidingbunches(2),starttime(3),stoptime(4)} output: {runnum: [nominalenergy,ncollidingbunches,starttime,stoptime,nls] } ''' result={} t=lumiTime.lumiTime() for run in runlist: summary=runsummaryData[run] start=datetime.strptime(summary[3],'%m/%d/%y %H:%M:%S') stop=datetime.strptime(summary[4],'%m/%d/%y %H:%M:%S') starttime=coral.TimeStamp(start.year,start.month,start.day,start.hour,start.minute,start.second,0) stoptime=coral.TimeStamp(stop.year,stop.month,stop.day,stop.hour,stop.minute,stop.second,0) result[run]=[filename,summary[1],summary[2],starttime,stoptime,0] return result
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 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 addEntry(schema,datatableName,entryinfo,branchinfo): ''' input: entryinfo (revision_id(0),entry_id(1),entry_name(2),data_id(3)) branchinfo (branch_id,branch_name) 1.allocate and insert a new revision into the revisions table 2.allocate and insert a new entry into the entry table with the new revision 3.inset into data_rev table with new data_id ,revision)id mapping insert into revisions(revision_id,branch_id,branch_name,comment,ctime) values() insert into datatablename_entries (entry_id,revision_id) values() insert into datatablename_rev(data_id,revision_id) values() ''' try: revisiontableName=nameDealer.revisionTableName() entrytableName=nameDealer.entryTableName(datatableName) revtableName=nameDealer.revmapTableName(datatableName) db=dbUtil.dbUtil(schema) tabrowDefDict={} tabrowDefDict['REVISION_ID']='unsigned long long' tabrowDefDict['BRANCH_ID']='unsigned long long' tabrowDefDict['BRANCH_NAME']='string' tabrowDefDict['CTIME']='time stamp' tabrowValueDict={} tabrowValueDict['REVISION_ID']=entryinfo[0] tabrowValueDict['BRANCH_ID']=branchinfo[0] tabrowValueDict['BRANCH_NAME']=branchinfo[1] tabrowValueDict['CTIME']=coral.TimeStamp() db.insertOneRow(revisiontableName,tabrowDefDict,tabrowValueDict) tabrowDefDict={} tabrowDefDict['REVISION_ID']='unsigned long long' tabrowDefDict['ENTRY_ID']='unsigned long long' tabrowDefDict['NAME']='string' tabrowValueDict={} tabrowValueDict['REVISION_ID']=entryinfo[0] tabrowValueDict['ENTRY_ID']=entryinfo[1] tabrowValueDict['NAME']=entryinfo[2] db.insertOneRow(entrytableName,tabrowDefDict,tabrowValueDict) tabrowDefDict={} tabrowDefDict['REVISION_ID']='unsigned long long' tabrowDefDict['DATA_ID']='unsigned long long' tabrowValueDict={} tabrowValueDict['REVISION_ID']=entryinfo[0] tabrowValueDict['DATA_ID']=entryinfo[3] db.insertOneRow(revtableName,tabrowDefDict,tabrowValueDict) except: raise
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)
def createBranch(schema, name, parentname, comment=''): ''' create a new branch/tag under given parentnode insert into revisions(revision_id,branch_id,branch_name,name,comment,ctime) values() return (revisionid,parentid,parentname) ''' try: parentid = None revisionid = 0 if not parentname is None: qHandle = schema.newQuery() qHandle.addToTableList(nameDealer.revisionTableName()) qHandle.addToOutputList('REVISION_ID', 'revision_id') qCondition = coral.AttributeList() qCondition.extend('parentname', 'string') qCondition['parentname'].setData(parentname) qResult = coral.AttributeList() qResult.extend('revision_id', 'unsigned long long') qHandle.defineOutput(qResult) qHandle.setCondition('NAME=:parentname', qCondition) cursor = qHandle.execute() while cursor.next(): parentid = cursor.currentRow()['revision_id'].data() del qHandle else: parentname = 'ROOT' iddealer = idDealer.idDealer(schema) revisionid = iddealer.generateNextIDForTable( nameDealer.revisionTableName()) db = dbUtil.dbUtil(schema) tabrowDefDict = {} tabrowDefDict['REVISION_ID'] = 'unsigned long long' tabrowDefDict['BRANCH_ID'] = 'unsigned long long' tabrowDefDict['BRANCH_NAME'] = 'string' tabrowDefDict['NAME'] = 'string' tabrowDefDict['COMMENT'] = 'string' tabrowDefDict['CTIME'] = 'time stamp' tabrowValueDict = {} tabrowValueDict['REVISION_ID'] = revisionid tabrowValueDict['BRANCH_ID'] = parentid tabrowValueDict['BRANCH_NAME'] = parentname tabrowValueDict['NAME'] = name tabrowValueDict['COMMENT'] = comment tabrowValueDict['CTIME'] = coral.TimeStamp() db.insertOneRow(nameDealer.revisionTableName(), tabrowDefDict, tabrowValueDict) return (revisionid, parentid, parentname) except: raise
def createNorm(schema, normname, lumitype, istypedefault, branchinfo, comment=''): ''' branchinfo(normrevisionid,branchname) ''' try: entry_id = revisionDML.entryInBranch(schema, nameDealer.luminormv2TableName(), normname, branchinfo[1]) if entry_id is None: (revision_id, entry_id, data_id) = revisionDML.bookNewEntry( schema, nameDealer.luminormv2TableName()) entryinfo = (revision_id, entry_id, normname, data_id) revisionDML.addEntry(schema, nameDealer.luminormv2TableName(), entryinfo, branchinfo) else: (revision_id, data_id) = revisionDML.bookNewRevision( schema, nameDealer.luminormv2TableName()) revisionDML.addRevision(schema, nameDealer.luminormv2TableName(), (revision_id, data_id), branchinfo) tabrowDefDict = { 'DATA_ID': 'unsigned long long', 'ENTRY_ID': 'unsigned long long', 'ENTRY_NAME': 'string', 'LUMITYPE': 'string', 'ISTYPEDEFAULT': 'unsigned int', 'COMMENT': 'string', 'CTIME': 'time stamp' } tabrowValueDict = { 'DATA_ID': data_id, 'ENTRY_ID': entry_id, 'ENTRY_NAME': normname, 'LUMITYPE': lumitype, 'ISTYPEDEFAULT': istypedefault, 'COMMENT': comment, 'CTIME': coral.TimeStamp() } db = dbUtil.dbUtil(schema) db.insertOneRow(nameDealer.luminormv2TableName(), tabrowDefDict, tabrowValueDict) return (revision_id, entry_id, data_id) except: raise
def addRevision(schema,datatableName,revisioninfo,branchinfo): ''' 1.insert a new revision into the revisions table 2.insert into data_id, revision_id pair to datatable_revmap insert into revisions(revision_id,branch_id,branch_name,ctime) values() insert into datatable_rev(data_id,revision_id) values()) input: revisioninfo (revision_id(0),data_id(1)) branchinfo (branch_id(0),branch_name(1)) ''' try: revisiontableName=nameDealer.revisionTableName() revtableName=nameDealer.revmapTableName(datatableName) db=dbUtil.dbUtil(schema) tabrowDefDict={} tabrowDefDict['REVISION_ID']='unsigned long long' tabrowDefDict['BRANCH_ID']='unsigned long long' tabrowDefDict['BRANCH_NAME']='string' tabrowDefDict['CTIME']='time stamp' tabrowValueDict={} tabrowValueDict['REVISION_ID']=revisioninfo[0] tabrowValueDict['BRANCH_ID']=branchinfo[0] tabrowValueDict['BRANCH_NAME']=branchinfo[1] tabrowValueDict['CTIME']=coral.TimeStamp() db.insertOneRow(revisiontableName,tabrowDefDict,tabrowValueDict) tabrowDefDict={} tabrowDefDict['REVISION_ID']='unsigned long long' tabrowDefDict['DATA_ID']='unsigned long long' tabrowValueDict={} tabrowValueDict['REVISION_ID']=revisioninfo[0] tabrowValueDict['DATA_ID']=revisioninfo[1] db.insertOneRow(revtableName,tabrowDefDict,tabrowValueDict) except: raise
qCondition=coral.AttributeList() qCondition.extend('begintime','time stamp') qCondition.extend('endtime','time stamp') lumiquery.addToOutputList('TO_CHAR(TIME,\'MM/DD/YY HH24:MI:SS\')','timestr') lumiquery.addToOutputList('DELIVERED') lumiquery.defineOutput(qResult) lute=lumiTime.lumiTime() begtimeStr='01/01/12 00:00:00' reqtimemaxT=datetime.datetime.now() print options.begin,options.end if options.begin: begtimeStr=options.begin reqtimeminT=lute.StrToDatetime(options.begin,customfm='%m/%d/%y %H:%M:%S') if options.end: reqtimemaxT=lute.StrToDatetime(options.end,customfm='%m/%d/%y %H:%M:%S') qCondition['begintime'].setData(coral.TimeStamp(reqtimeminT.year,reqtimeminT.month,reqtimeminT.day,reqtimeminT.hour,reqtimeminT.minute,reqtimeminT.second,0)) qCondition['endtime'].setData(coral.TimeStamp(reqtimemaxT.year,reqtimemaxT.month,reqtimemaxT.day,reqtimemaxT.hour,reqtimemaxT.minute,reqtimemaxT.second,0)) lumiquery.setCondition('TIME>=:begintime AND TIME<=:endtime',qCondition) cursor=lumiquery.execute() result={}#{ordinalnumber:delivered} while next(cursor): timeStr=cursor.currentRow()['timestr'].data() runTime=lute.StrToDatetime(timeStr,customfm='%m/%d/%y %H:%M:%S') delivered=cursor.currentRow()['DELIVERED'].data() ordinalday=runTime.toordinal() if ordinalday not in result: result[ordinalday]=0. result[ordinalday]+=delivered session.transaction().commit() del lumiquery del session
import coral import unittest thisMoment = coral.TimeStamp() anotherMoment = coral.TimeStamp(2007, 12, 21, 12, 10, 30, 10000000) otherMoment = coral.TimeStamp(day=1, month = 10, year = 2007, hour = 12, minute = 30, second = 20, nanosecond = 230000000) class PyCoralTimeTest(unittest.TestCase): def setUp(self): print '[OVAL] setUp' def testTimeStampModule(self): print '[OVAL] Test PyCoral TimeStamp module' print coral.TimeStamp.__doc__ print "thisMoment :: ",thisMoment.day(),"/",thisMoment.month(),"/",thisMoment.year(),"/",thisMoment.hour(),"/",thisMoment.minute(),"/",thisMoment.second(),"/", (thisMoment.nanosecond() / 100000000) print "anotherMoment:: ",anotherMoment.day(),"/",anotherMoment.month(),"/",anotherMoment.year(),"/",anotherMoment.hour(),"/",anotherMoment.minute(),"/",anotherMoment.second(),"/", (anotherMoment.nanosecond() / 100000000) print "otherMoment:: ",otherMoment.day(),"/",otherMoment.month(),"/",otherMoment.year(),"/",otherMoment.hour(),"/",otherMoment.minute(),"/",otherMoment.second(),"/", (otherMoment.nanosecond() / 100000000) def tearDown(self): print '[OVAL] tearDown' if __name__=="__main__": unittest.main()
print("Element w[0] isNull OR not after setData(None): ", w[0].isNull()) print(str(w[0])) w[0].shareData(w[1]) print("Elements w[0] and w[1] after shareData = ", str(w[0]), str(w[1])) spec = w[0].specification() print("Attribute Specification details of w[0] = ", spec.name(), spec.typeName()) print(str(spec)) print("Comparison Results of specifications of w[0] and w[1] = ", cmp(w[0].specification(), w[1].specification())) print("Comparison Results of specifications of z[2] and w[2] = ", cmp(z[2].specification(), w[2].specification())) f = coral.Date() g = coral.TimeStamp() h = coral.Blob() w.extend("f", "date") w.extend("g", "time stamp") w.extend("h", "blob") li1 = [] li2 = [] for j in range(1, 500): li1.append(j) del j pickle.dump(li1, h, 1) w[5].setData(f)
description.insertColumn("ID", "int") description.setPrimaryKey("ID") description.insertColumn("TheDate", "date") description.insertColumn("TheTime", "time stamp", 6) print("About to create the table") table = schema.createTable(description) rowBuffer = coral.AttributeList() table.dataEditor().rowBuffer(rowBuffer) for i in range(0, 5): rowBuffer["ID"].setData(i) rowBuffer["TheDate"].setData(coral.Date(2005, 11, i + 1)) rowBuffer["TheTime"].setData(coral.TimeStamp()) table.dataEditor().insertRow(rowBuffer) bulkInserter = table.dataEditor().bulkInsert(rowBuffer, 3) fraction = 111111111 for i in range(5, 10): fraction = fraction / 10 rowBuffer["ID"].setData(i) rowBuffer["TheDate"].setData(coral.Date(2005, 11, i + 1)) thisMoment = coral.TimeStamp() rowBuffer["TheTime"].setData( coral.TimeStamp(thisMoment.year(), thisMoment.month(), thisMoment.day(), thisMoment.hour(), thisMoment.minute(), thisMoment.second(), (i - 4) * fraction))
def checkData(i): try: global m_rowBuffer row = m_rowBuffer if (row[0].data() != i): raise Exception("Unexpected value for variable ", row[0].specification().name()) if (i % 3 == 0): if (not row[1].isNull()): raise Exception("Unexpected NOTNULL data for variable ", row[1].specification().name()) else: if (row[1].isNull()): raise Exception("Unexpected NULL data for variable ", row[1].specification().name()) if (i % 2 == 0): temp = True else: temp = False if (row[1].data() != temp): raise Exception("Unexpected value for variable ", row[1].specification().name()) if (row[2].data() != (i * 2) % 256): raise Exception("Unexpected value for variable ", row[2].specification().name()) if (ord(row[3].data()) != (i * 2) % 128): raise Exception("Unexpected value for variable ", row[3].specification().name()) if (row[4].data() != (i * 3) % 2048): raise Exception("Unexpected value for variable ", row[4].specification().name()) if (row[5].data() != (i * 3) % 2048 - 1024): raise Exception("Unexpected value for variable ", row[5].specification().name()) if (row[6].data() != (i * 4) % 1000): raise Exception("Unexpected value for variable ", row[6].specification().name()) if (row[7].data() != (i * 4) % 1000 - 500): raise Exception("Unexpected value for variable ", row[7].specification().name()) if (row[8].data() != (i * 4) % 1001): raise Exception("Unexpected value for variable ", row[8].specification().name()) if (row[9].data() != (i * 4) % 1001 - 500): raise Exception("Unexpected value for variable ", row[9].specification().name()) if (row[10].data() != i % 123456789): raise Exception("Unexpected value for variable ", row[10].specification().name()) if (row[11].data() != i % 123456789 - 500): raise Exception("Unexpected value for variable ", row[11].specification().name()) if (i % 4 == 0): if (not row[12].isNull()): raise Exception("Unexpected NOTNULL data for variable ", row[12].specification().name()) else: if (row[12].isNull()): raise Exception("Unexpected NULL data for variable ", row[12].specification().name()) if (abs(row[12].data() / (i + 0.123) - 1) > 1e-324): raise Exception("Unexpected value for variable ", row[12].specification().name()) if (abs(row[13].data() / (0.123456789 - 2.3 * i) - 1) > 1e-324): raise Exception("Unexpected value for variable ", row[13].specification().name()) if (abs(row[14].data() / (0.123456789 + 2.3 * i) - 1) > 1e-324): raise Exception("Unexpected value for variable ", row[14].specification().name()) blob = row[15].data() p1 = pickle.load(blob) blobSize = 1000 * (i % 100 + 1) if (len(p1) != blobSize): raise Exception("Unexpected blob size for variable ", row[15].specification().name()) for j in range(0, blobSize): if (p1[j] != (i + j) % 256): raise Exception("Unexpected value for variable ", row[15].specification().name()) if (row[16].data() != coral.Date(2006, 1, i % 31 + 1)): raise Exception("Unexpected value for variable ", row[16].specification().name()) if (row[17].data() != coral.TimeStamp(2006, 1, 12, 15, 47, i % 60, 0)): raise Exception("Unexpected value for variable ", row[17].specification().name()) os1 = "A general String : " + str(i % 5) s1 = str(os1) if (row[18].data() != s1): raise Exception("Unexpected value for variable " + row[18].specification().name()) os2 = "...." + str(i % 10) s2 = str(os2) if (row[19].data() != s2): raise Exception("Unexpected value for variable ", row[19].specification().name()) os3 = "Value : " + str(i) s3 = str(os3) if (row[20].data() != s3): raise Exception("Unexpected value for variable ", row[20].specification().name()) print "CheckData SUCCESS " except Exception, e: raise Exception("CheckData FAILURE " + str(e))
def fillData(i): try: global m_rowBuffer row = m_rowBuffer row[0].setData(i) if (i % 3 == 0): row[1].setData(None) else: if (i % 2 == 0): temp = True else: temp = False row[1].setData(temp) row[2].setData((i * 2) % 256) row[3].setData((i * 2) % 128) row[4].setData((i * 3) % 2048) row[5].setData((i * 3) % 2048 - 1024) row[6].setData((i * 4) % 1000) row[7].setData((i * 4) % 1000 - 500) row[8].setData((i * 4) % 1001) row[9].setData((i * 4) % 1001 - 500) row[10].setData(i % 123456789) row[11].setData(i % 123456789 - 500) if (i % 4 == 0): row[12].setData(None) else: row[12].setData(i + 0.123) row[13].setData(0.123456789 - 2.3 * i) row[14].setData(0.123456789 + 2.3 * i) blob = coral.Blob() row[15].setData(blob) blobSize = 1000 * (i % 100 + 1) #blob.resize( blobSize ); p = [] for j in range(0, blobSize): p.append((i + j) % 256) pickle.dump(p, blob, True) row[15].setData(blob) row[16].setData(coral.Date(2006, 1, i % 31 + 1)) row[17].setData(coral.TimeStamp(2006, 1, 12, 15, 47, i % 60, 0)) os1 = "A general String : " + str(i % 5) s1 = str(os1) row[18].setData(s1) os2 = "...." + str(i % 10) s2 = str(os2) row[19].setData(s2) os3 = "Value : " + str(i) s3 = str(os3) row[20].setData(s3) print "FillData SUCCESS " except Exception, e: raise Exception("FillData FAILURE " + str(e))
lumiquery.addToOutputList('DELIVERED') lumiquery.defineOutput(qResult) lute = lumiTime.lumiTime() begtimeStr = '01/01/12 00:00:00' reqtimemaxT = datetime.datetime.now() print(options.begin, options.end) if options.begin: begtimeStr = options.begin reqtimeminT = lute.StrToDatetime(options.begin, customfm='%m/%d/%y %H:%M:%S') if options.end: reqtimemaxT = lute.StrToDatetime(options.end, customfm='%m/%d/%y %H:%M:%S') qCondition['begintime'].setData( coral.TimeStamp(reqtimeminT.year, reqtimeminT.month, reqtimeminT.day, reqtimeminT.hour, reqtimeminT.minute, reqtimeminT.second, 0)) qCondition['endtime'].setData( coral.TimeStamp(reqtimemaxT.year, reqtimemaxT.month, reqtimemaxT.day, reqtimemaxT.hour, reqtimemaxT.minute, reqtimemaxT.second, 0)) lumiquery.setCondition('TIME>=:begintime AND TIME<=:endtime', qCondition) cursor = lumiquery.execute() result = {} #{ordinalnumber:delivered} while next(cursor): timeStr = cursor.currentRow()['timestr'].data() runTime = lute.StrToDatetime(timeStr, customfm='%m/%d/%y %H:%M:%S') delivered = cursor.currentRow()['DELIVERED'].data() ordinalday = runTime.toordinal() if ordinalday not in result: result[ordinalday] = 0.
import coral import unittest date1 = coral.Date() date2 = coral.Date(2007,9,10) timestamp1 = coral.TimeStamp() timestamp2 = coral.TimeStamp(2007, 12, 21, 12, 10, 30, 10000000) blob1 = coral.Blob(100) blob2 = coral.Blob(200) list1 = coral.AttributeList() list1.extend("a","date") list1.extend("b","time stamp") list1.extend("c","blob") list1BeforeMerging = len(list1) list1[0].setData(date1) list1[1].setData(timestamp1) list1[2].setData(blob1) print("------------------------------------------------------") print("Length of list1 before merging = " , list1BeforeMerging) print("Contents of list1 before merging") for attr in list1: print("Atribute Name =" , attr.specification().name() , ":TypeName =" , attr.specification().typeName() , ":Value = " , attr.data()) print("------------------------------------------------------") list2 = coral.AttributeList() list2.extend("c","blob") list2.extend("d","time stamp") list2.extend("e","date") list2BeforeMerging = len(list2) list2[0].setData(blob1)
import os import coral import unittest import sys #startRef = sys.gettotalrefcount() #endRef = sys.gettotalrefcount() dateData = coral.Date(year=2006, month=10, day=10) timeStampData = coral.TimeStamp() blobData = coral.Blob() aList1 = coral.AttributeList() aList2 = coral.AttributeList() class PyCoralAttributeListTest(unittest.TestCase): def setUp(self): print '[OVAL] setUp' print coral.AttributeList.__doc__ def testAttributeListSimpleData(self): print '[OVAL] testAttributeListSimpleData' # Extend AttributeList aList1.extend("c", "char") aList1.extend("i", "int") aList1.extend("dd", "date") aList1.extend("tm", "time stamp") aList1.extend("blob1", "blob") aList1.extend("floatVar", "float") aList1.extend("uSlongVar", "unsigned long")
def generateLumidata(lumirundatafromfile, lsdatafromfile, rundatafromdb, lsdatafromdb, replacelsMin, replacelsMax): ''' input: perrunresultfromfile=[]#source,starttime,stoptime,nls perlsresultfromfile={} #{lumilsnum:instlumiub} lumirundatafromdb=[] #[source,nominalegev,ncollidingbunches,starttime,stoptime,nls] lumilsdatafromdb={}#{lumilsnum:[cmslsnum(0),instlumi(1),instlumierror(2),instlumiquality(3),beamstatus(4),beamenergy(5),numorbit(6),startorbit(7),cmsbxindexblob(8),beamintensityblob_1(9),beamintensityblob_2(10),bxlumivalue_occ1(11),bxlumierror_occ1(12),bxlumiquality_occ1(13),bxlumivalue_occ2(14),bxlumierror_occ2(15),bxlumiquality_occ2(16),bxlumivalue_et(17),bxlumierror_et(18),bxlumiquality_et(19)]} ''' lumip = lumiParameters.ParametersObject() numorbit = lumip.numorbit startorbit = 0 fakebeamenergy = 4000. fakebeamstatus = 'STABLE BEAMS' fakefloatArray = array.array('f') fakeidxArray = array.array('h') fakeshortArray = array.array('h') for bxidx in range(1, 3565): fakeidxArray.append(bxidx) fakefloatArray.append(0.) fakeshortArray.append(0) lumirundata = [] lumilsdata = {} if rundatafromdb: lumirundata = rundatafromdb lumirundata[0] = rundatafromdb[0] + '+file:' + lumirundatafromfile[0] else: lu = lumiTime.lumiTime() source = '+file:' + lumirundatafromfile[0] nominalegev = fakebeamenergy ncollidingbunches = 72 starttime = lumirundatafromfile[1] stoptime = lumirundatafromfile[2] starttimeT = lu.timestampTodatetimeUTC(starttime) stoptimeT = lu.timestampTodatetimeUTC(stoptime) print(starttimeT.day, starttimeT.month, starttimeT.year) starttimeT_coral = coral.TimeStamp(starttimeT.year, starttimeT.month, starttimeT.day, starttimeT.hour, starttimeT.minute, starttimeT.second, 0) stoptimeT_coral = coral.TimeStamp(stoptimeT.year, stoptimeT.month, stoptimeT.day, stoptimeT.hour, stoptimeT.minute, stoptimeT.second, 0) nls = lumirundatafromfile[3] lumirundata = [ source, nominalegev, ncollidingbunches, starttimeT_coral, stoptimeT_coral, nls ] if lsdatafromdb: lumilsdata = lsdatafromdb if replacelsMin > len(lsdatafromdb): print('[INFO]Operation: extend an existing run from LS=', replacelsMin) lumirundata[5] += len(lsdatafromfile) else: print( '[INFO]Operation: replace instlumi in an existing run LS range=', replacelsMin, replacelsMax) else: print('[INFO]Operation: insert a new fake run') for lumilsnum in range(replacelsMin, replacelsMax + 1): instlumi = lsdatafromfile[lumilsnum] if lumilsnum in lsdatafromdb.keys(): #if this is a hole lumilsdata[lumilsnum][1] = instlumi else: #if this is an extension instlumierror = 0.0 instlumiquality = 0 startorbit = (lumilsnum - 1) * numorbit cmsbxindexblob = CommonUtil.packArraytoBlob(fakeshortArray) beamintensityblob_1 = CommonUtil.packArraytoBlob(fakefloatArray) beamintensityblob_2 = CommonUtil.packArraytoBlob(fakefloatArray) bxlumivalue_occ1 = CommonUtil.packArraytoBlob(fakefloatArray) bxlumierror_occ1 = CommonUtil.packArraytoBlob(fakefloatArray) bxlumiquality_occ1 = CommonUtil.packArraytoBlob(fakeshortArray) bxlumivalue_occ2 = CommonUtil.packArraytoBlob(fakefloatArray) bxlumierror_occ2 = CommonUtil.packArraytoBlob(fakefloatArray) bxlumiquality_occ2 = CommonUtil.packArraytoBlob(fakeshortArray) bxlumivalue_et = CommonUtil.packArraytoBlob(fakefloatArray) bxlumierror_et = CommonUtil.packArraytoBlob(fakefloatArray) bxlumiquality_et = CommonUtil.packArraytoBlob(fakeshortArray) lumilsdata[lumilsnum] = [ 0, instlumi, instlumierror, instlumiquality, fakebeamstatus, fakebeamenergy, 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 ] return (lumirundata, lumilsdata)