def setUp(self):
        """Create a Controller, TriggerGate and PoolSynchronization objects from
        dummy configurations
        """
        unittest.TestCase.setUp(self)
        try:
            from mock import Mock
        except ImportError:
            self.skipTest("mock module is not available")
        pool = FakePool()
        dummy_tg_ctrl = createPoolController(pool, dummyPoolTGCtrlConf01)
        self.dummy_tg = createPoolTriggerGate(pool, dummy_tg_ctrl,
                                              dummyTriggerGateConf01)
        dummy_tg_ctrl.add_element(self.dummy_tg)
        pool.add_element(dummy_tg_ctrl)
        pool.add_element(self.dummy_tg)
        self.conf_ctrl = createControllerConfiguration(dummy_tg_ctrl,
                                                       [self.dummy_tg])

        self.ctrls = get_acq_ctrls([self.conf_ctrl])
        # self.cfg = createPoolSynchronizationConfiguration((dummy_tg_ctrl,),
        #                                                   ((self.dummy_tg,),),)
        # Create mock and define its functions
        ctrl_methods = ['PreStartAll', 'StartAll', 'PreStartOne', 'StartOne',
                        'PreStateAll', 'StateAll', 'PreStateOne', 'StateOne',
                        'PreSynchAll', 'PreSynchOne', 'SynchOne', 'SynchAll']
        self.mock_tg_ctrl = Mock(spec=ctrl_methods)
        self.mock_tg_ctrl.StateOne.return_value = (State.Moving, 'triggering')

        dummy_tg_ctrl.ctrl = self.mock_tg_ctrl
        self.tgaction = PoolSynchronization(self.dummy_tg)
        self.tgaction.add_element(self.dummy_tg)
예제 #2
0
 def acquire(self, integ_time, repetitions, latency_time):
     """Acquire with a dummy C/T synchronized by a hardware start
     trigger from a dummy T/G."""
     self.prepare(integ_time, repetitions, latency_time, 1)
     conf_ct_ctrl_1 = createTimerableControllerConfiguration(
         self.channel_ctrl, [self.channel])
     ctrls = get_timerable_ctrls([conf_ct_ctrl_1], AcqMode.Timer)
     conf_tg_ctrl_1 = createControllerConfiguration(self.tg_ctrl,
                                                    [self.tg])
     synch_ctrls = get_acq_ctrls([conf_tg_ctrl_1])
     self.synchronization = self.create_action(PoolSynchronization,
                                               [self.tg])
     # add data listeners
     self.add_listeners([self.channel])
     # creating acquisition actions
     self.acquisition = self.create_action(PoolAcquisitionHardware,
                                           [self.channel])
     self.acq_args = ([conf_ct_ctrl_1], integ_time, repetitions)
     # prepare synchronization description
     total_interval = integ_time + latency_time
     group = {
         SynchParam.Delay: {SynchDomain.Time: 0},
         SynchParam.Active: {SynchDomain.Time: integ_time},
         SynchParam.Total: {SynchDomain.Time: total_interval},
         SynchParam.Repeats: repetitions
     }
     synch_description = [group]
     # get the current number of jobs
     jobs_before = get_thread_pool().qsize
     self.acquisition.run(ctrls, integ_time, repetitions, 0)
     self.synchronization.run(synch_ctrls, synch_description)
     self.wait_finish()
     self.do_asserts(repetitions, jobs_before)
