def __init__(self, cav):
     #self.bpm_ch_amp_phase_dic[BPM_Wrapper] = (graphDataAmp,graphDataPhase)
     self.cav = cav
     self.alias = cav.getId().split(":")[1]
     self.isGood = true
     self.isMeasured = false
     self.isAnalyzed = false
     self.pos = 0.
     self.bpm_amp_phase_dict = {}
     self.bpm_wrappers = []
     #--- use or not in phase scan analysis
     self.bpm_wrappers_useInPhaseAnalysis = []
     #--- use or not in BPMs' amplitudes analysis
     self.bpm_wrappers_useInAmpBPMs = []
     #--- BPM wrappers for BPM0 and BPM1 during cavity phase setup after the phase scan
     self.bpm_wrapper0 = null
     self.bpm_wrapper1 = null
     self.phaseDiffPlot = BasicGraphData()
     self.phaseDiffPlot.setGraphPointSize(7)
     self.phaseDiffPlot.setGraphColor(Color.BLUE)
     self.phaseDiffPlotTh = BasicGraphData()
     self.phaseDiffPlotTh.setDrawPointsOn(false)
     self.phaseDiffPlotTh.setGraphColor(Color.RED)
     self.phaseDiffPlotTh.setLineThick(3)
     #----cavity's parameters
     self.initDesignAmp = 0.
     self.initDesignPhase = 0.
     #-- design parameters will be defined after analysis of the phase scan data
     self.designAmp = 0.
     self.designPhase = 0.
     self.avg_gap_phase = 0.  # this is a model parameter that will be used in rescaling
     #--- initial live parameters are measured after initialization
     self.initLiveAmp = 0.
     self.initLivePhase = 0.
     #live phase will be defined after scan
     self.livePhase = 0.
     self.scanPhaseShift = -18.0
     self.real_scanPhaseShift = 0.
     #--- avg. phase error and harmonic amp after harmonics fitting during phase scan
     self.phase_scan_harm_err = 0.
     self.phase_scan_harm_amp = 0.
     self.phase_scan_harm_funcion = HramonicsFunc([
         0.,
     ])
     self.energy_guess_harm_funcion = HramonicsFunc([
         0.,
     ])
     self.eKinOutPlot = BasicGraphData()
     self.eKinOutPlot.setGraphPointSize(7)
     self.eKinOutPlot.setGraphColor(Color.BLUE)
     self.eKinOutPlotTh = BasicGraphData()
     self.eKinOutPlotTh.setDrawPointsOn(false)
     self.eKinOutPlotTh.setGraphColor(Color.RED)
     self.eKinOutPlotTh.setLineThick(3)
     self.eKinOutPlot.setGraphProperty(GRAPH_LEGEND_KEY,
                                       " Ekin Out " + self.alias)
     self.eKinOutPlotTh.setGraphProperty(GRAPH_LEGEND_KEY,
                                         " Ekin Out Fit " + self.alias)
     #--- energy params
     self.eKin_in_guess = 0.  # is used for CCL4 forward analysis
     self.eKin_out_guess = 0.  # is used for CCL4 forward analysis
     self.eKin_in = 0.
     self.eKin_out = 0.
     self.eKin_err = 0.
     self.bpm_eKin_out = 0.
     self.model_eKin_out = 0.
     #------- the rescale data bucket
     self.rescaleBacket = CavityRescaleBucket(self)
     #------- the longitudinal Twiss parameters bucket
     self.longTwissBucket = Long_Twiss_Bucket(self)
     #------- LLRF Buffer resettings PVs
     self.ch_aff_mode = ChannelFactory.defaultFactory().getChannel(
         "SCL_LLRF:FCM" + self.alias.replace("Cav", "") + ":AFF_Mode")
     self.ch_aff_reset = ChannelFactory.defaultFactory().getChannel(
         "SCL_LLRF:FCM" + self.alias.replace("Cav", "") + ":AFF_Reset")
     #------- Amplitude set goal value PV
     self.ampl_goal_pv = ChannelFactory.defaultFactory().getChannel(
         "SCL_LLRF:FCM" + self.alias.replace("Cav", "") + ":cavAmpGoal")
	def __init__(self,cav):
		#self.bpm_ch_amp_phase_dic[BPM_Wrapper] = (graphDataAmp,graphDataPhase)
		self.cav = cav
		self.alias = cav.getId().split(":")[1]		
		self.isGood = true
		self.isMeasured = false
		self.isAnalyzed = false
		self.pos = 0.
		self.bpm_amp_phase_dict = {}
		self.bpm_wrappers = []
		#--- use or not in phase scan analysis
		self.bpm_wrappers_useInPhaseAnalysis = []
		#--- use or not in BPMs' amplitudes analysis
		self.bpm_wrappers_useInAmpBPMs = []
		#--- BPM wrappers for BPM0 and BPM1 during cavity phase setup after the phase scan
		self.bpm_wrapper0 = null
		self.bpm_wrapper1 = null
		self.phaseDiffPlot = BasicGraphData()
		self.phaseDiffPlot.setGraphPointSize(7)
		self.phaseDiffPlot.setGraphColor(Color.BLUE)
		self.phaseDiffPlotTh = BasicGraphData()
		self.phaseDiffPlotTh.setDrawPointsOn(false)
		self.phaseDiffPlotTh.setGraphColor(Color.RED)
		self.phaseDiffPlotTh.setLineThick(3)
		#----cavity's parameters 
		self.initDesignAmp = 0.
		self.initDesignPhase = 0.
		#-- design parameters will be defined after analysis of the phase scan data
		self.designAmp = 0.
		self.designPhase = 0.
		self.avg_gap_phase = 0.  # this is a model parameter that will be used in rescaling 
		#--- initial live parameters are measured after initialization 
		self.initLiveAmp = 0.
		self.initLivePhase = 0.
		#live phase will be defined after scan
		self.livePhase = 0.
		self.scanPhaseShift = -18.0
		self.real_scanPhaseShift = 0.
		#--- avg. phase error and harmonic amp after harmonics fitting during phase scan
		self.phase_scan_harm_err = 0.
		self.phase_scan_harm_amp = 0.
		self.phase_scan_harm_funcion = HramonicsFunc([0.,])
		self.energy_guess_harm_funcion = HramonicsFunc([0.,])
		self.eKinOutPlot = BasicGraphData()
		self.eKinOutPlot.setGraphPointSize(7)
		self.eKinOutPlot.setGraphColor(Color.BLUE)
		self.eKinOutPlotTh = BasicGraphData()
		self.eKinOutPlotTh.setDrawPointsOn(false)
		self.eKinOutPlotTh.setGraphColor(Color.RED)
		self.eKinOutPlotTh.setLineThick(3)	
		self.eKinOutPlot.setGraphProperty(GRAPH_LEGEND_KEY," Ekin Out "+self.alias)		
		self.eKinOutPlotTh.setGraphProperty(GRAPH_LEGEND_KEY," Ekin Out Fit "+self.alias)		
		#--- energy params
		self.eKin_in_guess = 0. # is used for CCL4 forward analysis
		self.eKin_out_guess = 0. # is used for CCL4 forward analysis		
		self.eKin_in = 0.
		self.eKin_out = 0.
		self.eKin_err = 0.
		self.bpm_eKin_out = 0.
		self.model_eKin_out = 0.
		#------- the rescale data bucket
		self.rescaleBacket = CavityRescaleBucket(self)
		#------- the longitudinal Twiss parameters bucket
		self.longTwissBucket = Long_Twiss_Bucket(self)
