Example general_features.py file:
#!/usr/bin/env python
#
# file name: $HOME/sardanaMacros/general_features.py
#
# this file contains the general hook and general condition macros
#
# hooks and general condition are enabled/disabled by the macros defined in handleGeneralFeatures.py
#
from sardana.macroserver.macro import *
import HasyUtils
class gc_macro(Macro):
""" General condition macro """
result_def = [
[ 'condition_result', Type.Integer, None, "the condition result"],
]
def run(self):
import random
self.output("Scan check_condition")
if random.random() > 0.5:
self.output("Repeat point")
return 1
else:
self.output("DO NOT Repeat point")
return 0
#
# define detectorName and detectorRoot outside the Macros because they are used twice
#
detectorName = 'lmbd'
detectorRoot = "/gpfs/current/raw"
class gh_pre_scan(Macro):
”'
prepareDetectorAttrs() uses the input arguments and the MacroServer
environment variables ScanFile and ScanID to set these detector attributes:
FileDir|SaveFilePath|saving_directory: /<rootDir>/<scanName>/<detectorName>
/gpfs/current/raw/au_00001/lmbd
FilePrefix|saving_prefix: <scanName>
au_00001
NbFrames|FrameNumbers|acq_nb_frames: 1
FileStartNum|saving_next_number: 0
This directory is created:
rootDir + "/" + scanName + "/" + detectorName
/gpfs/current/raw/au_00001/lmbd
As a safety measure, rootDir is compared with FileDir|SaveFilePath|saving_directory.
An error is thrown, if the values are incompatible. Both
strings are compatible, if FileDir starts with rootDir
So far Pilatus, Lambda and Lima (Andor) servers are supported
”'
def run( self):
self.output( "general_features.pre_scan hook")
if not HasyUtils.isInMg( self, detectorName):
self.output( "general_features.gh_pre_scan: %s not in the MG, DONE" % detectorName)
return True
if not HasyUtils.prepareDetectorAttrs( self, name = detectorName, rootDir = detectorRoot):
self.output( "general_features.gh_pre_scan: prepareDetectors: returned error")
return False
return True
class gh_post_scan(Macro):
def run( self):
if not HasyUtils.isInMg( self, detectorName):
self.output( "general_features.gh_post_scan: %s not in the MG, DONE" % detectorName)
return True
self.output( "general_features.post_scan %s to %s" % (detectorName, detectorRoot))
if not HasyUtils.resetDetectorAttrs( self, name = detectorName, rootDir = detectorRoot):
self.output( "general_features.gh_pre_scan: prepareDetectors: returned error")
return False
return True
class gh_pre_move(Macro):
""" General hook pre-move macro """
def run(self):
self.output(" General hook pre-move macro")
class gh_post_move(Macro):
""" General hook post-move macro """
def run(self):
self.output(" General hook post-move macro")
class gh_pre_acq(Macro):
""" General hook pre-acq macro """
def run(self):
self.output(" General hook pre-acq macro")
class gh_post_acq(Macro):
""" General hook post-acq macro """
def run(self):
self.output(" General hook post-acq macro")
class gh_post_step(Macro):
""" General hook post-step macro """
def run(self):
self.output(" General hook post-step macro")
Example general_functions.py file:
#!/usr/bin/env python
#
# file name: $HOME/sardanaMacros/generalFunctions/general_functions.py
#
# this file contains the general on_stop function
#
# it is enabled/disabled by the macros defined in handleGeneralFeatures.py
#
import PyTango
def general_on_stop():
print( "General on_stop is called")