예제 #3
0
 def acquire(self, integ_time, repetitions, latency_time):
     """Acquire with a dummy C/T synchronized by a hardware start
     trigger from a dummy T/G."""
     self.ct_ctrl_1.set_ctrl_par("synchronization", AcqSynch.HardwareStart)
     conf_ct_ctrl_1 = createTimerableControllerConfiguration(
         self.ct_ctrl_1, [self.ct_1_1])
     ctrls = get_timerable_ctrls([conf_ct_ctrl_1], AcqMode.Timer)
     conf_tg_ctrl_1 = createControllerConfiguration(self.tg_ctrl_1,
                                                    [self.tg_1_1])
     synch_ctrls = get_acq_ctrls([conf_tg_ctrl_1])
     self.synchronization = self.create_action(PoolSynchronization,
                                               [self.tg_1_1])
     # add data listeners
     self.add_listeners([self.ct_1_1])
     # creating acquisition actions
     self.acquisition = self.create_action(PoolAcquisitionHardware,
                                           [self.ct_1_1])
     self.acq_args = ([conf_ct_ctrl_1], integ_time, repetitions)
     # prepare synchronization description
     total_interval = integ_time + latency_time
     group = {
         SynchParam.Delay: {SynchDomain.Time: 0},
         SynchParam.Active: {SynchDomain.Time: integ_time},
         SynchParam.Total: {SynchDomain.Time: total_interval},
         SynchParam.Repeats: repetitions
     }
     synchronization = [group]
     # get the current number of jobs
     jobs_before = get_thread_pool().qsize
     self.acquisition.run(ctrls, integ_time, repetitions, 0)
     self.synchronization.run(synch_ctrls, synchronization)
     self.wait_finish()
     self.do_asserts(repetitions, jobs_before)
예제 #4
0
    def setUp(self):
        """Create a Controller, TriggerGate and PoolSynchronization objects from
        dummy configurations
        """
        unittest.TestCase.setUp(self)
        try:
            from mock import Mock
        except ImportError:
            self.skipTest("mock module is not available")
        pool = FakePool()
        dummy_tg_ctrl = createPoolController(pool, dummyPoolTGCtrlConf01)
        self.dummy_tg = createPoolTriggerGate(pool, dummy_tg_ctrl,
                                              dummyTriggerGateConf01)
        dummy_tg_ctrl.add_element(self.dummy_tg)
        pool.add_element(dummy_tg_ctrl)
        pool.add_element(self.dummy_tg)
        self.conf_ctrl = createControllerConfiguration(dummy_tg_ctrl,
                                                       [self.dummy_tg])

        self.ctrls = get_acq_ctrls([self.conf_ctrl])
        # self.cfg = createPoolSynchronizationConfiguration((dummy_tg_ctrl,),
        #                                                   ((self.dummy_tg,),),)
        # Create mock and define its functions
        ctrl_methods = [
            'PreStartAll', 'StartAll', 'PreStartOne', 'StartOne',
            'PreStateAll', 'StateAll', 'PreStateOne', 'StateOne',
            'PreSynchAll', 'PreSynchOne', 'SynchOne', 'SynchAll'
        ]
        self.mock_tg_ctrl = Mock(spec=ctrl_methods)
        self.mock_tg_ctrl.StateOne.return_value = (State.Moving, 'triggering')

        dummy_tg_ctrl.ctrl = self.mock_tg_ctrl
        self.tgaction = PoolSynchronization(self.dummy_tg)
        self.tgaction.add_element(self.dummy_tg)
