コード例 #1
0
ファイル: CommonUtil.py プロジェクト: EricBAdamsUMDCP/cmssw-1
def packArraytoBlob(iarray):
    '''
    Inputs:
    inputarray: a python array
    '''
    result = coral.Blob()
    result.write(iarray.tostring())
    return result
コード例 #2
0
ファイル: DmlOperations.py プロジェクト: cms-externals/coral
    def atomicOperations(self):
        "AtomicOperations method of DmlOperations"
        try:
            print("In AtomicOperations")
            session = self.m_svc.connect(self.m_connectionString,
                                         coral.access_Update)

            session.transaction().start()

            editor1 = session.nominalSchema().tableHandle("T1").dataEditor()
            rowBuffer1 = coral.AttributeList()
            rowBuffer1.extend("id", "long")
            rowBuffer1.extend("t", "long long")
            rowBuffer1.extend("X", "float")
            rowBuffer1.extend("Y", "double")
            rowBuffer1.extend("Z", "double")
            rowBuffer1.extend("Comment", "string")
            rowBuffer1.extend("Data", "blob")

            for i in range(0, 10):
                id = i + 1
                rowBuffer1["id"].setData(id)
                t = 1
                t <<= 4 * i
                rowBuffer1["t"].setData(t)
                x = 1 + (i + 1) * 0.001
                rowBuffer1["X"].setData(x)
                y = 2 + (i + 1) * 0.0001
                rowBuffer1["Y"].setData(y)
                z = i * 1.1
                rowBuffer1["Z"].setData(z)
                os = "Row " + str(i + 1)
                comment = str(os)
                rowBuffer1["Comment"].setData(comment)

                blobSize = 1000 * (i + 1)
                #blob.resize( blobSize )
                blob = coral.Blob()
                p = []
                for j in range(0, blobSize):
                    p.append((i + j) % 256)

                pickle.dump(p, blob, True)
                rowBuffer1["Data"].setData(blob)
                if (i % 4 == 2):
                    rowBuffer1["Z"].setData(None)

                #Insert the row
                editor1.insertRow(rowBuffer1)

            # Delete some rows.
            deleteCondition = "Z > :z"
            deleteData = coral.AttributeList()
            deleteData.extend("z", "float")
            deleteData[0].setData(7)
            rowsDeleted = editor1.deleteRows(deleteCondition, deleteData)
            print("Deleted ", rowsDeleted, " rows.")
            if (rowsDeleted != 3):
                raise Exception("Unexpected number of rows deleted")

            #Update some rows.
            updateAction = "t = t + :offset"
            updateCondition = "X < :x"
            updateData = coral.AttributeList()
            updateData.extend("offset", "int")
            updateData.extend("x", "float")
            updateData[0].setData(111)
            updateData[1].setData(1.003)
            rowsUpdated = editor1.updateRows(updateAction, updateCondition,
                                             updateData)
            print("Updated ", rowsUpdated, " rows.")
            if (rowsUpdated != 2):
                raise Exception("Unexpected number of rows updated")

            session.transaction().commit()

            del session

            return True

        except Exception as e:
            raise Exception("Error in AtomicOperations method: " + str(e))
            return False
コード例 #3
0
import os
import filecmp
import unittest

print "---------------------------------------------"
print "Note: The Input File should reside in the current directory"
print "Note: The Output File will be created in the current Directory"
print "---------------------------------------------"
inputFile = raw_input("Input file name for writing to Blob:")
outputFile = raw_input("Output file name for writing from Blob:")
print "----------------------------------------------"

inf = open(inputFile, 'rb')
ouf = open(outputFile, 'wb')

toReadIntoBlob = coral.Blob()
tempBlob = coral.Blob(100)
toReadIntoBlob.append(tempBlob)
print "After append, Blob Size = ", toReadIntoBlob.size()
toReadIntoBlob.extend(2500)
print "After 1 extend, Blob Size = ", toReadIntoBlob.size()
toReadIntoBlob.extend(80)
print "After 2 extends Blob Size = ", toReadIntoBlob.size()
toReadIntoBlob.resize(os.path.getsize(inputFile))
print "After Resize Blob Size = ", toReadIntoBlob.size()

inf.readinto(toReadIntoBlob)


