Exemple #1
0
def fillPileUpNoiseLumi(db,
                        tag,
                        dataIn,
                        folderName="/CALO/Ofl/Noise/PileUpNoiseLumi"):

    data = 0.
    data = dataIn

    if db.existsFolder(folderName):
        folder = db.getFolder(folderName)
    else:
        #create new folder
        print "Folder", folderName, "does not exit yet. Creating it now."
        folder = createFolder(db, folderName)

    since = cool.ValidityKeyMin
    until = cool.ValidityKeyMax

    payload = cool.Record(folder.payloadSpecification())
    payload["LBAvInstLumi"] = data
    payload["Valid"] = 0
    folder.storeObject(since, until, payload, cool.ChannelId(0), tag)
    folder.storeObject(since, until, payload, cool.ChannelId(1), tag)

    return 0
Exemple #2
0
    def getCells(self, systemId, pointInTime):
        """
        Returns a CaloCondBlob object for the given system.
        """

        validityKey = getCoolValidityKey(pointInTime)
        self.log().debug("Validity key is %s", validityKey)
        try:
            #=== Have we retrieved data previously?
            key = (systemId, validityKey)
            obj = self.__objDict.get(key)
            #=== ... if not, get it from DB
            if not obj:
                channelId = cool.ChannelId(systemId)
                obj = self.__folder.findObject(validityKey, channelId,
                                               self.__tag)
                self.log().debug("Fetching from DB: %s", obj)
                blob = obj.payload()[0]
                self.log().debug("blob size: %d", blob.size())
                #=== store object in dictionary
                self.__objDict[key] = obj
            #=== get blob
            blob = obj.payload()[0]
            self.log().debug("blob size: %d", blob.size())

            #=== create CaloCondBlob object
            flt = g.CaloCondBlobFlt.getInstance(blob)
            return flt
        except Exception as e:
            self.log().error(
                "Fetching of systemId=%i failed with exception %s", systemId,
                e)
            return None
Exemple #3
0
def fillFolder(folder,data=[],iovMin=cool.ValidityKeyMin,iovMax=cool.ValidityKeyMax):
    
    nB1=0
    nB2=0
    nColl=0

    for bcid in data:
        if (bcid & 0x1): nB1+=1
        if (bcid & 0x2): nB2+=1
        if (bcid & 0x3 == 0x3): nColl+=1
        pass

    
    payload=cool.Record(folder.payloadSpecification())

    payload['Beam1Bunches']=nB1
    payload['Beam2Bunches']=nB2
    payload['LuminousBunches']=nColl

    btype=getattr(ROOT,"coral::Blob")
    
    bcmask=btype()
    bcmask.resize(3564)

    for i,d in enumerate(data):
        bcmask[i]=d


    payload['BCIDmasks']=bcmask
            

    print("Storing CaloCondBlob object")
    folder.storeObject(iovMin, iovMax, payload, cool.ChannelId(0))

    return
Exemple #4
0
 def zeroBlob(self, systemId):
     """
     Resets blob size to zero
     """
     try:
         chanNum = cool.ChannelId(systemId)
         data = self.__chanDictRecord.get(systemId)
         if not data:
             spec = self.__folder.payloadSpecification()
             data = cool.Record(spec)
             self.__chanDictRecord[chanNum] = data
         blob = data['CaloCondBlob16M']
         blob.resize(0)
     except Exception as e:
         self.log().critical(e)
         return None