예제 #5
0
    def continuous_acquisition(self, offset, active_interval, passive_interval,
                               repetitions, integ_time):
        """Executes measurement running the TGGeneration and Acquisition actions
        according the test parameters. Checks the lengths of the acquired data.
        """
        # obtaining elements created in the BasePoolTestCase.setUp
        tg_1_1 = self.tgs['_test_tg_1_1']
        tg_ctrl_1 = tg_1_1.get_controller()
        ct_1_1 = self.cts['_test_ct_1_1']  # hw synchronized
        ct_2_1 = self.cts['_test_ct_2_1']  # sw synchronized
        ct_ctrl_1 = ct_1_1.get_controller()
        ct_ctrl_1.set_ctrl_par("synchronization", AcqSynch.HardwareTrigger)
        ct_ctrl_2 = ct_2_1.get_controller()
        self.channel_names.append('_test_ct_1_1')
        self.channel_names.append('_test_ct_2_1')

        conf_ct_ctrl_1 = createTimerableControllerConfiguration(ct_ctrl_1,
                                                                [ct_1_1])
        conf_ct_ctrl_2 = createTimerableControllerConfiguration(ct_ctrl_2,
                                                                [ct_2_1])
        hw_ctrls = get_timerable_ctrls([conf_ct_ctrl_1],
                                       acq_mode=AcqMode.Timer)
        sw_ctrls = get_timerable_ctrls([conf_ct_ctrl_2],
                                       acq_mode=AcqMode.Timer)
        sw_master = sw_ctrls[0].master
        conf_tg_ctrl_1 = createControllerConfiguration(tg_ctrl_1, [tg_1_1])
        synch_ctrls = get_acq_ctrls([conf_tg_ctrl_1])
        # creating synchronization action
        self.synchronization = self.create_action(PoolSynchronization,
                                                  [tg_1_1])
        self.synchronization.add_listener(self)
        # add_listeners
        self.add_listeners([ct_1_1, ct_2_1])
        # creating acquisition actions
        self.hw_acq = self.create_action(PoolAcquisitionHardware, [ct_1_1])
        self.sw_acq = self.create_action(PoolAcquisitionSoftware, [ct_2_1])
        self.sw_acq_args = (sw_ctrls, integ_time, sw_master)
        self.sw_acq_kwargs = dict(synch=True)

        total_interval = active_interval + passive_interval
        group = {
            SynchParam.Delay: {SynchDomain.Time: offset},
            SynchParam.Active: {SynchDomain.Time: active_interval},
            SynchParam.Total: {SynchDomain.Time: total_interval},
            SynchParam.Repeats: repetitions
        }
        synch_description = [group]
        # get the current number of jobs
        jobs_before = get_thread_pool().qsize
        self.hw_acq.run(hw_ctrls, integ_time, repetitions, 0)
        self.synchronization.run(synch_ctrls, synch_description)
        # waiting for acquisition and synchronization to finish
        while (self.hw_acq.is_running()
               or self.sw_acq._is_busy()
               or self.synchronization.is_running()):
            time.sleep(.1)
        self.do_asserts(repetitions, jobs_before)
예제 #6
0
 def createElements(self, ctrl_klass, ctrl_lib, ctrl_props):
     # create controller and element
     ctrl_conf = createCtrlConf(self.pool, 'tgctrl01', ctrl_klass,
                                ctrl_lib, ctrl_props)
     elem_conf = createElemConf(self.pool, 1, 'tg01')
     self.tg_ctrl = createPoolController(self.pool, ctrl_conf)
     self.tg_elem = createPoolTriggerGate(self.pool, self.tg_ctrl,
                                          elem_conf)
     # add controller and elements to containers
     self.tg_ctrl.add_element(self.tg_elem)
     self.pool.add_element(self.tg_ctrl)
     self.pool.add_element(self.tg_elem)
     # create Synchronization action and its configuration
     self.conf_ctrl = createControllerConfiguration(self.tg_ctrl,
                                                    [self.tg_elem])
     self.ctrls = get_acq_ctrls([self.conf_ctrl])
     self.tgaction = PoolSynchronization(self.tg_elem)
     self.tgaction.add_element(self.tg_elem)
예제 #7
0
 def createElements(self, ctrl_klass, ctrl_lib, ctrl_props):
     # create controller and element
     ctrl_conf = createCtrlConf(self.pool, 'tgctrl01', ctrl_klass, ctrl_lib,
                                ctrl_props)
     elem_conf = createElemConf(self.pool, 1, 'tg01')
     self.tg_ctrl = createPoolController(self.pool, ctrl_conf)
     self.tg_elem = createPoolTriggerGate(self.pool, self.tg_ctrl,
                                          elem_conf)
     # add controller and elements to containers
     self.tg_ctrl.add_element(self.tg_elem)
     self.pool.add_element(self.tg_ctrl)
     self.pool.add_element(self.tg_elem)
     # create Synchronization action and its configuration
     self.conf_ctrl = createControllerConfiguration(self.tg_ctrl,
                                                    [self.tg_elem])
     self.ctrls = get_acq_ctrls([self.conf_ctrl])
     self.tgaction = PoolSynchronization(self.tg_elem)
     self.tgaction.add_element(self.tg_elem)
