Files
x04sa-es3/script/spec/sdStartup.py
gac-x04sa 2ed890b76b Startup
2018-10-18 17:36:39 +02:00

427 lines
15 KiB
Python

#==============================================================================
# Macroname: sdStartup.mac
# =============
#
# $Date: 2009/05/28 10:09:21 $
# $Header: /cvs/G/SPEC/local/X04SA/ES3/sdStartup.mac,v 1.10 2009/05/28 10:09:21 schlepuetz Exp $
#+
# $Source: /cvs/G/SPEC/local/X04SA/ES3/sdStartup.mac,v $
# $Revision: 1.10 $
#
# Description: specialized startup macro for the surface diffraction station.
# includes all setup routines required to use the pixel detector.
#
# Note:
#
# Author(s): C. M. Schlepuetz (CS)
# Co-author(s): P. R. Willmott (PW)
# Address: Surface Diffraction Station
# Materials Science Beamline X04SA
# Swiss Light Source (SLS)
# Paul Scherrer Institut
# CH - 5232 Villigen PSI
# Created: 2005/06/10
#
#-
# Chained macro definitions affected by this macro:
# -------------------------------------------------
# - none
#
# Change Log:
# -----------
#
# 2005/06/10 (CS):
# - created the first version of this macro.
#
# 2005/11/30 (CS):
# - modified sdStartup to make sure that no previous experiment is still active
# when starting a new one.
#
# 2006/04/24 (CS):
# - changed call to 'setsample' (which was part of the hkl-workaround) to
# 'startgeo'.
#
# 2006/08/08 (CS):
# - avoid that a logfile is overwritten if sdStartup is called twice with the
# same logfile name. Now, information is appended to an existing logfile.
# - included call to scanlist.mac in sdStartup.
#
# 2008/02/20 (CS):
# - removed links to 'specmacros' and 'scanlogs' in directory tree. This led to
# confusion and sometimes the duplication of the data if links were not
# followed correctly by backup software.
#
# 2008/02/21 (CS):
# - removed 'archives' directory under 'pixel'
# - renamed 'analyzed_data' to 'analysis_runtime'
#
# 2009/05/27 (CS):
# - enable scanlists and scanlogs by default (remove user option to turn it on)
# - force use of pixel detector (shortened setup routine)
#
# 2009/05/28 (CS):
# - change permissions of pixel directory recursively by 'a+w' automatically
# when created (chmod -R a+w pixel).
#
#==============================================================================
#
global SD_STARTUP_MAC
#
SD_STARTUP_MAC = DOFILE # Save the name of this macro file.
_sav_geo_mot = 1 # spec's global variable used by setscans macro
#+
#==============================================================================
# This macro file contains the following commands:
#-
#
#+
#------------------------------------------------------------------------------
# sdStartuphelp - generates this help text. This is obtained by
# displaying the file sd_startup.txt, which should sit in
# the same directory as this file.
#-
def helpSdStartup 'sdStartuphelp'
def sdStartupHelp 'sdStartuphelp'
def sdstartuphelp 'sdStartuphelp'
def sdStartuphelp '{
# =============
unix (sprintf ("dirname %s", _MAC), _1)
ll = length (_1)
if (substr (_1, ll, 1) == "\n") _1 = substr (_1, 1, (ll - 1))
file = sprintf ("%s/sms.txt", _1)
if (file_info (file, "-e")) {
unix (sprintf ("cat %s | less", file))
} else {
printf ("\n Macros available in file sd_startup.mac ($Revision: 1.10 $):\n")
print " =============="
print ""
print " sdStartuphelp - creates this help text"
print " sdStartup - startup routine for the surface diffraction"
print " station. Sets all important parameters and"
print " paths."
print " sdShutdown - shutdown routine for the surface diffraction"
print " station. Resets all paths and filenames to"
print " standard values to prevent writing to"
print " experiment-specific files."
}
}'
#+
#------------------------------------------------------------------------------
# sdStartup - startup procedure for the surface diffraction station.
# It sets up important parameters and the data storage
# environment for the experiment. Experimental data is
# stored in the following directory structure:
#
# [<E-ACCOUNT>]
# `-- <PROJECT_NAME>
# |-- analysis_runtime # on-the-fly analysis during experiments
# |-- archive # backup directory for experimental data (zip)
# | |-- images # zip-files of images
# | |-- imagelogs # zip-files of imagelogs
# |-- fotos # fotos of experimental setup, etc.
# |-- pixel # pixel detector related information
# | |-- flatfield # flatfield data
# | | |-- flatfield(1) # 1st flatfield data set
# | | |-- flatfield(2) # 2nd flatfield data set
# | | `-- ... # ...
# | |-- imagelogs # logfiles for each individual pixel image
# | |-- images # the pixel detector images themselves
# |-- software # user made software (i.e. shell scripts, etc.)
# | |-- matlab # matlab routines for data analysis
# | |-- shell_scripts # shell scripts
# `-- spec # SPEC related information
# |-- logs # logfiles (.spec, .log, etc.)
# |-- scanlogs # log files for each individual scan
# `-- specmacros # working directory for user made SPEC macros
#
# <PROJECT_NAME> is set during the startup procedure. If the user is running
# from an e-account, the above directory tree is created inside the e-account
# directory <E-ACCOUNT> (i.e. e10003/<PROJECTNAME>/pixel/...)
#-
def sdStartup '{
# =========
global DATAFILE, LOGFILE, DO_DIR
global TITLE, COUNT, UPDATE
global SDSTARTUP_ON, SDSTARTUP_PROJECT
local dataBaseDir, expBaseDir, pixelBaseDir
local eAccount, projectDirName, _dir
local _append, _cont
local specFile
dataBaseDir = "/sls/X04SA/data/"
expBaseDir = "/sls/X04SA/data/x04sa/ES3/expdata/"
pixelBaseDir = "/sls/X04SA/data/x04sa/ES3/pixel/"
tmpLog = "/tmp/tmpLog.spec"
def sdStartupCleanupOnce \'
tty_cntl("se")
\'
cdef("cleanup_once","sdStartupCleanupOnce;","sdStartup_cleanup_once_key")
if(SDSTARTUP_ON){
printf("Currently, the following experiment is still active:\n%s\n", \\
SDSTARTUP_PROJECT)
tty_cntl("so")
if(yesno("Close the active experiment and start a new one?",0)){
tty_cntl("se")
close(DATAFILE)
close(LOGFILE)
} else{
tty_cntl("se")
printf("Startup routine aborted...\n")
exit
}
}
# turn on logging to a temporary file (this will be moved to
# the projects permanent log file later).
on(tmpLog)
#-------------------------------
# get information on the project
tty_cntl("so")
if(yesno("Are you using an e-account?",0) == 1){
eAccount=getsval("Please enter your e-account name \(i.e. e10003\)")
}
else{
eAccount=""
}
tty_cntl("se")
_cont=0
while(_cont==0){
printf("\nPlease enter a name for your project\'s data directory ending ")
printf("with the current\ndate in the following format: _yyyymmdd")
printf("\(e.g., Ni111_20050226\)\n")
tty_cntl("so")
projectDirName=getsval("Project name:","")
tty_cntl("se")
# set up the project directory
if(eAccount != ""){
_dir=sprintf("%s%s/%s/",dataBaseDir,eAccount,projectDirName)
}
else{
_dir=sprintf("%s%s/",expBaseDir,projectDirName)
}
printf("\nYour project directory name is:\n %s\n",projectDirName)
tty_cntl("so")
if(yesno("Is that o.k.?",1)){
_cont=1
}
tty_cntl("se")
if(file_info(_dir,"-d")== 1){
printf("\nDirectory %s already exists!\n", _dir)
printf("It contains the following items:\n")
unix(sprintf("ls -g --color %s",_dir))
tty_cntl("so")
if(yesno("Change your project name?",1)==0){
_cont=1
_append=1
} else{
_cont=0
}
tty_cntl("se")
}
}
printf("\nYour data will be stored in\n %s\n", _dir)
SDSTARTUP_PROJECT = projectDirName
#----------------------------------
# set up the project directory tree
cmd_file="/tmp/startup_cmd.sh"
unix(sprintf("rm -f %s",cmd_file))
open(cmd_file)
fprintf(cmd_file,"mkdir %s\n", _dir)
fprintf(cmd_file,"cd %s\n", _dir)
fprintf(cmd_file,"mkdir spec pixel fotos software analysis_runtime ")
fprintf(cmd_file,"archive \n")
fprintf(cmd_file,"# create subdirs of archive\n")
fprintf(cmd_file,"cd archive; mkdir images imagelogs; cd ..\n")
fprintf(cmd_file,"# create subdirs of spec\n")
fprintf(cmd_file,"cd spec; mkdir logs scanlogs specmacros; cd ..\n")
fprintf(cmd_file,"# create subdirs of pixel\n")
fprintf(cmd_file,"cd pixel; mkdir images imagelogs ")
fprintf(cmd_file,"flatfield; cd ..\n")
fprintf(cmd_file,"# create subdirs of software\n")
fprintf(cmd_file,"cd software; mkdir matlab shell_scripts; cd ..\n")
fprintf(cmd_file,"# change permissions on pixel directory\n")
fprintf(cmd_file,"chmod -R a+w pixel\n")
close(cmd_file)
unix(sprintf("chmod 700 %s; %s",cmd_file,cmd_file))
unix(sprintf("rm -f %s",cmd_file))
printf("directory structure:\n")
unix(sprintf("tree %s",_dir),_tmp)
print _tmp #this ensures that the tree appears in the log file
# set working directory
chdir(sprintf("%s%s",_dir,"spec/specmacros"))
DO_DIR=sprintf("%s%s",_dir,"spec/specmacros")
# open the spec file
specFile=sprintf("%sspec/logs/%s.spec",_dir,projectDirName)
eval(sprintf("newfile %s 0",specFile))
# turn on the log file and copy
# contents of temporary log into it.
LOGFILE=sprintf("%sspec/logs/%s.log",_dir,projectDirName)
close(tmpLog)
if(file_info(LOGFILE,"-e")){
# if logfile already exists, append contents of temporary file to the end.
open(LOGFILE)
fprintf(LOGFILE,"\n\n-----------------------------------------------\n\n")
close(LOGFILE)
unix(sprintf("cat %s >> %s",tmpLog,LOGFILE))
unix(sprintf("rm -f %s",tmpLog))
} else{
unix(sprintf("mv %s %s",tmpLog,LOGFILE))
}
on(LOGFILE)
tty_cntl("so")
TITLE=getsval("\nTitle for scan headers (i.e. sample name)",TITLE)
COUNT = getval("Default count time for ct and uct",COUNT)
UPDATE = getval("Update interval for umv, uct, etc. in seconds",UPDATE)
tty_cntl("se")
# set geometry parameters
printf("\nSet the geometry parameters: \(startgeo\)\n")
startgeo
# set scan options
printf("\nSet some scan options: \(setscans\)\n")
setscans
# enable scanlogs
if (SCANLOG_MAC){
eval(sprintf("scanlogSetPath %s%s", _dir,"spec/scanlogs/"))
scanlogOn
}
# enable scanlist
if (SCANLIST_MAC){
eval(sprintf("scanlistFilename %s%s",_dir,"spec/logs/scanlist.txt"))
scanlistOn
}
# set plot options
printf("\nSet some plotting options: \(setplot\)\n")
setplot
# set up the pixel detector as default detector
printf("\nSet up the PILATUS Pixel detector\n")
if(eAccount != ""){
eprint "e-Accounts are not yet supported in conjunction with the pixel"
eprint "detector. This is due to write permission errors and will be"
eprint "resolved with the new generation of the pixel detector control"
eprint "software. Please contact your user-supporter if you encounter"
eprint "this problem here."
exit
} else{
pixFilePath = sprintf("%s%s%s","../../expdata/",projectDirName,\\
"/pixel/images/")
eval(sprintf("pixsetup %s",pixFilePath)) # run the setup routine
pixon # enable the pixel detector
# turn on logging for each image taken to standard path:
pixLogPath = sprintf("%s%s", _dir,"pixel/imagelogs/")
eval(sprintf("pixlogon %s", pixLogPath))
}
printf("\n%s\n%s\n%s\n",\\
"Your experiment has been set up successfully. Please remember to",\\
"run \'sdShutdown\' after completing your measurements to prevent",\\
"other users from accidentally modifying your experimental data.")
SDSTARTUP_ON = 1
cdef("cleanup_once","","sdStartup_cleanup_once_key","delete")
}'
#+
#------------------------------------------------------------------------------
# sdShutdown - Cleanup procedure to be executed after an experiment.
# Experimental files are closed and logging is redirected
# to some standard files. The entire experimenal environ-
# ment used before is abandoned by SPEC.
#-
def sdShutdown '{
# ==========
global DATAFILE, LOGFILE, DO_DIR
# reset the current working directory to standard location
chdir(sprintf("%s","~/specmacros"))
# close the SPEC data file and reopen the standard file.
close(DATAFILE)
eval(sprintf("newfile %s 0","/sls/X04SA/data/x04sa/ES3/tmp/dummy.spec"))
# close the SPEC log file and reset the global variable to the standard value
close(LOGFILE)
LOGFILE = "/sls/X04SA/data/x04sa/ES3/tmp/dummy.log"
# redirect pixel detector output to standard locations
pixsetpath "tmp/"
pixlogoff
SDSTARTUP_ON = 0
}'
#+
#------------------------------------------------------------------------------
#-
#####################################################
# emacs setup: force text mode to get no help with #
# indentation and force use of spaces #
# when tabbing. #
# Local Variables: #
# mode:text #
# indent-tabs-mode:nil #
# End: #
#####################################################
#
# $Log: sdStartup.mac,v $
# Revision 1.10 2009/05/28 10:09:21 schlepuetz
# change permissions on pixel directory automatically by a+w
#
# Revision 1.9 2009/05/27 15:59:36 schlepuetz
# shortened setup routine
#
# Revision 1.8 2008/02/21 09:59:25 schlepuetz
# updated documentation
#
# Revision 1.7 2008/02/21 09:55:35 schlepuetz
# removed archives directory under pixel, renamed analyzed_data to analysis_runtime
#
# Revision 1.6 2008/02/20 09:10:13 schlepuetz
# removed links to specmacros and scanlogs in directory tree
#
# Revision 1.5 2006/08/11 10:34:10 schlepuetz
# improved output formatting of sdStartup
#
# Revision 1.4 2006/08/08 14:07:38 schlepuetz
# prevent overwrite of old log files, added enable/disble of scanlist
#
# Revision 1.3 2006/05/04 10:15:23 schlepuetz
# call startgeo instead of setsample
#
# Revision 1.2 2005/11/30 15:33:11 schlepuetz
# modified sdStartup to make sure that no previous experiment is still active when starting a new one.
#
# Revision 1.1 2005/11/10 11:24:07 schlepuetz
# first tested version of this file
#
#
#============================= End of $RCSfile: sdStartup.mac,v $ ===