Exemple #5
0
def createSqlite(sqliteName,
                 folderName,
                 foldertag,
                 iovMin=cool.ValidityKeyMin,
                 iovMax=cool.ValidityKeyMax,
                 inputFileName=None,
                 defaultvalue=1.0):

    dbSvc = cool.DatabaseSvcFactory.databaseService()

    if os.access(sqliteName, os.R_OK):
        print("UPDATING existing sqlite file", sqliteName)
        db = dbSvc.openDatabase(
            "sqlite://;schema=" + sqliteName + ";dbname=CONDBR2", False)
    else:
        print("Creating new sqlite file", sqliteName)
        db = dbSvc.createDatabase("sqlite://;schema=" + sqliteName +
                                  ";dbname=CONDBR2")

    spec = cool.RecordSpecification()
    spec.extend('CaloCondBlob16M', cool.StorageType.Blob16M)

    desc = '<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type="71" clid="40774348" /></addrHeader><typeName>AthenaAttributeList</typeName>'

    if db.existsFolder(folderName):
        folder = db.getFolder(folderName)
    else:
        print("Creating COOL folder/tag  %s/%s" % (folderName, foldertag))
        #folder = db.createFolder(folderName, spec, desc, cool.FolderVersioning.MULTI_VERSION, True)
        folderSpec = cool.FolderSpecification(
            cool.FolderVersioning.MULTI_VERSION, spec)
        folder = db.createFolder(folderName, folderSpec, desc, True)
        pass

    if inputFileName is None or len(inputFileName) == 0:
        print("No input given. Create empty blob")
        data = cool.Record(spec)
    else:
        data = CaloCondBlobWriterFromFile(spec, inputFileName, defaultvalue)

    print("Storing CaloCondBlob object")
    folder.storeObject(iovMin, iovMax, data, cool.ChannelId(0), foldertag,
                       True)

    db.closeDatabase()
Exemple #6
0
    def getCells(self, systemId):
        """
        Returns a CaloCondBlob object of given system Id.
        """

        #try:
        chanNum = cool.ChannelId(systemId)
        flt = self.__chanDictCells.get(chanNum, None)
        #=== ... if not, get it from DB
        if not flt:
            #=== create new blob
            spec = self.__folder.payloadSpecification()
            data = cool.Record(spec)
            self.__chanDictRecord[chanNum] = data
            for key in data:
                blob = data[key]
            flt = g.CaloCondBlobFlt.getInstance(blob)

        self.__chanDictCells[chanNum] = flt
        return flt
