from org.csstudio.opibuilder.scriptUtil import DataUtil 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 pvName_xResponse = widget.getParent().getMacroValue("P") + "_x" pvName_yResponse = widget.getParent().getMacroValue("P") + "_y" pv_xResponse = PVFactory.createPV(pvName_xResponse) pv_xResponse.start() pv_yResponse = PVFactory.createPV(pvName_yResponse) pv_yResponse.start() statusX = pv_xResponse.isConnected() statusY = pv_yResponse.isConnected() cnt = 0 while ( ( not (statusX and statusY) ) and (cnt<10) ): cnt += 1 time.sleep( 0.2 ) statusX = pv_xResponse.isConnected() statusY = pv_yResponse.isConnected() if( cnt >= 10 ): ConsoleUtil.writeInfo( "Could not connect to rate PVs " + pvName_xResponse + " or " + pvName_yResponse ) ConsoleUtil.writeInfo( "Bailing ... " ) exit flatRateX = PVUtil.getDoubleArray( pv_xResponse ); flatRateY = PVUtil.getDoubleArray( pv_yResponse ); pv_yResponse.stop() pv_yResponse.stop() # gainX = DataUtil.createDoubleArray(len(flatRateX)) # gainY = DataUtil.createDoubleArray(len(flatRateY)) # # Calculate the gain factors for X profile # sumX = 0.0 # for bin in range( len( flatRateX ) ): # if( flatRateX[bin] > 1.0e-11 ) : # gainX[bin] = 1.0 / flatRateX[bin] # sumX += flatRateX[bin] # for bin in range( len( flatRateX ) ): # if( len( flatRateX ) > 0 ): # gainX[bin] *= ( sumX / len( flatRateX ) ) # if( 20 < gainX[bin] or gainX[bin] < 0.05 ): # gainX[bin] = 1.0 # # # Calculate the gain factors for Y profile # sumY = 0.0 # for bin in range( len( flatRateY ) ): # if( flatRateY[bin] > 1.0e-11 ) : # gainY[bin] = 1.0 / flatRateY[bin] # sumY += flatRateY[bin] # for bin in range( len( flatRateY ) ): # if( len( flatRateY ) > 0 ): # gainY[bin] *= ( sumY / len( flatRateY ) ) # if( 20 < gainY[bin] or gainY[bin] < 0.05 ): # gainY[bin] = 1.0 pvName_xGain = widget.getParent().getMacroValue("P") + "_x_gain" pvName_yGain = widget.getParent().getMacroValue("P") + "_y_gain" pv_xGain = PVFactory.createPV(pvName_xGain) pv_xGain.start() pv_yGain = PVFactory.createPV(pvName_yGain) pv_yGain.start() statusX = pv_xGain.isConnected() statusY = pv_yGain.isConnected() cnt = 0 while ( ( not (statusX and statusY) ) and (cnt<10) ): cnt += 1 time.sleep( 0.2 ) statusX = pv_xGain.isConnected() statusY = pv_yGain.isConnected() if( cnt >= 10 ): ConsoleUtil.writeInfo( "Could not connect to rate PVs " + pvName_xGain + " or " + pvName_yGain ) ConsoleUtil.writeInfo( "Bailing ... " ) exit # pv_xGain.setValue(gainX); # pv_yGain.setValue(gainY); pv_xGain.setValue(flatRateX); pv_yGain.setValue(flatRateY); pv_xGain.stop() pv_yGain.stop()