from org.csstudio.opibuilder.scriptUtil import PVUtil from org.csstudio.opibuilder.scriptUtil import WidgetUtil from org.csstudio.opibuilder.scriptUtil import ConsoleUtil from org.csstudio.utility.pv import PVFactory import re import os import time import sys import os.path def connectPV(pvName): pvN = PVFactory.createPV(pvName) pvN.start() cnt = 0 status1 = pvN.isConnected() while (( not (status1)) and (cnt<5) ): cnt += 1 time.sleep(0.1) status1 = pvN.isConnected() if (cnt<5): val = PVUtil.getString(pvN) else: ConsoleUtil.writeInfo( "epics PV " + pvName + " is NOT connected!") pvN.stop() return val Motor= widget.getParent().getMacroValue("P") PVFileSystem =Motor + "saveData_fileSystem" PVSubDir =Motor + "saveData_subDir" PVBaseName =Motor + "saveData_baseName" PVFullPathName=Motor + "saveData_fullPathName" PVmdaFileName =Motor + "saveData_fileName" #--- connect to the saveData PVs FileSystem=connectPV(PVFileSystem) # ConsoleUtil.writeInfo( "FileSystem = " + str(FileSystem)) SubDir=connectPV(PVSubDir) # ConsoleUtil.writeInfo( "SubDir = " + str(SubDir)) BaseName=connectPV(PVBaseName) # ConsoleUtil.writeInfo( "BaseName = " + str(BaseName)) FullPathName=connectPV(PVFullPathName) # ConsoleUtil.writeInfo( "FullPathName = " + str(FullPathName)) mdaFileName=connectPV(PVmdaFileName) # ConsoleUtil.writeInfo( "mdaFileName = " + str(mdaFileName)) dirName_mda_asc=FileSystem + "/" + SubDir + "/" root_osname = os.environ['EPICS_OSNAME'] root_version = os.environ['EPICS_ROOT_VERSION'] ConsoleUtil.writeInfo( "ROOT OSNAME is " + root_osname) envCmd = 'source /gapps/root/%s/%s/bin/thisroot.csh /gapps/root/%s/%s ;' % (root_osname, root_version, root_osname, root_version) analysisCmd = 'analyzeCollimatorScan --input-directory=' + dirName_mda_asc + ' ' + mdaFileName + ' ; ' xtermCmd = "xterm -geometry 80x10 -e '" + envCmd + " printenv; sleep 1; " + analysisCmd + " ' &> /dev/null &" cmd = xtermCmd ConsoleUtil.writeInfo( "Will issue command " + cmd ) status = os.system(cmd)