diff --git a/site_ansto/instrument/config/hmm/hmm_configuration_common_1.tcl b/site_ansto/instrument/config/hmm/hmm_configuration_common_1.tcl index 079c3bea..e51ff156 100644 --- a/site_ansto/instrument/config/hmm/hmm_configuration_common_1.tcl +++ b/site_ansto/instrument/config/hmm/hmm_configuration_common_1.tcl @@ -1,5 +1,5 @@ -# $Revision: 1.21 $ -# $Date: 2007-10-31 22:03:54 $ +# $Revision: 1.22 $ +# $Date: 2007-11-01 01:57:43 $ # Author: Ferdi Franceschini # Based on the examples in the hs_test.tcl sample configuration by Mark Lesha. # http://gumtree.ansto.gov.au:9080/nbicms/bragg-systems/histogram-server/hs_test.tcl/view @@ -14,6 +14,50 @@ # ::histogram_memory::_initialize # #@see ::histogram_memory::_initialize +set sim_mode [SplitReply [hmm_simulation]] +if {$sim_mode == "true"} { + MakeHM hmm SIM + MakeHM hmm_xy SIM + MakeHM hmm_xt SIM + MakeHM hmm_yt SIM + MakeHM hmm_x SIM + MakeHM hmm_y SIM + MakeHM hmm_t SIM + hmm configure daq Stopped + hmm configure statuscheck false + namespace eval histogram_memory { + proc hmc {_start _preset _mode _pause pauseval} { + bm mode $_mode; + bm preset $_preset; + hmm countblock; + } + } + proc ::histogram_memory::initialize {} { + hmm configure hmaddress http://das1-[SplitReply [instrument]]:8080; + hmm configure username spy; + hmm configure password 007; + hmm configure hmDataPath ../HMData; + } +} else { + MakeHM hmm anstohttp; + MakeHM hmm_xy anstohttp; + MakeHM hmm_xt anstohttp; + MakeHM hmm_yt anstohttp; + MakeHM hmm_x anstohttp; + MakeHM hmm_y anstohttp; + MakeHM hmm_t anstohttp; + + MakeHMControl_ANSTO hmc bm hmm; +} + +hmm configure rank 3 +hmm_xy configure rank 2 +hmm_xt configure rank 2 +hmm_yt configure rank 2 +hmm_x configure rank 1 +hmm_y configure rank 1 +hmm_t configure rank 1 + namespace eval histogram_memory { ::utility::mkVar detector_active_height_mm Float user active_height true detector true true @@ -682,7 +726,7 @@ proc OAT_TABLE {args} { set bbnum [llength $param($coord)] set hmm_xml(OAT,${coord}_BOUNDARIES) "" if {$bbnum > 2} { - set NO${coord}CH [expr $bbnum - 1] + set NO${coord}CH [expr {$bbnum - 1}] if {[info exists param(N${coord}C)]} { set NO${coord}CH $param(N${coord}C) } @@ -697,7 +741,7 @@ proc OAT_TABLE {args} { } if {[info exists param(N${coord}C)]} { set NO${coord}CH $param(N${coord}C) - for {set bb $b0; set i 0} {$i <= [set NO${coord}CH]} {incr i; set bb [expr $bb + $bstep] } { + for {set bb $b0; set i 0} {$i <= [set NO${coord}CH]} {incr i; set bb [expr {$bb + $bstep}] } { lappend hmm_xml(OAT,${coord}_BOUNDARIES) $bb } } else { @@ -708,7 +752,7 @@ proc OAT_TABLE {args} { } set brange [expr {abs($bfinal - $b0)}] set NO${coord}CH [expr {int(floor(abs($brange/$bstep)))}] - for {set bb $b0} {1} {set bb [expr $bb + $bstep] } { + for {set bb $b0} {1} {set bb [expr {$bb + $bstep}] } { lappend hmm_xml(OAT,${coord}_BOUNDARIES) $bb if [expr {abs($bfinal - $bb) < abs($bstep)}] { break } } @@ -814,40 +858,40 @@ proc ::histogram_memory::configure_dims {} { # set hmm_dim2 [hmmdictitemval hmm oat_nxc_eff] # } if {[instname] == "wombat"} { - array set dim_map { - hmm {{hmm_dim0 oat_ntc_eff} {hmm_dim1 stitch_nyc} {hmm_dim2 stitch_nxc}} - hmm,fat_read_data_type HISTOPERIOD_XYT - hmm_xy {{hmm_dim0 stitch_nyc} {hmm_dim1 stitch_nxc}} - hmm_xy,fat_read_data_type TOTAL_HISTOGRAM_XY - hmm_xt {{hmm_dim0 oat_ntc_eff} {hmm_dim1 stitch_nxc}} - hmm_xt,fat_read_data_type TOTAL_HISTOGRAM_XT - hmm_yt {{hmm_dim0 oat_ntc_eff} {hmm_dim1 stitch_nyc}} - hmm_yt,fat_read_data_type TOTAL_HISTOGRAM_YT - hmm_x {{hmm_dim0 stitch_nxc}} - hmm_x,fat_read_data_type TOTAL_HISTOGRAM_X - hmm_y {{hmm_dim0 stitch_nyc}} - hmm_y,fat_read_data_type TOTAL_HISTOGRAM_Y - hmm_t {{hmm_dim0 oat_ntc_eff}} - hmm_t,fat_read_data_type TOTAL_HISTOGRAM_T + array set dim_map { + hmm {{hmm_dim0 oat_ntc_eff} {hmm_dim1 stitch_nyc} {hmm_dim2 stitch_nxc}} + hmm,fat_read_data_type HISTOPERIOD_XYT + hmm_xy {{hmm_dim0 stitch_nyc} {hmm_dim1 stitch_nxc}} + hmm_xy,fat_read_data_type TOTAL_HISTOGRAM_XY + hmm_xt {{hmm_dim0 oat_ntc_eff} {hmm_dim1 stitch_nxc}} + hmm_xt,fat_read_data_type TOTAL_HISTOGRAM_XT + hmm_yt {{hmm_dim0 oat_ntc_eff} {hmm_dim1 stitch_nyc}} + hmm_yt,fat_read_data_type TOTAL_HISTOGRAM_YT + hmm_x {{hmm_dim0 stitch_nxc}} + hmm_x,fat_read_data_type TOTAL_HISTOGRAM_X + hmm_y {{hmm_dim0 stitch_nyc}} + hmm_y,fat_read_data_type TOTAL_HISTOGRAM_Y + hmm_t {{hmm_dim0 oat_ntc_eff}} + hmm_t,fat_read_data_type TOTAL_HISTOGRAM_T + } + } else { + array set dim_map { + hmm {{hmm_dim0 oat_ntc_eff} {hmm_dim1 oat_nyc_eff} {hmm_dim2 oat_nxc_eff}} + hmm,fat_read_data_type HISTOPERIOD_XYT + hmm_xy {{hmm_dim0 oat_nyc_eff} {hmm_dim1 oat_nxc_eff}} + hmm_xy,fat_read_data_type TOTAL_HISTOGRAM_XY + hmm_xt {{hmm_dim0 oat_ntc_eff} {hmm_dim1 oat_nxc_eff}} + hmm_xt,fat_read_data_type TOTAL_HISTOGRAM_XT + hmm_yt {{hmm_dim0 oat_ntc_eff} {hmm_dim1 oat_nyc_eff}} + hmm_yt,fat_read_data_type TOTAL_HISTOGRAM_YT + hmm_x {{hmm_dim0 oat_nxc_eff}} + hmm_x,fat_read_data_type TOTAL_HISTOGRAM_X + hmm_y {{hmm_dim0 oat_nyc_eff}} + hmm_y,fat_read_data_type TOTAL_HISTOGRAM_Y + hmm_t {{hmm_dim0 oat_ntc_eff}} + hmm_t,fat_read_data_type TOTAL_HISTOGRAM_T + } } -} else { - array set dim_map { - hmm {{hmm_dim0 oat_ntc_eff} {hmm_dim1 oat_nyc_eff} {hmm_dim2 oat_nxc_eff}} - hmm,fat_read_data_type HISTOPERIOD_XYT - hmm_xy {{hmm_dim0 oat_nyc_eff} {hmm_dim1 oat_nxc_eff}} - hmm_xy,fat_read_data_type TOTAL_HISTOGRAM_XY - hmm_xt {{hmm_dim0 oat_ntc_eff} {hmm_dim1 oat_nxc_eff}} - hmm_xt,fat_read_data_type TOTAL_HISTOGRAM_XT - hmm_yt {{hmm_dim0 oat_ntc_eff} {hmm_dim1 oat_nyc_eff}} - hmm_yt,fat_read_data_type TOTAL_HISTOGRAM_YT - hmm_x {{hmm_dim0 oat_nxc_eff}} - hmm_x,fat_read_data_type TOTAL_HISTOGRAM_X - hmm_y {{hmm_dim0 oat_nyc_eff}} - hmm_y,fat_read_data_type TOTAL_HISTOGRAM_Y - hmm_t {{hmm_dim0 oat_ntc_eff}} - hmm_t,fat_read_data_type TOTAL_HISTOGRAM_T - } -} foreach hm_obj [sicslist type histmem] { set rank [SplitReply [$hm_obj configure rank]] @@ -861,22 +905,43 @@ proc ::histogram_memory::configure_dims {} { $hm_obj init for {set i 0} {$i < $rank} {incr i} { - set hmm_length [expr $hmm_length * [set hmm_dim$i] ] + set hmm_length [expr {$hmm_length * [set hmm_dim$i]} ] $hm_obj configure dim$i [set hmm_dim$i] } } } -proc ::histogram_memory::set_frame_freq {freq} { - set clock_scale_ns 1000.0 - OAT_TABLE -set T_MAX [expr 1.0e9/($freq*$clock_scale_ns)] - hmm configure fat_frame_frequency $freq - hmm stop - hmm init 0 - hmm init +## +# @brief Sets the histogram memory frame frequency to the given value. +# +# @param freq Frequency in Hz.\n +# @param frame_source INTERNAL (default) or EXTERNAL +# +# If freq=0 then it sets the frequency to 50Hz with an internal frame source. This is useful +# if you are setting the frequency from a chopper which is stopped. +proc ::histogram_memory::set_frame_freq {freq {frame_source INTERNAL}} { + if {$freq < 0} { + return -code error "Frequency must not be negative" + } +#TODO Add tolerance parameters to choppercontroller + if {abs($freq - 0) <= [expr {2.0/60.0}]} { + hmm configure fat_frame_source INTERNAL + set newfreq 50 + } else { + hmm configure fat_frame_source [string toupper $frame_source] + ::set newfreq $freq + } + if [ catch { + ::histogram_memory::stop + set clock_scale_ns 1000.0 + OAT_TABLE -set T_MAX [expr {1.0e9/($newfreq*$clock_scale_ns)}] + hmm configure fat_frame_frequency $newfreq + hmm init + } errmsg ] { + return -code error $errmsg + } } publish ::histogram_memory::set_frame_freq user -definealias set_hmfreq ::histogram_memory::set_frame_freq proc ::histogram_memory::t_max {} { set frame_freq [SplitReply [hmm configure fat_frame_frequency]] @@ -957,7 +1022,6 @@ proc ::histogram_memory::post_count {} {} hmm configure statuscheck true hmm stop hmm configure statuscheck false - ::histogram_memory::post_count } errmsg ] { return -code error $errmsg } @@ -991,7 +1055,7 @@ proc ::histogram_memory::post_count {} {} # @param preset: The interpretation of the preset depends on the count method. # @see count_method proc ::histogram_memory::count_size {preset} { - hmm configure FAT_COUNT_SIZE [expr 100.0 * $preset] + hmm configure FAT_COUNT_SIZE [expr {100.0 * $preset}] hmm init 0 hmm init } @@ -1028,7 +1092,7 @@ namespace eval ::histogram_memory { # # @param cmd is one of start, stop, pause, mode, preset, loadconf # @param args is an optional list of arguments for the given command - proc histmem {cmd args} { + proc _histmem {cmd args} { if [ catch { switch $cmd { "start" { @@ -1046,6 +1110,9 @@ namespace eval ::histogram_memory { "preset" { eval "::histogram_memory::count_size $args" } + "setfreq" { + eval "::histogram_memory::set_frame_freq $args" + } "loadconf" { # Loads configuration tables (OAT, FAT, ...) to histogram server if {$args == ""} { @@ -1055,11 +1122,10 @@ namespace eval ::histogram_memory { } } default { - error "Available commands are, start stop pause mode preset loadconf" + error "Available commands are, start stop pause mode preset setfreq loadconf" } } } errmsg ] { return -code error $errmsg } } - publish histmem user