예제 #1
0
 def _find_optics_and_errors_in_job(self, madx_job, output_dir):
     new_lines = ""
     modifiers = ""
     in_modifiers = False
     with open(madx_job, "r") as madx_job_data:
         for line in madx_job_data:
             if "%OPTICS_END" in line and in_modifiers:
                 in_modifiers = False
             if in_modifiers:
                 modifiers += line
             if "%OPTICS_START" in line and not in_modifiers:
                 in_modifiers = True
             if not "%OPTICS_START" in line and not "%OPTICS_END" in line:
                 if "%ERROR" in line:
                     clean_line = line.replace(
                         "%ERROR",
                         "")  # Example: %ERROR kq8.l1b1 = kq8.l1b1 + 2e-5;
                     var_value = clean_line.replace(";", "").replace(
                         "\n", "").split("=")[1].split("+")
                     var_value = var_value if len(
                         var_value) == 2 else var_value[0].split("-")
                     self._errors[output_dir][var_value[0].strip()] = float(
                         var_value[1])
                     new_lines += clean_line
                 else:
                     new_lines += line
     iotools.write_string_into_new_file(madx_job, new_lines)
     return modifiers
예제 #2
0
def _generate_driving_terms(sdds_file_path, output_path, start_turn, end_turn):
    driving_terms_path = os.path.join(output_path, DRIVING_TERMS_FILENAME)
    driving_terms_text = DRIVING_TERMS_TEMPL % {"SDDS_PATH": sdds_file_path,
                                                "START_TURN": start_turn,
                                                "END_TURN": end_turn}
    print "Writing DrivingTerms file into: ", driving_terms_path
    iotools.write_string_into_new_file(driving_terms_path, driving_terms_text)
    return driving_terms_path
예제 #3
0
 def _prepare_tracking_scripts(self):
     for template, output_job, output_dir in zip(
         self._madx_template_paths, self._madx_file_paths, self._output_paths
     ):
         dict_to_replace = {"%DATA_PATH": self._data_path, "%OUTPUT_PATH": output_dir}
         self._replace_keywords_in_file(template, output_job, dict_to_replace)
         self._errors[output_dir] = {}
         modifiers = self._find_optics_and_errors_in_job(output_job, output_dir)
         iotools.write_string_into_new_file(os.path.join(output_dir, "modifiers.madx"), modifiers)
예제 #4
0
def _generate_driving_terms(sdds_file_path, output_path, start_turn, end_turn):
    driving_terms_path = os.path.join(output_path, DRIVING_TERMS_FILENAME)
    driving_terms_text = DRIVING_TERMS_TEMPL % {
        "SDDS_PATH": sdds_file_path,
        "START_TURN": start_turn,
        "END_TURN": end_turn
    }
    print("Writing DrivingTerms file into: ", driving_terms_path)
    iotools.write_string_into_new_file(driving_terms_path, driving_terms_text)
    return driving_terms_path
예제 #5
0
def _generate_drive_inp(output_path, tune_x, tune_y, nat_tune_x, nat_tune_y):
    drive_inp_path = os.path.join(output_path, DRIVE_INP_FILENAME)
    if nat_tune_x is not None and nat_tune_y is not None:
        nat_tune_text = NAT_TUNE_TMPL % {"NAT_TUNE_X": nat_tune_x,
                                         "NAT_TUNE_Y": nat_tune_y}
    else:
        nat_tune_text = ""
    drive_inp_text = DRIVE_INP_TEMPL % {"TUNE_X": tune_x,
                                        "TUNE_Y": tune_y,
                                        "NAT_TUNE_TEXT": nat_tune_text}
    print "Writing Drive.inp file into: ", drive_inp_path
    iotools.write_string_into_new_file(drive_inp_path, drive_inp_text)
    return drive_inp_path
예제 #6
0
 def _prepare_tracking_scripts(self):
     for template, output_job, output_dir in zip(self._madx_template_paths,
                                                 self._madx_file_paths,
                                                 self._output_paths):
         dict_to_replace = {
             "%DATA_PATH": self._data_path,
             "%OUTPUT_PATH": output_dir
         }
         self._replace_keywords_in_file(template, output_job,
                                        dict_to_replace)
         self._errors[output_dir] = {}
         modifiers = self._find_optics_and_errors_in_job(
             output_job, output_dir)
         iotools.write_string_into_new_file(
             os.path.join(output_dir, "modifiers.madx"), modifiers)
예제 #7
0
def _generate_drive_inp(output_path, tune_x, tune_y, nat_tune_x, nat_tune_y,
                        tune_window):
    drive_inp_path = os.path.join(output_path, DRIVE_INP_FILENAME)
    if nat_tune_x is not None and nat_tune_y is not None:
        nat_tune_text = NAT_TUNE_TMPL % {
            "NAT_TUNE_X": str(nat_tune_x),
            "NAT_TUNE_Y": str(nat_tune_y)
        }
    else:
        nat_tune_text = ""
    drive_inp_text = DRIVE_INP_TEMPL % {
        "TUNE_X": str(tune_x),
        "TUNE_Y": str(tune_y),
        "ISTUN": str(tune_window),
        "NAT_TUNE_TEXT": nat_tune_text
    }
    print("Writing Drive.inp file into: ", drive_inp_path)
    iotools.write_string_into_new_file(drive_inp_path, drive_inp_text)
    return drive_inp_path
예제 #8
0
 def _find_optics_and_errors_in_job(self, madx_job, output_dir):
     new_lines = ""
     modifiers = ""
     in_modifiers = False
     with open(madx_job, "r") as madx_job_data:
         for line in madx_job_data:
             if "%OPTICS_END" in line and in_modifiers:
                 in_modifiers = False
             if in_modifiers:
                 modifiers += line
             if "%OPTICS_START" in line and not in_modifiers:
                 in_modifiers = True
             if not "%OPTICS_START" in line and not "%OPTICS_END" in line:
                 if "%ERROR" in line:
                     clean_line = line.replace("%ERROR", "")  # Example: %ERROR kq8.l1b1 = kq8.l1b1 + 2e-5;
                     var_value = clean_line.replace(";", "").replace("\n", "").split("=")[1].split("+")
                     var_value = var_value if len(var_value) == 2 else var_value[0].split("-")
                     self._errors[output_dir][var_value[0].strip()] = float(var_value[1])
                     new_lines += clean_line
                 else:
                     new_lines += line
     iotools.write_string_into_new_file(madx_job, new_lines)
     return modifiers