Commit 2bb7cb95 authored by Marie Claire Lagier's avatar Marie Claire Lagier

ID26FastShutter class

parent e7a8d7bf
from bliss import setup_globals
from id26.scripts.beamline_parameters import ID26Parameters, switch_instance
#TEST_ZAP [10]: multiplexer_opiom_cc1.getAllPossibleValues()
# Out [10]: {'ACQ_TRIG': ['COUNT', 'ZAP'], 'SOFT_SHUTTER': ['CLOSE', 'OPEN']}
'''
package: id26.calc_controllers.counter_offsets
class: ID26FastShutter
name: fsh
opiom: $opiom_cc1
multiplexer: multiplexer_opiom_cc1
'''
class ID26FastShutter (ID26Parameters):
def __init__ (self, name, config_dict):
self.opiom = config_dict['opiom']
self.multiplexer = config_dict['multiplexer']
print(config_dict)
def __info__(self):
msg = self._fstate()
msg += " "
msg += 'ON' if self.opiom.registers()['IMA']&0xe else 'OFF'
return(msg)
def _fstate(self):
return (self.multiplexer.getOutputStat('SOFT_SHUTTER'))
def open (self):
self.multiplexer.switch('soft_shutter','open')
def close (self):
self.multiplexer.switch('soft_shutter','close')
def on (self):
'''
Activates the open/close of shutter before/after counting
"IMA 0x%02x 0x0e", mode << 1 ; mode = 1
'''
if self.opiom.comm_ack('IMA 0x{0:02x} 0x0e'.format(1<<1)) != 'OK':
raise RuntimeError ('Bad answer from opiom')
def off (self):
'''
Activates the open/close of shutter before/after counting
"IMA 0x%02x 0x0e", mode << 1 ; mode = 0
'''
if self.opiom.comm_ack('IMA 0x{0:02x} 0x0e'.format(0<<1)) != 'OK':
raise RuntimeError ('Bad answer from opiom')
class ID26OffsetShutter (ID26Parameters):
def __init__ (self):
pass
def open (self):
pass
def close (self):
pass
from bliss.controllers.counter import CalcCounterController
"""
config example:
- plugin: bliss
module: counter_offsets
class: ID26CounterOffsets
name: counter_offset
inputs:
- counter: $diode
tags: data1
- counter: $diode2
tags: data2
outputs:
- name: out1
package: id26.calc_controllers.counter_offsets
class: ID26CounterOffsets
name: counter_offset
inputs:
- counter: $p201A
tags: data1
- counter: $p201A:I00
tags: data2
outputs:
- name: sub_I00
"""
class MeanCalcCounterController(CalcCounterController):
def calc_function(self, input_dict):
csum = 0
for cnt in self.inputs:
csum += input_dict[self.tags[cnt.name]]
csum = csum / float(len(self.inputs))
return {self.tags[self.outputs[0].name]: csum}
class ID26AutoOffsets (CalcCounterController, ID26Parameters):
def __init__ (self, name, config_dict):
CalcCounterController.__init__(self, name, config_dict)
param_name = 'auto_offset_parameters'
_defaults = {}
_defaults['offset_shutter'] = 0
ID26Parameters.__init__(self,
param_name,
_defaults,
no_setup = ['offset_shutter'] #because case 1 not implemented yet: attenuatores and fast-shutter
)
chopper = setup_globals.chopper
def calc_function(self, input_dict):
csum = 2
print ('input_dict',input_dict)
print ('inputs',self.inputs)
print ('tagss',self.tags)
print ('counter',self.counter)
print ('outputs',self.outputs)
for cnt in self.inputs:
print (cnt.name)
print (self.tags[cnt.name])
print (input_dict[self.tags[cnt.name]])
return {self.tags[self.outputs[0].name]: csum}
# @switch_instance
def auto_offset (self, count_time = 4 ):
if self.parameters.offset_shutter:
print ("WARNING: offset_shutter set to 1. I am only closing fshutter and all attenuators.")
#i00_offsets = SUB_OFFSET[cnt_num("I00")]
#gs26_att_on
#att_old = A[att]
#mv att 63
#fshclose; fsoff
else :
print ("AUTO_OFFSETS--closing chopper...")
CHOPPER.move(0)
self.reset_offsets()
'''
ct cnt_time
OFFSETS_NOISE_SPEC_WARNING_IDX = 0
OFFSETS_NOISE_WARNING_SPEC_MAX = 3
while ((S[cnt_num(MMSPECTRO_PAR["xes_det"])]/S[cnt_num("sec")]) > OFFSETS_NOISE_SPEC ) {
_warning_msg = "WARNING !!!! You have high noise on your spectrometer detector. I am counting again...\n"
cprint(_warning_msg, 2, 0, 0, 0)
OFFSETS_NOISE_SPEC_WARNING_IDX += 1
if (OFFSETS_NOISE_SPEC_WARNING_IDX > OFFSETS_NOISE_WARNING_SPEC_MAX) {
_error_msg = "ERROR !!!! REACHED MAXIMUM NUMER OF OFF WARNING MESSAGES. EXITING !!!!\n"
cprint(_error_msg, 2, 0, 0, 0)
exit
}
ct cnt_time
}
# Fill SUB_OFFSET with requested counters &
# (set define_offset_cnts in setup to activate substraction during counting)
for (ii=0;ii<COUNTERS;ii++) {
if (S[cnt_num("sec")] !=0) {
SUB_OFFSET[ii] = S[ii]/S[cnt_num("sec")]
} else {
cprint(sprintf(" ERROR : calculating offsets failed. S[sec]=%f. \n", S[sec]), 1)
}
}
# APD PSEUDOS COUNTERS
SUB_OFFSET[cnt_num("apd_dif")] = 0
SUB_OFFSET[cnt_num("apd_rat")] = 0
SUB_OFFSET[cnt_num("apd")] = 0
SUB_OFFSET[cnt_num("apd_gnd")] = 0
SUB_OFFSET[cnt_num("apd_exc")] = 0
SUB_OFFSET[cnt_num("ICR")] = 0
SUB_OFFSET[cnt_num("OCR")] = 0
SUB_OFFSET[cnt_num("ketek")] = 0
printf("AUTO_OFFSETS--Setting offsets to fixed values: apd = %g \n", SUB_OFFSET[cnt_num("apd")])
printf("AUTO_OFFSETS--Setting offsets to fixed values: apd_gnd = %g \n", SUB_OFFSET[cnt_num("apd_gnd")])
printf("AUTO_OFFSETS--Setting offsets to fixed values: apd_exc = %g \n", SUB_OFFSET[cnt_num("apd_exc")])
printf("AUTO_OFFSETS--Setting offsets to fixed values: ICR = %g \n", SUB_OFFSET[cnt_num("ICR")])
printf("AUTO_OFFSETS--Setting offsets to fixed values: OCR = %g \n", SUB_OFFSET[cnt_num("OCR")])
printf("AUTO_OFFSETS--Setting offsets to fixed values: ketek = %g \n", SUB_OFFSET[cnt_num("ketek")])
if (OFFSET_SHUTTER) {
print "WARNING: global variable OFFSET_SHUTTER set to 1. I am only opening fshutter and all attenuators."
SUB_OFFSET[cnt_num("I00")] = i00_offsets
gs26_att_on
mv att att_old
} else {
print "AUTO_OFFSETS--opening chopper..."
mv chopper 1
}
if (A[energy]>15) {
print "AUTO_OFFSETS--WARNING: Above 15 keV the I00 offsets may not be correct!! Close shutter for good offset measurement."
}
FSCAN_SHUTTER_CONTROL = fscan_shutter_before
if (status_fshutter_before) {fshopen}
print "AUTO_OFFSETS--End."
'''
def reset_offsets (self):
printf("Reset offsets to 0 for all counters\n")
self.sub_offset = 0
#for (ii=0;ii<COUNTERS;ii++) {
# SUB_OFFSET[ii] = 0
#}
Markdown is supported
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