# $Revision: 1.18 $ # $Date: 2007-10-03 00:07:26 $ # 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) #------------------------------------------------------------------------ #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_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 ::utility::mkVar _hmm_hor_axis Text user hor_axis true detector false true ::utility::mkVar _hmm_hor_axis_alias Text user hor_axis_alias true detector false true ::utility::mkVar _hmm_vert_axis_alias Text user vert_axis_alias true detector false true ::utility::mkVar _hmm_hor_channel_name Text user hor_channel_name true detector false true _hmm_vert_axis y_pixel_offset _hmm_vert_axis_alias dvaxis _hmm_hor_axis polar_angle _hmm_hor_axis_alias dtheta _hmm_hor_channel_name horizontal_channel_number ############################################## # Creating the histogram memories in SICS ############################################## # Make a histogram memory object hmm, allows control of the # remote histogram server via http, and acquisition # of histogram period data. ############################################## # Configuring the histogram server ############################################## # Procedure to read a single config (or any) file, return content as a string. proc returnconfigfile {filename} { set fh [open $filename] set xml [read $fh] #set xml [list [read $fh]] debug_msg $xml value close $fh return [subst $xml] } # Initialize the histogram server. # This call to hmm init (with init 1 configured) causes the histogram server # to be loaded with the specified configuration files. Subsequent inits (with init 0 configured) # only cause specific histogram server FAT settings to be updated. # If the histogram server's default configfiles are adequate, the init 1 stage can be skipped. # Before configuring, make sure the server is stopped, since configuration # 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 setup {} { set configuration "::histogram_memory::returnconfigfile config/hmm/anstohm_linked.xml" debug_msg $configuration hmm configure statuscheck true hmm configure histmode transparent hmm stop hmm configure statuscheck false 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 # Restore the init level to 0, subesquent inits will only upload specified FAT settings to histogram server. hmm configure init 0 ############################################## # Configuring the histogram memories in SICS ############################################## # 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 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. proc hmmdictitemval {histomem dictitem} { set resp [$histomem configure $dictitem] set retn [lindex [split $resp " "] 2] return $retn } ############################################## # Create beam monitor counter # and histogram memory control object # (ANSTO customized versions) ############################################## # Make our special HMControl_ANSTO object with the bm controlling the hmm. # This version can pause the histogram server after the count expires # instead of just stopping it, so we can generate multiple datasets # during a scan, or overlap data acquired at different scan stations. # It can also terminate either on the counter or any of the histogram objects. #ffr MakeHMControl_ANSTO hmc bm hmm, move to inst specific config ############################################## # Creating scans and creating/attaching # associated objects such as motors to drive, # extra counters etc. ############################################## # # Define two scan objects which use the beam monitor counter. # # For hmscan, the hmc object uses the bm counter to control # acquisition duration. In other words, the acquisition duration # is controlled via SICS. This is fine if the duration doesn't # need to be controlled to an accuracy of less than one second. # The bm only allows control of acquisition duration based on # elapsed time or number of monitor counts. # # For scan2, the histogram server controls acquisition duration. # In addition to time or monitor count based termination conditions, # the histogram server can be configured to terminate after a # specific number of frames or periods have elapsed, or can be # terminated in response to an external dataset signal. # The accuracy of control of the acquisition duration is much higher # (milliseconds versus hundreds of milliseconds). # Also, the histogram server can be configured to extend acquisition # so that only whole frames or periods are acquired. # Termination condition is normally already configured via # the histogram server's configuration files. # If a static termination condition is already configured, # scan2_runa can be called, with no termination condition required. # But if the SICS user wants to dynamically commit the termination # condition configuration to the histogram server, # a wrapper function scan2_runb should be called instead. # This allows the termination condition configuration to be written to # the histogram server dynamically, under the control of SICS. # The histogram server has a wider range of options for # termination condition, and there are three termination condition # arguments instead of the usual two for SICS counter objects. # # In both cases, we make the bm the master counter for the scan, # so that bm statistics are acquired during the scan. # # 17/11/06 NOTE: The Beam Monitor is not yet interfaced directly to the # Histogram Server. This means that for BM-controlled acquisitions, # SICS needs to use the BM counter (i.e. use hmscan not scan2). # # EXAMPLES: For scan running over 5 stops and acquisition of 1 sec at each stop: # hmscan run 5 timer 1 (termination controlled by the beam monitor) # scan2_runb 5 TIME 100 IMMEDIATE (termination controlled by the histogram server) # # # Call is: scan2_runa proc scan2_runa {n} { # The termination condition is ignored, because the # histogram server controls the acquisition duration # directly in this case. scan2 run $n timer 0 } # # Call is: scan2_runb proc scan2_runb {n count_method count_size count_stop} { # Commit the termination conditions to the histogram server. # hmm configure stores the values in the dictionary, # then hmm init causes them to be sent to the histogram server. # We just 'assume' they are successfully written. hmm configure FAT_COUNT_METHOD $count_method hmm configure FAT_COUNT_SIZE $count_size hmm configure FAT_COUNT_STOP $count_stop hmm init # The termination condition is ignored, because the # histogram server controls the acquisition duration # directly in this case. So, use 'timer 0' here. scan2 run $n timer 0 } # Simulated counter. No error rate. Required for technical reasons... # This counter is used only to block execution till the bm count is actually reached, # for the scan example using hmc and bm objects to control the acquisition duration from SICS. MakeCounter blockctr SIM -1.0 blockctr SetExponent 0 blockctr SetMode timer blockctr SetPreset 0 # Later on we can add some motors to drive... #Motor som2 ASIM 0 100 -1.0 0.01 #hmscan add som2 0 1 ############################################## # Support for using expanded histogram period # to create interlaced/overlapped histograms ############################################## # Define an OAT offset variable to use with both scans: # It is possible to effectively offset the histogram filler's # OAT table by an arbitrary amount. For overlapped data acquisitions, we can # configure an oversized histogram period using the EXPAND_OAT parameters # in the FAT. Then at each scan stop, before acqisition commences the offset # can be adjusted using the OFFSET_OAT paramters of the FAT. By progressively # stepping the OFFSET_OAT, an overlapped image can be built up. # The global variable oatoffset is defined for this purpose. # During the scan, this variable is incremented and can be passed # in to an argument of set_oat_offset to provide progressively # increasing offset, producing an overlapped histogram. # global oatoffset # #Function to apply OAT offsets to the histogram server. proc set_oat_offset {oatoff_x oatoff_y oatoff_t} { hmm configure FAT_OFFSET_OAT_X $oatoff_x hmm configure FAT_OFFSET_OAT_Y $oatoff_y hmm configure FAT_OFFSET_OAT_T $oatoff_t hmm init return } ############################################## # Support for data acquisition ############################################## # A simple procedure to read the histogram data through SICS # and dump the data to a numbered file. proc savehistodata {histomem filename} { set fh [open $filename "w"] # To get the whole memory, we don't need to specify the start or end arguments. # But we need to specify the bank number, this sets the type of data to be read. # set histodata [$histomem get [hmmdictitemval $histomem bank]] # clientput $histodata value puts -nonewline $fh $histodata close $fh return } ############################################## ############################################## ## Scan Callback Procedures ## ############################################## ############################################## # The prepare callback gets called at the start of the scan. # We use it to pause the histogram server, in order to commence the DAQ. # This 'primes' the DAE also (i.e. device drivers reboot the hardware, # buffering processes are started, etc.) proc prepare {} { #clientput "Enter prepare" value # # Before configuring the bm, do a short count. # This will cause the counter to reconnect if it needs to... bm count 0 timer # Now configure the beam monitor counter for better performance. # (Set a high counter sample rate to get better accuracy). bm send set scan=1 bm send set sample=1000 # Make sure the histogram server is stopped, this guarantees DAQ not in progress already. hmm stop # Zero the OAT offsets (whether used or not). global oatoffset set oatoffset 0 set_oat_offset 0 0 0 # # stdscan prepare $scanobjectname $userobjectname #clientput "hmm pause being done..." value # Pause the histogram server, this primes the DAE for acqisition. hmm pause #clientput "Exit prepare" value return } # The count_bm_controlled callback gets called at the start of dataset acquisition. # We use it to perform the dataset acquisition, via the hmc object. # Note we do NOT call stdscan count, since we don't need to run the bm counter twice. proc count_bm_controlled {mode preset} { ::histogram_memory::count -set feedback status BUSY #clientput "Enter count" value #stdscan count $scanobjectname $userobjectname $point $mode $preset # Start the acquisition, runs till the beam monitor terminates # and then enter paused mode (we have added fifth argument to allow this). # In fact, execution proceeds immediately (the hmc call doesn't block). hmc start $preset $mode pause # Now call the simulated counter. This will cause execution to block # till the hmc acquisition actually finishes. Otherwise, execution will # charge on regardless and the finish callback function gets called # before the last dataset acquisition has finished! blockctr count 0 #clientput "Exit count" value ::histogram_memory::count -set feedback status IDLE return } # The count_hs_controlled callback gets called at the start of dataset acquisition. # We use it to perform the dataset acquisition, controlled by the histogram server. # Note we do NOT call stdscan count, since we don't need to run the bm counter twice. proc hs_count_hs_controlled {scanobjectname userobjectname point mode preset} { #clientput "Enter count" value #stdscan count $scanobjectname $userobjectname $point $mode $preset # Start the acquisition, runs till the histogram server auto-terminates. # This is done by specifying the termination object to be the histogram server, # not the counter object (place a 1 in 6th argument to hmc object). # The termination condition for the bm counter is just set to a large time period. # After the acquisition terminates, the beam monitor therefore has the correct # status reading and the 'Monitor' entry in the scan data table will be correct. hmc start 1000000000 timer pause 1 # Now call the simulated counter. This will cause execution to block # till the hmc acquisition actually finishes. Otherwise, execution will # charge on regardless and the finish callback function gets called # before the last dataset acquisition has finished! blockctr count 0 #clientput "Exit count" value return } # The collect callback gets called at the end of the dataset acquisition. # We can put stuff here to retrieve data collected at each scan point, # and set up OAT offsets or other parameters that might need to be varied # from point to point at the histogram server, ready for the next scan point. # In this example, an increasing oatoffset variable is used to configure # the histogram server's OAT offset in the x direction, to produce # an overlapped histogram period acquisition. # Other things might be done here including adjustment of termination # condition based on beam monitor count. # Code for adjusting ancillaries, moving secondary motion stages etc. etc. # from point to point should probably be put into a drive callback function # (but not in this example script). proc hs_collect {scanobjectname userobjectname point} { #clientput "Enter collect" value set rslt [stdscan collect $scanobjectname $userobjectname $point] # Apply an OAT offset in the x direction (e.g. along tube number axis). global oatoffset incr oatoffset set_oat_offset $oatoffset 0 0 # Checking the beam monitor #clientput [bm send read] value # At each scan point, read the total x-y histogram # ans save it. This gets cleared at the start of # each dataset (when restarting from paused state), # so it represents the hstogram acquired per scan point. #clientput "Exit collect" value return } # The finish callback gets called at the end of the scan. # We use it to stop the histogram server, terminating the dataset. proc finish {} { #clientput "Enter finish" value # stdscan finish $scanobjectname $userobjectname #clientput "hmm stop being done..." value hmm stop # Just in case someone expects zero OAT offsets later on ;) set_oat_offset 0 0 0 # Get and write the data from the main histogram to disk (filename "HistoData"). # Sicne this is the first (and only) access to hmm data, it is retrieved from # the server and we don't need to do hmm init first to force update hmm memory. # hmm init # savehistodata hmm "../data/HistoData" # #clientput "Exit finish" value return } proc count_withbm {mode preset} { prepare; count_bm_controlled $mode $preset; finish; } proc init {} { } proc graphics_hpath_setup {parent} { } proc commands_hpath_setup {parent} { } proc instrument_hpath_setup {parent} { } proc experiment_hpath_setup {parent} { } proc set_sobj_attributes {} { # SICS commands sicslist setatt blockctr privilege internal; # histogram memory macros sicslist setatt ::histogram_memory::finish privilege internal; sicslist setatt ::histogram_memory::hs_count_hs_controlled privilege internal; sicslist setatt ::histogram_memory::count_bm_controlled privilege internal; sicslist setatt ::histogram_memory::prepare privilege internal; sicslist setatt ::histogram_memory::set_oat_offset privilege internal; sicslist setatt ::histogram_memory::scan2_runb privilege internal; sicslist setatt ::histogram_memory::scan2_runa privilege internal; sicslist setatt ::histogram_memory::returnconfigfile privilege internal; sicslist setatt ::histogram_memory::count_withbm privilege internal; sicslist setatt ::histogram_memory::save privilege internal; foreach hm_obj [sicslist type histmem] { set_sicsobj_atts $hm_obj detector @none $hm_obj true true; sicslist setatt $hm_obj privilege user sicslist setatt $hm_obj kind hobj sicslist setatt $hm_obj nxsave false } } 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 array unset ${proc_name}_array 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] } ## # @brief Provides a standard set of subcommands for the histogram server table # configuration commands. # # @param tag Table identifier, one of BAT CAT FAT NAT OAT SAT SRV # @param attributes Defines the list of attributes which you will be allowed to set. # @param element_list Defines the list of elements which you will be allowed to set. # Use "" if your table doesn't contain any elements. # @param args This can be empty, or a list of name value pairs for the attributes # and elements which you want to set or one of the subcommands listed below. # If args is empty this function will simply return an xml fragment for the named table, # # Subcommands\n # -clear clears the table\n # -init A list of name value pairs. If you use attribute or element names then # the corresponding table entries will be initilised to the given values, any # attributes or elements which aren't specified will be cleared. You can also # specify extra parameters to store in the table which might be required to # specify limits or constants which may be necessary for deriving configuration # parameters.\n # -get return the value for the named attribute or element\n # -attlist list all of the attributes with their values.\n # TODO Allow for top level content in tables and attributes in sub-elements proc XXX_TABLE {tag attributes element_list args} { global hmm_xml if {[llength $args] == 1} { set arguments [lindex $args 0] } else { set arguments $args } set opt [lindex $arguments 0] set arglist [lrange $arguments 1 end] switch -- $opt { "" { foreach att $attributes { if {$hmm_xml($tag,[string toupper $att]) != ""} { append table "$att=\"$hmm_xml($tag,$att)\"\n" } } set content "" foreach name $element_list { append content "\n<$name>\n$hmm_xml($tag,$name)\n" } if {[info exists table]} { return "<$tag\n$table>$content\n" } } "-clear" { foreach att $attributes { set hmm_xml($tag,[string toupper $att]) "" } foreach element $element_list { set hmm_xml($tag,[string toupper $element]) "" } } "-init" { foreach att $attributes { set hmm_xml($tag,[string toupper $att]) "" } foreach element $element_list { set hmm_xml($tag,[string toupper $element]) "" } foreach {par val} $arglist { set hmm_xml($tag,[string toupper $par]) $val } } "-get" { set par [string toupper [lindex $arglist 0]] if {[info exists hmm_xml($tag,$par)]} { return $hmm_xml($tag,$par) } else { foreach name [array names hmm_xml $tag,* ] { lappend valid_params [lindex [split $name ,] 1] } error_msg "$par should be one of $valid_params" } } "-attlist" { # List attributes foreach att $attributes { if {$hmm_xml($tag,$att) != ""} { lappend table $att $hmm_xml($tag,[string toupper $att]) } } if {[info exists table]} { clientput $table } } default { array set param [string toupper $arguments] foreach att [string toupper $attributes] { if {[info exists param($att)]} { if {[info exists hmm_xml($tag,${att}_MIN)]} { if {$param($att) <= $hmm_xml($tag,${att}_MIN)} { error_msg "$att must be greater than $hmm_xml($tag,${att}_MIN)" } } if {[info exists hmm_xml($tag,${att}_MAX)]} { if {$param($att) >= $hmm_xml($tag,${att}_MAX)} { error_msg "$att must be less than $hmm_xml($tag,${att}_MAX)" } } set hmm_xml($tag,$att) $param($att) } } foreach element [string toupper $element_list] { if {[info exists param($element)]} { set hmm_xml($tag,$element) $param($element) } } } } } ## # @brief Base Address Table configuration parameters as maintained by SICS # # @see XXX_TABLE for subcommands. proc BAT_TABLE {args} { set attributes {FRAME_FREQUENCY SIZE_PERIOD COUNT_METHOD COUNT_SIZE READ_DATA_TYPE} set elements "" set tag BAT global hmm_xml switch -glob -- [lindex $args 0] { "" { XXX_TABLE $tag $attributes $elements $args } "-*" { XXX_TABLE $tag $attributes $elements $args } default { XXX_TABLE $tag $attributes $elements $args } } } BAT_TABLE -clear ## # @brief CAlibration Table configuration parameters as maintained by SICS # # @see XXX_TABLE for subcommands. proc CAT_TABLE {args} { set attributes {FRAME_FREQUENCY SIZE_PERIOD COUNT_METHOD COUNT_SIZE READ_DATA_TYPE} set elements "" set tag CAT global hmm_xml switch -glob -- [lindex $args 0] { "" { XXX_TABLE $tag $attributes $elements $args } "-*" { XXX_TABLE $tag $attributes $elements $args } default { XXX_TABLE $tag $attributes $elements $args } } } CAT_TABLE -clear ## # @brief Frequency Address Table configuration parameters as maintained by SICS # # @see XXX_TABLE for subcommands. proc FAT_TABLE {args} { set attributes {FRAME_FREQUENCY SIZE_PERIOD COUNT_METHOD COUNT_SIZE READ_DATA_TYPE} set elements "" set tag FAT global hmm_xml switch -glob -- [lindex $args 0] { "" { XXX_TABLE $tag $attributes $elements $args } "-*" { XXX_TABLE $tag $attributes $elements $args } default { XXX_TABLE $tag $attributes $elements $args } } } FAT_TABLE -clear ## # @brief Offset Address Table configuration parameters as maintained by SICS # # @param -clear clears OAT_TABLE XML fragment # @param -init X_MIN X_MAX Y_MIN Y_MAX # Initialise minimum and maximum bin boundaries. # @param -get # @param -attlist # @param -clear clears the oat table and the fat table SIZE_PERIOD # # Sets X_BOUNDARIES, Y_BOUNDARIES and T_BOUNDARIES # @see XXX_TABLE for subcommands. proc OAT_TABLE {args} { global hmm_xml set attributes {NO_OAT_X_CHANNELS NO_OAT_Y_CHANNELS NO_OAT_T_CHANNELS} set tag OAT set coord_list {X Y T} set elements $coord_list switch -glob -- [lindex $args 0] { "" { XXX_TABLE $tag $attributes $elements $args } "-*" { XXX_TABLE $tag $attributes $elements $args } "-clear" { XXX_TABLE $tag $attributes $elements $args FAT_TABLE SIZE_PERIOD "" } 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]] foreach coord $coord_list { if {[info exists param($coord)]} { set bbnum [llength $param($coord)] set hmm_xml(OAT,${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,${coord}_BOUNDARIES) [lrange $param($coord) 0 [set NO${coord}CH]] set hmm_xml(OAT,$coord) ${coord}_BOUNDARIES } elseif {$bbnum == 2} { set hmm_xml(OAT,$coord) $param($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,${coord}_BOUNDARIES) $bb } } else { set bmax [set hmm_xml(OAT,${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,${coord}_BOUNDARIES) $bb if [expr {abs($bmax - $bb) < abs($bstep)}] { break } } } } else { error_msg "You must specify at least two bin boundaries for $coord" } } } set arglist [list NO_OAT_X_CHANNELS $NOXCH NO_OAT_Y_CHANNELS $NOYCH NO_OAT_T_CHANNELS $NOTCH] XXX_TABLE $tag $attributes $elements $arglist FAT_TABLE SIZE_PERIOD [expr {$NOXCH*$NOYCH*$NOTCH}] return [XXX_TABLE $tag $attributes $elements] } } } OAT_TABLE -clear ## # @brief Spatial Allocation Table configuration parameters as maintained by SICS # # @see XXX_TABLE for subcommands. proc SAT_TABLE {args} { set attributes {FRAME_FREQUENCY SIZE_PERIOD COUNT_METHOD COUNT_SIZE READ_DATA_TYPE} set elements "" set tag SAT global hmm_xml switch -glob -- [lindex $args 0] { "" { XXX_TABLE $tag $attributes $elements $args } "-*" { XXX_TABLE $tag $attributes $elements $args } default { XXX_TABLE $tag $attributes $elements $args } } } SAT_TABLE -clear proc ::histogram_memory::clear_tables {} { BAT_TABLE -clear CAT_TABLE -clear FAT_TABLE -clear OAT_TABLE -clear SAT_TABLE -clear } proc inst_defaults {} { global ::histogram_memory::hmm_def_filename return $::histogram_memory::hmm_def_filename } proc dae_type {} { global ::histogram_memory::hmm_dae_type return $::histogram_memory::hmm_dae_type } proc ::histogram_memory::configure_server {instdef} { variable hmm_def_filename variable hmm_dae_type set hmm_def_filename $instdef # rank is always 3, but some or all of the dimensions can be 1 hmm configure rank 3 foreach hm_obj [sicslist type histmem] { $hm_obj configure hmaddress http://das1-[instname].nbi.ansto.gov.au:8080 $hm_obj configure username spy $hm_obj configure password 007 } ::histogram_memory::setup if {[instname] == "wombat"} { hmm_dim1 [hmmdictitemval hmm stitch_nyc] hmm_dim2 [hmmdictitemval hmm stitch_nxc] } else { hmm_dim1 [hmmdictitemval hmm oat_nyc_eff] hmm_dim2 [hmmdictitemval hmm oat_nxc_eff] } hmm_dim0 [hmmdictitemval hmm oat_ntc_eff] hmm_length [expr {[SplitReply [hmm_dim0]] * [SplitReply [hmm_dim1]] * [SplitReply [hmm_dim2]]} ] 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 Publish ::histogram_memory::count_bm_controlled user Publish ::histogram_memory::prepare user Publish ::histogram_memory::set_oat_offset user Publish ::histogram_memory::scan2_runb user Publish ::histogram_memory::scan2_runa user Publish ::histogram_memory::returnconfigfile user Publish ::histogram_memory::count_withbm user Publish ::histogram_memory::save user Publish BAT_TABLE user Publish CAT_TABLE user Publish FAT_TABLE user Publish OAT_TABLE user Publish SAT_TABLE user namespace eval ::histogram_memory { command count {text:monitor,timer mode float: preset} { ::histogram_memory::prepare ::histogram_memory::count_bm_controlled $mode $preset; ::histogram_memory::finish } ::histogram_memory::count -addfb text status ::histogram_memory::count -set feedback status IDLE }