def doSetPreset(self, **preset): new_preset = preset if P_MON_SF in preset and P_MON_NSF in preset: if self._attached_flipper.read() == ON: m = preset[P_MON_SF] else: m = preset[P_MON_NSF] new_preset = {P_MON: m} elif P_MON_SF in preset or P_MON_NSF in preset: self.log.warning('Incorrect preset setting. Specify either both ' '%s and %s or only %s.', P_MON_SF, P_MON_NSF, P_MON) return elif P_TIME_SF in preset and P_TIME_NSF in preset: if self._attached_flipper.read() == ON: t = preset[P_TIME_SF] else: t = preset[P_TIME_NSF] new_preset = {P_TIME: t} elif P_TIME_SF in preset or P_TIME_NSF in preset: self.log.warning('Incorrect preset setting. Specify either both ' '%s and %s or only %s.', P_TIME_SF, P_TIME_NSF, P_TIME) return elif P_MON in preset: new_preset = {P_MON: preset[P_MON]} elif P_TIME in preset: new_preset = {P_TIME: preset[P_TIME]} Detector.doSetPreset(self, **new_preset)
def doPreinit(self, mode): if len(self._attached_others) != 1 or not isinstance( self._attached_others[0], Configuration): raise ConfigurationError( 'pilatus detectors require exactly one "other" channel that ' 'is an instance of {}'.format(Configuration)) self._cfg_channel = self._attached_others[0]._dev GenericDetector.doPreinit(self, mode)
def doStart(self): # open shutter if self.ctrl_gammashutter: self._attached_gammashutter.maw(OPEN) if self.ctrl_photoshutter: self._attached_photoshutter.maw(OPEN) Detector.doStart(self) self._prepared = False
def doStop(self): Detector.doStop(self) # close shutter if self.ctrl_photoshutter: self._attached_photoshutter.maw(CLOSED) if self.ctrl_gammashutter: self._attached_gammashutter.maw(CLOSED) self._prepared = False
def doPrepare(self): if not self._prepared: # close shutter if self.ctrl_photoshutter: self._attached_photoshutter.maw(CLOSED) if self.ctrl_gammashutter: self._attached_gammashutter.maw(CLOSED) Detector.doPrepare(self) self._prepared = True
def doFinish(self): Detector.doFinish(self) self._check_shutter() # close shutter if self.ctrl_photoshutter: self._attached_photoshutter.maw(CLOSED) if self.ctrl_gammashutter: self._attached_gammashutter.maw(CLOSED) self._prepared = False
def doResume(self): Detector.doResume(self) if self.pausepv: paused = self._get_pv('pausepv') if paused != 0: self._put_pv('pausepv', 0) else: self.log.info('Device is not paused.') else: self.log.warning( 'Cant resume, provide pausepv parameter for this to work')
def doInit(self, session_mode): Detector.doInit(self, session_mode) self._img = self._attached_images[0] if session_mode == MASTER: if not self._attached_images or \ not isinstance(self._attached_images[0], (KWSImageChannel, VirtualKWSImageChannel)): raise ConfigurationError( self, 'KWSDetector needs a KWSChannel ' 'as attached image') self.kwscounting = False
def doPause(self): Detector.doPause(self) if self.pausepv: paused = self._get_pv('pausepv') if paused != 1: self._put_pv('pausepv', 1) else: self.log.info('Device is already paused.') else: self.log.warning( 'Cant pause, provide pausepv parameter for this to work')
def _presetiter(self): for i, dev in enumerate(self._attached_lives): if i == 0: yield ("live", dev) yield ("live%d" % (i + 1), dev) for itm in Detector._presetiter(self): yield itm
def doRead(self, maxage=0): ret = GenericDetector.doRead(self, maxage) meastime = float(ret[0]) monitor = int(ret[1]) counts = int(ret[2]) if meastime >= self._attached_timers[0].preselection: difftim = meastime = 0 else: difftim = meastime - self._last_time monrate = monitor / meastime if meastime else 0 if monitor == 0 and self._last_moncounts > 0: self._last_moncounts = 0 monrate_inst = (monitor - self._last_moncounts) / difftim if difftim \ else 0 detrate = counts / meastime if meastime else 0 if counts == 0 and self._last_counts > 0: self._last_counts = 0 detrate_inst = (counts - self._last_counts) / difftim if difftim \ else 0 self._setROParam('rates', [[detrate, monrate], [detrate_inst, monrate_inst]]) self._last_time = meastime self._last_counts = counts self._last_moncounts = monitor return ret
def duringMeasureHook(self, elapsed): ret = GenericDetector.duringMeasureHook(self, elapsed) if ret == INTERMEDIATE: [detrate, monrate], [detrate_inst, monrate_inst] = self.rates self.log.info('Monitor: rate: %8.3f counts/s, instantaneous ' 'rate: %8.3f counts/s', monrate, monrate_inst) self.log.info('Signal: rate: %8.3f counts/s, instantaneous ' 'rate: %8.3f counts/s', detrate, detrate_inst) return ret
def doStart(self): try: if self._attached_rc.read(0) != 'on': self.log.warning('radial collimator is not moving!') except NicosError: self.log.warning('could not check radial collimator', exc=1) self._update() self._last_time = 0 self._last_counts = 0 self._last_moncounts = 0 self._starttime = currenttime() self._setROParam('rates', [[0., 0.], [0., 0.]]) session.action('run# %06d' % session.experiment.lastpoint) GenericDetector.doStart(self)
def doSetPreset(self, **preset): Detector.doSetPreset(self, **preset) preset = self._getPreset(preset) if not preset: return for dev in self._attached_lives: dev.islive = False for name in preset: if name in self._presetkeys and self._presetkeys[name] and \ name.startswith("live"): dev = self._presetkeys[name] dev.ismaster = True dev.islive = True self.log.debug(" presets: %s", preset) self.log.debug("presetkeys: %s", self._presetkeys) self.log.debug(" masters: %s", self._masters) self.log.debug(" slaves: %s", self._slaves)
def doStop(self): Detector.doStop(self) self.kwscounting = False if self._attached_shutter and self.openshutter: self._attached_shutter.maw('closed')
def doStart(self): if self._attached_shutter and self.openshutter: self._attached_shutter.maw('open') self.kwscounting = True Detector.doStart(self)
def doPrepare(self): self._configure() Detector.doPrepare(self)
def doSetPreset(self, **preset): # override time preset in realtime mode if self.mode in ('realtime', 'realtime_external'): # set counter card preset to last RT slice preset = {'t': self._img.slices[-1] / 1000000.0} Detector.doSetPreset(self, **preset)
def doInit(self, mode): GenericDetector.doInit(self, mode) if mode == SIMULATION: return self._import_detinfo()
def doResume(self): GenericDetector.doResume(self) # Reset the time for instantaneous rates calculation self._last_time = 0
def duringMeasureHook(self, elapsed): if self._saveIntermediateFlag: self._saveIntermediate() self._saveIntermediateFlag = False return Detector.duringMeasureHook(self, elapsed)
def doInfo(self): for p in ('timechannels', 'timeinterval', 'delay', 'channelwidth'): self._pollParam(p) ret = GenericDetector.doInfo(self) return ret
def doSetPreset(self, **preset): GenericDetector.doSetPreset(self, **preset) if not self._user_comment: # Comment must be fulfilled for data sink self._user_comment = 'No comment'
def doStart(self): # First start all the channels (if applicable) and then # set the detector startpv Detector.doStart(self) self._put_pv('startpv', 1, wait=True)
def doPrepare(self): GenericDetector.doPrepare(self) self.readArrays(FINAL) # update readresult of image channels
def doPreinit(self, mode): GenericDetector.doPreinit(self, mode)
def doFinish(self): Detector.doFinish(self) if self.autoshutter: self._attached_shutter.maw('close')
def doFinish(self): # After setting the startpv to 0 # finish all the channels self._put_pv('startpv', 0, wait=False) Detector.doFinish(self)
def doPreinit(self, mode): EpicsDeviceEss.doPreinit(self, mode) Detector.doPreinit(self, mode)
def doStop(self): # After setting the startpv to 0 # stop all the channels self._put_pv('startpv', 0, wait=False) Detector.doStop(self)