namespace eval histogram_memory { variable HMOBJ set HMOBJ hmm } proc ::histogram_memory::initialise_dictionary {} { variable HMOBJ if [catch { $HMOBJ configure init 0 $HMOBJ configure statuscheck true $HMOBJ init $HMOBJ stop $HMOBJ configure statuscheck false $HMOBJ init # ::histogram_memory::hmm_set_read_type HISTOPERIOD_XY } msg ] { return -code error "([info level 0]) $msg" } } publish ::histogram_memory::initialise_dictionary user proc ::histogram_memory::select_read_type {type} { variable HMOBJ # Instrument specific X and Y dimension names variable INST_NXC variable INST_NYC if [catch { $HMOBJ configure read_data_period_number 0 switch [string toupper $type] { "HISTOGRAM_XYT" - "HISTOPERIOD_XYT" { $HMOBJ configure rank 3 $HMOBJ configure dim0 [SplitReply [$HMOBJ configure $INST_NXC]] $HMOBJ configure dim1 [SplitReply [$HMOBJ configure $INST_NYC]] $HMOBJ configure dim2 [SplitReply [$HMOBJ configure oat_ntc_eff]] $HMOBJ configure READ_DATA_TYPE "HISTOPERIOD_XYT" set hmm_ext "" } "HISTOGRAM_XY" - "HISTOPERIOD_XY" { $HMOBJ configure rank 2 $HMOBJ configure dim0 [SplitReply [$HMOBJ configure $INST_NXC]] $HMOBJ configure dim1 [SplitReply [$HMOBJ configure $INST_NYC]] $HMOBJ configure READ_DATA_TYPE "HISTOPERIOD_XY" set hmm_ext "_xy" } "HISTOGRAM_XT" - "HISTOPERIOD_XT" { $HMOBJ configure rank 2 $HMOBJ configure dim0 [SplitReply [$HMOBJ configure $INST_NXC]] $HMOBJ configure dim1 [SplitReply [$HMOBJ configure oat_ntc_eff]] $HMOBJ configure READ_DATA_TYPE "HISTOPERIOD_XT" set hmm_ext "_xt" } "HISTOGRAM_YT" - "HISTOPERIOD_YT" { $HMOBJ configure rank 2 $HMOBJ configure dim0 [SplitReply [$HMOBJ configure oat_ntc_eff]] $HMOBJ configure dim1 [SplitReply [$HMOBJ configure $INST_NYC]] $HMOBJ configure READ_DATA_TYPE "HISTOPERIOD_YT" set hmm_ext "_ty" } "HISTOGRAM_X" - "HISTOPERIOD_X" { $HMOBJ configure rank 1 $HMOBJ configure dim0 [SplitReply [$HMOBJ configure $INST_NXC]] $HMOBJ configure READ_DATA_TYPE "HISTOPERIOD_X" set hmm_ext "_x" } "HISTOGRAM_Y" - "HISTOPERIOD_Y" { $HMOBJ configure rank 1 $HMOBJ configure dim0 [SplitReply [$HMOBJ configure $INST_NYC]] $HMOBJ configure READ_DATA_TYPE "HISTOPERIOD_Y" set hmm_ext "_y" } "HISTOGRAM_T" - "HISTOPERIOD_T" { $HMOBJ configure rank 1 $HMOBJ configure dim0 [SplitReply [$HMOBJ configure oat_ntc_eff]] $HMOBJ configure READ_DATA_TYPE "HISTOPERIOD_T" set hmm_ext "_t" } "HISTOGRAM_XP" { $HMOBJ configure rank 2 $HMOBJ configure dim0 [SplitReply [$HMOBJ configure $INST_NXC]] $HMOBJ configure dim1 [SplitReply [$HMOBJ configure maximum_period]] $HMOBJ configure READ_DATA_TYPE "HISTOPERIOD_XP" set hmm_ext "_total_xp" } "TOTAL_HISTOGRAM_XY" { $HMOBJ configure rank 2 $HMOBJ configure dim0 [SplitReply [$HMOBJ configure $INST_NXC]] $HMOBJ configure dim1 [SplitReply [$HMOBJ configure $INST_NYC]] $HMOBJ configure READ_DATA_TYPE $type set hmm_ext "_total_xy" } "TOTAL_HISTOGRAM_XT" { $HMOBJ configure rank 2 $HMOBJ configure dim0 [SplitReply [$HMOBJ configure $INST_NXC]] $HMOBJ configure dim1 [SplitReply [$HMOBJ configure oat_ntc_eff]] $HMOBJ configure READ_DATA_TYPE $type set hmm_ext "_total_xt" } "TOTAL_HISTOGRAM_YT" { $HMOBJ configure rank 2 $HMOBJ configure dim0 [SplitReply [$HMOBJ configure oat_ntc_eff]] $HMOBJ configure dim1 [SplitReply [$HMOBJ configure $INST_NYC]] $HMOBJ configure READ_DATA_TYPE $type set hmm_ext "_total_ty" } "TOTAL_HISTOGRAM_XP" { $HMOBJ configure rank 2 $HMOBJ configure dim0 [SplitReply [$HMOBJ configure $INST_NXC]] $HMOBJ configure dim1 [expr 1 + [SplitReply [$HMOBJ configure maximum_period]]] $HMOBJ configure READ_DATA_TYPE $type set hmm_ext "_total_xp" } "TOTAL_HISTOGRAM_YP" { $HMOBJ configure rank 2 $HMOBJ configure dim0 [expr 1 + [SplitReply [$HMOBJ configure maximum_period]]] $HMOBJ configure dim1 [SplitReply [$HMOBJ configure $INST_NYC]] $HMOBJ configure READ_DATA_TYPE $type set hmm_ext "_total_py" } "TOTAL_HISTOGRAM_XYP" { $HMOBJ configure rank 3 $HMOBJ configure dim0 [expr 1 + [SplitReply [$HMOBJ configure maximum_period]]] $HMOBJ configure dim1 [SplitReply [$HMOBJ configure $INST_NYC]] $HMOBJ configure dim2 [SplitReply [$HMOBJ configure $INST_NXC]] $HMOBJ configure READ_DATA_TYPE $type set hmm_ext "_total_xyp" } "TOTAL_HISTOGRAM_X" { $HMOBJ configure rank 1 $HMOBJ configure dim0 [SplitReply [$HMOBJ configure $INST_NXC]] $HMOBJ configure READ_DATA_TYPE $type set hmm_ext "_total_x" } "TOTAL_HISTOGRAM_Y" { $HMOBJ configure rank 1 $HMOBJ configure dim0 [SplitReply [$HMOBJ configure $INST_NYC]] $HMOBJ configure READ_DATA_TYPE $type set hmm_ext "_total_y" } "TOTAL_HISTOGRAM_T" { $HMOBJ configure rank 1 $HMOBJ configure dim0 [SplitReply [$HMOBJ configure oat_ntc_eff]] $HMOBJ configure READ_DATA_TYPE $type set hmm_ext "_total_t" } "TOTAL_HISTOGRAM_P" { $HMOBJ configure rank 1 $HMOBJ configure dim0 [expr 1 + [SplitReply [$HMOBJ configure maximum_period]]] $HMOBJ configure READ_DATA_TYPE $type set hmm_ext "_total_p" } default { error "ERROR: [info level 0], unknown data type $type" } } } msg ] { return -code error "([info level 0]) $msg" } return $hmm_ext } publish ::histogram_memory::select_read_type user ## # @brief Instrument specific configurations can redefine this # to select extra read data types or override one of the # common data types for the histogram memory. proc ::histogram_memory::is_select_read_type {type} { variable HMOBJ # Instrument specific X and Y dimension names variable INST_NXC variable INST_NYC return "notfound" } publish ::histogram_memory::is_select_read_type user ## # @brief Set the read data type, if there is no instrument # specific type then set a common type. proc ::histogram_memory::hmm_set_read_type {type} { variable HMOBJ if [ catch { set hmm_ext [is_select_read_type $type] if {$hmm_ext == "notfound"} { set hmm_ext [select_read_type $type] } $HMOBJ configure hmm_ext $hmm_ext } msg ] { return -code error "([info level 0]) $msg" } } ## # @brief Generate the "axes" string for NeXus plotable data and # link the axes to the data group proc ::histogram_memory::gen_axes {alist} { variable histmem_axes if [ catch { foreach axis_ID $alist { hsetprop $histmem_axes($axis_ID) link data_set set axis_name [lindex [split $histmem_axes($axis_ID) "/" ] end] lappend axes_list $axis_name } set axes [join $axes_list ":"] } msg ] { return -code error "([info level 0]) $msg" } return $axes } ## # @brief Defines axes for each histmem data type # @return {rank $rank dimstr $dimstr axis_list $axis_list hmmdatname $hmmdatname} proc ::histogram_memory::set_axes {typelist} { variable histmem_axes variable HMOBJ variable HP_HMM # Instrument specific X and Y dimension names variable INST_NXC variable INST_NYC if [catch { set signal 1 foreach type $typelist { switch [string toupper $type] { "HISTOGRAM_XYT" - "HISTOPERIOD_XYT" { lappend rank 3 set dim0 [SplitReply [$HMOBJ configure oat_ntc_eff]] set dim1 [SplitReply [$HMOBJ configure $INST_NYC]] set dim2 [SplitReply [$HMOBJ configure $INST_NXC]] lappend dimstr "$dim0,$dim1,$dim2" lappend hmmslabstart [list 0 0 0] lappend hmmslabend [list $dim0 $dim1 $dim2] lappend hmmperiodsize [expr $dim0 * $dim1 * $dim2] lappend axeslist [::histogram_memory::gen_axes {SVAR TOF VER HOR}] lappend siglist $signal lappend hmmdatname $HMOBJ } "HISTOGRAM_XY" - "HISTOPERIOD_XY" { lappend rank 2 set dim0 [SplitReply [$HMOBJ configure $INST_NYC]] set dim1 [SplitReply [$HMOBJ configure $INST_NXC]] lappend dimstr "$dim0,$dim1" lappend hmmslabstart [list 0 0] lappend hmmslabend [list $dim0 $dim1] lappend hmmperiodsize [expr $dim0 * $dim1] lappend axeslist [::histogram_memory::gen_axes {SVAR VER HOR}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_xy" } "HISTOGRAM_XT" - "HISTOPERIOD_XT" { lappend rank 2 set dim0 [SplitReply [$HMOBJ configure oat_ntc_eff]] set dim1 [SplitReply [$HMOBJ configure $INST_NXC]] lappend dimstr "$dim0,$dim1" lappend hmmslabstart [list 0 0] lappend hmmslabend [list $dim0 $dim1] lappend hmmperiodsize [expr $dim0 * $dim1] lappend axeslist [::histogram_memory::gen_axes {SVAR TOF HOR}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_xt" } "HISTOGRAM_YT" - "HISTOPERIOD_YT" { lappend rank 2 set dim0 [SplitReply [$HMOBJ configure oat_ntc_eff]] set dim1 [SplitReply [$HMOBJ configure $INST_NYC]] lappend dimstr "$dim0,$dim1" lappend hmmslabstart [list 0 0] lappend hmmslabend [list $dim0 $dim1] lappend hmmperiodsize [expr $dim0 * $dim1] lappend axeslist [::histogram_memory::gen_axes {SVAR TOF VER}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_ty" } "HISTOGRAM_X" - "HISTOPERIOD_X" { lappend rank 1 set dim0 [SplitReply [$HMOBJ configure $INST_NXC]] lappend dimstr "$dim0" lappend hmmslabstart [list 0] lappend hmmslabend [list $dim0] lappend hmmperiodsize $dim0 lappend axeslist [::histogram_memory::gen_axes {SVAR HOR}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_x" } "HISTOGRAM_Y" - "HISTOPERIOD_Y" { lappend rank 1 set dim0 [SplitReply [$HMOBJ configure $INST_NYC]] lappend dimstr "$dim0" lappend hmmslabstart [list 0] lappend hmmslabend [list $dim0] lappend hmmperiodsize $dim0 lappend axeslist [::histogram_memory::gen_axes {SVAR VER}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_y" } "HISTOGRAM_T" - "HISTOPERIOD_T" { lappend rank 1 set dim0 [SplitReply [$HMOBJ configure oat_ntc_eff]] lappend dimstr "$dim0" lappend hmmslabstart [list 0] lappend hmmslabend [list $dim0] lappend hmmperiodsize $dim0 lappend axeslist [::histogram_memory::gen_axes {SVAR TOF}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_t" } "HISTOGRAM_XP" { lappend rank 2 set dim0 [SplitReply [expr 1 + [$HMOBJ configure maximum_period]]] set dim1 [SplitReply [$HMOBJ configure $INST_NXC]] lappend dimstr "$dim0,$dim1" lappend hmmslabstart [list 0 0] lappend hmmslabend [list $dim0 $dim1] lappend hmmperiodsize [expr $dim0 * $dim1] lappend axeslist [::histogram_memory::gen_axes {SVAR PER HOR}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_total_xp" } "TOTAL_HISTOGRAM_XY" { lappend rank 2 set dim0 [SplitReply [$HMOBJ configure $INST_NYC]] set dim1 [SplitReply [$HMOBJ configure $INST_NXC]] lappend dimstr "$dim0,$dim1" lappend hmmslabstart [list 0 0] lappend hmmslabend [list $dim0 $dim1] lappend hmmperiodsize [expr $dim0 * $dim1] lappend axeslist [::histogram_memory::gen_axes {SVAR VER HOR}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_total_xy" } "TOTAL_HISTOGRAM_XY_CORRECTED" { lappend rank 2 set dim0 [SplitReply [$HMOBJ configure $INST_NYC]] set dim1 [SplitReply [$HMOBJ configure $INST_NXC]] lappend dimstr "$dim0,$dim1" lappend hmmslabstart [list 0 0] lappend hmmslabend [list $dim0 $dim1] lappend hmmperiodsize [expr $dim0 * $dim1] lappend axeslist [::histogram_memory::gen_axes {SVAR VER HOR}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_total_xy_corrected" } "TOTAL_HISTOGRAM_XT" { lappend rank 2 set dim0 [SplitReply [$HMOBJ configure oat_ntc_eff]] set dim1 [SplitReply [$HMOBJ configure $INST_NXC]] lappend dimstr "$dim0,$dim1" lappend hmmslabstart [list 0 0] lappend hmmslabend [list $dim0 $dim1] lappend hmmperiodsize [expr $dim0 * $dim1] lappend axeslist [::histogram_memory::gen_axes {SVAR TOF HOR}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_total_xt" } "TOTAL_HISTOGRAM_YT" { lappend rank 2 set dim0 [SplitReply [$HMOBJ configure oat_ntc_eff]] set dim1 [SplitReply [$HMOBJ configure $INST_NYC]] lappend dimstr "$dim0,$dim1" lappend hmmslabstart [list 0 0] lappend hmmslabend [list $dim0 $dim1] lappend hmmperiodsize [expr $dim0 * $dim1] lappend axeslist [::histogram_memory::gen_axes {SVAR TOF VER}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_total_ty" } "TOTAL_HISTOGRAM_XP" { lappend rank 2 set dim0 [SplitReply [$HMOBJ configure $INST_NXC]] set dim1 [expr 1 + [SplitReply [$HMOBJ configure maximum_period]]] lappend dimstr "$dim0,$dim1" lappend hmmslabstart [list 0 0] lappend hmmslabend [list $dim0 $dim1] lappend hmmperiodsize [expr $dim0 * $dim1] lappend axeslist [::histogram_memory::gen_axes {SVAR HOR PER}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_total_xp" } "TOTAL_HISTOGRAM_YP" { lappend rank 2 set dim0 [expr 1 + [SplitReply [$HMOBJ configure maximum_period]]] set dim1 [SplitReply [$HMOBJ configure $INST_NYC]] lappend dimstr "$dim0,$dim1" lappend hmmslabstart [list 0 0] lappend hmmslabend [list $dim0 $dim1] lappend hmmperiodsize [expr $dim0 * $dim1] lappend axeslist [::histogram_memory::gen_axes {SVAR PER VER}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_total_py" } "TOTAL_HISTOGRAM_XYP" { lappend rank 3 set dim0 [expr 1 + [SplitReply [$HMOBJ configure maximum_period]]] set dim1 [SplitReply [$HMOBJ configure $INST_NYC]] set dim2 [SplitReply [$HMOBJ configure $INST_NXC]] lappend dimstr "$dim0,$dim1,$dim2" lappend hmmslabstart [list 0 0 0] lappend hmmslabend [list $dim0 $dim1 $dim2] lappend hmmperiodsize [expr $dim0 * $dim1 * $dim2] lappend axeslist [::histogram_memory::gen_axes {SVAR PER VER HOR}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_total_xyp" } "TOTAL_HISTOGRAM_X" { lappend rank 1 set dim0 [SplitReply [$HMOBJ configure $INST_NXC]] lappend dimstr "$dim0" lappend hmmslabstart [list 0] lappend hmmslabend [list $dim0] lappend hmmperiodsize $dim0 lappend axeslist [::histogram_memory::gen_axes {SVAR HOR}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_total_x" } "TOTAL_HISTOGRAM_X_CORRECTED" { lappend rank 1 set dim0 [SplitReply [$HMOBJ configure $INST_NXC]] lappend dimstr "$dim0" lappend hmmslabstart [list 0] lappend hmmslabend [list $dim0] lappend hmmperiodsize $dim0 lappend axeslist [::histogram_memory::gen_axes {SVAR HOR}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_total_x_corrected" } "TOTAL_HISTOGRAM_Y" { lappend rank 1 set dim0 [SplitReply [$HMOBJ configure $INST_NYC]] lappend dimstr "$dim0" lappend hmmslabstart [list 0] lappend hmmslabend [list $dim0] lappend hmmperiodsize $dim0 lappend axeslist [::histogram_memory::gen_axes {SVAR VER}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_total_y" } "TOTAL_HISTOGRAM_T" { lappend rank 1 set dim0 [SplitReply [$HMOBJ configure oat_ntc_eff]] lappend dimstr "$dim0" lappend hmmslabstart [list 0] lappend hmmslabend [list $dim0] lappend hmmperiodsize $dim0 lappend axeslist [::histogram_memory::gen_axes {SVAR TOF}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_total_t" } "TOTAL_HISTOGRAM_P" { lappend rank 1 set dim0 [expr 1 + [SplitReply [$HMOBJ configure maximum_period]]] lappend dimstr "$dim0" lappend hmmslabstart [list 0] lappend hmmslabend [list $dim0] lappend hmmperiodsize $dim0 lappend axeslist [::histogram_memory::gen_axes {SVAR PER}] lappend siglist $signal lappend hmmdatname "${HMOBJ}_total_p" } default { error "ERROR: [info level 0], unknown data type $type" } } incr signal } hsetprop $HP_HMM hmmrank $rank hsetprop $HP_HMM hmmdimstr $dimstr hsetprop $HP_HMM hmmslabstart $hmmslabstart hsetprop $HP_HMM hmmslabend $hmmslabend hsetprop $HP_HMM hmmperiodsize $hmmperiodsize hsetprop $HP_HMM hmmdatname $hmmdatname hsetprop $HP_HMM @axes $axeslist hsetprop $HP_HMM @signal $siglist } msg ] { return -code error "([info level 0]) $msg" } return ok } publish ::histogram_memory::hmm_set_read_type user proc ::histogram_memory::gethmm {type} { variable HMOBJ if [catch { # set currType [SplitReply [$HMOBJ configure READ_DATA_TYPE]] ::histogram_memory::hmm_set_read_type $type set hmdata [hmm get 1] # ::histogram_memory::hmm_set_read_type $currType } msg ] { return -code error "([info level 0]) $msg" } return $hmdata } publish ::histogram_memory::gethmm user proc ::histogram_memory::hmm_xy {cmd hmdirect} { if [catch { if {$cmd == "get" && $hmdirect == 1} { return [gethmm HISTOPERIOD_XY] } } msg ] { return -code error "([info level 0]) $msg" } } publish ::histogram_memory::hmm_xy user proc ::histogram_memory::hdb_hmget {hpath} { if [ catch { # set hpath [SplitReply [sicslist ::histogram_memory::hdb_hmget hdb_path]] ::histogram_memory::hmm_set_read_type [hgetpropval $hpath read_data_type] } msg ] { return -code error "([info level 0]) $msg" } hmm get 1 } namespace eval ::nexus::histmem { variable HMOBJ set HMOBJ hmm proc hmm_set_sdsinfo {} { variable HMOBJ if [catch { set dim0 [SplitReply [$HMOBJ configure dim0]] set dim1 [SplitReply [$HMOBJ configure dim1]] set dim2 [SplitReply [$HMOBJ configure dim2]] set rank [expr 1 + [SplitReply [$HMOBJ configure rank]]] switch $rank { 2 { set dimstr "-1,$dim0" set hmslabstart [list 0] set hmslabend [list $dim0] set hmperiodsize $dim0 } 3 { set dimstr "-1,$dim0,$dim1" set hmslabstart [list 0 0] set hmslabend [list $dim0 $dim1] set hmperiodsize [expr $dim0 * $dim1] } 4 { set dimstr "-1,$dim0,$dim1,$dim2" set hmslabstart [list 0 0 0] set hmslabend [list $dim0 $dim1 $dim2] set hmperiodsize [expr $dim0 * $dim1 * $dim2] } default { error "ERROR: [info level 0] invalid rank $rank. Must be 2, 3, or 4" } } $HMOBJ configure hmslabstart $hmslabstart $HMOBJ configure hmslabend $hmslabend $HMOBJ configure hmperiodsize $hmperiodsize set hmm_ext [SplitReply [$HMOBJ configure hmm_ext]] broadcast nxscript updatedictvar padimstr $dimstr nxscript updatedictvar padimstr $dimstr broadcast nxscript updatedictvar parank $rank nxscript updatedictvar parank $rank broadcast nxscript updatedictvar pahmm_ext $hmm_ext nxscript updatedictvar pahmm_ext $hmm_ext } msg ] { return -code error "([info level 0]) $msg" } } } publish ::nexus::histmem::nxopen user publish ::nexus::histmem::hmm_set_sdsinfo user publish ::nexus::histmem::savehmm user publish ::histogram_memory::hdb_hmget user namespace eval histogram_memory { set HMSCOBJ hmscobj set HP_HMM /sics/$HMSCOBJ/hmm MakeSICSObj hmscobj SCT_OBJECT hfactory $HP_HMM script "::histogram_memory::hdb_hmget $HP_HMM" hdbReadOnly intvarar 10 hsetprop $HP_HMM read_data_type HISTOPERIOD_XY hsetprop $HP_HMM savecmd ::nexus::histmem::save hsetprop $HP_HMM sdsinfo ::nexus::histmem::sdsinfo hsetprop $HP_HMM datatype_savelist HISTOPERIOD_XY hsetprop $HP_HMM save_periods single_period hsetprop $HP_HMM privilege user hsetprop $HP_HMM nxsave false hsetprop $HP_HMM mutable true hsetprop $HP_HMM control false hsetprop $HP_HMM data true hsetprop $HP_HMM klass parameter hsetprop $HP_HMM nxalias hmscobj_hmm hsetprop $HP_HMM sicsdev none #hsetprop /sics/hmscobj/data #sicspoll add /sics/hmscobj/data hdb sicslist setatt $HMSCOBJ kind scobj sicslist setatt $HMSCOBJ klass NXdetector sicslist setatt $HMSCOBJ long_name detector sicslist setatt $HMSCOBJ privilege user }