Merged new hdb and nexus code.

r2099 | ffr | 2007-07-22 15:23:41 +1000 (Sun, 22 Jul 2007) | 2 lines
This commit is contained in:
Ferdi Franceschini
2007-07-22 15:23:41 +10:00
committed by Douglas Clowes
parent 4e407d0a73
commit 8770acc191
37 changed files with 2404 additions and 645 deletions

View File

@@ -6,7 +6,7 @@ dradius=/$(entryName),NXentry/$(inst),NXinstrument/$(detector),NXdetector/SDS ra
dheight=/$(entryName),NXentry/$(inst),NXinstrument/$(detector),NXdetector/SDS height -type NX_FLOAT32 -attr {units,mm}
detangle_rad=/$(entryName),NXentry/$(inst),NXinstrument/$(detector),NXdetector/SDS arc -type NX_FLOAT32 -attr {units,radians}
detangle_degrees=/$(entryName),NXentry/$(inst),NXinstrument/$(detector),NXdetector/SDS arc -type NX_FLOAT32 -attr {units,degrees}
dtheta=/$(entryName),NXentry/$(inst),NXinstrument/$(detector),NXdetector/SDS polar_angle -type NX_FLOAT32 -LZW -rank 2 -dim {-1,$(padim1)} -attr {units,degrees}
dtheta=/$(entryName),NXentry/$(inst),NXinstrument/$(detector),NXdetector/SDS two_theta -type NX_FLOAT32 -LZW -rank 2 -dim {-1,$(padim1)} -attr {units,degrees}
dvaxis=/$(entryName),NXentry/$(inst),NXinstrument/$(detector),NXdetector/SDS y_pixel_offset -type NX_FLOAT32 -LZW -rank 1 -dim {$(padim0)} -attr {units,mm}
dhaxis=/$(entryName),NXentry/$(inst),NXinstrument/$(detector),NXdetector/SDS x_pixel_offset -type NX_FLOAT32 -LZW -rank 1 -dim {$(padim1)} -attr {units,mm}
drowindex=/$(entryName),NXentry/$(inst),NXinstrument/$(detector),NXdetector/SDS $(row_index_name) -type NX_INT32 -LZW -rank 1 -dim {$(padim0)}

View File

@@ -9,6 +9,7 @@ scandata=/$(entryName),NXentry/data,NXdata/NXVGROUP
scanhoraxis=/$(entryName),NXentry/data,NXdata/NXVGROUP
scanvertaxis=/$(entryName),NXentry/data,NXdata/NXVGROUP
scanvar=/$(entryName),NXentry/data,NXdata/NXVGROUP
scantwotheta=/$(entryName),NXentry/scan_step,NXdata/SDS two_theta -type NX_FLOAT32 -attr {units,degree} -attr {long_name,two_theta}
scanstep=/$(entryName),NXentry/scan_step,NXdata/SDS value -type NX_FLOAT32 -attr {units,degree} -attr {long_name,stepsize}
#histogram=/$(entryName),NXentry/histogram,NXdata/NXVGROUP
#scanvar=/$(entryName),NXentry/$(scan_variable),NXdata/NXVGROUP

View File

