Commit 4d4392b7 authored by Matias Guijarro's avatar Matias Guijarro Committed by Sebastien Petitdemange
Browse files

several class renaming.

 - renamed (CounterAcqDevice, IntegratingAcqDevice) -> (CounterAcquisitionDevice, IntegratingAcquisitionDevice) to be more coherent
with others acquisition devices
 - renamed IntegratingAcquisitionDevice -> IntegratingCounterAcquisitionDevice
 - renamed CounterAcquisitionDevice -> SamplingCounterAcquisitionDevice
 - renamed ReadAllHandler -> GroupedReadHandler
parent aff89935
......@@ -237,7 +237,7 @@ class Counter(object):
def read_all_handler(self):
"""
Should return a handler which is has the interface of SamplingCounter.ReadAllHandler.
Should return a handler which is has the interface of SamplingCounter.GroupedReadHandler.
This Handler will be used to group counters to read all values at once.
"""
if self.__default_read_all_handler:
......@@ -255,7 +255,7 @@ class SamplingCounter(Counter):
raise NotImplementedError
def __init__(self, name, controller):
Counter.__init__(self,name,controller,DefaultSamplingReadAllHandler)
Counter.__init__(self,name,controller,DefaultSamplingCounterGroupedReadHandler)
def read(self):
handler = self.read_all_handler()
......
......@@ -27,7 +27,7 @@ from bliss.common.temperature import Input, Output, TempControllerCounter
from bliss.common.task_utils import *
from bliss.common.motor_group import Group
from bliss.common.measurement import SamplingCounter, IntegratingCounter
from bliss.scanning.acquisition.counter import CounterAcqDevice, IntegratingAcqDevice
from bliss.scanning.acquisition.counter import SamplingCounterAcquisitionDevice, IntegratingCounterAcquisitionDevice
from bliss.scanning.chain import AcquisitionChain
from bliss.scanning import scan as scan_module
from bliss.scanning.acquisition.timer import SoftwareTimerMaster
......@@ -41,11 +41,11 @@ from bliss.data.scan import get_data
_log = logging.getLogger('bliss.scans')
class TimestampPlaceholder:
def __init__(self):
self.name = 'timestamp'
def _get_counters(mg, missing_list):
counters = list()
if mg is not None:
......@@ -57,7 +57,6 @@ def _get_counters(mg, missing_list):
missing_list.append(cnt_name)
return counters
def _get_all_counters(counters):
all_counters, missing_counters = [], []
if counters:
......@@ -75,12 +74,11 @@ def _get_all_counters(counters):
"Hint: disable inactive counters."
% ", ".join(missing_counters))
return all_counters
def default_master_configuration(device, scan_pars):
"""
This function should create and configured
a device acquisition which could also
This function should create and configure
an acquisition device which could also
be a master for other devices.
@returns the acq_device + counters parameters
......@@ -128,12 +126,12 @@ def default_chain(chain,scan_pars,counters):
try:
read_all_handler = cnt.read_all_handler()
except NotImplementedError:
chain.add(timer, CounterAcqDevice(cnt, count_time=count_time, npoints=npoints))
chain.add(timer, SamplingCounterAcquisitionDevice(cnt, count_time=count_time, npoints=npoints))
else:
uniq_id = read_all_handler.id()
cnt_acq_device = read_cnt_handler.get(uniq_id)
if cnt_acq_device is None:
cnt_acq_device = CounterAcqDevice(read_all_handler, count_time=count_time, npoints=npoints)
cnt_acq_device = SamplingCounterAcquisitionDevice(read_all_handler, count_time=count_time, npoints=npoints)
chain.add(timer, cnt_acq_device)
read_cnt_handler[uniq_id] = cnt_acq_device
cnt_acq_device.add_counter_to_read(cnt)
......@@ -151,12 +149,12 @@ def default_chain(chain,scan_pars,counters):
try:
read_all_handler = cnt.read_cnt_handler()
except NotImplementedError:
chain.add(master_acq_device,IntegratingAcqDevice(cnt,count_time=count_time,npoints=npoints))
chain.add(master_acq_device,IntegratingCounterAcquisitionDevice(cnt,count_time=count_time,npoints=npoints))
else:
uniq_id = read_all_handler.id()
cnt_acq_device = integrating_cnt_handler.get(uniq_id)
if cnt_acq_device is None:
cnt_acq_device = IntegratingAcqDevice(read_all_handler,count_time=count_time,npoints=npoints)
cnt_acq_device = IntegratingCounterAcquisitionDevice(read_all_handler,count_time=count_time,npoints=npoints)
chain.add(master_acq_device, cnt_acq_device)
integrating_cnt_handler[uniq_id] = cnt_acq_device
cnt_acq_device.add_counter_to_read(cnt)
......
......@@ -7,17 +7,18 @@
import numpy
import time
from gevent import event,sleep
import gevent
from gevent import event
from bliss.common.event import dispatcher
from ..chain import AcquisitionDevice,AcquisitionChannel
from ..chain import AcquisitionDevice, AcquisitionChannel
from bliss.common.measurement import SamplingCounter
class CounterAcqDevice(AcquisitionDevice):
class SamplingCounterAcquisitionDevice(AcquisitionDevice):
SIMPLE_AVERAGE,TIME_AVERAGE,INTEGRATE = range(3)
def __init__(self,counter,
count_time=None,npoints=1,
mode=SIMPLE_AVERAGE,**keys):
count_time=None, npoints=1,
mode=SIMPLE_AVERAGE, **keys):
"""
Helper to manage acquisition of a sampling counter.
......@@ -29,8 +30,8 @@ class CounterAcqDevice(AcquisitionDevice):
of time spend to measure all values. And *INTEGRATION* which sum all integration
and then normalize it when the *count_time*.
"""
prepare_once = keys.pop('prepare_once',npoints > 1 and True or False)
start_once = keys.pop('start_once',npoints > 1 and True or False)
prepare_once = keys.pop('prepare_once', npoints > 1)
start_once = keys.pop('start_once', npoints > 1)
npoints = max(1,npoints)
AcquisitionDevice.__init__(self, counter, counter.name, "zerod",
npoints=npoints,
......@@ -39,7 +40,7 @@ class CounterAcqDevice(AcquisitionDevice):
start_once=start_once,
**keys)
self._count_time = count_time
if not isinstance(counter,SamplingCounter.ReadAllHandler):
if not isinstance(counter, SamplingCounter.GroupedReadHandler):
self.channels.append(AcquisitionChannel(counter.name,numpy.double, (1,)))
self._nb_acq_points = 0
self._event = event.Event()
......@@ -92,7 +93,7 @@ class CounterAcqDevice(AcquisitionDevice):
def read():
return numpy.array(self.device.read(*self.__counters_list),
dtype=numpy.double)
else: # read_all
else:
def read():
return numpy.array(self.device.read(),
dtype=numpy.double)
......@@ -116,7 +117,7 @@ class CounterAcqDevice(AcquisitionDevice):
end_read = time.time()
read_time = end_read - start_read
if self.__mode != CounterAcqDevice.TIME_AVERAGE:
if self.__mode != SamplingCounterAcquisitionDevice.TIME_AVERAGE:
acc_value += read_value
else:
acc_value += read_value * (end_read - start_read)
......@@ -126,14 +127,14 @@ class CounterAcqDevice(AcquisitionDevice):
current_time = time.time()
if (current_time + (acc_read_time / nb_read)) > stop_time:
break
sleep(0) # Be able to kill the task
gevent.sleep(0) # Be able to kill the task
self._nb_acq_points += 1
if self.__mode == CounterAcqDevice.TIME_AVERAGE:
if self.__mode == SamplingCounterAcquisitionDevice.TIME_AVERAGE:
data = acc_value / nb_read
else:
data = acc_value / acc_read_time
if self.__mode == CounterAcqDevice.INTEGRATE:
if self.__mode == SamplingCounterAcquisitionDevice.INTEGRATE:
data *= self._count_time
channel_data = {name:data[index] for index,name in enumerate(counter_name)}
......@@ -143,20 +144,19 @@ class CounterAcqDevice(AcquisitionDevice):
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)
class IntegratingCounterAcquisitionDevice(AcquisitionDevice):
def __init__(self, counter, count_time=None, npoints=1, **keys):
prepare_once = keys.pop('prepare_once', npoints > 1)
start_once = keys.pop('start_once', npoints > 1)
npoints = max(1,npoints)
AcquisitionDevice.__init__(self, counter, integrating_device.name, "zerod",
AcquisitionDevice.__init__(self, counter, counter.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.channels.append(AcquisitionChannel(counter.name,numpy.double, (1,)))
self._nb_acq_points = 0
def prepare(self):
......
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