Exemplo n.º 1
0
def resolve_and_run_file(input_file,
                         output_file=None,
                         log_file=None,
                         madx_path=MADX_PATH):
    _check_files(input_file, output_file, log_file)
    main_file_content = iotools.read_all_lines_in_textfile(input_file)
    full_madx_script = resolve(main_file_content, output_file, log_file)
    return run(full_madx_script, log_file, madx_path)
Exemplo n.º 2
0
def _resolve_required_macros(file_content):
    """
    Recursively searches for "!@require lib" annotations in the input script,
    adding the required macros library calls to the script header.
    """
    call_commands = ""
    for line in file_content.split("\n"):
        match = re.search("^!@require\s+([^\s]+).*$", line)
        if not match is None:
            required_macros = _add_macro_lib_ending(match.group(1))
            required_macros_file = os.path.abspath(os.path.join(CURRENT_PATH, LIB, required_macros))
            if not os.path.exists(required_macros_file):
                print >> sys.stderr, "Trying to import non existing macros library \"" + required_macros + "\". Aborting."
                sys.exit(-1)
            call_commands += _resolve_required_macros(iotools.read_all_lines_in_textfile(required_macros_file))
            call_commands += "call, file = \"" + required_macros_file + "\";\n"
    return call_commands
Exemplo n.º 3
0
def _resolve_required_macros(file_content):
    """
    Recursively searches for "!@require lib" annotations in the input script,
    adding the required macros library calls to the script header.
    """
    call_commands = ""
    for line in file_content.split("\n"):
        match = re.search("^!@require\s+([^\s]+).*$", line)
        if not match is None:
            required_macros = _add_macro_lib_ending(match.group(1))
            required_macros_file = os.path.abspath(
                os.path.join(CURRENT_PATH, LIB, required_macros))
            if not os.path.exists(required_macros_file):
                print >> sys.stderr, "Trying to import non existing macros library \"" + required_macros + "\". Aborting."
                sys.exit(-1)
            call_commands += _resolve_required_macros(
                iotools.read_all_lines_in_textfile(required_macros_file))
            call_commands += "call, file = \"" + required_macros_file + "\";\n"
    return call_commands
Exemplo n.º 4
0
def _run_single_esrf_madx_simulation(seed_path_tuple):
    seed = seed_path_tuple[0]
    run_data_path = seed_path_tuple[1]
    dict_for_replacing = dict(
            ESRF_MODEL=os.path.join(CURRENT_PATH, "..", "..", "MODEL", "ESRF"),
            SEED=str(seed),
            SEED1=str(1 + seed * 5),
            SEED2=str(2 + seed * 5),
            SEED3=str(3 + seed * 5),
            SEED4=str(4 + seed * 5),
            SEED5=str(5 + seed * 5),
            RUN_DATA_PATH=run_data_path)
    raw_madx_mask = iotools.read_all_lines_in_textfile(os.path.join(CURRENT_PATH, 'job.systematic.ESRF.mask'))
    madx_job = raw_madx_mask % dict_for_replacing

    start_time = time.time()
    madxrunner.runForInputString(madx_job, stdout=open(os.devnull, "w"))
    end_time = time.time()
    return end_time - start_time
Exemplo n.º 5
0
def _run_single_lhc_madx_simulation(seed_path_tuple):
    seed = seed_path_tuple[0]
    run_data_path = seed_path_tuple[1]
    model_dir_path = seed_path_tuple[2]
    errors_path = seed_path_tuple[3]
    accelerator = seed_path_tuple[4]
    energy = seed_path_tuple[5]
    tunex = seed_path_tuple[6]
    tuney = seed_path_tuple[7]
    uncertainties = seed_path_tuple[8]
    base_sequence = LHC_RUNI_BASE_SEQ
    if accelerator.upper().endswith("RUNII_2016"):
        base_sequence = LHC_RUNII_2016_BASE_SEQ
    elif accelerator.upper().endswith("RUNII"):
        base_sequence = LHC_RUNII_BASE_SEQ
    dict_for_replacing = dict(
            BB_PATH=BB_PATH,
            BASE_SEQ=base_sequence,
            ERR_NUM=str((seed % 60) + 1).zfill(4),
            UNCERTAINTIES=uncertainties,
            SEED=str(seed),
            RUN_DATA_PATH=run_data_path,
            ERRORS_PATH=errors_path,
            ACCEL=accelerator.upper().replace("RUNII", "").replace("_2016", ""),
            BEAM=accelerator.upper().replace("LHC", "").replace("RUNII", "").replace("_2016", ""),

            PATH=model_dir_path,
            QMX=tunex,
            QMY=tuney,
            ENERGY=energy
            )
    raw_madx_mask = iotools.read_all_lines_in_textfile(os.path.join(CURRENT_PATH, 'job.systematic.LHC.mask'))
    madx_job = raw_madx_mask % dict_for_replacing

    start_time = time.time()
    madxrunner.runForInputString(madx_job, stdout=open(os.devnull, "w"))
    end_time = time.time()
    return end_time - start_time
Exemplo n.º 6
0
 def __parse_template(self, template_path):
     template_content = iotools.read_all_lines_in_textfile(template_path)
     placeholder_list = self.__get_placeholders_from_string(
         template_content)
     return placeholder_list
Exemplo n.º 7
0
 def __parse_template(self, template_path):
     template_content = iotools.read_all_lines_in_textfile(template_path)
     placeholder_list = self.__get_placeholders_from_string(template_content)
     return placeholder_list
Exemplo n.º 8
0
def resolve_and_run_file(input_file, output_file=None, log_file=None, madx_path=MADX_PATH):
    _check_files(input_file, output_file, log_file)
    main_file_content = iotools.read_all_lines_in_textfile(input_file)
    full_madx_script = resolve(main_file_content, output_file, log_file)
    return run(full_madx_script, log_file, madx_path)