Exemple #1
0
    def testTfsFileWriter(self):
        file_from_tfs_writer = "test.out"
        tfs_file_writer = Utilities.tfs_file_writer.TfsFileWriter.open(
            file_from_tfs_writer)
        tfs_file_writer.add_string_descriptor("NAME", "TWISS")
        tfs_file_writer.add_float_descriptor("MASS", 0.938272013)
        tfs_file_writer.add_comment("I am a comment")
        tfs_file_writer.add_column_names("NAME S BETX ALFX BETY ALFY".split())
        tfs_file_writer.add_column_datatypes("%s %le %le %le %le %le".split())
        tfs_file_writer.add_table_row(
            "BTVSS.6L2.B1  1.125  131.5873094  -1.899115044  67.61780908 1.699566347"
            .split())
        tfs_file_writer.write_to_file()
        self.__created_files.append(
            tfs_file_writer.get_absolute_file_name_path())

        file_assumed = "test2.out"
        f_out = open(file_assumed, "w")
        f_out.write('@ NAME %s "TWISS"\n')
        f_out.write('@ MASS %le 0.938272013\n')
        f_out.write('# I am a comment\n')
        f_out.write('* NAME S BETX ALFX BETY ALFY\n')
        f_out.write('$ %s %le %le %le %le %le\n')
        f_out.write(
            "BTVSS.6L2.B1 1.125 131.5873094 -1.899115044 67.61780908 1.699566347"
        )
        f_out.close()
        self.__created_files.append(file_assumed)

        self.assertTrue(
            Utilities.ndiff.compare_files_and_ignore_whitespace(
                tfs_file_writer.get_absolute_file_name_path(), file_assumed),
            "Created tfs file is not equal to assumed file")
Exemple #2
0
    def testTfsFileWriter(self):
        file_from_tfs_writer = "test.out"
        tfs_file_writer = Utilities.tfs_file_writer.TfsFileWriter.open(file_from_tfs_writer)
        tfs_file_writer.add_string_descriptor("NAME", "TWISS")
        tfs_file_writer.add_float_descriptor("MASS", 0.938272013)
        tfs_file_writer.add_comment("I am a comment")
        tfs_file_writer.add_column_names("NAME S BETX ALFX BETY ALFY".split())
        tfs_file_writer.add_column_datatypes("%s %le %le %le %le %le".split())
        tfs_file_writer.add_table_row("BTVSS.6L2.B1  1.125  131.5873094  -1.899115044  67.61780908 1.699566347".split())
        tfs_file_writer.write_to_file()
        self.__created_files.append(tfs_file_writer.get_absolute_file_name_path())

        file_assumed = "test2.out"
        f_out = open(file_assumed, "w")
        f_out.write('@ NAME %s "TWISS"\n')
        f_out.write('@ MASS %le 0.938272013\n')
        f_out.write('# I am a comment\n')
        f_out.write('* NAME S BETX ALFX BETY ALFY\n')
        f_out.write('$ %s %le %le %le %le %le\n')
        f_out.write("BTVSS.6L2.B1 1.125 131.5873094 -1.899115044 67.61780908 1.699566347")
        f_out.close()
        self.__created_files.append(file_assumed)

        self.assertTrue(
                    Utilities.ndiff.compare_files_and_ignore_whitespace(tfs_file_writer.get_absolute_file_name_path(),
                                                                            file_assumed),
                        "Created tfs file is not equal to assumed file"
                        )