class PyCoralBlobReadWriteTest(unittest.TestCase):
    def setUp(self):
コード例 #4
0
ファイル: TestDriver.py プロジェクト: Teemperor/cms-externals
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))
コード例 #5
0
    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")
        aList1.extend("sLongVar", "long")
        aList1.extend("boolVar", "bool")

        print "Lenght of aList1 ", len(aList1)
        print " "

        print "Extend other attribute list"

        # Extend second AttributeList
        aList2.extend("d", "char")
        aList2.extend("e", "int")
        aList2.extend("ddList2", "date")
        aList2.extend("timeList1", "time stamp")
        aList2.extend("timeList2", "time stamp")
        aList2.extend("floatVarList2", "float")
        aList2.extend("longLongVar", "long long")
        aList2.extend("doubleVar", "double")
        aList2.extend("longDoubleVar", "long double")
        aList2.extend("blobList2", "blob")
        aList2.extend("boolVar2", "bool")

        print "Assgn values to aList1 attributes"

        aList1['c'].setData('z')
        j = 10
        aList1['i'].setData(65537 - j)
        aList1['dd'].setData(dateData)
        aList1['tm'].setData(timeStampData)
        aList1['floatVar'].setData(3.0003)
        aList1['uSlongVar'].setData(4294967295L)
        aList1['sLongVar'].setData(2147483647L)
        aList1['boolVar'].setData(True)

        aList2['d'].setData(None)  # Set NULL
        aList2['e'].shareData(aList1[1])
        aList2['ddList2'].shareData(aList1[2])
        aList2['timeList1'].setData(timeStampData)
        aList2['timeList2'].setData(timeStampData)
        aList2['floatVarList2'].shareData(aList1[5])
        aList2['longLongVar'].setData(9223372036854775807L)
        aList2['doubleVar'].setData(2147483647)
        aList2['longDoubleVar'].setData(36778826444)
        aList2['blobList2'].shareData(aList1[4])
        aList2['boolVar2'].setData(False)

        # Read/ Write test of BLOB
        inputFile = raw_input("File name to be read into BLOB: ")
        outputFile = raw_input("Output file to be read from BLOB: ")

        inf = open(inputFile, 'rb')
        ouf = open(outputFile, 'wb')

        toReadIntoBlob = coral.Blob(os.path.getsize(inputFile))
        toWriteBlob = coral.Blob(os.path.getsize(inputFile))

        inf.readinto(toReadIntoBlob)

        aList1['blob1'].setData(toReadIntoBlob)
        toWriteBlob = aList1[4].data()

        ouf.write(toWriteBlob)

        print "Attribute in aList1 ...", " size = ", len(aList1)

        for attr in aList1:
            print "Name = ", attr.specification().name(
            ), "Type Name = ", attr.specification().name(
            ), " Value = ", attr.data()

        print "Attribute in aList2 ...", " size = ", len(aList2)

        for attr2 in aList2:
            print attr2

        print "Merge aList1 with aList2 "
        aList1.merge(aList2)

        print "Attribute in aList1 ...", " size = ", len(aList1)

        for attribute in aList1:
            print attribute
コード例 #6
0
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")
コード例 #7
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)
コード例 #8
0
    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)
    w[6].setData(g)
コード例 #9
0
import os
import filecmp
import unittest

print "---------------------------------------------"
print "Note: The Input File should reside in the current directory"
print "Note: The Output File will be created in the current Directory"
print "---------------------------------------------"
inputFile = raw_input("Input file name for writing to Blob:")
outputFile = raw_input("Output file name for writing from Blob:")
print "----------------------------------------------"

inf = open(inputFile, 'rb')
ouf = open(outputFile, 'wb')

toReadIntoBlob = coral.Blob(os.path.getsize(inputFile))
print toReadIntoBlob
print "To Read Into Blob Size = ", toReadIntoBlob.size()
toWriteBlob = coral.Blob(os.path.getsize(inputFile))
print toWriteBlob
print "To Write Blob Size = ", toWriteBlob.size()

inf.readinto(toReadIntoBlob)

attrList = coral.AttributeList()
attrList.extend("blob1", "blob")


class PyCoralBlobReadWriteTest(unittest.TestCase):
    def setUp(self):
        print '[OVAL] setUp'