Source code for pycaldaq_rcs

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# Copyright 2012-2015 Frédéric Magniette, Miguel Rubio-Roy, LLR
#

import bindpyrame,time,json

[docs]def initialize(): "Perform the initialize transition. If not in UNDEFINED state, the necessary transitions to get to that state will also be performed beforehand" return transition("ecal","init","deinit")
[docs]def deinitialize(): "Perform the deinitialize transition. If not in READY state, the necessary transitions to get to that state will also be performed beforehand" return transition("ecal","deinit","undef")
[docs]def fconfigure(): "Perform the configure transition. If not in READY state, the necessary transitions to get to that state will also be performed beforehand" return transition("ecal","fconfig","inval")
[docs]def configure(): "Perform the configure transition. If not in READY state, the necessary transitions to get to that state will also be performed beforehand" return transition("ecal","config","inval")
[docs]def validate(): "Perform the validate transition. If not in RECONFIGURED state, the necessary transitions to get to that state will also be performed beforehand" return transition("ecal","validate","undef")
[docs]def invalidate(): "Perform the invalidate transition. If not in CONFIGURED state, the necessary transitions to get to that state will also be performed beforehand" return transition("ecal","inval","undef")
[docs]def start_acq(acq): "Perform the start_acq transition. If not in CONFIGURED state, the necessary transitions to get to that state will also be performed beforehand" return transition("ecal","start_acq","undef",json.dumps(acq))
[docs]def stop_acq(): "Perform the stop_acq transition. If not in ACQUIRING state, the necessary transitions to get to that state will also be performed beforehand" return transition("ecal","stop_acq","undef")
[docs]def list_dev(dev_type,root): "Get the list of devices from the current configuration of type *dev_type* descendants of device *root*." return rc_call("get_name_sublist_cmod",dev_type,root).split(",")
[docs]def get_state(): "Get current state of ecal state machine" return rc_call("get_state_ecal","ecal")
[docs]def get_dev_id(dev_name): "Get id of device *dev_name*" return rc_call("get_id_cmod",dev_name)
[docs]def get_var(var_name): "Get value of *var_name* in module varmod" return rc_call("getvar_varmod","varmod","default",var_name)
[docs]def get_param(dev_name,param_name): "Get value of parameter *param_name* of device *dev_name* in the current configuration" return rc_call("get_param_cmod",dev_name,param_name)
[docs]def reconfigure(dev_name,func,*params): "Perform a reconfiguration by running function *func* on device *dev_name* with *params* arguments" return rc_call("reconfigure_ecal","ecal",dev_name,func,*params)
################################## def new_run(run_name,mode="append"): return new_run_rcs("storage",run_name,mode) def new_acq(acq_name,run,mode="append",convert_script="undef"): return new_acq_rcs("storage",acq_name,run,mode,convert_script) def wait_acq_finished(acq): return wait_acq_finished_rcs("storage",acq) def wait_run_finished(run): return wait_run_finished_rcs("storage",run) def set_param_run(run,name,value): return set_param_run_rcs("storage",run,name,value) def get_param_run(run,name): return set_param_run_rcs("storage",run,name) def set_param_acq(acq,name,value): return set_param_acq_rcs("storage",acq,name,value) def get_param_acq(acq,name): return set_param_acq_rcs("storage",acq,name) progress_acq=0
[docs]def timed_acq(acq_name,run,acq_time): "Performed a timed acquisition named *acq_name* in run *run* (object returned by new_run) during *acq_time* seconds" global progress_acq acq=new_acq(acq_name,run) print("acquiring for %.0f s"%(acq_time)) progress_acq=0 start_acq(acq) div=100 try: for i in range(div): int_sleep(float(acq_time)/div) progress_acq=i finally: stop_acq() progress_acq=100 return acq
[docs]def nb_hits_acq(acq_name,run,nb_hits): "Perform an acquisition with *nb_hits* hits, named *acq_name* in run *run* (object returned by new_run)" global progress_acq acq=new_acq(acq_name,run) print("acquiring for %d hits"%(nb_hits)) progress_acq=0 start_acq(acq) curr_nb_hits=0 try: while curr_nb_hits<nb_hits: int_sleep(1) curr_nb_hits=float(get_var("nb_hits")) progress_acq=min(int(curr_nb_hits/float(nb_hits)*100),99) finally: stop_acq() progress_acq=100 return acq
[docs]def nb_spills_acq(acq_name,run,nb_spills): "Performed an acquisition named *acq_name* in run *run* (object returned by new_run) during *nb_spills* spills" global progress_acq acq=new_acq(acq_name,run) print("acquiring for %d spills"%(nb_spills)) progress_acq=0 start_acq(acq) curr_nb_spills=0 try: while curr_nb_spills<nb_spills: int_sleep(1) curr_nb_spills=float(get_var("nb_spills")) progress_acq=min(int(curr_nb_spills/float(nb_spills)*100),99) finally: stop_acq() progress_acq=100 return acq
##################################
[docs]def timed_scurves(acq_name,run,trig_max,trig_min,step,acq_time,roctype): "Perform an timed S-curve run named *run_name*. Start on trigger threshold *trig_max* and descend with *step* down to *trig_min*. Each step takes *acq_time* seconds. *roctype* defined the type of ROC (skiroc,spiroc2d,...)" return generic_scurves("timed",acq_name,run,trig_max,trig_min,step,acq_time,roctype)
[docs]def nb_hits_scurves(acq_name,run,trig_max,trig_min,step,nb_hits,roctype): "Perform an S-curve run named *run_name* with a defined number of hits *nb_hits* per step. Start on trigger threshold *trig_max* and descend with *step* down to *trig_min*. *roctype* defined the type of ROC (skiroc,spiroc2d,...)" return generic_scurves("nb_hits",acq_name,run,trig_max,trig_min,step,nb_hits,roctype)
progress_trig_scurves=0 def generic_scurves(wait_type,acq_name,run,trig_max,trig_min,step,wait,roctype): global progress_trig_scurves progress_trig_scurves=0 for trig in range(trig_max,trig_min-step,-step): progress_trig_scurves=int(float(trig_max-trig)/float(trig_max-trig_min+step)*100) print("scurves threshold %d"%(trig)) for roc in list_dev(roctype,"root"): reconfigure(roc,"set_gtrigger_%s"%(roctype),str(trig)) c_acq_name="%s/scurve_trig%d"%(acq_name,trig) if wait_type=="timed": acq=timed_acq(c_acq_name,run,wait) elif wait_type=="nb_hits": acq=nb_hits_acq(c_acq_name,run,wait) else: raise Exception("unknown wait_type %s"%(wait_type)) progress_trig_scurves=100 return acq ##################################
[docs]def run_cmdfile(filename): "Run as python code every line of *filename* separately until a line with the keyword *quit* is found" with open(filename) as f: for s in f: if s[0:4]=="quit": return -1 eval(s) return 0
###### Moving table def table_goto(point_name): dst_x=None dst_y=None #analyse point name and calculate coordinates in mm from the zero blue cross if point_name=="center": dst_x=0 dst_y=8.3+90 if point_name=="zero": dst_x=0 dst_y=0 if point_name[0:4]=="grid": pos=int(point_name[4:]) print("position=%d"%(pos)) if pos<0 or pos>80: raise Exception("grid pos is out of table possibilities (1-54 available)") g_x=1+2*(pos%9) g_y=1+(pos-pos%9)/9*2 print("grid position %d,%d"%(g_x,g_y)) dst_x=90-g_x*10 dst_y=8.3+g_y*10 if dst_x==None or dst_y==None: raise Exception("unknown position %s"%(point_name)) #conversion in table steps dst_x=int(dst_x*800) dst_y=int(dst_y*-16000) #getting present position of the table retcode,res=rc_pycall("get_pos_pk_xli","axis_x") if retcode==0: raise Exception("unable to get x position : %s"%(res)) pos_x=int(res) retcode,res=rc_pycall("get_pos_pk_xli","axis_y") if retcode==0: raise Exception("unable to get y position : %s"%(res)) pos_y=int(res) #calculate the move mov_x=dst_x-pos_x mov_y=dst_y-pos_y #move print("moving from %d,%d to %d,%d move is %d,%d"%(pos_x,pos_y,dst_x,dst_y,mov_x,mov_y)) #axis x retcode,res=rc_pycall("move_pk_xli","axis_x",str(mov_x),"5","5") if retcode==0: raise Exception("unable to move x axis : %s"%(res)) #remove y brake retcode,res=rc_pycall("set_output_pk_xli","axis_y","8","1") if retcode==0: raise Exception("unable to remove y brake : %s"%(res)) #move y retcode,res=rc_pycall("move_pk_xli","axis_y",str(mov_y),"20","20") if retcode==0: raise Exception("unable to move y axis : %s"%(res)) #set y brake retcode,res=rc_pycall("set_output_pk_xli","axis_y","8","0") if retcode==0: raise Exception("unable to set y brake : %s"%(res)) execfile("/opt/pyrame/common_rcs.py")