Exemple #7
0
    def register(self, since=(MINRUN, MINLBK), until=(MAXRUN, MAXLBK), tag=""):
        """
        Registers the folder in the database.
        - since: lower limit of IOV
        - until: upper limit of IOV
        - tag  : The cool folder tag to write to

        The interpretation of the 'since' and 'until' inputs depends on their type:
        - tuple(int,int) : run and lbk number 
        - integer        : Values are interpreted as unix time stamps
                           If since<0, current time is assumed
                           If until<0, infinity is assumed
        - string         : time stamp of format 'yyyy-mm-dd hh:mm:ss'
        """

        #=== check for inconsistent input
        if type(since) != type(until):
            raise Exception("Inconsistent types: since=%s, until=%s" %
                            (type(since), type(until)))

        #=== write to user tag only if multiversion mode
        userTagOnly = True
        if self.__folder.versioningMode(
        ) == cool.FolderVersioning.SINGLE_VERSION:
            userTagOnly = False
            #=== no folder Tag allowed for singleversion
            if tag != "":
                self.log().warning(
                    "Trying to store with tag \"%s\" to SINGLE_VERSION folder",
                    tag)
                self.log().warning("... resetting tag to \"\"!")
                tag = ""

        #=== get IOV limits
        sinceCool = getCoolValidityKey(since, True)
        untilCool = getCoolValidityKey(until, False)
        if untilCool <= sinceCool:
            raise Exception("Until(%i) <= Since(%i)" % (untilCool, sinceCool))

        #=== build IOV string
        iovString = ""
        if isinstance(since, tuple):
            iovString = "[%i,%i] - [%i,%i]" % (since[0], since[1], until[0],
                                               until[1])
        else:
            sinceInfo = time.localtime(sinceCool // UNIX2COOL)
            untilInfo = time.localtime(min(UNIXTMAX, (untilCool // UNIX2COOL)))
            untilStr = "<infinity>"
            if untilCool < cool.ValidityKeyMax:
                untilStr = time.asctime(untilInfo)
                if (untilCool // UNIX2COOL) > UNIXTMAX:
                    untilStr = " > " + untilStr
            iovString = "[%s] - [%s]" % (time.asctime(sinceInfo), untilStr)

        #=== build tag
        folderTag = tag

        #=== print info
        self.log().info("Registering folder %s with tag \"%s\"",
                        self.__folder.fullPath(), folderTag)
        self.log().info("... with IOV          : %s", iovString)
        #self.log().info( "... with comment field: \"%s\"", self.__chanDictDrawer[48].getComment()                  )

        #=== register all channels by increasing channel number
        chanList = sorted(self.__chanDictRecord.keys())
        for chanNum in chanList:
            data = self.__chanDictRecord[chanNum]
            strout = "cool channel=%4i" % chanNum
            self.log().debug("Registering %s %s", (strout, data))
            channelId = cool.ChannelId(chanNum)
            self.__folder.storeObject(sinceCool, untilCool, data, channelId,
                                      folderTag, userTagOnly)
        noiseB   = float(fields[4])
        flt = fltDict[systemId][1]
        
        flt.setData(hash,gain,0,noiseA)
        if mu > 0 and dt > 0:
           # new normalization
           if dt > 25:
              noiseB /= math.sqrt(mu/53.*10.)
           else:
              noiseB /= math.sqrt(mu/29.*10.) 
        pass
        flt.setData(hash,gain,1,noiseB)
        
    #=== write to DB
    for systemId, dataList in fltDict.iteritems():
      if (systemId<48):
        sysName  = systemDict[systemId][3]
        log.info("Committing BLOB for %s" % sysName)
        channelId = cool.ChannelId(systemId)
        log.info("Cool channel ID %s" % channelId)
        data = dataList[0]
        folder.storeObject(iovSince, iovUntil, data, channelId, folderTag)
        
except Exception, e:
    log.fatal("Exception caught:")
    print e

#=== close the database
db.closeDatabase()

Exemple #9
0
    dbSvc = cool.DatabaseSvcFactory.databaseService()
    try:
        db = dbSvc.openDatabase(dbname)
    except Exception, e:
        print "Problems connecting to database:", e
        return None

    #Set up Channel Selection:
    sel = None
    print selection
    ss = selection.split(",")
    for s in ss:
        if len(s) == 0: continue
        idx = s.find(":")
        if idx == -1:
            c1 = cool.ChannelId(int(s))
            c2 = c1
        else:
            c1 = cool.ChannelId(int(s[:idx]))
            c2 = cool.ChannelId(int(s[1 + idx:]))
        #print "ExtractFolderInfo: Add channel range",c1,"to",c2
        if sel is None:
            sel = cool.ChannelSelection(
                c1, c2, cool.ChannelSelection.sinceBeforeChannel)
        else:
            sel.addRange(c1, c2)

    if sel is None:
        print "ExtractFolderInfo: No COOL channel selection given, work on all channels"
        sel = cool.ChannelSelection.all()
Exemple #10
0
                    drawerOfc.setOfc(drawerOfc.FieldB,channel,adc,phaseF,sample,float(ofc[1]))
                    drawerOfc.setOfc(drawerOfc.FieldC,channel,adc,phaseF,sample,float(ofc[2]))
                    drawerOfc.setOfc(drawerOfc.FieldG,channel,adc,phaseF,sample,float(ofc[3]))
                else:
                    raise ("Impossible objVersion: %i" % objVersion)

                #=== increment counters
                adc += 1
                if adc>1:
                    adc     = 0
                    sample += 1
                if sample>6:
                    sample = 0
                    phase += 1
                    
        #=== store blob in folder/channel
        channelId = cool.ChannelId(chan)
        folder.storeObject(iovSince, iovUntil, data, channelId)
    #<--end of chan loop

    #=== add comment to comment channel
    data = cool.Record( spec )
    blob = data['TileCalibBlobOfc']
    cmt = g.TileCalibDrawerCmt.getInstance(blob,author,comment)
    channelId = cool.ChannelId(g.TileCalibUtils.getCommentChannel())
    folder.storeObject(iovSince, iovUntil, data, channelId)
    #<---end of file loop

db.closeDatabase()

Exemple #11
0
def extractFolderInfo(dbname,globaltag="",checkFolders=[],runnumber=cool.ValidityKeyMax>>32,selection=""):
    dbSvc = cool.DatabaseSvcFactory.databaseService()
    try:
        db= dbSvc.openDatabase(dbname)
    except Exception as e:
        print ("Problems connecting to database:",e)
        return None

    #Set up Channel Selection:
    sel=None
    print (selection)
    ss=selection.split(",")
    for s in ss:
        if len(s)==0:continue
        idx=s.find(":");
        if idx==-1:
            c1=cool.ChannelId(int(s))
            c2=c1
        else:
            c1=cool.ChannelId(int(s[:idx]))
            c2=cool.ChannelId(int(s[1+idx:]))
        #print ("ExtractFolderInfo: Add channel range",c1,"to",c2)
        if sel is None:
            sel=cool.ChannelSelection(c1,c2,cool.ChannelSelection.sinceBeforeChannel);
        else:
            sel.addRange(c1,c2);
                               
    if sel is None:
        print ("ExtractFolderInfo: No COOL channel selection given, work on all channels")
        sel=cool.ChannelSelection.all()
        
        
    folderInfoList=list()

    nodelist=db.listAllNodes()
    for fn in nodelist:
        if not db.existsFolder(fn): continue
        if len(checkFolders):
            takeFolder=False
            for cf in checkFolders:
                if cf[-1] is "/": cf=cf[0:-1]
                idx=len(cf)
                if fn.startswith(cf) and (idx>=len(fn) or fn[idx]=="/"):
                    takeFolder=True
                    break                 
            if not takeFolder: continue
            
        f=db.getFolder(fn)
        print ("Analyzing",fn)
        #Parse Folder description:
        #Model:
        #<timeStamp>run-lumi</timeStamp><symlinks>ILArAutoCorr</symlinks><key>LArAutoCorr</key><addrHeader><address_header service_type="71" clid="255786016" /></addrHeader><typeName>LArAutoCorrComplete</typeName>  -
        # Get Type
        descr=f.description()
        i1=descr.find("<typeName>")+len("<typeName>")
        i2=descr.find("</typeName>",i1)
        if (i1==-1 or i2==-1):
            print ("ERROR could not get typename of object stored in folder",fn)
            continue
        typename=descr[i1:i2]

        
        i1=descr.find("<key>")+len("<key>")
        i2=descr.find("</key>",i1)
        if (i1==-1 or i2==-1):
            print ("ERROR could not get SG key of object stored in folder",fn)
            continue
        key=descr[i1:i2]


        #Loop over all tags
        
        tagList=f.listTags()
        if len(tagList)==0:
            tagList=[""]
        elif len(tagList)>1 and globaltag!="":
            try:
                tagList=[f.resolveTag(globaltag)]
            except Exception:
                print ("Hierachical tag", globaltag,"not defined in folder",fn)
                return None

        for t in tagList:
            itr=f.findObjects(runnumber<<32,sel,t)
            minIOV=cool.ValidityKeyMax>>32
            maxIOV=cool.ValidityKeyMin>>32
            #Loop over all objects to get IOV
            while itr.goToNext():
                obj=itr.currentRef()
                #payload=obj.payload()
                since=obj.since()>>32
                until=obj.until()>>32
                #print (fn,t,since,until)
                if minIOV>since: minIOV=since
                if maxIOV<until: maxIOV=until
            itr.close()

            #Form tuple:
            folderinfo=(fn,typename,key,t,minIOV,maxIOV)
            folderInfoList+=[folderinfo]

    db.closeDatabase()
    return folderInfoList
    myfolder = None
    if creation:
        myfolder = db.createFolder(folderPath, spec, desc,
                                   cool.FolderVersioning.MULTI_VERSION, True)
    else:
        myfolder = db.getFolder(folderPath)
    #iovMin=cool.ValidityKeyMin
    iovMin = (222222 << 32)
    iovMax = cool.ValidityKeyMax
    uploadCount = 0
    try:
        for hashId in mydata:
            payload = cool.Record(spec)
            payload['data'] = mydata[hashId]
            print mydata[hashId]
            channelID = cool.ChannelId(hashId)
            myfolder.storeObject(iovMin, iovMax, payload, channelID)
            uploadCount += 1
    except Exception, e:
        print "Problem uploading ", e
        db.closeDatabase()
        return 0
    db.closeDatabase()
    return uploadCount


def main():
    """'main()' command to make an SQLite db from a pixel calibration text file.
  The calibration file format is as sent by
  Tayfun Ince, but the identifier format may be either the svn format one (link below) or
  that prepared by Geraldine Conti. Different parsers are supplied in the IBLTotParser