예제 #8
0
    def continuous_acquisition(self, offset, active_interval, passive_interval,
                               repetitions, integ_time):
        """Executes measurement running the TGGeneration and Acquisition actions
        according the test parameters. Checks the lengths of the acquired data.
        """
        # obtaining elements created in the BasePoolTestCase.setUp
        tg_1_1 = self.tgs['_test_tg_1_1']
        tg_ctrl_1 = tg_1_1.get_controller()
        ct_1_1 = self.cts['_test_ct_1_1']  # hw synchronized
        ct_2_1 = self.cts['_test_ct_2_1']  # sw synchronized
        ct_ctrl_1 = ct_1_1.get_controller()
        ct_ctrl_1.set_ctrl_par("synchronization", AcqSynch.HardwareTrigger)
        ct_ctrl_2 = ct_2_1.get_controller()
        self.channel_names.append('_test_ct_1_1')
        self.channel_names.append('_test_ct_2_1')

        conf_ct_ctrl_1 = createTimerableControllerConfiguration(
            ct_ctrl_1, [ct_1_1])
        conf_ct_ctrl_2 = createTimerableControllerConfiguration(
            ct_ctrl_2, [ct_2_1])
        hw_ctrls = get_timerable_ctrls([conf_ct_ctrl_1],
                                       acq_mode=AcqMode.Timer)
        sw_ctrls = get_timerable_ctrls([conf_ct_ctrl_2],
                                       acq_mode=AcqMode.Timer)
        sw_master = sw_ctrls[0].master
        conf_tg_ctrl_1 = createControllerConfiguration(tg_ctrl_1, [tg_1_1])
        synch_ctrls = get_acq_ctrls([conf_tg_ctrl_1])
        # creating synchronization action
        self.synchronization = self.create_action(PoolSynchronization,
                                                  [tg_1_1])
        self.synchronization.add_listener(self)
        # add_listeners
        self.add_listeners([ct_1_1, ct_2_1])
        # creating acquisition actions
        self.hw_acq = self.create_action(PoolAcquisitionHardware, [ct_1_1])
        self.sw_acq = self.create_action(PoolAcquisitionSoftware, [ct_2_1])
        # Since we deposit the software acquisition action on the PoolThread's
        # queue we can not rely on the action's state - one may still wait
        # in the queue (its state has not changed to running yet) and we would
        # be depositing another one. This way we may be starting multiple
        # times the same action (with the same elements involved), what results
        # in "already involved in operation" errors.
        # Use an external Event flag to mark if we have any software
        # acquisition action pending.
        self.sw_acq_busy = threading.Event()
        self.sw_acq.add_finish_hook(self.sw_acq_busy.clear)
        self.sw_acq_args = (sw_ctrls, integ_time, sw_master)
        self.sw_acq_kwargs = {}

        total_interval = active_interval + passive_interval
        group = {
            SynchParam.Delay: {
                SynchDomain.Time: offset
            },
            SynchParam.Active: {
                SynchDomain.Time: active_interval
            },
            SynchParam.Total: {
                SynchDomain.Time: total_interval
            },
            SynchParam.Repeats: repetitions
        }
        synchronization = [group]
        # get the current number of jobs
        jobs_before = get_thread_pool().qsize
        self.hw_acq.run(hw_ctrls, integ_time, repetitions, 0)
        self.synchronization.run(synch_ctrls, synchronization)
        # waiting for acquisition and synchronization to finish
        while (self.hw_acq.is_running() or self.sw_acq.is_running()
               or self.synchronization.is_running()):
            time.sleep(.1)
        self.do_asserts(repetitions, jobs_before)
