Example #1
0
    def __init__(self,dbconn=None,pidfile='/tmp/cache.pid', **kw):
        # use of Master assumes that there are not a lot of new PVs being
        # added to the cache so that this lookup of PVs can be done once.
        MasterDB.__init__(self,dbconn=dbconn,**kw)

        self.db.set_autocommit(1)
        self.pid   = self.get_cache_pid()
        self.pidfile = pidfile
        self._table_alerts = self.db.tables['alerts']
        self.pvs   = {}
        self.data  = {}
        self.alert_data = {}
        self.db.set_autocommit(0)
        self.last_update = 0
Example #2
0
    def sync_with_cache(self,update_vals=False):
        """ initialize pv lists, insert times, etc with cache
        use update_vals to force insert of cache values into
        the archive (as on startup)
n       """
        newpvs = []
        cache_values = []
        self.get_cache_names()
        pvtable_data = self.pv_table.select()
        print ' This is sync with cache ', update_vals, len(self.cache_names), len(pvtable_data)
        self.db.use(self.master_db)
        now = time.time()
        print 'masterdb %s / data=%s' % ( self.master_db, len(pvtable_data))
        if update_vals:
            x = self.db.exec_fetch("select pvname,value,ts from cache")
            current_cache = {}
            for i in x:
                current_cache[i['pvname']] = i
                
        for pvdata in pvtable_data:
            name = normalize_pvname(pvdata['name'])
            
            if name not in self.cache_names:
                newpvs.append((name, epics.PV(name)))
            elif update_vals:  
                r = current_cache.get(name,None)
                if r is not None:
                    ts = r['ts']
                    if now - ts > SEC_DAY: ts = now
                    cache_values.append((name,ts,r['value']))

        if len(newpvs)>0:
            epics.poll()
            m = MasterDB()
            for pvname, pv in newpvs:
                if pv.connected:
                    m.add_pv(pvname)
            m.close()
        # now switch to archiving database, and (perhaps) insert values from cache
        if self.dbname is not None:
            self.db.use(self.dbname)
            for name,ts,value in cache_values:
                self.update_value(name,ts,value)
        print 'Sync with Cache Done'
Example #3
0
 def __init__(self,dbconn=None,**kw):
     MasterDB.__init__(self,dbconn=dbconn,**kw)
     self.inst_pos  = self.db.tables['instrument_positions']
Example #4
0
 def __init__(self,dbconn=None,**kw):
     # use of MasterDB assumes that there are not a lot of new PVs being
     # added to the cache so that this lookup of PVs can be done once.
     MasterDB.__init__(self,dbconn=dbconn,**kw)
Example #5
0
 def __init__(self,dbconn=None,**kw):
     MasterDB.__init__(self,dbconn=dbconn,**kw)
     self.alerts = self.db.tables['alerts']