def getLinacAccLattice(self,names,xml_file_name):
		"""
		Returns the linac accelerator lattice for specified sequence names and for a specified XML file.
		"""	
		if(len(names) < 1):
			msg = "The SNS_LinacLatticeFactory method getLinacAccLattice(names,xml_file_name): you have to specify the names array!"
			msg = msg + os.linesep
			msg = msg + "Stop."
			msg = msg + os.linesep
			orbitFinalize(msg)
		#----- let's parse the XML file
		acc_da = XmlDataAdaptor.adaptorForFile(xml_file_name)
		return self.getLinacAccLatticeFromDA(names,acc_da)
Example #2
0
	def getLinacAccLattice(self,names,xml_file_name):
		"""
		Returns the linac accelerator lattice for specified sequence names and for a specified XML file.
		"""	
		if(len(names) < 1):
			msg = "The SNS_LinacLatticeFactory method getLinacAccLattice(names,xml_file_name): you have to specify the names array!"
			msg = msg + os.linesep
			msg = msg + "Stop."
			msg = msg + os.linesep
			orbitFinalize(msg)
		#----- let's parse the XML file
		acc_da = XmlDataAdaptor.adaptorForFile(xml_file_name)
		return self.getLinacAccLatticeFromDA(names,acc_da)
Example #3
0
"""

import sys
import time

# import the XmlDataAdaptor XML parser
from orbit.utils.xml import XmlDataAdaptor

from jparc_lattice_factory_lib import JPARC_Linac_Lattice_XAL_Generator
from jparc_lattice_factory_lib import JPARC_Linac_Lattice_Transformation
from jparc_lattice_factory_lib import LI_MEBT2_RF_Gaps_Mode_Fix

print "==============START======================="
#---- the XML file name with the structure
xml_file_name = "./jparc_xal_xml/jparc-LI_RCS-40mA_-2483_20160603.xdxf"
acc_da = XmlDataAdaptor.adaptorForFile(xml_file_name)
acc_seqs_init_da = acc_da.childAdaptors("sequence")
print "Acc seq n=", len(acc_seqs_init_da)

jparc_lattice_gen = JPARC_Linac_Lattice_XAL_Generator(acc_seqs_init_da)
lattice_da = jparc_lattice_gen.makeLattice_da()

#---- Transformation of the lattice: all RCS and ACS cavities
#---- with A and B indeces will be combined
transformation = JPARC_Linac_Lattice_Transformation(lattice_da)
lattice_da = transformation.getTransformedLattice()

#---- Fix the mode parameters of RF gaps in the LI_MEBT2 sequence
LI_MEBT2_RF_Gaps_Mode_Fix(lattice_da)

lattice_da.writeToFile("../jparc_linac_lattice_xml/jparc_linac.xml")
Example #4
0
    """
	returns the child node of DA with particular name
	"""
    for da_ind in range(len(lattice_da.childAdaptors()) - 1):
        node_da = lattice_da.childAdaptors()[da_ind]
        name = node_da.stringValue("name")
        if (name == node_name):
            return node_da
    return None


#==============================================================
#                START of SCRIPT
#==============================================================
xml_file_name = "../sns_linac_xml/sns_linac.xml"
sns_lattice_da = XmlDataAdaptor.adaptorForFile(xml_file_name)

dtl_da = getChildDA(sns_lattice_da, "DTL3")

#---- make vacuum window node and add it to the end of the DTL
window_length = 0.005
pos = dtl_da.doubleValue("length") - window_length - 0.00001
vacwin_node = make_vacwin_da("DTL:VACWIN", window_length, pos)
dtl_da.addChildAdaptor(vacwin_node)

#---- print a structure of the new data adaptor DTL3
#print dtl_da.makeXmlText()

#---- create the factory instance
sns_linac_factory = SNS_LinacLatticeFactory()
sns_linac_factory.setMaxDriftLength(0.1)
import sys
import time

# import the XmlDataAdaptor XML parser
from orbit.utils.xml import XmlDataAdaptor


print "==============START======================="

#---- define the sequences in the linac accelerator lattice
names = ["MEBT","DTL1","DTL2","DTL3","DTL4","DTL5","DTL6","CCL1","CCL2","CCL3","CCL4","SCLMed","SCLHigh","HEBT1","HEBT2"]

#---- the XML file name with the structure
xml_file_name = "../sns_linac_xml/sns_linac.xml"
acc_da = XmlDataAdaptor.adaptorForFile(xml_file_name)

#-----------MEBT

quad_apert_dict = {}
quad_apert_dict["MEBT_Mag:QH01"]="0.032"
quad_apert_dict["MEBT_Mag:QV02"]="0.032"
quad_apert_dict["MEBT_Mag:QH03"]="0.032"
quad_apert_dict["MEBT_Mag:QV04"]="0.032"
quad_apert_dict["MEBT_Mag:QH05"]="0.042"
quad_apert_dict["MEBT_Mag:QV06"]="0.042"
quad_apert_dict["MEBT_Mag:QH07"]="0.042"
quad_apert_dict["MEBT_Mag:QH08"]="0.042"
quad_apert_dict["MEBT_Mag:QV09"]="0.042"
quad_apert_dict["MEBT_Mag:QH10"]="0.042"
quad_apert_dict["MEBT_Mag:QV11"]="0.032"
xml_data_adaptor = XmlDataAdaptor("Test")
xml_data_adaptor.setValue("txt","results")
xml_data_adaptor.setValue("arr_int",[0,1,2,3])
xml_data_adaptor.setValue("arr_double",[-1.,-2.,-3.,-4.])
chld1 = xml_data_adaptor.createChild("child1")
chld2 = chld1.createChild("child2")
chld2.setValue("arr_double1",[-1.,-2.,-3.,-4.])
chld2.setValue("val",0.123456789e-17)
xml_text = xml_data_adaptor.makeXmlText()
print xml_text
xml_data_adaptor.writeToFile("test.xml")
print "==================writing to a file is done============================"
print "======================================================================="

xml_data_adaptor_new = XmlDataAdaptor.adaptorForFile("test.xml")
xml_text = xml_data_adaptor_new.makeXmlText()
print "====================After reading the file============================="
print xml_text
print "======================================================================="
child1 = xml_data_adaptor_new.childAdaptors("child1")[0]
child2 = child1.childAdaptors("child2")[0]
print " child2 int arr =",child2.intArrayValue("arr_double1")
print " child2 double arr =",child2.doubleArrayValue("arr_double1")
print " child2 double val =",child2.doubleArrayValue("val")
print " child2 double val =",child2.doubleValue("val")
print "======================================================================="
#-----Deep Copy of XmlDataAdaptor
xml_data_adaptor_copy = xml_data_adaptor_new.getDeepCopy()
child1 = xml_data_adaptor_copy.childAdaptors("child1")[0]
child2 = child1.childAdaptors("child2")[0]
#---- define the sequences in the linac accelerator lattice
names = [
    "MEBT", "DTL1", "DTL2", "DTL3", "DTL4", "DTL5", "DTL6", "CCL1", "CCL2",
    "CCL3", "CCL4", "SCLMed", "SCLHigh", "HEBT1", "HEBT2"
]
root_name = "../sns_linac_xml/"

#---- the XML file name with the linac structures
xml_file_names = []
xml_file_names.append("sns_linac.xml")
xml_file_names.append("sns_sts_linac.xml")

for xml_file_name in xml_file_names:
    print "========start file=", xml_file_name
    acc_da = XmlDataAdaptor.adaptorForFile(root_name + xml_file_name)
    accSeqs_da = acc_da.childAdaptors()
    for accSeq_da in accSeqs_da:
        print "     start seq.=", accSeq_da.getName()
        for node_da in accSeq_da.childAdaptors():
            if (node_da.hasAttribute("type")
                    and ((node_da.stringValue("type") == "QUAD") or
                         (node_da.stringValue("type") == "BEND"))):
                length = node_da.doubleValue("length")
                params_da = node_da.childAdaptors("parameters")[0]
                if (params_da.hasAttribute("effLength")):
                    effLength = params_da.doubleValue("effLength")
                    node_da.setValue("length", effLength)
                params_da.removeAttribute("effLength")
                if (xml_file_name.find("_aprt") >= 0):
                    setAprtParamsToBEND(node_da)
print "Start."

xml_data_adaptor = XmlDataAdaptor("Test")
xml_data_adaptor.setValue("txt","results")
xml_data_adaptor.setValue("arr_int",[0,1,2,3])
xml_data_adaptor.setValue("arr_double",[-1.,-2.,-3.,-4.])
chld1 = xml_data_adaptor.createChild("child1")
chld2 = chld1.createChild("child2")
chld2.setValue("arr_double1",[-1.,-2.,-3.,-4.])
chld2.setValue("val",0.123456789e-17)
xml_text = xml_data_adaptor.makeXmlText()
print xml_text
xml_data_adaptor.writeToFile("test.xml")
print "==================writing to a file is done============================"
print "======================================================================="

xml_data_adaptor_new = XmlDataAdaptor.adaptorForFile("test.xml")
xml_text = xml_data_adaptor_new.makeXmlText()
print "====================After reading the file============================="
print xml_text
print "======================================================================="
child1 = xml_data_adaptor_new.childAdaptors("child1")[0]
child2 = child1.childAdaptors("child2")[0]
print " child2 int arr =",child2.intArrayValue("arr_double1")
print " child2 double arr =",child2.doubleArrayValue("arr_double1")
print " child2 double val =",child2.doubleArrayValue("val")
print " child2 double val =",child2.doubleValue("val")

print "Stop."