예제 #9
0
    def continuous_acquisition(self, offset, active_interval, passive_interval,
                               repetitions, integ_time):
        """Executes measurement running the TGGeneration and Acquisition actions
        according the test parameters. Checks the lengths of the acquired data.
        """
        # obtaining elements created in the BasePoolTestCase.setUp
        tg_1_1 = self.tgs['_test_tg_1_1']
        tg_ctrl_1 = tg_1_1.get_controller()
        ct_1_1 = self.cts['_test_ct_1_1']  # hw synchronized
        ct_2_1 = self.cts['_test_ct_2_1']  # sw synchronized
        ct_ctrl_1 = ct_1_1.get_controller()
        ct_ctrl_1.set_ctrl_par("synchronization", AcqSynch.HardwareTrigger)
        ct_ctrl_2 = ct_2_1.get_controller()
        self.channel_names.append('_test_ct_1_1')
        self.channel_names.append('_test_ct_2_1')

        conf_ct_ctrl_1 = createTimerableControllerConfiguration(ct_ctrl_1,
                                                                [ct_1_1])
        conf_ct_ctrl_2 = createTimerableControllerConfiguration(ct_ctrl_2,
                                                                [ct_2_1])
        hw_ctrls = get_timerable_ctrls([conf_ct_ctrl_1],
                                       acq_mode=AcqMode.Timer)
        sw_ctrls = get_timerable_ctrls([conf_ct_ctrl_2],
                                       acq_mode=AcqMode.Timer)
        sw_master = sw_ctrls[0].master
        conf_tg_ctrl_1 = createControllerConfiguration(tg_ctrl_1, [tg_1_1])
        synch_ctrls = get_acq_ctrls([conf_tg_ctrl_1])
        # creating synchronization action
        self.synchronization = self.create_action(PoolSynchronization,
                                                  [tg_1_1])
        self.synchronization.add_listener(self)
        # add_listeners
        self.add_listeners([ct_1_1, ct_2_1])
        # creating acquisition actions
        self.hw_acq = self.create_action(PoolAcquisitionHardware, [ct_1_1])
        self.sw_acq = self.create_action(PoolAcquisitionSoftware, [ct_2_1])
        # Since we deposit the software acquisition action on the PoolThread's
        # queue we can not rely on the action's state - one may still wait
        # in the queue (its state has not changed to running yet) and we would
        # be depositing another one. This way we may be starting multiple
        # times the same action (with the same elements involved), what results
        # in "already involved in operation" errors.
        # Use an external Event flag to mark if we have any software
        # acquisition action pending.
        self.sw_acq_busy = threading.Event()
        self.sw_acq.add_finish_hook(self.sw_acq_busy.clear)
        self.sw_acq_args = (sw_ctrls, integ_time, sw_master)
        self.sw_acq_kwargs = {}

        total_interval = active_interval + passive_interval
        group = {
            SynchParam.Delay: {SynchDomain.Time: offset},
            SynchParam.Active: {SynchDomain.Time: active_interval},
            SynchParam.Total: {SynchDomain.Time: total_interval},
            SynchParam.Repeats: repetitions
        }
        synchronization = [group]
        # get the current number of jobs
        jobs_before = get_thread_pool().qsize
        self.hw_acq.run(hw_ctrls, integ_time, repetitions, 0)
        self.synchronization.run(synch_ctrls, synchronization)
        # waiting for acquisition and synchronization to finish
        while (self.hw_acq.is_running()
               or self.sw_acq.is_running()
               or self.synchronization.is_running()):
            time.sleep(.1)
        self.do_asserts(repetitions, jobs_before)