Exemplo n.º 1
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.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)
Exemplo n.º 2
0
    def hw_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 = self.tgs[self.tg_elem_name]
        tg_ctrl = tg.get_controller()
        # crating configuration for TGGeneration
        tg_cfg = createPoolSynchronizationConfiguration((tg_ctrl,),
                                                        ((tg,),))
        # creating PoolSynchronization action
        self.createPoolSynchronization([tg])

        channels = []
        for name in self.channel_names:
            channels.append(self.cts[name])

        ct_ctrl = self.ctrls[self.chn_ctrl_name]

        # add_listeners
        self.addListeners(channels)
        # creating acquisition configurations
        self.hw_acq_cfg = createCTAcquisitionConfiguration((ct_ctrl,),
                                                           (channels,))
        # creating acquisition actions
        self.hw_acq = PoolAcquisitionHardware(channels[0])
        for channel in channels:
            self.hw_acq.add_element(channel)

        # get the current number of jobs
        jobs_before = get_thread_pool().qsize

        ct_ctrl.set_ctrl_par('synchronization', AcqSynch.HardwareTrigger)

        hw_acq_args = ()
        hw_acq_kwargs = {
            'integ_time': integ_time,
            'repetitions': repetitions,
            'config': self.hw_acq_cfg,
        }
        self.hw_acq.run(hw_acq_args, **hw_acq_kwargs)
        tg_args = ()
        tg_kwargs = {
            'offset': offset,
            'active_interval': active_interval,
            'passive_interval': passive_interval,
            'repetitions': repetitions,
            'config': tg_cfg
        }
        self.tggeneration.run(*tg_args, **tg_kwargs)
        # waiting for acquisition and tggeneration to finish
        while self.hw_acq.is_running() or self.tggeneration.is_running():
            time.sleep(1)

        self.do_asserts(self.channel_names, repetitions, jobs_before)
Exemplo n.º 3
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.tg_cfg = createPoolSynchronizationConfiguration(
         (self.tg_ctrl, ),
         ((self.tg_elem, ), ),
     )
     self.tgaction = PoolSynchronization(self.tg_elem)
     self.tgaction.add_element(self.tg_elem)
Exemplo n.º 4
0
    def setUp(self):
        """Create a Controller, TriggerGate and PoolSynchronization objects from
        dummy configurations
        """
        unittest.TestCase.setUp(self)
        pool = FakePool()

        dummy_tg_ctrl = createPoolController(pool, dummyPoolTGCtrlConf01)
        self.dummy_tg = createPoolTriggerGate(pool, dummy_tg_ctrl,
                                              dummyTriggerGateConf01)
        # marrying the element with the controller
        dummy_tg_ctrl.add_element(self.dummy_tg)

        self.cfg = createPoolSynchronizationConfiguration(
            (dummy_tg_ctrl, ), ((self.dummy_tg, ), ))

        # marrying the element with the action
        self.tg_action = PoolSynchronization(self.dummy_tg)
        self.tg_action.add_element(self.dummy_tg)
Exemplo n.º 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_2_1 = self.tgs['_test_tg_1_1']
        tg_ctrl_2 = tg_2_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_2 = ct_2_1.get_controller()
        self.channel_names.append('_test_ct_1_1')
        self.channel_names.append('_test_ct_2_1')
        # crating configuration for TGGeneration
        tg_cfg = createPoolSynchronizationConfiguration((tg_ctrl_2,),
                                                        ((tg_2_1,),))
        # creating TGGeneration action
        self.createPoolSynchronization([tg_2_1])
        # add_listeners
        self.addListeners([ct_1_1, ct_2_1])
        # creating acquisition configurations
        self.hw_acq_cfg = createCTAcquisitionConfiguration((ct_ctrl_1,),
                                                           ((ct_1_1,),))
        self.sw_acq_cfg = createCTAcquisitionConfiguration((ct_ctrl_2,),
                                                           ((ct_2_1,),))
        # creating acquisition actions
        self.hw_acq = PoolAcquisitionHardware(ct_1_1)
        self.sw_acq = 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.hw_acq.add_element(ct_1_1)
        self.sw_acq.add_element(ct_2_1)

        # get the current number of jobs
        jobs_before = get_thread_pool().qsize

        self.sw_acq_args = ()
        self.sw_acq_kwargs = {
            'synch': True,
            'integ_time': integ_time,
            'repetitions': 1,
            'config': self.sw_acq_cfg
        }
        ct_ctrl_1.set_ctrl_par('synchronization', AcqSynch.HardwareTrigger)
        hw_acq_args = ()
        hw_acq_kwargs = {
            'integ_time': integ_time,
            'repetitions': repetitions,
            'config': self.hw_acq_cfg,
        }
        self.hw_acq.run(*hw_acq_args, **hw_acq_kwargs)
        tg_args = ()
        total_interval = active_interval + passive_interval
        synchronization = [{SynchParam.Delay: {SynchDomain.Time: offset},
                            SynchParam.Active: {SynchDomain.Time: active_interval},
                            SynchParam.Total: {SynchDomain.Time: total_interval},
                            SynchParam.Repeats: repetitions}]
        tg_kwargs = {
            'config': tg_cfg,
            'synchronization': synchronization
        }
        self.tggeneration.run(*tg_args, **tg_kwargs)
        # waiting for acquisition and tggeneration to finish
        while (self.hw_acq.is_running() or
               self.sw_acq.is_running() or
               self.tggeneration.is_running()):
            time.sleep(1)
        self.do_asserts(self.channel_names, repetitions, jobs_before)