class SCL_Cavity_Wrapper:
    def __init__(self, cav):
        #self.bpm_ch_amp_phase_dic[BPM_Wrapper] = (graphDataAmp,graphDataPhase)
        self.cav = cav
        self.alias = cav.getId().split(":")[1]
        self.isGood = true
        self.isMeasured = false
        self.isAnalyzed = false
        self.pos = 0.
        self.bpm_amp_phase_dict = {}
        self.bpm_wrappers = []
        #--- use or not in phase scan analysis
        self.bpm_wrappers_useInPhaseAnalysis = []
        #--- use or not in BPMs' amplitudes analysis
        self.bpm_wrappers_useInAmpBPMs = []
        #--- BPM wrappers for BPM0 and BPM1 during cavity phase setup after the phase scan
        self.bpm_wrapper0 = null
        self.bpm_wrapper1 = null
        self.phaseDiffPlot = BasicGraphData()
        self.phaseDiffPlot.setGraphPointSize(7)
        self.phaseDiffPlot.setGraphColor(Color.BLUE)
        self.phaseDiffPlotTh = BasicGraphData()
        self.phaseDiffPlotTh.setDrawPointsOn(false)
        self.phaseDiffPlotTh.setGraphColor(Color.RED)
        self.phaseDiffPlotTh.setLineThick(3)
        #----cavity's parameters
        self.initDesignAmp = 0.
        self.initDesignPhase = 0.
        #-- design parameters will be defined after analysis of the phase scan data
        self.designAmp = 0.
        self.designPhase = 0.
        self.avg_gap_phase = 0.  # this is a model parameter that will be used in rescaling
        #--- initial live parameters are measured after initialization
        self.initLiveAmp = 0.
        self.initLivePhase = 0.
        #live phase will be defined after scan
        self.livePhase = 0.
        self.scanPhaseShift = -18.0
        self.real_scanPhaseShift = 0.
        #--- avg. phase error and harmonic amp after harmonics fitting during phase scan
        self.phase_scan_harm_err = 0.
        self.phase_scan_harm_amp = 0.
        self.phase_scan_harm_funcion = HramonicsFunc([
            0.,
        ])
        self.energy_guess_harm_funcion = HramonicsFunc([
            0.,
        ])
        self.eKinOutPlot = BasicGraphData()
        self.eKinOutPlot.setGraphPointSize(7)
        self.eKinOutPlot.setGraphColor(Color.BLUE)
        self.eKinOutPlotTh = BasicGraphData()
        self.eKinOutPlotTh.setDrawPointsOn(false)
        self.eKinOutPlotTh.setGraphColor(Color.RED)
        self.eKinOutPlotTh.setLineThick(3)
        self.eKinOutPlot.setGraphProperty(GRAPH_LEGEND_KEY,
                                          " Ekin Out " + self.alias)
        self.eKinOutPlotTh.setGraphProperty(GRAPH_LEGEND_KEY,
                                            " Ekin Out Fit " + self.alias)
        #--- energy params
        self.eKin_in_guess = 0.  # is used for CCL4 forward analysis
        self.eKin_out_guess = 0.  # is used for CCL4 forward analysis
        self.eKin_in = 0.
        self.eKin_out = 0.
        self.eKin_err = 0.
        self.bpm_eKin_out = 0.
        self.model_eKin_out = 0.
        #------- the rescale data bucket
        self.rescaleBacket = CavityRescaleBucket(self)
        #------- the longitudinal Twiss parameters bucket
        self.longTwissBucket = Long_Twiss_Bucket(self)
        #------- LLRF Buffer resettings PVs
        self.ch_aff_mode = ChannelFactory.defaultFactory().getChannel(
            "SCL_LLRF:FCM" + self.alias.replace("Cav", "") + ":AFF_Mode")
        self.ch_aff_reset = ChannelFactory.defaultFactory().getChannel(
            "SCL_LLRF:FCM" + self.alias.replace("Cav", "") + ":AFF_Reset")
        #------- Amplitude set goal value PV
        self.ampl_goal_pv = ChannelFactory.defaultFactory().getChannel(
            "SCL_LLRF:FCM" + self.alias.replace("Cav", "") + ":cavAmpGoal")
        #print "debug conncted cav=",self.alias

    def getLiveAmlitudeSetGoal(self):
        if (self.ampl_goal_pv.connectAndWait(3.0)):
            return self.ampl_goal_pv.getValDbl()
        return 0.

    def setAFF_Off(self):
        if (self.ch_aff_mode.connectAndWait(0.1)):
            self.ch_aff_mode.putVal(0)

    def setAFF_On(self):
        if (self.ch_aff_mode.connectAndWait(0.1)):
            self.ch_aff_mode.putVal(2)

    def resetAFF(self):
        if (self.ch_aff_reset.connectAndWait(0.1)):
            self.ch_aff_reset.putVal(1)

    def setBlankBeam(self, bool_val):
        self.cav.setBlankBeam(bool_val)

    def setUpBPM_Wrappers(self, bpm_wrappers, scl_long_tuneup_controller):
        self.bpm_amp_phase_dict = {}
        self.bpm_wrappers = []
        self.bpm_wrappers_useInPhaseAnalysis = []
        self.bpm_wrappers_useInAmpBPMs = []
        for bpm_wrapper in bpm_wrappers:
            #we will use all bpm_wrappers even if they are before the cavity
            #if(bpm_wrapper.getPosition() > self.getPosition() and bpm_wrapper.isGood):
            if (bpm_wrapper.isGood):
                self.bpm_wrappers.append(bpm_wrapper)
                self.bpm_wrappers_useInPhaseAnalysis.append(true)
                self.bpm_wrappers_useInAmpBPMs.append(true)
                (graphDataAmp, graphDataPhase) = (BasicGraphData(),
                                                  BasicGraphData())
                graphDataAmp.setGraphPointSize(5)
                graphDataPhase.setGraphPointSize(5)
                graphDataAmp.setGraphColor(Color.BLUE)
                graphDataPhase.setGraphColor(Color.BLUE)
                graphDataPhase.setGraphProperty(GRAPH_LEGEND_KEY,
                                                " Phase " + bpm_wrapper.alias)
                graphDataAmp.setGraphProperty(GRAPH_LEGEND_KEY,
                                              " Amp " + bpm_wrapper.alias)
                self.bpm_amp_phase_dict[bpm_wrapper] = (graphDataAmp,
                                                        graphDataPhase)
        # HEBT2 BPMs should not be used in the phase and amp analysis (pending the XAL Online Model fix)
        for ind in range(len(self.bpm_wrappers)):
            bpm_wrapper = self.bpm_wrappers[ind]
            #---- HEBT2 should be excluded - usually energy is wrong for beam transport to HEBT2
            if (bpm_wrapper.pos > 280.):
                self.bpm_wrappers_useInPhaseAnalysis[ind] = false
                self.bpm_wrappers_useInAmpBPMs[ind] = false
        # longitudinal twiss bucket update
        self.longTwissBucket.update()

    def setBPM_0_1_Wrappers(self, bpm_wrapper0, bpm_wrapper1):
        self.phaseDiffPlot.removeAllPoints()
        self.phaseDiffPlotTh.removeAllPoints()
        self.bpm_wrapper0 = null
        self.bpm_wrapper1 = null
        if (self.bpm_amp_phase_dict.has_key(bpm_wrapper0)):
            self.bpm_wrapper0 = bpm_wrapper0
        if (self.bpm_amp_phase_dict.has_key(bpm_wrapper1)):
            self.bpm_wrapper1 = bpm_wrapper1
        self.phaseDiffPlot.removeAllPoints()
        legendKey = GRAPH_LEGEND_KEY
        txt = self.alias + " Phase diff "
        self.phaseDiffPlotTh.setGraphProperty(legendKey, txt + "Fit")
        if (self.bpm_wrapper0 != null and self.bpm_wrapper1 != null):
            self.phaseDiffPlot.setGraphProperty(
                legendKey,
                txt + self.bpm_wrapper0.alias + " " + self.bpm_wrapper1.alias)
        else:
            self.phaseDiffPlot.setGraphProperty(legendKey, txt)

    def clean(self):
        for bpm_wrapper in self.bpm_wrappers:
            (graphDataAmp,
             graphDataPhase) = self.bpm_amp_phase_dict[bpm_wrapper]
            graphDataAmp.removeAllPoints()
            graphDataPhase.removeAllPoints()
        self.livePhase = 0.
        self.isMeasured = false
        self.isAnalyzed = false
        self.phase_scan_harm_err = 0.
        self.phase_scan_harm_amp = 0.
        self.avg_gap_phase = 0.
        self.eKin_err = 0.
        self.model_eKin_out = 0.
        self.bpm_eKin_out = 0.
        self.real_scanPhaseShift = 0.
        self.phase_scan_harm_funcion.setParamArr([
            0.,
        ])
        self.phaseDiffPlot.removeAllPoints()
        self.phaseDiffPlotTh.removeAllPoints()
        self.eKinOutPlot.removeAllPoints()
        self.eKinOutPlotTh.removeAllPoints()
        #---clean the rescale data
        self.rescaleBacket.clean()
        #---clean longitudinal Twiss data
        self.longTwissBucket.clean()

    def addScanPointToPhaseDiffData(self):
        if (self.bpm_wrapper0 == null or self.bpm_wrapper1 == null): return
        (graphDataAmp0,
         graphDataPhase0) = self.bpm_amp_phase_dict[self.bpm_wrapper0]
        (graphDataAmp1,
         graphDataPhase1) = self.bpm_amp_phase_dict[self.bpm_wrapper1]
        if (graphDataPhase0.getNumbOfPoints() !=
                graphDataPhase1.getNumbOfPoints()):
            return
        n_points = graphDataPhase0.getNumbOfPoints()
        ind = n_points - 1
        x = graphDataPhase0.getX(ind)
        y = graphDataPhase1.getY(ind) - graphDataPhase0.getY(ind)
        self.phaseDiffPlot.addPoint(x, y)

    def recalculatePhaseDiffData(self):
        if (self.bpm_wrapper0 == null or self.bpm_wrapper1 == null): return
        (graphDataAmp0,
         graphDataPhase0) = self.bpm_amp_phase_dict[self.bpm_wrapper0]
        (graphDataAmp1,
         graphDataPhase1) = self.bpm_amp_phase_dict[self.bpm_wrapper1]
        if (graphDataPhase0.getNumbOfPoints() !=
                graphDataPhase1.getNumbOfPoints()):
            return
        x_arr = []
        y_arr = []
        for ind in range(graphDataPhase0.getNumbOfPoints()):
            x_arr.append(graphDataPhase0.getX(ind))
            y_arr.append(graphDataPhase1.getY(ind) - graphDataPhase0.getY(ind))
        self.phaseDiffPlot.removeAllPoints()
        self.phaseDiffPlot.addPoint(x_arr, y_arr)

    def getAmpPhaseGraphs(self, bpm_wrapper):
        if (self.bpm_amp_phase_dict.has_key(bpm_wrapper)):
            (graphDataAmp,
             graphDataPhase) = self.bpm_amp_phase_dict[bpm_wrapper]
            return (graphDataAmp, graphDataPhase)
        return (null, null)

    def setPosition(self, accSeq):
        self.pos = accSeq.getPosition(self.cav)

    def getPosition(self):
        return self.pos

    def writeDataToXML(self, root_da):
        cav_wrapper_da = root_da.createChild(self.alias)
        cav_wrapper_da.setValue("cav", self.cav.getId())
        bpm0_name = "null"
        bpm1_name = "null"
        if (self.bpm_wrapper0 != null): bpm0_name = self.bpm_wrapper0.alias
        if (self.bpm_wrapper1 != null): bpm1_name = self.bpm_wrapper1.alias
        cav_wrapper_da.setValue("bpm0", bpm0_name)
        cav_wrapper_da.setValue("bpm1", bpm1_name)
        cav_wrapper_da.setValue("isGood", self.isGood)
        cav_wrapper_da.setValue("isMeasured", self.isMeasured)
        cav_wrapper_da.setValue("isAnalyzed", self.isAnalyzed)
        #--------------------------------
        cav_wrapper_params_da = cav_wrapper_da.createChild("Params")
        cav_wrapper_params_da.setValue("initDesignAmp", self.initDesignAmp)
        cav_wrapper_params_da.setValue("initDesignPhase", self.initDesignPhase)
        cav_wrapper_params_da.setValue("designAmp", self.designAmp)
        cav_wrapper_params_da.setValue("designPhase", self.designPhase)
        cav_wrapper_params_da.setValue("avg_gap_phase", self.avg_gap_phase)
        cav_wrapper_params_da.setValue("initLiveAmp", self.initLiveAmp)
        cav_wrapper_params_da.setValue("initLivePhase", self.initLivePhase)
        cav_wrapper_params_da.setValue("livePhase", self.livePhase)
        cav_wrapper_params_da.setValue("scanPhaseShift", self.scanPhaseShift)
        cav_wrapper_params_da.setValue("phase_scan_harm_err",
                                       self.phase_scan_harm_err)
        cav_wrapper_params_da.setValue("phase_scan_harm_amp",
                                       self.phase_scan_harm_amp)
        cav_wrapper_params_da.setValue("eKin_in_guess", self.eKin_in_guess)
        cav_wrapper_params_da.setValue("eKin_out_guess", self.eKin_out_guess)
        cav_wrapper_params_da.setValue("eKin_in", self.eKin_in)
        cav_wrapper_params_da.setValue("eKin_out", self.eKin_out)
        cav_wrapper_params_da.setValue("eKin_err", self.eKin_err)
        cav_wrapper_params_da.setValue("bpm_eKin_out", self.bpm_eKin_out)
        cav_wrapper_params_da.setValue("model_eKin_out", self.model_eKin_out)
        cav_wrapper_params_da.setValue("real_scanPhaseShift",
                                       self.real_scanPhaseShift)
        #--------- write the cavity rescale data
        self.rescaleBacket.writeDataToXML(cav_wrapper_da)
        #---------------------------------
        cav_wrapper_phase_harm_da = cav_wrapper_da.createChild(
            "Phase_Harm_Func")
        cav_wrapper_phase_harm_da.setValue(
            "params_arr", self.phase_scan_harm_funcion.getTxtParamArr())
        cav_wrapper_energy_harm_da = cav_wrapper_da.createChild(
            "Eenergy_guess_Harm_Func")
        cav_wrapper_energy_harm_da.setValue(
            "params_arr", self.energy_guess_harm_funcion.getTxtParamArr())
        #----------------------------------
        dumpGraphDataToDA(self.phaseDiffPlot, cav_wrapper_da, "Phase_Diff_GD",
                          "%8.3f", "%8.3f")
        dumpGraphDataToDA(self.phaseDiffPlotTh, cav_wrapper_da,
                          "Phase_Diff_Fit_GD", "%8.3f", "%8.3f")
        dumpGraphDataToDA(self.eKinOutPlot, cav_wrapper_da, "Ekin_Out_GD",
                          "%8.3f", "%10.4f")
        dumpGraphDataToDA(self.eKinOutPlotTh, cav_wrapper_da,
                          "Ekin_Out_Fit_GD", "%8.3f", "%10.4f")
        #------------------------------------
        cav_wrapper_bpm_list_da = cav_wrapper_da.createChild("bpm_arr")
        txt = ""
        for bpm_wrapper in self.bpm_wrappers:
            txt = txt + " " + bpm_wrapper.alias
        cav_wrapper_bpm_list_da.setValue("bpm_wrappers", txt)
        cav_wrapper_bpm_list_da = cav_wrapper_da.createChild(
            "bpm_use_in_phase_analysis_arr")
        txt = ""
        for bool_val in self.bpm_wrappers_useInPhaseAnalysis:
            val = "0"
            if (bool_val): val = "1"
            txt = txt + " " + val
        cav_wrapper_bpm_list_da.setValue("use_arr", txt)
        cav_wrapper_bpm_list_da = cav_wrapper_da.createChild(
            "bpm_use_in_amp_analysis_arr")
        txt = ""
        for bool_val in self.bpm_wrappers_useInAmpBPMs:
            val = "0"
            if (bool_val): val = "1"
            txt = txt + " " + val
        cav_wrapper_bpm_list_da.setValue("use_arr", txt)
        #---------------------------------------------
        cav_wrapper_scan_data_da = cav_wrapper_da.createChild("scan_data")
        for bpm_wrapper in self.bpm_wrappers:
            if (self.bpm_amp_phase_dict.has_key(bpm_wrapper)):
                (graphDataAmp,
                 graphDataPhase) = self.bpm_amp_phase_dict[bpm_wrapper]
                cav_wrapper_scan_data_bpm_da = cav_wrapper_scan_data_da.createChild(
                    bpm_wrapper.alias)
                dumpGraphDataToDA(graphDataPhase, cav_wrapper_scan_data_bpm_da,
                                  "phase", "%8.3f", "%8.3f")
                dumpGraphDataToDA(graphDataAmp, cav_wrapper_scan_data_bpm_da,
                                  "amplitude", "%8.3f", "%10.3g")

    def readDataFromXML(self, cav_wrapper_da, scl_long_tuneup_controller):
        #print "debug ============= cav_wrapper_da=",cav_wrapper_da.name()
        self.bpm_wrapper0 = scl_long_tuneup_controller.getBPM_Wrapper(
            cav_wrapper_da.stringValue("bpm0"))
        self.bpm_wrapper1 = scl_long_tuneup_controller.getBPM_Wrapper(
            cav_wrapper_da.stringValue("bpm1"))
        self.isGood = Boolean(cav_wrapper_da.intValue("isGood")).booleanValue()
        self.isMeasured = Boolean(
            cav_wrapper_da.intValue("isMeasured")).booleanValue()
        self.isAnalyzed = Boolean(
            cav_wrapper_da.intValue("isAnalyzed")).booleanValue()
        #--------- read parameters-------------------------
        cav_wrapper_params_da = cav_wrapper_da.childAdaptor("Params")
        self.initDesignAmp = cav_wrapper_params_da.doubleValue("initDesignAmp")
        self.initDesignPhase = cav_wrapper_params_da.doubleValue(
            "initDesignPhase")
        self.designAmp = cav_wrapper_params_da.doubleValue("designAmp")
        self.designPhase = cav_wrapper_params_da.doubleValue("designPhase")
        self.avg_gap_phase = cav_wrapper_params_da.doubleValue("avg_gap_phase")
        self.initLiveAmp = cav_wrapper_params_da.doubleValue("initLiveAmp")
        self.initLivePhase = cav_wrapper_params_da.doubleValue("initLivePhase")
        self.livePhase = cav_wrapper_params_da.doubleValue("livePhase")
        self.scanPhaseShift = cav_wrapper_params_da.doubleValue(
            "scanPhaseShift")
        self.phase_scan_harm_err = cav_wrapper_params_da.doubleValue(
            "phase_scan_harm_err")
        self.phase_scan_harm_amp = cav_wrapper_params_da.doubleValue(
            "phase_scan_harm_amp")
        self.eKin_in_guess = cav_wrapper_params_da.doubleValue("eKin_in_guess")
        self.eKin_out_guess = cav_wrapper_params_da.doubleValue(
            "eKin_out_guess")
        self.eKin_in = cav_wrapper_params_da.doubleValue("eKin_in")
        self.eKin_out = cav_wrapper_params_da.doubleValue("eKin_out")
        self.eKin_err = cav_wrapper_params_da.doubleValue("eKin_err")
        self.bpm_eKin_out = cav_wrapper_params_da.doubleValue("bpm_eKin_out")
        self.model_eKin_out = cav_wrapper_params_da.doubleValue(
            "model_eKin_out")
        self.real_scanPhaseShift = cav_wrapper_params_da.doubleValue(
            "real_scanPhaseShift")
        #--------- read the cavity rescale data
        self.rescaleBacket.readDataFromXML(cav_wrapper_da)
        #--------- read harm. functions-------------------------
        cav_wrapper_phase_harm_da = cav_wrapper_da.childAdaptor(
            "Phase_Harm_Func")
        self.phase_scan_harm_funcion.parsePramArr(
            cav_wrapper_phase_harm_da.stringValue("params_arr"))
        cav_wrapper_energy_harm_da = cav_wrapper_da.childAdaptor(
            "Eenergy_guess_Harm_Func")
        self.energy_guess_harm_funcion.parsePramArr(
            cav_wrapper_energy_harm_da.stringValue("params_arr"))
        #--------- read phase Diff. graph data
        readGraphDataFromDA(self.phaseDiffPlot, cav_wrapper_da,
                            "Phase_Diff_GD")
        readGraphDataFromDA(self.phaseDiffPlotTh, cav_wrapper_da,
                            "Phase_Diff_Fit_GD")
        readGraphDataFromDA(self.eKinOutPlot, cav_wrapper_da, "Ekin_Out_GD")
        readGraphDataFromDA(self.eKinOutPlotTh, cav_wrapper_da,
                            "Ekin_Out_Fit_GD")
        #--------- loop over bpm wrappers for this cavity
        cav_wrapper_bpm_list_da = cav_wrapper_da.childAdaptor("bpm_arr")
        bpm_wrapper_alias_arr = cav_wrapper_bpm_list_da.stringValue(
            "bpm_wrappers").split()
        cav_wrapper_bpm_list_da = cav_wrapper_da.childAdaptor(
            "bpm_use_in_phase_analysis_arr")
        use_in_phase_analysis_arr = cav_wrapper_bpm_list_da.stringValue(
            "use_arr").split()
        cav_wrapper_bpm_list_da = cav_wrapper_da.childAdaptor(
            "bpm_use_in_amp_analysis_arr")
        use_in_amp_analysis_arr = cav_wrapper_bpm_list_da.stringValue(
            "use_arr").split()
        bpm_wrapper_arr = []
        for bpm_wrapper_alias in bpm_wrapper_alias_arr:
            bpm_wrapper = scl_long_tuneup_controller.getBPM_Wrapper(
                bpm_wrapper_alias)
            bpm_wrapper_arr.append(bpm_wrapper)
        bpm_wrappers = []
        use_in_phase_arr = []
        use_in_amp_arr = []
        for ind in range(len(bpm_wrapper_arr)):
            bpm_wrapper = bpm_wrapper_arr[ind]
            if (bpm_wrapper != null):
                bpm_wrappers.append(bpm_wrapper)
                use_in_phase_arr.append(use_in_phase_analysis_arr[ind])
                use_in_amp_arr.append(use_in_amp_analysis_arr[ind])
        use_in_phase_analysis_arr = use_in_phase_arr
        use_in_amp_analysis_arr = use_in_amp_arr
        self.setUpBPM_Wrappers(bpm_wrappers, scl_long_tuneup_controller)
        for ind in range(len(self.bpm_wrappers)):
            bpm_wrapper = self.bpm_wrappers[ind]
            self.bpm_wrappers_useInPhaseAnalysis[ind] = Boolean(
                int(use_in_phase_analysis_arr[ind])).booleanValue()
            self.bpm_wrappers_useInAmpBPMs[ind] = Boolean(
                int(use_in_amp_analysis_arr[ind])).booleanValue()
        #-------- read the phase scan data
        # we have to keep in mind that in self.bpm_wrappers we have only bpm wrappers that exist in the
        # scl_long_tuneup_controller.bpm_wrappers and therefore exist in the self.bpm_amp_phase_dict as keys
        # Threfore they have (graphDataAmp,graphDataPhase) and we just have to fill them out.
        cav_wrapper_scan_data_da = cav_wrapper_da.childAdaptor("scan_data")
        for bpm_wrapper in self.bpm_wrappers:
            if (not self.bpm_amp_phase_dict.has_key(bpm_wrapper)): continue
            (graphDataAmp,
             graphDataPhase) = self.bpm_amp_phase_dict[bpm_wrapper]
            cav_wrapper_scan_data_bpm_da = cav_wrapper_scan_data_da.childAdaptor(
                bpm_wrapper.alias)
            if (cav_wrapper_scan_data_bpm_da != null):
                readGraphDataFromDA(graphDataPhase,
                                    cav_wrapper_scan_data_bpm_da, "phase")
                readGraphDataFromDA(graphDataAmp, cav_wrapper_scan_data_bpm_da,
                                    "amplitude")
