Commit 4b41c3f6 authored by Sebastien Petitdemange's avatar Sebastien Petitdemange
Browse files

integrating counter: new interface to create counters.

parent eadf1a3d
......@@ -274,3 +274,41 @@ class DefaultSamplingCounterGroupedReadHandler(SamplingCounter.GroupedReadHandle
return self.controller.read_all(*counters)
class IntegratingCounter(Counter):
class GroupedReadHandler(GroupedReadMixin):
def get_values(self, from_index, *counters):
"""
this method should return a list of reads values in the same order
as the counter_name
"""
raise NotImplementedError
"""
Base class for integrated counters.
"""
def __init__(self, name, controller, acquisition_controller):
Counter.__init__(self, name, controller, DefaultIntegratingCounterGroupedReadHandler)
self.__acquisition_controller_ref = weakref.ref(acquisition_controller)
def get_values(self, from_index=0):
"""
Overwrite in your class to provide a useful integrated counter class
this method is called after the prepare and start on the master handler.
this method can block until the data is ready or not and return empty data.
When data is ready should return the data from the acquisition
point **from_point_index**
"""
raise NotImplementedError
@property
def acquisition_controller(self):
return self.__acquisition_controller_ref()
class DefaultIntegratingCounterGroupedReadHandler(IntegratingCounter.GroupedReadHandler):
"""
Default read all handler for controller which have read_all method
"""
def get_values(self, from_index, *counters):
return self.controller.get_values(from_index, *counters)
......@@ -142,3 +142,47 @@ class CounterAcqDevice(AcquisitionDevice):
self._ready_flag = True
self._ready_event.set()
class IntegratingAcqDevice(AcquisitionDevice):
def __init__(self,integrating_device,
count_time=None,npoints=1,**keys):
prepare_once = keys.pop('prepare_once',npoints > 1 and True or False)
start_once = keys.pop('start_once',npoints > 1 and True or False)
npoints = max(1,npoints)
AcquisitionDevice.__init__(self, counter, integrating_device.name, "zerod",
npoints=npoints,
trigger_type=AcquisitionDevice.SOFTWARE,
prepare_once=prepare_once,
start_once=start_once,
**keys)
self._count_time = count_time
self.channels.append(AcquisitionChannel(integrating_device.name,numpy.double, (1,)))
self._nb_acq_points = 0
def prepare(self):
self._nb_acq_points = 0
self._stop_flag = False
def start(self):
pass
def stop(self):
self._stop_flag = True
def trigger(self):
pass
def reading(self):
from_point_index = 0
while self._nb_acq_points < self.npoints and not self._stop_flag:
data = self.device.get_value(from_point_index)
if data:
from_point_index += len(data)
self._nb_acq_points += len(data)
channel_data = {self.name:data}
dispatcher.send("new_data",self,
{"channel_data": channel_data})
gevent.idle()
else:
gevent.sleep(count_time/2.)
......@@ -10,6 +10,7 @@ from bliss.common.event import dispatcher
import time
import gevent
import numpy
import weakref
class SoftwareTimerMaster(AcquisitionMaster):
def __init__(self,count_time,sleep_time=None, **keys):
......@@ -55,3 +56,30 @@ class SoftwareTimerMaster(AcquisitionMaster):
def stop(self):
pass
class IntegratingTimerMaster(object):
def __init__(self):
self.__count_time = 1.
@property
def count_time(self):
return self.__count_time
@count_time.setter
def count_time(self,value):
self.__count_time = value
def prepare(self):
integrated_devices = [x.device for x in self.slaves]
self._prepare(integrated_devices)
def start(self):
self._start()
def trigger(self):
pass
def _prepare(self,integrated_devices):
""" Overwrite in your class if you need it """
pass
def _start(self):
""" Overwrite in your class if you need it """
pass
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment