Пример #1
0
    def combineTwoSeqs(self, seq_name, acc_seq0_da, acc_seq1_da):
        accSeq_da = XmlDataAdaptor(seq_name)
        accSeq_da.setValue("name", seq_name)
        accSeq_da.setValue("bpmFrequency", 324.0E6)
        length0 = acc_seq0_da.doubleValue("length")
        length1 = acc_seq1_da.doubleValue("length")
        accSeq_da.setValue("length", length0 + length1)
        accElems0_da = acc_seq0_da.childAdaptors("accElement")
        accElems1_da = acc_seq1_da.childAdaptors("accElement")
        for accElem_da in accElems1_da:
            pos = accElem_da.doubleValue("pos") + length0
            accElem_da.setValue("pos", pos)
        accElems_da = accElems0_da + accElems1_da

        #-----------------------------------------
        def positionComp(node1_da, node2_da):
            if (node1_da.doubleValue("pos") > node2_da.doubleValue("pos")):
                return 1
            else:
                if (node1_da.doubleValue("pos") == node2_da.doubleValue("pos")
                    ):
                    return 0
            return -1

        #===================================
        accElems_da.sort(positionComp)
        #-----------------------------------------
        cav_pos_avg = 0.
        count = 0
        for accElem_da in accElems_da:
            if (accElem_da.stringValue("type") == "RFGAP"):
                cav_pos_avg += accElem_da.doubleValue("pos")
                params_da = accElem_da.childAdaptors("parameters")[0]
                params_da.setValue("cavity", seq_name)
                count += 1
        cav_pos_avg /= count
        cavs_da = acc_seq0_da.childAdaptors("Cavities")[0]
        cav_da = cavs_da.childAdaptors("Cavity")[0]
        cav_da.setValue("pos", cav_pos_avg)
        cav_da.setValue("name", seq_name)
        for accElem_da in accElems_da:
            accSeq_da.addChildAdaptor(accElem_da)
        cavs_da = accSeq_da.createChild("Cavities")
        cavs_da.addChildAdaptor(cav_da)
        return accSeq_da
Пример #2
0
    def makeSequence(self, xal_acc_seq_da):
        accSeq_name = xal_acc_seq_da.stringValue("id")
        accSeq_da = XmlDataAdaptor(accSeq_name)
        accSeq_da.setValue("name", accSeq_name)
        accSeq_da.setValue("bpmFrequency", 324.0E6)
        accSeq_length = xal_acc_seq_da.doubleValue("len")
        accSeq_da.setValue("length", accSeq_length)
        #=========================================
        cavities_da = []
        cav_name_gap_counter_dict = {}
        #=========================================
        nodes_da = []
        for xal_node_da in xal_acc_seq_da.childAdaptors("node"):
            node_da = self.acc_node_gen.getAccNode(xal_node_da)
            if (node_da != None): nodes_da.append(node_da)
        #=========================================
        #  let's calculate all RG not hidden in the sub-sequences
        xal_count_rg = 0
        xal_total_length = 0.
        for xal_node_da in xal_acc_seq_da.childAdaptors("node"):
            if (xal_node_da.hasAttribute("len")):
                if (xal_node_da.stringValue("type") != "DCV"
                        and xal_node_da.stringValue("type") != "DCH"):
                    xal_total_length += xal_node_da.doubleValue("len")
            if (xal_node_da.stringValue("type") == "RG"):
                xal_count_rg += 1
        #======= add RG that are in additional sub-sequences
        for xal_acc_seq_in_da in xal_acc_seq_da.childAdaptors("sequence"):
            node_da = self.acc_node_gen.getNodeRG_forSubSeq(
                cavities_da, cav_name_gap_counter_dict, xal_acc_seq_in_da)
            """
			parent_name = xal_acc_seq_da.stringValue("id")
			child_name = xal_acc_seq_in_da.stringValue("id")
			child_type = xal_acc_seq_in_da.stringValue("type")
			child_len = xal_acc_seq_in_da.stringValue("len")
			child_nodes_da = xal_acc_seq_in_da.childAdaptors("node")
			child_nodes_n = len(child_nodes_da)
			st = "parent seq="+parent_name+" child seq="+child_name+" type="+child_type+" len="+child_len+"  n_childs="+str(child_nodes_n)
			print st	
			"""
            xal_count_rg += 1
            nodes_da.append(node_da)
        #===================================
        # add RG - RF Gaps and create additional cavities
        if (xal_acc_seq_da.hasAttribute("type")):
            if (xal_acc_seq_da.stringValue("type") == "DTLTank"
                    or xal_acc_seq_da.stringValue("type") == "CCL"):
                for xal_node_da in xal_acc_seq_da.childAdaptors("node"):
                    node_da = self.acc_node_gen.getNodeRG_forCavity(
                        cavities_da, cav_name_gap_counter_dict, xal_acc_seq_da,
                        xal_node_da)
                    if (node_da != None): nodes_da.append(node_da)
        #===================================
        def positionComp(node1_da, node2_da):
            if (node1_da.doubleValue("pos") > node2_da.doubleValue("pos")):
                return 1
            else:
                if (node1_da.doubleValue("pos") == node2_da.doubleValue("pos")
                    ):
                    return 0
            return -1

        #===================================
        nodes_da.sort(positionComp)
        orbit_count_rg = 0
        total_length = 0.
        for node_da in nodes_da:
            total_length += node_da.doubleValue("length")
            #print "debug node=",node_da.stringValue("name")," L=",node_da.doubleValue("length"), " total L=",total_length
            if (node_da.stringValue("type") == "RFGAP"): orbit_count_rg += 1
            accSeq_da.addChildAdaptor(node_da)
        st = "debug difference seq= %10s " % accSeq_name
        st += " xal_rg_n = %2d" % xal_count_rg
        st += " orbit_rfgap_n = %2d" % orbit_count_rg
        st += " l_diff= %+8.6f" % (xal_total_length - total_length)
        st += " L = %8.4f" % accSeq_da.doubleValue("length")
        print st
        #   set up the cavities positions as average of all rf gaps
        #   and modes for these gaps
        self.acc_node_gen.setCavitiesPositions(cavities_da, nodes_da)
        #===================================
        cavities_in_seq_da = accSeq_da.createChild("Cavities")
        for cavity_da in cavities_da:
            cavities_in_seq_da.addChildAdaptor(cavity_da)
        #===================================
        return accSeq_da
Пример #3
0
class JPARC_Linac_Lattice_XAL_Generator:
    def __init__(self, xal_acc_seqs_init_da):
        self.xal_acc_seqs_da = self.filter_sequences(xal_acc_seqs_init_da)
        self.jparc_lattice_da = XmlDataAdaptor("JPARC_LINAC")
        self.acc_seqs_da = []
        self.acc_node_gen = Acc_Node_JPARC_Generator()

    def filter_sequences(self, xal_acc_seqs_init_da):
        """
		filter out the original sequences (Data Adaptors)
		"""
        do_not_use_names = []
        do_not_use_names.append("RCS")
        do_not_use_names.append("LI_IS")
        do_not_use_names.append("LI_LEBT")
        do_not_use_names.append("LI_RFQ")

        def filter_seq_name(seq_name):
            res = False
            for bad_name in do_not_use_names:
                res = res or (seq_name.find(bad_name) >= 0)
            return res

        xal_acc_seqs_da = []
        for xal_acc_seq_da in xal_acc_seqs_init_da:
            seq_name = xal_acc_seq_da.stringValue("id")
            #print "debug seq =",seq_name
            if (not filter_seq_name(seq_name)):
                xal_acc_seqs_da.append(xal_acc_seq_da)
        return xal_acc_seqs_da

    def makeLattice_da(self):
        self.jparc_lattice_da = XmlDataAdaptor("JPARC_LINAC")
        self.acc_seqs_da = []
        for xal_acc_seq_da in self.xal_acc_seqs_da:
            accSeq_da = self.makeSequence(xal_acc_seq_da)
            self.acc_seqs_da.append(accSeq_da)
            self.jparc_lattice_da.addChildAdaptor(accSeq_da)
        #---- perform the check of the elements' positions
        self.elementsPosCechk()
        return self.jparc_lattice_da

    def makeSequence(self, xal_acc_seq_da):
        accSeq_name = xal_acc_seq_da.stringValue("id")
        accSeq_da = XmlDataAdaptor(accSeq_name)
        accSeq_da.setValue("name", accSeq_name)
        accSeq_da.setValue("bpmFrequency", 324.0E6)
        accSeq_length = xal_acc_seq_da.doubleValue("len")
        accSeq_da.setValue("length", accSeq_length)
        #=========================================
        cavities_da = []
        cav_name_gap_counter_dict = {}
        #=========================================
        nodes_da = []
        for xal_node_da in xal_acc_seq_da.childAdaptors("node"):
            node_da = self.acc_node_gen.getAccNode(xal_node_da)
            if (node_da != None): nodes_da.append(node_da)
        #=========================================
        #  let's calculate all RG not hidden in the sub-sequences
        xal_count_rg = 0
        xal_total_length = 0.
        for xal_node_da in xal_acc_seq_da.childAdaptors("node"):
            if (xal_node_da.hasAttribute("len")):
                if (xal_node_da.stringValue("type") != "DCV"
                        and xal_node_da.stringValue("type") != "DCH"):
                    xal_total_length += xal_node_da.doubleValue("len")
            if (xal_node_da.stringValue("type") == "RG"):
                xal_count_rg += 1
        #======= add RG that are in additional sub-sequences
        for xal_acc_seq_in_da in xal_acc_seq_da.childAdaptors("sequence"):
            node_da = self.acc_node_gen.getNodeRG_forSubSeq(
                cavities_da, cav_name_gap_counter_dict, xal_acc_seq_in_da)
            """
			parent_name = xal_acc_seq_da.stringValue("id")
			child_name = xal_acc_seq_in_da.stringValue("id")
			child_type = xal_acc_seq_in_da.stringValue("type")
			child_len = xal_acc_seq_in_da.stringValue("len")
			child_nodes_da = xal_acc_seq_in_da.childAdaptors("node")
			child_nodes_n = len(child_nodes_da)
			st = "parent seq="+parent_name+" child seq="+child_name+" type="+child_type+" len="+child_len+"  n_childs="+str(child_nodes_n)
			print st	
			"""
            xal_count_rg += 1
            nodes_da.append(node_da)
        #===================================
        # add RG - RF Gaps and create additional cavities
        if (xal_acc_seq_da.hasAttribute("type")):
            if (xal_acc_seq_da.stringValue("type") == "DTLTank"
                    or xal_acc_seq_da.stringValue("type") == "CCL"):
                for xal_node_da in xal_acc_seq_da.childAdaptors("node"):
                    node_da = self.acc_node_gen.getNodeRG_forCavity(
                        cavities_da, cav_name_gap_counter_dict, xal_acc_seq_da,
                        xal_node_da)
                    if (node_da != None): nodes_da.append(node_da)
        #===================================
        def positionComp(node1_da, node2_da):
            if (node1_da.doubleValue("pos") > node2_da.doubleValue("pos")):
                return 1
            else:
                if (node1_da.doubleValue("pos") == node2_da.doubleValue("pos")
                    ):
                    return 0
            return -1

        #===================================
        nodes_da.sort(positionComp)
        orbit_count_rg = 0
        total_length = 0.
        for node_da in nodes_da:
            total_length += node_da.doubleValue("length")
            #print "debug node=",node_da.stringValue("name")," L=",node_da.doubleValue("length"), " total L=",total_length
            if (node_da.stringValue("type") == "RFGAP"): orbit_count_rg += 1
            accSeq_da.addChildAdaptor(node_da)
        st = "debug difference seq= %10s " % accSeq_name
        st += " xal_rg_n = %2d" % xal_count_rg
        st += " orbit_rfgap_n = %2d" % orbit_count_rg
        st += " l_diff= %+8.6f" % (xal_total_length - total_length)
        st += " L = %8.4f" % accSeq_da.doubleValue("length")
        print st
        #   set up the cavities positions as average of all rf gaps
        #   and modes for these gaps
        self.acc_node_gen.setCavitiesPositions(cavities_da, nodes_da)
        #===================================
        cavities_in_seq_da = accSeq_da.createChild("Cavities")
        for cavity_da in cavities_da:
            cavities_in_seq_da.addChildAdaptor(cavity_da)
        #===================================
        return accSeq_da

    def elementsPosCechk(self):
        """
		It will check that the positions of all accElements are inside the sequence.
		It also will move some elements to the right sequence
		"""
        eps = 0.0000001
        #---------move LI_S16B:FCT00 and LI_S16B:SCT00 to LI_MEBT2
        seq0 = None
        seq1 = None
        for acc_seq_da in self.acc_seqs_da:
            if (acc_seq_da.stringValue("name") == "LI_S16B"):
                seq0 = acc_seq_da
            if (acc_seq_da.stringValue("name") == "LI_MEBT2"):
                seq1 = acc_seq_da
        bad_nodes_da = []
        for node_da in seq0.childAdaptors("accElement"):
            if (node_da.stringValue("name") == "LI_S16B:FCT00"):
                bad_nodes_da.append(node_da)
            if (node_da.stringValue("name") == "LI_S16B:SCT00"):
                bad_nodes_da.append(node_da)
        length = seq0.doubleValue("length")
        nodes_da = seq0.childAdaptors()
        for node_da in bad_nodes_da:
            nodes_da.remove(node_da)
            pos0 = node_da.doubleValue("pos")
            pos1 = pos0 - length
            node_da.setValue("pos", pos1)
            seq1.addChildAdaptor(node_da)
        nodes_da = seq1.childAdaptors()
        #---------------------------------------------------------
        #---- remove node=LI_L3BD100:BLMP66 from LI_L3BD100
        for acc_seq_da in self.acc_seqs_da:
            if (acc_seq_da.stringValue("name") == "LI_L3BD100"):
                nodes_da = acc_seq_da.childAdaptors()
                bad_node_da = None
                for node_da in nodes_da:
                    if (node_da.hasAttribute("name")
                            and node_da.stringValue("name")
                            == "LI_L3BD100:BLMP66"):
                        bad_node_da = node_da
                nodes_da.remove(bad_node_da)
        #----------------------------------------------------------
        #---- set pos to 1.9493572 for LI_ACS19B:FCT00 and LI_ACS19B:SCT00
        for acc_seq_da in self.acc_seqs_da:
            if (acc_seq_da.stringValue("name") == "LI_ACS19B"):
                nodes_da = acc_seq_da.childAdaptors("accElement")
                for node_da in nodes_da:
                    if (node_da.stringValue("name") == "LI_ACS19B:FCT00" or
                            node_da.stringValue("name") == "LI_ACS19B:SCT00"):
                        node_da.setValue("pos", 1.9493572)
        #---------------------------------------------------------
        for acc_seq_da in self.acc_seqs_da:
            length = acc_seq_da.doubleValue("length")
            for node_da in acc_seq_da.childAdaptors("accElement"):
                pos = node_da.doubleValue("pos")
                if (pos > length + eps):
                    st = "debug bad node position! Seq.=" + acc_seq_da.stringValue(
                        "name")
                    st += " L=" + str(length)
                    st += " node=" + node_da.stringValue("name")
                    st += " pos=" + str(pos)
                    print st
Пример #4
0
 def getTransformedLattice(self):
     jparc_lattice_da = XmlDataAdaptor("JPARC_LINAC")
     for seq_name in self.acc_seq_names:
         accSeq_da = self.getAccSeq(seq_name)
         jparc_lattice_da.addChildAdaptor(accSeq_da)
     return jparc_lattice_da
Пример #5
0
]
for xml_file_name in xml_file_names:
    print "file =", xml_file_name
    acc_da = XmlDataAdaptor.adaptorForFile(xml_file_name)

    for name in names:
        accSeq_da = acc_da.childAdaptors(name)[0]
        nodes = accSeq_da.childAdaptors()
        #==================
        start_marker = XmlDataAdaptor("accElement")
        start_marker.setValue("name", name + "_START")
        start_marker.setValue("length", "0.0")
        start_marker.setValue("pos", "0.0")
        start_marker.setValue("type", "MARKER")
        param_da = XmlDataAdaptor("parameters")
        start_marker.addChildAdaptor(param_da)
        #===================
        end_marker = XmlDataAdaptor("accElement")
        end_marker.setValue("name", name + "_END")
        end_marker.setValue("length", "0.0")
        end_marker.setValue("pos", accSeq_da.stringValue("length"))
        end_marker.setValue("type", "MARKER")
        param_da = XmlDataAdaptor("parameters")
        end_marker.addChildAdaptor(param_da)
        #===================
        ind_end = getFirstInd(nodes, "Cavities")
        if (ind_end >= 0):
            accSeq_da.addChildAdaptor(end_marker, ind_end)
        else:
            accSeq_da.addChildAdaptor(end_marker)
        accSeq_da.addChildAdaptor(start_marker, 0)