class SCL_Cavity_Wrapper:
	def __init__(self,cav):
		#self.bpm_ch_amp_phase_dic[BPM_Wrapper] = (graphDataAmp,graphDataPhase)
		self.cav = cav
		self.alias = cav.getId().split(":")[1]		
		self.isGood = true
		self.isMeasured = false
		self.isAnalyzed = false
		self.pos = 0.
		self.bpm_amp_phase_dict = {}
		self.bpm_wrappers = []
		#--- use or not in phase scan analysis
		self.bpm_wrappers_useInPhaseAnalysis = []
		#--- use or not in BPMs' amplitudes analysis
		self.bpm_wrappers_useInAmpBPMs = []
		#--- BPM wrappers for BPM0 and BPM1 during cavity phase setup after the phase scan
		self.bpm_wrapper0 = null
		self.bpm_wrapper1 = null
		self.phaseDiffPlot = BasicGraphData()
		self.phaseDiffPlot.setGraphPointSize(7)
		self.phaseDiffPlot.setGraphColor(Color.BLUE)
		self.phaseDiffPlotTh = BasicGraphData()
		self.phaseDiffPlotTh.setDrawPointsOn(false)
		self.phaseDiffPlotTh.setGraphColor(Color.RED)
		self.phaseDiffPlotTh.setLineThick(3)
		#----cavity's parameters 
		self.initDesignAmp = 0.
		self.initDesignPhase = 0.
		#-- design parameters will be defined after analysis of the phase scan data
		self.designAmp = 0.
		self.designPhase = 0.
		self.avg_gap_phase = 0.  # this is a model parameter that will be used in rescaling 
		#--- initial live parameters are measured after initialization 
		self.initLiveAmp = 0.
		self.initLivePhase = 0.
		#live phase will be defined after scan
		self.livePhase = 0.
		self.scanPhaseShift = -18.0
		self.real_scanPhaseShift = 0.
		#--- avg. phase error and harmonic amp after harmonics fitting during phase scan
		self.phase_scan_harm_err = 0.
		self.phase_scan_harm_amp = 0.
		self.phase_scan_harm_funcion = HramonicsFunc([0.,])
		self.energy_guess_harm_funcion = HramonicsFunc([0.,])
		self.eKinOutPlot = BasicGraphData()
		self.eKinOutPlot.setGraphPointSize(7)
		self.eKinOutPlot.setGraphColor(Color.BLUE)
		self.eKinOutPlotTh = BasicGraphData()
		self.eKinOutPlotTh.setDrawPointsOn(false)
		self.eKinOutPlotTh.setGraphColor(Color.RED)
		self.eKinOutPlotTh.setLineThick(3)	
		self.eKinOutPlot.setGraphProperty(GRAPH_LEGEND_KEY," Ekin Out "+self.alias)		
		self.eKinOutPlotTh.setGraphProperty(GRAPH_LEGEND_KEY," Ekin Out Fit "+self.alias)		
		#--- energy params
		self.eKin_in_guess = 0. # is used for CCL4 forward analysis
		self.eKin_out_guess = 0. # is used for CCL4 forward analysis		
		self.eKin_in = 0.
		self.eKin_out = 0.
		self.eKin_err = 0.
		self.bpm_eKin_out = 0.
		self.model_eKin_out = 0.
		#------- the rescale data bucket
		self.rescaleBacket = CavityRescaleBucket(self)
		#------- the longitudinal Twiss parameters bucket
		self.longTwissBucket = Long_Twiss_Bucket(self)
		
	def setBlankBeam(self,bool_val):
		self.cav.setBlankBeam(bool_val)		
		
	def setUpBPM_Wrappers(self,bpm_wrappers,scl_long_tuneup_controller):
		self.bpm_amp_phase_dict = {}
		self.bpm_wrappers = []
		self.bpm_wrappers_useInPhaseAnalysis = []
		self.bpm_wrappers_useInAmpBPMs = []
		for bpm_wrapper in bpm_wrappers:
			#we will use all bpm_wrappers even if they are before the cavity
			#if(bpm_wrapper.getPosition() > self.getPosition() and bpm_wrapper.isGood):
			if(bpm_wrapper.isGood):
				self.bpm_wrappers.append(bpm_wrapper)
				self.bpm_wrappers_useInPhaseAnalysis.append(true)
				self.bpm_wrappers_useInAmpBPMs.append(true)
				(graphDataAmp,graphDataPhase) = (BasicGraphData(),BasicGraphData())
				graphDataAmp.setGraphPointSize(5)
				graphDataPhase.setGraphPointSize(5)
				graphDataAmp.setGraphColor(Color.BLUE)
				graphDataPhase.setGraphColor(Color.BLUE)
				graphDataPhase.setGraphProperty(GRAPH_LEGEND_KEY," Phase "+bpm_wrapper.alias)
				graphDataAmp.setGraphProperty(GRAPH_LEGEND_KEY," Amp "+bpm_wrapper.alias)
				self.bpm_amp_phase_dict[bpm_wrapper] = (graphDataAmp,graphDataPhase)
		# HEBT2 BPMs should not be used in the phase and amp analysis (pending the XAL Online Model fix)
		for ind in range(len(self.bpm_wrappers)):
			bpm_wrapper = self.bpm_wrappers[ind]
			#---- HEBT2 should be excluded - usually energy is wrong for beam transport to HEBT2
			if(bpm_wrapper.pos > 280.):
				self.bpm_wrappers_useInPhaseAnalysis[ind] = false
				self.bpm_wrappers_useInAmpBPMs[ind] = false
		# longitudinal twiss bucket update
		self.longTwissBucket.update()
 
	def setBPM_0_1_Wrappers(self,bpm_wrapper0,bpm_wrapper1):
		self.phaseDiffPlot.removeAllPoints()
		self.phaseDiffPlotTh.removeAllPoints()		
		self.bpm_wrapper0 = null
		self.bpm_wrapper1 = null	
		if(self.bpm_amp_phase_dict.has_key(bpm_wrapper0)):
			self.bpm_wrapper0 = bpm_wrapper0
		if(self.bpm_amp_phase_dict.has_key(bpm_wrapper1)):
			self.bpm_wrapper1 = bpm_wrapper1
		self.phaseDiffPlot.removeAllPoints()
		legendKey = GRAPH_LEGEND_KEY
		txt = self.alias + " Phase diff "
		self.phaseDiffPlotTh.setGraphProperty(legendKey,txt + "Fit")
		if(self.bpm_wrapper0 != null and self.bpm_wrapper1 != null):
			self.phaseDiffPlot.setGraphProperty(legendKey,txt+self.bpm_wrapper0.alias+" "+self.bpm_wrapper1.alias)
		else:
			self.phaseDiffPlot.setGraphProperty(legendKey,txt)

	def clean(self):
		for bpm_wrapper in self.bpm_wrappers:
			(graphDataAmp,graphDataPhase) = self.bpm_amp_phase_dict[bpm_wrapper]
			graphDataAmp.removeAllPoints()
			graphDataPhase.removeAllPoints()
		self.livePhase = 0.
		self.isMeasured = false
		self.isAnalyzed = false	
		self.phase_scan_harm_err = 0.
		self.phase_scan_harm_amp = 0.
		self.avg_gap_phase = 0.
		self.eKin_err = 0.		
		self.model_eKin_out = 0.
		self.bpm_eKin_out = 0.
		self.real_scanPhaseShift = 0.		
		self.phase_scan_harm_funcion.setParamArr([0.,])
		self.phaseDiffPlot.removeAllPoints()
		self.phaseDiffPlotTh.removeAllPoints()
		self.eKinOutPlot.removeAllPoints()
		self.eKinOutPlotTh.removeAllPoints()
		#---clean the rescale data
		self.rescaleBacket.clean()
		#---clean longitudinal Twiss data
		self.longTwissBucket.clean()
		
	def addScanPointToPhaseDiffData(self):
		if(self.bpm_wrapper0 == null or self.bpm_wrapper1 == null): return
		(graphDataAmp0,graphDataPhase0) = self.bpm_amp_phase_dict[self.bpm_wrapper0]
		(graphDataAmp1,graphDataPhase1) = self.bpm_amp_phase_dict[self.bpm_wrapper1]
		if(graphDataPhase0.getNumbOfPoints() != graphDataPhase1.getNumbOfPoints()): return
		n_points = graphDataPhase0.getNumbOfPoints()
		ind = n_points-1
		x = graphDataPhase0.getX(ind)
		y = graphDataPhase1.getY(ind) - graphDataPhase0.getY(ind)
		self.phaseDiffPlot.addPoint(x,y)
		
	def recalculatePhaseDiffData(self):
		if(self.bpm_wrapper0 == null or self.bpm_wrapper1 == null): return
		(graphDataAmp0,graphDataPhase0) = self.bpm_amp_phase_dict[self.bpm_wrapper0]
		(graphDataAmp1,graphDataPhase1) = self.bpm_amp_phase_dict[self.bpm_wrapper1]
		if(graphDataPhase0.getNumbOfPoints() != graphDataPhase1.getNumbOfPoints()): return
		x_arr = []
		y_arr = []
		for ind in range(graphDataPhase0.getNumbOfPoints()):
			x_arr.append(graphDataPhase0.getX(ind))
			y_arr.append(graphDataPhase1.getY(ind) - graphDataPhase0.getY(ind))
		self.phaseDiffPlot.removeAllPoints()
		self.phaseDiffPlot.addPoint(x_arr,y_arr)
		
	def getAmpPhaseGraphs(self,bpm_wrapper):
		if(self.bpm_amp_phase_dict.has_key(bpm_wrapper)):
			(graphDataAmp,graphDataPhase) = self.bpm_amp_phase_dict[bpm_wrapper]
			return (graphDataAmp,graphDataPhase)
		return (null,null)
 
	def setPosition(self,accSeq):
		self.pos = accSeq.getPosition(self.cav)
		
	def getPosition(self):
		return self.pos

	def writeDataToXML(self,root_da):
		cav_wrapper_da = root_da.createChild(self.alias)
		cav_wrapper_da.setValue("cav",self.cav.getId())
		bpm0_name = "null"
		bpm1_name = "null"
		if(self.bpm_wrapper0 != null): bpm0_name = self.bpm_wrapper0.alias
		if(self.bpm_wrapper1 != null): bpm1_name = self.bpm_wrapper1.alias
		cav_wrapper_da.setValue("bpm0",bpm0_name)
		cav_wrapper_da.setValue("bpm1",bpm1_name)
		cav_wrapper_da.setValue("isGood",self.isGood )
		cav_wrapper_da.setValue("isMeasured",self.isMeasured)
		cav_wrapper_da.setValue("isAnalyzed",self.isAnalyzed)
		#--------------------------------
		cav_wrapper_params_da = cav_wrapper_da.createChild("Params")
		cav_wrapper_params_da.setValue("initDesignAmp",self.initDesignAmp)
		cav_wrapper_params_da.setValue("initDesignPhase",self.initDesignPhase)
		cav_wrapper_params_da.setValue("designAmp",self.designAmp)
		cav_wrapper_params_da.setValue("designPhase",self.designPhase)
		cav_wrapper_params_da.setValue("avg_gap_phase",self.avg_gap_phase)
		cav_wrapper_params_da.setValue("initLiveAmp",self.initLiveAmp)
		cav_wrapper_params_da.setValue("initLivePhase",self.initLivePhase)
		cav_wrapper_params_da.setValue("livePhase",self.livePhase)
		cav_wrapper_params_da.setValue("scanPhaseShift",self.scanPhaseShift)
		cav_wrapper_params_da.setValue("phase_scan_harm_err",self.phase_scan_harm_err)
		cav_wrapper_params_da.setValue("phase_scan_harm_amp",self.phase_scan_harm_amp)
		cav_wrapper_params_da.setValue("eKin_in_guess",self.eKin_in_guess)
		cav_wrapper_params_da.setValue("eKin_out_guess",self.eKin_out_guess)
		cav_wrapper_params_da.setValue("eKin_in",self.eKin_in)
		cav_wrapper_params_da.setValue("eKin_out",self.eKin_out)
		cav_wrapper_params_da.setValue("eKin_err",self.eKin_err)
		cav_wrapper_params_da.setValue("bpm_eKin_out",self.bpm_eKin_out)
		cav_wrapper_params_da.setValue("model_eKin_out",self.model_eKin_out)
		cav_wrapper_params_da.setValue("real_scanPhaseShift",self.real_scanPhaseShift)
		#--------- write the cavity rescale data
		self.rescaleBacket.writeDataToXML(cav_wrapper_da)
		#---------------------------------
		cav_wrapper_phase_harm_da = cav_wrapper_da.createChild("Phase_Harm_Func")
		cav_wrapper_phase_harm_da.setValue("params_arr",self.phase_scan_harm_funcion.getTxtParamArr())
		cav_wrapper_energy_harm_da = cav_wrapper_da.createChild("Eenergy_guess_Harm_Func")
		cav_wrapper_energy_harm_da.setValue("params_arr",self.energy_guess_harm_funcion.getTxtParamArr())
		#----------------------------------
		dumpGraphDataToDA(self.phaseDiffPlot,cav_wrapper_da,"Phase_Diff_GD","%8.3f","%8.3f")	
		dumpGraphDataToDA(self.phaseDiffPlotTh,cav_wrapper_da,"Phase_Diff_Fit_GD","%8.3f","%8.3f")	
		dumpGraphDataToDA(self.eKinOutPlot,cav_wrapper_da,"Ekin_Out_GD","%8.3f","%10.4f")	
		dumpGraphDataToDA(self.eKinOutPlotTh,cav_wrapper_da,"Ekin_Out_Fit_GD","%8.3f","%10.4f")	
		#------------------------------------
		cav_wrapper_bpm_list_da = cav_wrapper_da.createChild("bpm_arr")
		txt = ""
		for bpm_wrapper in self.bpm_wrappers:
			txt = txt +" "+ bpm_wrapper.alias
		cav_wrapper_bpm_list_da.setValue("bpm_wrappers",txt)
		cav_wrapper_bpm_list_da = cav_wrapper_da.createChild("bpm_use_in_phase_analysis_arr")
		txt = ""
		for bool_val in self.bpm_wrappers_useInPhaseAnalysis:
			val = "0"
			if(bool_val): val = "1"
			txt = txt +" "+ val
		cav_wrapper_bpm_list_da.setValue("use_arr",txt)
		cav_wrapper_bpm_list_da = cav_wrapper_da.createChild("bpm_use_in_amp_analysis_arr")
		txt = ""
		for bool_val in self.bpm_wrappers_useInAmpBPMs:
			val = "0"
			if(bool_val): val = "1"
			txt = txt +" "+ val
		cav_wrapper_bpm_list_da.setValue("use_arr",txt)
		#---------------------------------------------
		cav_wrapper_scan_data_da = cav_wrapper_da.createChild("scan_data")
		for bpm_wrapper in self.bpm_wrappers:
			if(self.bpm_amp_phase_dict.has_key(bpm_wrapper)):
				(graphDataAmp,graphDataPhase) = self.bpm_amp_phase_dict[bpm_wrapper]
				cav_wrapper_scan_data_bpm_da = cav_wrapper_scan_data_da.createChild(bpm_wrapper.alias)
				dumpGraphDataToDA(graphDataPhase,cav_wrapper_scan_data_bpm_da,"phase","%8.3f","%8.3f")
				dumpGraphDataToDA(graphDataAmp,cav_wrapper_scan_data_bpm_da,"amplitude","%8.3f","%10.3g")
								
	def readDataFromXML(self,cav_wrapper_da,scl_long_tuneup_controller):
		#print "debug ============= cav_wrapper_da=",cav_wrapper_da.name()
		self.bpm_wrapper0 = scl_long_tuneup_controller.getBPM_Wrapper(cav_wrapper_da.stringValue("bpm0"))
		self.bpm_wrapper1 = scl_long_tuneup_controller.getBPM_Wrapper(cav_wrapper_da.stringValue("bpm1"))
		self.isGood = Boolean(cav_wrapper_da.intValue("isGood")).booleanValue()
		self.isMeasured = Boolean(cav_wrapper_da.intValue("isMeasured")).booleanValue()
		self.isAnalyzed = Boolean(cav_wrapper_da.intValue("isAnalyzed")).booleanValue()
		#--------- read parameters-------------------------
		cav_wrapper_params_da = cav_wrapper_da.childAdaptor("Params")	
		self.initDesignAmp = cav_wrapper_params_da.doubleValue("initDesignAmp")
		self.initDesignPhase = cav_wrapper_params_da.doubleValue("initDesignPhase")
		self.designAmp = cav_wrapper_params_da.doubleValue("designAmp")
		self.designPhase = cav_wrapper_params_da.doubleValue("designPhase")
		self.avg_gap_phase =	cav_wrapper_params_da.doubleValue("avg_gap_phase")
		self.initLiveAmp = cav_wrapper_params_da.doubleValue("initLiveAmp")
		self.initLivePhase = cav_wrapper_params_da.doubleValue("initLivePhase")
		self.livePhase = cav_wrapper_params_da.doubleValue("livePhase")
		self.scanPhaseShift = cav_wrapper_params_da.doubleValue("scanPhaseShift")
		self.phase_scan_harm_err = cav_wrapper_params_da.doubleValue("phase_scan_harm_err")
		self.phase_scan_harm_amp = cav_wrapper_params_da.doubleValue("phase_scan_harm_amp")
		self.eKin_in_guess = cav_wrapper_params_da.doubleValue("eKin_in_guess")
		self.eKin_out_guess  = cav_wrapper_params_da.doubleValue("eKin_out_guess")
		self.eKin_in = cav_wrapper_params_da.doubleValue("eKin_in")
		self.eKin_out = cav_wrapper_params_da.doubleValue("eKin_out")
		self.eKin_err = cav_wrapper_params_da.doubleValue("eKin_err")
		self.bpm_eKin_out  = cav_wrapper_params_da.doubleValue("bpm_eKin_out")
		self.model_eKin_out  = cav_wrapper_params_da.doubleValue("model_eKin_out")
		self.real_scanPhaseShift  = cav_wrapper_params_da.doubleValue("real_scanPhaseShift")
		#--------- read the cavity rescale data
		self.rescaleBacket.	readDataFromXML(cav_wrapper_da)
		#--------- read harm. functions-------------------------
		cav_wrapper_phase_harm_da = cav_wrapper_da.childAdaptor("Phase_Harm_Func")
		self.phase_scan_harm_funcion.parsePramArr(cav_wrapper_phase_harm_da.stringValue("params_arr"))
		cav_wrapper_energy_harm_da = cav_wrapper_da.childAdaptor("Eenergy_guess_Harm_Func")
		self.energy_guess_harm_funcion.parsePramArr(cav_wrapper_energy_harm_da.stringValue("params_arr"))
		#--------- read phase Diff. graph data		
		readGraphDataFromDA(self.phaseDiffPlot,cav_wrapper_da,"Phase_Diff_GD")
		readGraphDataFromDA(self.phaseDiffPlotTh,cav_wrapper_da,"Phase_Diff_Fit_GD")
		readGraphDataFromDA(self.eKinOutPlot,cav_wrapper_da,"Ekin_Out_GD")
		readGraphDataFromDA(self.eKinOutPlotTh,cav_wrapper_da,"Ekin_Out_Fit_GD")		
		#--------- loop over bpm wrappers for this cavity
		cav_wrapper_bpm_list_da = cav_wrapper_da.childAdaptor("bpm_arr")
		bpm_wrapper_alias_arr = cav_wrapper_bpm_list_da.stringValue("bpm_wrappers").split()
		cav_wrapper_bpm_list_da = cav_wrapper_da.childAdaptor("bpm_use_in_phase_analysis_arr")
		use_in_phase_analysis_arr = cav_wrapper_bpm_list_da.stringValue("use_arr").split()
		cav_wrapper_bpm_list_da = cav_wrapper_da.childAdaptor("bpm_use_in_amp_analysis_arr")
		use_in_amp_analysis_arr = cav_wrapper_bpm_list_da.stringValue("use_arr").split()
		bpm_wrapper_arr = []
		for bpm_wrapper_alias in bpm_wrapper_alias_arr:
			bpm_wrapper = scl_long_tuneup_controller.getBPM_Wrapper(bpm_wrapper_alias)
			bpm_wrapper_arr.append(bpm_wrapper)
		bpm_wrappers = []
		use_in_phase_arr = []
		use_in_amp_arr = []
		for ind in range(len(bpm_wrapper_arr)):
			bpm_wrapper = bpm_wrapper_arr[ind]
			if(bpm_wrapper != null):
				bpm_wrappers.append(bpm_wrapper)
				use_in_phase_arr.append(use_in_phase_analysis_arr[ind])
				use_in_amp_arr.append(use_in_amp_analysis_arr[ind])
		use_in_phase_analysis_arr = use_in_phase_arr
		use_in_amp_analysis_arr = use_in_amp_arr
		self.setUpBPM_Wrappers(bpm_wrappers,scl_long_tuneup_controller)
		for ind in range(len(self.bpm_wrappers)):
			bpm_wrapper = self.bpm_wrappers[ind]
			self.bpm_wrappers_useInPhaseAnalysis[ind] = Boolean(int(use_in_phase_analysis_arr[ind])).booleanValue()
			self.bpm_wrappers_useInAmpBPMs[ind] = 		Boolean(int(use_in_amp_analysis_arr[ind])).booleanValue()
		#-------- read the phase scan data
		# we have to keep in mind that in self.bpm_wrappers we have only bpm wrappers that exist in the 
		# scl_long_tuneup_controller.bpm_wrappers and therefore exist in the self.bpm_amp_phase_dict as keys
		# Threfore they have (graphDataAmp,graphDataPhase) and we just have to fill them out.
		cav_wrapper_scan_data_da = cav_wrapper_da.childAdaptor("scan_data")
		for bpm_wrapper in self.bpm_wrappers:
			if(not self.bpm_amp_phase_dict.has_key(bpm_wrapper)): continue
			(graphDataAmp,graphDataPhase) = self.bpm_amp_phase_dict[bpm_wrapper]
			cav_wrapper_scan_data_bpm_da = cav_wrapper_scan_data_da.childAdaptor(bpm_wrapper.alias)
			if(cav_wrapper_scan_data_bpm_da != null):
				readGraphDataFromDA(graphDataPhase,cav_wrapper_scan_data_bpm_da,"phase")
				readGraphDataFromDA(graphDataAmp,cav_wrapper_scan_data_bpm_da,"amplitude")