@@ -1,3 +1,427 @@
## TODO Put all the nexus macros in the nexus namespace
MakeNXScript
sicsdatafactory new nxscript_data
namespace eval nexus {
variable nxdictionary
set exports [list newfile closefile save data]
eval namespace export $exports
datafilename
proc createfile {} {
global cfPath
variable nexusdic
variable state
variable nxFileOpen;
set nxdict_path $cfPath(nexus)/$nexusdic
set file_type [SplitReply [SicsDataSuffix]]
array set nxmode [list nx.hdf create5 hdf create5 h5 create5 nx5 create5 xml createxml];
dataFileName [newFileName $file_type]
::nexus::gen_nxdict $nexusdic
nxscript $nxmode($file_type) [SplitReply [dataFileName]] $nxdict_path;
set nxFileOpen true
set state(file,status) open
}
## \brief Sets 'new file' state to true
proc newfile {{type deflt } {nxdic nexus.dic}} {
variable nexusdic
variable state
if {$type == "deflt"} {
set type [SplitReply [SicsDataSuffix]]
}
set state(file,new) true
set nexusdic $nxdic
}
# Don't overwrite data from a previous SICS session
newfile
proc save_data {point} {
::nexus::nxreopenfile
foreach child [hlist /] {
if {[::utility::hgetplainprop /experiment data] == "true"} {
::nexus::savetree $child $point
}
}
::nexus::nxclosefile
}
## \brief save data collected by last data acquisition command.
#
# \param point experimental point number, this is the array index for mutable
# datasets in the nexus file. Optional, default = 0
#
# The save command will create a new file if the newfile state is set to true, or
# if the datatype property != the currentfiletype property of the /data hdb node.
proc save {{point 0}} {
variable state
::data::gumtree_save -set run_number $point
if {$state(file,new) == "true"} {
createfile
save_data $point
linkdata
hsetprop /data currentfiletype [::utility::hgetplainprop /data datatype]
set state(file,new) false
} else {
if {[::utility::hgetplainprop /data currentfiletype] != [::utility::hgetplainprop /data datatype]} {
createfile
save_data $point
linkdata
hsetprop /data currentfiletype [::utility::hgetplainprop /data datatype]
set state(file,new) false
}
save_data $point
}
}
## \brief Reopen the current file.
proc nxreopenfile {} {
global cfPath
variable nxFileOpen
variable nexusdic
if {$nxFileOpen == "false"} {
nxscript reopen [SplitReply [dataFileName]] $cfPath(nexus)/$nexusdic;
set nxFileOpen true;
}
}
## \brief Close the current file. You can reopen it with nxreopenfile
#
# \see nxreopenfile
proc nxclosefile {} {
variable nxFileOpen;
if {$nxFileOpen == "true"} {
nxscript close;
set nxFileOpen false;
set flist [split [SplitReply [dataFileName]] "/"];
set fname [lindex $flist [expr [llength $flist] - 1] ];
clientput "$fname updated" "event";
}
}
## \brief Records that a given data source should be linked to nexus data target.
#
# NOTE: If a link has already been recorded then it does nothing. This allows you to
# override default links set by a command. eg A "count" command may link axis_1 to
# the run number but a "scan" command which uses the count command can link axis_1 to
# a scan variable.
#
# Usage:
# data data_set datsource
# Records that /data/data_set should be linked to datsource and sets a data type identifier
# data axis 1|2|3|4 datsource
# Records that /data/axisn should be linked to datsource
# data clear
# Clears all link targets and sets the data type identifier to unknown
proc data {args} {
set dpath /data
set opt [lindex $args 0]
switch $opt {
"axis" {
set axnum [lindex $args 1]
if {[string is integer $axnum] == 0} {
error "ERROR: [info level -1]->data, index for data axis should be an integer, not $axnum"
}
set hp $dpath/axis_$axnum
if {[::utility::hgetplainprop $hp link] == "@none"} {
hsetprop $hp link [lindex $args 2]
hsetprop $hp long_name [getatt [lindex $args 2] long_name]
}
}
"data_set" {
hsetprop $dpath datatype [lindex [info level -1] 0]
set hp $dpath/data_set
if {[::utility::hgetplainprop $hp link] == "@none"} {
hsetprop $hp link [lindex $args 1]
hsetprop $hp long_name [getatt [lindex $args 1] long_name]
}
}
"clear" {
foreach child [hlist $dpath] {
hsetprop $dpath/$child link @none
hsetprop $dpath/$child long_name @none
}
}
default {error "ERROR: [info level -1]->data, Unsupported option $opt"}
}
}
# Internal commands
# All experimental data of interest is linked under the data group
proc linkdata {} {
array unset axes
set hpath /data
::nexus::nxreopenfile
foreach child [hlist $hpath] {
array set p_arr [::utility::hlistplainprop $hpath/$child]
if {$p_arr(data) == true && $p_arr(nxsave) == true} {
if {[info exists p_arr(nxalias)]} {
if {[info exists p_arr(type)] && $p_arr(type) == "nxvgroup"} {
if {$p_arr(link) != "@none"} {
nxscript makelink $p_arr(nxalias) $p_arr(link)
switch -glob $child {
"axis_*" {
set n [lindex [split $child _] 1]
set axes($n) [::utility::hgetplainprop $hpath/$child long_name]
nxscript putattribute $p_arr(link) axis $n
}
"data_set" {
nxscript putattribute $p_arr(link) signal 1
set data_set_alias $p_arr(link)
}
default {error "ERROR: [info level -1]->linkdata, Unsupported data path $hpath/$child"}
}
}
}
}
}
}
if {[info exists axes]} {
foreach n [lsort [array names axes]] {
nxscript putattribute $data_set_alias axes [set axes($n)]
}
}
::nexus::nxclosefile
::nexus::data clear
}
proc savetree {hpath {pt 0}} {
foreach child [hlist /$hpath] {
array unset p_arr
array set p_arr [::utility::hlistplainprop /$hpath/$child]
if {[info exists p_arr(type)] && $p_arr(type) == "nxvgroup"} {
return
}
set data_type [lindex [split [hinfo /$hpath/$child] , ] 0]
if {$p_arr(data) == true && $p_arr(nxsave) == true } {
if {[info exists p_arr(savecmd)] && [info exists p_arr(nxalias)] } {
if {[info exists p_arr(mutable)] && $p_arr(mutable) == "true" } {
$p_arr(savecmd) $p_arr(sicsdev) $p_arr(nxalias) $data_type point $pt
} else {
$p_arr(savecmd) $p_arr(sicsdev) $p_arr(nxalias) $data_type
}
} elseif {[info exists p_arr(savecmd)] || [info exists p_arr(nxalias)]} {
error_msg "/$hpath/$child must have both 'savecmd' and 'nxalias' properties\nThe actual property list for /$hpath/$child is [array get p_arr]"
}
::nexus::savetree $hpath/$child $pt
}
}
}
# Where do we get the SDS info from for tcl variables?
proc save_scalar {args} {
todo_msg "Save floats ints, use this for local variables, events and sicsvariable data"
# use putfloat $event(...) or uset putslab
}
proc save_sicsvar {svar nxarg args} {
todo_msg "Use this to save tcl arrays, good for beam monitor count arrays"
}
proc _gen_nxdict {hpath dict_path name nxc} {
variable nxdictionary
if {[::utility::hgetplainprop /$hpath data] == "false"} {
debug_msg "$hpath doesn't have a data property"
return
}
foreach child [hlist /$hpath] {
if {[::utility::hgetplainprop /$hpath/$child data] == true} {
set nxclass [::utility::hgetplainprop /$hpath/$child klass]
if {[string range $nxc 0 1] == "NX"} {
::nexus::_gen_nxdict $hpath/$child $dict_path/$name,$nxc $child $nxclass
} else {
# else construct SDS name by replacing '/' with '_' in path
::nexus::_gen_nxdict $hpath/$child $dict_path ${name}_$child $nxclass
}
}
}
array set p_arr [::utility::hlistplainprop /$hpath]
set data_type [lindex [split [hinfo /$hpath] , ] 0]
if {$p_arr(data) == "true" && $p_arr(nxsave) == "true" && [info exists p_arr(nxalias)]} {
set alias $p_arr(nxalias)
if {[info exists p_arr(sdsinfo)]} {
if {[info exists p_arr(mutable)] && $p_arr(mutable) == "true"} {
set nxdictionary($alias) "$dict_path/SDS $name [$p_arr(sdsinfo) $p_arr(sicsdev) $data_type mutable true]"
} else {
set nxdictionary($alias) "$dict_path/SDS $name [$p_arr(sdsinfo) $p_arr(sicsdev) $data_type mutable false]"
}
} elseif {[info exists p_arr(type)] && $p_arr(type) == "nxvgroup"} {
set nxdictionary($alias) "$dict_path/NXVGROUP"
}
}
}
proc gen_nxdict {nexusdic} {
global cfPath
variable nxdictionary
set nxdict_path $cfPath(nexus)/$nexusdic
array unset nxdictionary
foreach hp [hlist /] {
if {[::utility::hgetplainprop /$hp data] == true} {
set nxclass [::utility::hgetplainprop /$hp klass]
::nexus::_gen_nxdict $hp /entry1,NXentry $hp $nxclass
}
}
set fh [open $nxdict_path w]
puts $fh "##NXDICT-1.0"
puts $fh padim0=0
puts $fh padim1=0
puts $fh padim2=0
foreach {n v} [array get nxdictionary] {
puts $fh "$n = $v"
}
close $fh
}
proc show_nxdict {} {
variable nxdictionary
clientput [array get nxdictionary]
}
proc set_sobj_attributes {} {
# SICS commands
sicslist setatt nxscript privilege internal;
# SICS data objects
sicslist setatt nxscript_data privilege internal;
# nexus macros
sicslist setatt nxcreatefile privilege internal;
sicslist setatt addnxscanentry privilege internal;
sicslist setatt bm_addnxscanentry privilege internal;
# Set savecmd on SICS objects
foreach sobj [lrange [sicslist type motor] 1 end] {
sicslist setatt $sobj savecmd ::nexus::motor::save
sicslist setatt $sobj sdsinfo ::nexus::motor::sdsinfo
}
foreach sobj [sicslist type configurablevirtualmotor] {
sicslist setatt $sobj savecmd ::nexus::motor::save
sicslist setatt $sobj sdsinfo ::nexus::motor::sdsinfo
}
foreach sobj [sicslist type histmem] {
sicslist setatt $sobj savecmd ::nexus::histmem::save
sicslist setatt $sobj sdsinfo ::nexus::histmem::sdsinfo
}
foreach sobj [sicslist type sicsvariable] {
sicslist setatt $sobj savecmd ::nexus::sicsvariable::save
sicslist setatt $sobj sdsinfo ::nexus::sicsvariable::sdsinfo
}
foreach sobj [sicslist type singlecounter] {
sicslist setatt $sobj savecmd ::nexus::singlecounter::save
sicslist setatt $sobj sdsinfo ::nexus::singlecounter::sdsinfo
}
}
}
namespace import ::nexus::*
foreach expt $::nexus::exports {
publish $expt user
sicslist setatt $expt privilege internal
}
namespace eval ::nexus::histmem {
proc save {hm nxalias data_type args} {
set dim0 [SplitReply [$hm configure dim0]]
set dim1 [SplitReply [$hm configure dim1]]
set dim2 [SplitReply [$hm configure dim2]]
nxscript updatedictvar padim0 $dim0
nxscript updatedictvar padim1 $dim1
nxscript updatedictvar padim2 $dim2
set data_start 0
set datalen [expr {$dim0 * $dim1 * $dim2}]
set bank 0
if {[lindex $args 0] == "point"} {
set index [lindex $args 1]
nxscript putslab $nxalias [list $index 0 0 0] [list 1 $dim0 $dim1 $dim2] $hm $data_start $datalen $bank
} else {
}
}
proc sdsinfo {hm data_type args} {
array set param $args
array set hm_prop [attlist $hm]
if {$param(mutable) == true} {
return " -type NX_INT32 -LZW -rank 4 -dim {-1,\$(padim0),\$(padim1),\$(padim2)}"
} else {
return " -type NX_INT32 -LZW -rank 3 -dim {\$(padim0),\$(padim1),\$(padim2)}"
}
}
}
namespace eval ::nexus::motor {
# The save commands are called with the sobj name and nxalias
# The sdsinfo commands provide the SDS description for an nxdic
# save sphi alias float [point n]
proc save {motor nxalias data_type args} {
if {[lindex $args 0] == "point"} {
set index [lindex $args 1]
nxscript_data clear;
nxscript_data putfloat 0 [getVal [$motor] ]
nxscript putslab $nxalias [list $index] [list 1] nxscript_data
} else {
if {[getatt $motor type] == "motor"} {
nxscript putmot $nxalias $motor
} else {
nxscript putfloat $nxalias [SplitReply [$motor]]
}
}
}
proc sdsinfo {motor data_type args} {
array set param $args
array set mot_prop [attlist $motor]
set dtype [::nexus::hdb2nx_type $data_type]
if {$param(mutable) == true} {
return " -type $dtype -rank 1 -dim {-1} -attr {units,$mot_prop(units)} -attr {long_name,$mot_prop(long_name)}"
} else {
return " -type $dtype -attr {units,$mot_prop(units)} -attr {long_name,$mot_prop(long_name)}"
}
}
}
namespace eval ::nexus {
proc hdb2nx_type {dtype} {
switch $dtype {
int {return NX_INT32}
float {return NX_FLOAT32}
text {return NX_CHAR}
default {error "ERROR: [info level -1]->hdb2nx_type, Unknown type $dtype"}
}
}
}
namespace eval ::nexus::sicsvariable {
proc save {svar nxalias data_type args} {
set val [SplitReply [$svar]]
if {[lindex $args 0] == "point"} {
set index [lindex $args 1]
nxscript_data clear;
switch $data_type {
int {nxscript_data putint 0 $val}
float {nxscript_data putfloat 0 $val}
default {error "ERROR: [info level -1]->::nexus::sicsvariable::save, unknown type $data_type"}
}
nxscript putslab $nxalias [list $index] [list 1] nxscript_data
} else {
switch $data_type {
int {nxscript putint $nxalias $val}
float {nxscript putfloat $nxalias $val}
text {nxscript puttext $nxalias $val}
default {error "ERROR: [info level -1]->::nexus::sicsvariable::save, unknown type $data_type"}
}
}
}
proc sdsinfo {svar data_type args} {
array set param $args
set dtype [::nexus::hdb2nx_type $data_type]
if {$param(mutable) == true} {
return " -type $dtype -rank 1 -dim {-1}"
} else {
return " -type $dtype"
}
}
}
namespace eval ::nexus::singlecounter {
proc save {counter nxalias data_type args} {
todo_msg "Save counter: $counter"
}
proc sdsinfo {counter data_type args} {
todo_msg "Get sdsinfo for counter: $counter"
}
}
# TODO Return filename from nxcreatefile and call nxreopen nxclose etc
# TODO Make an nxscript namespace for all this.
@@ -9,57 +433,38 @@
set tmpstr [string map {"$" ""} {$Name: not supported by cvs2svn $}]
set nx_content_release_tag [lindex $tmpstr [expr [llength $tmpstr] - 1]]
set tmpstr [string map {"$" ""} {$Revision: 1.24 $}]
set tmpstr [string map {"$" ""} {$Revision: 1.25 $}]
set nx_content_revision_num [lindex $tmpstr [expr [llength $tmpstr] - 1]]
MakeNXScript
sicsdatafactory new nxscript_data
proc getVal {msg} {
return [string trim [lindex [split $msg =] 1 ] ]
}
proc newFileName {} {
proc newFileName {postfix} {
array set inst_mnem {quokka QKK womba WBT echidna ECH kowari KWR koala KOL taipan TPN platypus PLP pelican PLN}
sicsdatanumber incr;
set idNum [SplitReply [sicsdatanumber]];
set dataPath [SplitReply [sicsdatapath]];
set prefix [SplitReply [sicsdataprefix]];
set postfix [SplitReply [sicsdatapostfix]];
set date_time_arr [split [sicstime] " "]
set isodate [lindex $date_time_arr 0];
set isotime [string map {: -} [lindex $date_time_arr 1]];
return [format "%s/%s_%sT%s_%05d%s" $dataPath $prefix $isodate $isotime $idNum $postfix];
return [format "%s/%s%07d.%s" $dataPath $inst_mnem([instname]) $idNum $postfix]
}
proc nxcreatefile {nxdic {type nx.hdf}} {
global nxFileOpen cfPath nexusdic;
SicsDataPostFix .$type;
set nexusdic $nxdic
array set nxmode [list nx.hdf create5 h5 create5 nx5 create5 xml createxml];
dataFileName [newFileName]
dataFileName [newFileName $type]
nxscript $nxmode($type) [SplitReply [dataFileName]] $cfPath(nexus)/$nexusdic;
set nxFileOpen true
}
proc nxreopenfile {} {
global nxFileOpen cfPath nexusdic;
nxscript reopen [SplitReply [dataFileName]] $cfPath(nexus)/$nexusdic;
set nxFileOpen true;
}
proc nxclosefile {} {
global nxFileOpen;
if {$nxFileOpen == true} {
nxscript close;
set nxFileOpen false;
set flist [split [SplitReply [dataFileName]] "/"];
set fname [lindex $flist [expr [llength $flist] - 1] ];
clientput "$fname updated" "event";
}
}
set dradius 1.25
set ndect 128
set tubedia 0.0254
@@ -295,7 +700,21 @@ proc putslitmotors {nxobj point} {
}
}
publish nxcreatefile user
publish addnxscanentry user
publish bm_addnxscanentry user
namespace eval data {
command gumtree_save {int: run_number} {
save $run_number
}
sicslist setatt ::data::gumtree_save long_name save
array set param [::data::gumtree_save -list param]
::utility::mkData $param(run_number) run_number instrument privilege READ_ONLY mutable true control false
command gumtree_type {text:nx.hdf,xml type} {
SicsDataSuffix $type
}
sicslist set ::data::gumtree_type long_name file_type
::data::gumtree_type -set type [SplitReply [SicsDataSuffix]]
}
Publish nxcreatefile user
Publish addnxscanentry user
Publish bm_addnxscanentry user