def _handle_data_for_lhc():
    #.knob should always exist to be sent to LSA!
    src = os.path.join(
        os.path.join(_InputData.output_path, "changeparameters_couple.tfs"))
    dst = os.path.join(
        os.path.join(_InputData.output_path, "changeparameters_couple.knob"))
    Utilities.iotools.copy_item(src, dst)

    ##### for bumps
    if "bumps" in _InputData.variables_list:
        print "passing trough bumps loop"
        v = metaclass.twiss(
            os.path.join(_InputData.output_path,
                         "changeparameters_couple.tfs"))  # @UnusedVariable
        # v will be used in Bumps.py. Don't do such things again!(vimaier)
        Utilities.iotools.delete_item(
            os.path.join(_InputData.output_path,
                         "changeparameters_couple.tfs"))
        corrs = None  # Will be assigned in exec Bumps.py (vimaier)
        execfile(os.path.join(_InputData.path_to_optics_files_dir, "Bumps.py"))
        execfile(
            os.path.join(_InputData.path_to_optics_files_dir,
                         "mydictionary.py"))
        tfs_file_writer = Utilities.tfs_file_writer.TfsFileWriter(
            "changeparameters_couple.tfs", _InputData.output_path)
        tfs_file_writer.add_column_names("NAME DELTA".split())
        tfs_file_writer.add_column_datatypes("%s %le".split())
        for vcorr in corrs:
            tfs_file_writer.add_table_row([vcorr, corrs[vcorr]])
        tfs_file_writer.write_to_file()
    #####

    v = metaclass.twiss(
        os.path.join(_InputData.output_path, "changeparameters_couple.tfs"))
    mad_script = open(
        os.path.join(_InputData.output_path, "changeparameters_couple.madx"),
        "w")
    names = getattr(v, "NAME", [])
    delta = getattr(v, "DELTA", [])

    for i in range(len(names)):
        if "bumps" in _InputData.variables_list:
            if cmp(delta[i], 0) == 1:
                mad_script.write(names[i] + "->KICK:=" + str(-delta[i]) +
                                 ";\n")
            else:
                mad_script.write(names[i] + "->KICK:=" + str(-delta[i]) +
                                 ";\n")
        else:
            if cmp(delta[i], 0) == 1:
                mad_script.write(names[i] + " = " + names[i] + " " +
                                 str(-delta[i]) + ";\n")
            else:
                mad_script.write(names[i] + " = " + names[i] + " + " +
                                 str(-delta[i]) + ";\n")

    mad_script.write("return;")
    mad_script.close()
Exemple #4
0
def _handle_data_for_lhc():
    #.knob should always exist to be sent to LSA!
    src = os.path.join(os.path.join(_InputData.output_path, "changeparameters_couple.tfs"))
    dst = os.path.join(os.path.join(_InputData.output_path, "changeparameters_couple.knob"))
    Utilities.iotools.copy_item(src, dst)

    ##### for bumps
    if "bumps" in _InputData.variables_list:
        print "passing trough bumps loop"
        v = metaclass.twiss(os.path.join(_InputData.output_path, "changeparameters_couple.tfs"))  # @UnusedVariable
        # v will be used in Bumps.py. Don't do such things again!(vimaier)
        Utilities.iotools.delete_item(os.path.join(_InputData.output_path, "changeparameters_couple.tfs"))
        corrs = None # Will be assigned in exec Bumps.py (vimaier)
        execfile(os.path.join(_InputData.path_to_optics_files_dir, "Bumps.py"))
        execfile(os.path.join(_InputData.path_to_optics_files_dir, "mydictionary.py"))
        tfs_file_writer = Utilities.tfs_file_writer.TfsFileWriter("changeparameters_couple.tfs", _InputData.output_path)
        tfs_file_writer.add_column_names("NAME DELTA".split())
        tfs_file_writer.add_column_datatypes("%s %le".split())
        for vcorr in corrs:
            tfs_file_writer.add_table_row([vcorr, corrs[vcorr]])
        tfs_file_writer.write_to_file()
    #####

    v = metaclass.twiss(os.path.join(_InputData.output_path, "changeparameters_couple.tfs"))
    mad_script = open(os.path.join(_InputData.output_path, "changeparameters_couple.madx"), "w")
    names = getattr(v, "NAME", [])
    delta = getattr(v, "DELTA", [])

    for i in range(len(names)):
        if "bumps" in _InputData.variables_list:
            if cmp(delta[i], 0) == 1:
                mad_script.write(names[i] + "->KICK:=" + str(delta[i]) + ";\n")
            else:
                mad_script.write(names[i] + "->KICK:=" + str(delta[i]) + ";\n")
        else:
            if cmp(delta[i], 0) == 1:
                mad_script.write(names[i] + " = " + names[i] + " + " + str(delta[i]) + ";\n")
            else:
                mad_script.write(names[i] + " = " + names[i] + " " + str(delta[i]) + ";\n")

    mad_script.write("return;")
    mad_script.close()