Added detector height and width variables.

Use anstohm_linked.xml so we can override default config.
Specify alias names for data axes.
Define macros for generating X, Y, T axes from bin boundaries.
XXX_TABLE procs now support the following subcommands, -clear, -init, -get, -list
OAT_TABLE now calculates bin boundaries, this is useful for generating axes.
Initialise OAT and FAT tables.

r2116 | ffr | 2007-08-16 14:50:04 +1000 (Thu, 16 Aug 2007) | 8 lines
This commit is contained in:
Ferdi Franceschini
2007-08-16 14:50:04 +10:00
committed by Douglas Clowes
parent 000de2ec2b
commit a8d5cff322

View File

@@ -1,8 +1,17 @@
# $Revision: 1.15 $
# $Date: 2007-07-22 05:23:40 $
# $Revision: 1.16 $
# $Date: 2007-08-16 04:50:04 $
# Author: Mark Lesha (mle@ansto.gov.au)
# Last revision by: $Author: ffr $
##\file Provides generic code and parameters for configuring the ANSTO histogram memory server
# The instrument specific histogram memory configuration files must define an initialisation
# function with the following signature
# \code proc ::histogram_memory::initialize {}
# this function should call the generic initalisation function,
# ::histogram_memory::_initialize
#
#\see ::histogram_memory::_initialize
#-------------------------------------------------------------------------
# System: Histogram Server (sample)
#------------------------------------------------------------------------
@@ -10,15 +19,20 @@
#ffr MakeHM hmm anstohttp, move to inst specific config
namespace eval histogram_memory {
::utility::mkVar detector_active_height_mm Float user active_height true detector true true
sicslist setatt detector_active_height_mm units mm
::utility::mkVar detector_active_width_mm Float user active_width true detector true true
sicslist setatt detector_active_width_mm units mm
::utility::mkVar hmm_user_configpath Text manager user_configpath false detector true false
hmm_user_configpath ../user_config/hmm
::utility::mkVar hmm_dim0 Int user dim0 true detector true true
::utility::mkVar hmm_dim1 Int user dim1 true detector true true
::utility::mkVar hmm_dim2 Int user dim2 true detector true true
::utility::mkVar hmm_histmode Text user histmode true detector true true
::utility::mkVar hmm_bank Int user bank false detector true false
::utility::mkVar hmm_rank Int user rank true detector true true
::utility::mkVar hmm_start Int user start false detector true false
::utility::mkVar hmm_bank Int user bank false detector false false
::utility::mkVar hmm_rank Int user rank true detector false true
::utility::mkVar hmm_start Int user start false detector false false
::utility::mkVar hmm_length Int user length false detector false false
::utility::mkVar hmm_mode Text user mode true detector true true
::utility::mkVar _hmm_vert_axis Text user vert_axis true detector false true
@@ -63,20 +77,29 @@ namespace eval histogram_memory {
# during DAQ is not allowed. This requires init of the hmm object to level 0.
#
# Making sure the histogram server is stopped, so we can load configuration.
proc hmm_initialize {} {
hmm configure hmaddress http://das1-[SplitReply [instrument]]:8080
hmm configure username spy
hmm configure password 007
hmm configure hmDataPath ../HMData
proc setup {} {
set configuration "::histogram_memory::returnconfigfile config/hmm/anstohm_linked.xml"
debug_msg $configuration
hmm configure init 0
hmm init
hmm stop
hmm configure statuscheck true
hmm stop
hmm configure statuscheck false
hmm configure hmaddress http://localhost:8080
hmm configure username spy
hmm configure password 007
hmm configure hmDataPath ../HMData
hmm configure hmconfigscript $configuration
hmm configure init 0
hmm init
hmm configure statuscheck true
hmm stop
hmm configure statuscheck false
# Load the configuration to the histogram server.
hmm configure init 1
hmm init
hmm configure init 1
hmm init
# Restore the init level to 0, subesquent inits will only upload specified FAT settings to histogram server.
hmm configure init 0
hmm configure init 0
##############################################
# Configuring the histogram memories in SICS
@@ -85,7 +108,9 @@ namespace eval histogram_memory {
# Now issue stop to the server.
# This not only makes sure it's stopped, but lets us see certain configuration variables
# which get placed in the dictionary as part of the status checking done during the stop.
hmm stop
hmm configure statuscheck true
hmm stop
hmm configure statuscheck false
}
# Here, define a function to let us read back the value of dictionary items from the hmm
# such as OAT dimensions.
@@ -316,9 +341,11 @@ namespace eval histogram_memory {
::histogram_memory::count -set feedback status IDLE
array set param [::data::gumtree_save -list param]
data axis 1 $param(run_number)
data axis 2 ::histogram_memory::vertical_axis
data axis 3 ::histogram_memory::horizontal_axis
data axis 4 ::histogram_memory::time_channel
data data_set hmm
::hdb::set_save /instrument/detector true
::hdb::set_save /data true
::hdb::set_save / true
return
}
@@ -465,71 +492,392 @@ if 0 {
sicslist setatt ::histogram_memory::count_withbm privilege internal;
sicslist setatt ::histogram_memory::save privilege internal;
set_sicsobj_atts hmm detector @none hmm_data true true;
set_sicsobj_atts hmm detector @none data true true;
sicslist setatt hmm privilege user
sicslist setatt hmm kind hobj
sicslist setatt hmm nxsave true
}
proc clock_scale {args} {
switch $args {
"" { return 1 }
"units" { return "microseconds"}
default {
todo_msg "Set clock_scale as an integer number of nanoseconds"
}
}
}
## \brief Calculate axis array from a given list of bin boundaries
#
# \param proc_name Fully qualified name of the calling procedure
# \param scale_factor axis scale factor or @none
# \param offset axis offset or @none
# \param boundaries list of bin boundaries or @none
proc calc_axis {proc_name scale_factor offset boundaries args} {
variable state
variable ${proc_name}_array
set parlist [join $args]
set opt [lindex $parlist 0]
set arglist [lrange $parlist 1 end]
if {$scale_factor == "@none" || $boundaries == "@none"} {
# Don't calculate axis values, we're just setting or getting the graph_type
} else {
set i 0
if {$state($proc_name,graph_type) == "boundaries"} {
foreach bb $boundaries {
set val [expr {$scale_factor*$bb + $offset}]
lappend values $val
set ${proc_name}_array($i) $val
incr i
}
} else {
foreach b0 [lrange $boundaries 0 end-1] b1 [lrange $boundaries 1 end] {
set val [expr {$scale_factor*($b1 + $b0)/2.0 + $offset}]
lappend values $val
set ${proc_name}_array($i) $val
incr i
}
}
}
switch -- $opt {
"-arrayname" {
return "${proc_name}_array"
}
"-centres" {
set state($proc_name,graph_type) "centres"
}
"-boundaries" {
set state($proc_name,graph_type) "boundaries"
}
"-graph_type" {
return $state($proc_name,graph_type)
}
default {
return $values
}
}
}
# requires detector_active_width_mm det_radius_mm
proc y_pixel_offset {args} {
variable state
set opt [lindex $args 0]
set arglist [lrange $args 1 end]
set proc_name [namespace origin [lindex [info level 0] 0]]
switch -- $opt {
"-centres" - "-boundaries" - "-graph_type" {
return [calc_axis $proc_name @none @none @none $opt $arglist]
}
"-arrayname" {
set det_height_mm [SplitReply [detector_active_height_mm]]
set max_b [OAT_TABLE -get Y_max]
set min_b [OAT_TABLE -get Y_min]
set scale_factor [expr {$det_height_mm / ($max_b - $min_b)}]
return [calc_axis $proc_name 1.0 0.0 [OAT_TABLE -get Y_boundaries] $opt $arglist]
}
"-units" {
return "mm"
}
default {
set det_height_mm [SplitReply [detector_active_height_mm]]
set max_b [OAT_TABLE -get Y_max]
set min_b [OAT_TABLE -get Y_min]
set scale_factor [expr {$det_height_mm / ($max_b - $min_b)}]
return [calc_axis $proc_name 1.0 0.0 [OAT_TABLE -get Y_boundaries] $args]
}
}
}
set script_name ::histogram_memory::y_pixel_offset
publish $script_name user
sicslist setatt $script_name privilege internal
sicslist setatt $script_name kind script
sicslist setatt $script_name access read_only
sicslist setatt $script_name dtype floatvarar
sicslist setatt $script_name dlen 100
sicslist setatt $script_name klass detector
sicslist setatt $script_name mutable false
sicslist setatt $script_name long_name y_pixel_offset
sicslist setatt $script_name units [::histogram_memory::y_pixel_offset -units]
# requires detector_active_width_mm det_radius_mm
proc x_pixel_offset {args} {
variable state
set opt [lindex $args 0]
set arglist [lrange $args 1 end]
set proc_name [namespace origin [lindex [info level 0] 0]]
switch -- $opt {
"-centres" - "-boundaries" - "-graph_type" {
return [calc_axis $proc_name @none @none @none $opt $args]
}
"-arrayname" {
set det_width_mm [SplitReply [detector_active_width_mm]]
set max_b [OAT_TABLE -get X_max]
set min_b [OAT_TABLE -get X_min]
set scale_factor [expr {$det_width_mm / ($max_b - $min_b)}]
set offset 0.0
return [calc_axis $proc_name $scale_factor $offset [OAT_TABLE -get X_boundaries] $opt $arglist]
}
"-units" {
return "mm"
}
default {
set det_width_mm [SplitReply [detector_active_width_mm]]
set max_b [OAT_TABLE -get X_max]
set min_b [OAT_TABLE -get X_min]
set scale_factor [expr {$det_width_mm / ($max_b - $min_b)}]
set offset 0.0
return [calc_axis $proc_name $scale_factor $offset [OAT_TABLE -get X_boundaries] $args]
}
}
}
set script_name ::histogram_memory::x_pixel_offset
publish $script_name user
sicslist setatt $script_name privilege internal
sicslist setatt $script_name kind script
sicslist setatt $script_name access read_only
sicslist setatt $script_name dtype floatvarar
sicslist setatt $script_name dlen 100
sicslist setatt $script_name klass detector
sicslist setatt $script_name mutable false
sicslist setatt $script_name long_name x_pixel_offset
sicslist setatt $script_name units [::histogram_memory::x_pixel_offset -units]
proc time_channel {args} {
variable state
set opt [lindex $args 0]
set arglist [lrange $args 1 end]
set proc_name [namespace origin [lindex [info level 0] 0]]
switch -- $opt {
"-centres" - "-boundaries" - "-graph_type" {
return [calc_axis $proc_name @none @none @none $opt $args]
}
"-arrayname" {
return [calc_axis $proc_name [::histogram_memory::clock_scale] 0.0 [OAT_TABLE -get T_boundaries] $opt $arglist]
}
default {
return [calc_axis $proc_name [::histogram_memory::clock_scale] 0.0 [OAT_TABLE -get T_boundaries] $args]
}
}
}
set script_name ::histogram_memory::time_channel
publish $script_name user
sicslist setatt $script_name privilege internal
sicslist setatt $script_name kind script
sicslist setatt $script_name access read_only
sicslist setatt $script_name dtype floatvarar
sicslist setatt $script_name dlen 100
sicslist setatt $script_name klass detector
sicslist setatt $script_name mutable false
sicslist setatt $script_name long_name time_of_flight
sicslist setatt $script_name units [::histogram_memory::clock_scale units]
}
set hmm_xml(BAT_TABLE) ""
proc BAT_TABLE {args} {
global hmm_xml
set table_name [lindex [info level 0] 0]
switch -- $args {
"" {return $hmm_xml($table_name)}
-clear {set hmm_xml($table_name) ""}
default {}
}
}
set hmm_xml(CAT_TABLE) ""
proc CAT_TABLE {args} {
global hmm_xml
set table_name [lindex [info level 0] 0]
switch -- $args {
"" {return $hmm_xml($table_name)}
-clear {set hmm_xml($table_name) ""}
default {}
}
}
set hmm_xml(FAT_TABLE) ""
proc FAT_TABLE {args} {
global hmm_xml
set table_name [lindex [info level 0] 0]
set opt [lindex $args 0]
set arglist [lrange $args 1 end]
switch -- $opt {
"" {return $hmm_xml($table_name)}
"-clear" {set hmm_xml($table_name) ""}
"-init" {
foreach {par val} $arglist {
set hmm_xml(FAT_TABLE,$par) $val
}
}
"-get" {
set par [lindex $arglist 0]
if {[info exists hmm_xml(FAT_TABLE,$par)]} {
return $hmm_xml(FAT_TABLE,$par)
} else {
foreach name [array names hmm_xml FAT_TABLE,* ] {
lappend valid_params [lindex [split $name ,] 1]
}
error_msg "$par should be one of $valid_params"
}
}
"-list" {
clientput [array get hmm_xml $table_name,*]
}
default {
array set param [string toupper $args]
set hmm_xml(FAT_TABLE) "<FAT\n"
foreach att {SIZE_PERIOD COUNT_METHOD COUNT_SIZE READ_DATA_TYPE} {
if {[info exists param($att)]} {
if {[info exists hmm_xml(FAT_TABLE,${att}_MIN)]} {
if {$param($att) <= $hmm_xml(FAT_TABLE,${att}_MIN)} {
error_msg "$att must be greater than $hmm_xml(FAT_TABLE,${att}_MIN)"
}
}
if {[info exists hmm_xml(FAT_TABLE,${att}_MAX)]} {
if {$param($att) >= $hmm_xml(FAT_TABLE,${att}_MAX)} {
error_msg "$att must be less than $hmm_xml(FAT_TABLE,${att}_MAX)"
}
}
append hmm_xml(FAT_TABLE) "$att=\"$param($att)\"\n"
}
}
append hmm_xml(FAT_TABLE) "></FAT>"
}
}
}
set hmm_xml(NAT_TABLE) ""
proc NAT_TABLE {args} {
global hmm_xml
set table_name [lindex [info level 0] 0]
switch -- $args {
"" {return $hmm_xml($table_name)}
-clear {set hmm_xml($table_name) ""}
default {}
}
}
set hmm_xml(OAT_TABLE) ""
## \brief Initialize and setup OAT_TABLE
#
# \param -clear clears OAT_TABLE XML fragment
# \param -init x_min <x0> x_max <x1> y_min <y0> y_max <y1>
# Initialise minimum and maximum bin boundaries.
# \param -get
# \param -list
#
# Sets X_boundaries, Y_boundaries and T_boundaries
proc OAT_TABLE {args} {
global hmm_xml
set table_name [lindex [info level 0] 0]
set coord_list {X Y T}
switch -- [lindex $args 0] {
"" {return $hmm_xml(OAT_TABLE)}
"-clear" {set hmm_xml(OAT_TABLE) ""}
"-init" {
foreach {par val} [lrange $args 1 end] {
set hmm_xml(OAT_TABLE,$par) $val
}
}
"-get" {
set par [lindex $args 1]
if {[info exists hmm_xml(OAT_TABLE,$par)]} {
return $hmm_xml(OAT_TABLE,$par)
} else {
foreach name [array names hmm_xml OAT_TABLE,* ] {
lappend valid_params [lindex [split $name ,] 1]
}
error_msg "$par should be one of $valid_params"
}
}
"-list" {
clientput [array get hmm_xml $table_name,*]
}
default {
array set param $args
foreach coord $coord_list {
if {[info exists param($coord)] == 0} {
error_msg "You must specify $coord_list"
}
}
set NOXCH [SplitReply [hmm configure dim0]]
set NOYCH [SplitReply [hmm configure dim1]]
set NOTCH [SplitReply [hmm configure dim2]]
set hmm_xml(OAT_TABLE) {
<OAT NO_OAT_X_CHANNELS=\"$NOXCH\" NO_OAT_Y_CHANNELS=\"$NOYCH\" NO_OAT_T_CHANNELS=\"$NOTCH\">
$XTAG
$YTAG
$TTAG
</OAT>
}
foreach coord $coord_list {
if {[info exists param($coord)]} {
set bbnum [llength $param($coord)]
set hmm_xml(OAT_TABLE,${coord}_boundaries) ""
if {$bbnum > 2} {
set NO${coord}CH [expr $bbnum - 1]
if {[info exists param(N${coord}C)]} {
set NO${coord}CH $param(N${coord}C)
}
set hmm_xml(OAT_TABLE,${coord}_boundaries) [lrange $param($coord) 0 [set NO${coord}CH]]
set ${coord}TAG "<$coord>$hmm_xml(OAT_TABLE,${coord}_boundaries)</$coord>"
} elseif {$bbnum == 2} {
set ${coord}TAG "<$coord>$param($coord)</$coord>"
set b0 [lindex $param($coord) 0]
set bstep [expr {[lindex $param($coord) 1] - $b0}]
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] } {
lappend hmm_xml(OAT_TABLE,${coord}_boundaries) $bb
}
} else {
set bmax [set hmm_xml(OAT_TABLE,${coord}_max)]
set brange [expr {$bmax - $b0}]
set NO${coord}CH [expr {int(floor($brange/$bstep))}]
for {set bb $b0} {1} {set bb [expr $bb + $bstep] } {
lappend hmm_xml(OAT_TABLE,${coord}_boundaries) $bb
if [expr {abs($bmax - $bb) < abs($bstep)}] { break }
}
}
} else {
error_msg "You must specify at least two bin boundaries for $coord"
}
}
}
FAT_TABLE SIZE_PERIOD [expr {$NOXCH*$NOYCH*$NOTCH}]
set hmm_xml(OAT_TABLE) [subst $hmm_xml(OAT_TABLE)]
return $hmm_xml(OAT_TABLE)
}
}
}
proc BAT_TABLE {args} {}
proc CAT_TABLE {args} {}
set hmm_xml(FAT_TABLE) ""
proc FAT_TABLE {args} {
set hmm_xml(SAT_TABLE) ""
proc SAT_TABLE {args} {
global hmm_xml
if {$args == ""} {return $hmm_xml(FAT_TABLE)}
array set param [string toupper $args]
set hmm_xml(FAT_TABLE) "<FAT\n"
foreach att {SIZE_PERIOD COUNT_METHOD COUNT_SIZE READ_DATA_TYPE} {
if {[info exists param($att)]} {
append hmm_xml(FAT_TABLE) "$att=\"$param($att)\"\n"
}
set table_name [lindex [info level 0] 0]
switch -- $args {
"" {return $hmm_xml($table_name)}
-clear {set hmm_xml($table_name) ""}
default {}
}
append hmm_xml(FAT_TABLE) "></FAT>"
}
proc NAT_TABLE {args} {}
set hmm_xml(OAT_TABLE) ""
proc OAT_TABLE {args} {
set hmm_xml(SRV_TABLE) ""
proc SRV_TABLE {args} {
global hmm_xml
if {$args == ""} {return $hmm_xml(OAT_TABLE)}
array set param $args
set X_min -210; set X_max 210
set Y_min -110; set Y_max 110
set NOXCH [SplitReply [hmm configure dim0]]
set NOYCH [SplitReply [hmm configure dim1]]
set NOTCH [SplitReply [hmm configure dim2]]
foreach tag {XTAG YTAG TTAG} {set $tag ""}
set hmm_xml(OAT_TABLE) {
<OAT NO_OAT_X_CHANNELS=\"$NOXCH\" NO_OAT_Y_CHANNELS=\"$NOYCH\" NO_OAT_T_CHANNELS=\"$NOTCH\">
$XTAG
$YTAG
$TTAG
</OAT>
}
if {[info exists param(NTC)]} {
set NOTCH $param(NTC)
set table_name [lindex [info level 0] 0]
switch -- $args {
"" {return $hmm_xml($table_name)}
-clear {set hmm_xml($table_name) ""}
default {}
}
foreach coord {X Y T} {
if {[info exists param($coord)]} {
set ${coord}TAG "<$coord>$param($coord)</$coord>"
set bbnum [llength $param($coord)]
if {$bbnum > 2} {
set NO${coord}CH [expr $bbnum - 1]
} else {
if {$coord != "T"} {
set b0 [lindex $param($coord) 0]
set b1 [lindex $param($coord) 1]
set NO${coord}CH [expr {1+([set ${coord}_max] - [set ${coord}_min])/($b1 - $b0)}]
}
}
}
}
FAT_TABLE SIZE_PERIOD [expr {$NOXCH*$NOYCH*$NOTCH}]
set hmm_xml(OAT_TABLE) [subst $hmm_xml(OAT_TABLE)]
return $hmm_xml(OAT_TABLE)
}
proc SAT_TABLE {args} {}
proc SRV_TABLE {args} {}
proc ::histogram_memory::clear_tables {} {
BAT_TABLE -clear
CAT_TABLE -clear
FAT_TABLE -clear
NAT_TABLE -clear
OAT_TABLE -clear
SAT_TABLE -clear
SRV_TABLE -clear
}
proc inst_defaults {} {
global ::histogram_memory::hmm_def_filename
@@ -539,16 +887,36 @@ proc dae_type {} {
global ::histogram_memory::hmm_dae_type
return $::histogram_memory::hmm_dae_type
}
proc ::histogram_memory::configure_server {instdef dtype} {
proc ::histogram_memory::configure_server {instdef} {
variable hmm_def_filename
variable hmm_dae_type
set hmm_def_filename $instdef
set hmm_dae_type $dtype
set configuration "::histogram_memory::returnconfigfile config/hmm/anstohm_linked.xml"
debug_msg $configuration
hmm configure hmconfigscript $configuration
::histogram_memory::hmm_initialize
::histogram_memory::setup
if {[instname] == "wombat"} {
hmm_dim0 [hmmdictitemval hmm stitch_nyc]
hmm_dim1 [hmmdictitemval hmm stitch_nxc]
} else {
hmm_dim0 [hmmdictitemval hmm oat_nyc_eff]
hmm_dim1 [hmmdictitemval hmm oat_nxc_eff]
}
hmm_length [expr {[SplitReply [hmm_dim0]] * [SplitReply [hmm_dim1]]} ]
hmm_dim2 [hmmdictitemval hmm oat_ntc_eff]
hmm configure dim0 [SplitReply [hmm_dim0]]
hmm configure dim1 [SplitReply [hmm_dim1]]
hmm configure dim2 [SplitReply [hmm_dim2]]
}
## \brief Sets histogram server to default configuration, initialises SICS histogram memory
# dictionary values and clears and initialises SICS OAT BAT CAT FAT ... tables
proc ::histogram_memory::_initialize {} {
y_pixel_offset -centres
x_pixel_offset -centres
time_channel -boundaries
::histogram_memory::clear_tables
::histogram_memory::configure_server Filler_defaults
OAT_TABLE -init T_min 0 T_max 200000
FAT_TABLE -init SIZE_PERIOD_MAX 125000000
}
Publish ::histogram_memory::finish user
#Publish ::histogram_memory::hs_collect user
Publish ::histogram_memory::hs_count_hs_controlled user