Example #1
0
def _prepare_single_error_file(seed_path_tuple):
    err_num = str((seed_path_tuple[0] % 60) + 1).zfill(4)
    error_tables_dir = seed_path_tuple[1]
    beam = seed_path_tuple[2]
    energy = seed_path_tuple[3]
    b2_errors_path = os.path.abspath(os.path.join(CURRENT_PATH, "..", "..", "MODEL", "LHCB", "b2_errors"))
    madx_job = ""
    with open(os.path.join(CURRENT_PATH, 'error_table.mask'), 'r') as infile:
        for line in infile:
            new_line = line
            new_line = new_line.replace("%ERR_NUM", err_num)
            new_line = new_line.replace("%RUN_DATA_PATH", error_tables_dir)
            new_line = new_line.replace("%BEAM", beam)
            new_line = new_line.replace("%ENERGY", energy)
            new_line = new_line.replace("%B2_ERRORS_PATH", b2_errors_path)
            new_line = new_line.replace("%NUM_BEAM", beam.replace("B", ""))
            madx_job += new_line + "\n"
    madxrunner.runForInputString(madx_job, stdout=open(os.devnull, "w"))
def _prepare_single_error_file(seed_path_tuple):
    err_num = str((seed_path_tuple[0] % 60) + 1).zfill(4)
    error_tables_dir = seed_path_tuple[1]
    beam = seed_path_tuple[2]
    energy = seed_path_tuple[3]
    b2_errors_path = os.path.abspath(
        os.path.join(CURRENT_PATH, "..", "..", "MODEL", "LHCB", "b2_errors"))
    madx_job = ""
    with open(os.path.join(CURRENT_PATH, 'error_table.mask'), 'r') as infile:
        for line in infile:
            new_line = line
            new_line = new_line.replace("%ERR_NUM", err_num)
            new_line = new_line.replace("%RUN_DATA_PATH", error_tables_dir)
            new_line = new_line.replace("%BEAM", beam)
            new_line = new_line.replace("%ENERGY", energy)
            new_line = new_line.replace("%B2_ERRORS_PATH", b2_errors_path)
            new_line = new_line.replace("%NUM_BEAM", beam.replace("B", ""))
            madx_job += new_line + "\n"
    madxrunner.runForInputString(madx_job, stdout=open(os.devnull, "w"))
Example #3
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
Example #4
0
def run(full_madx_script, log_file=None, madx_path=MADX_PATH):
    """
    Runs MADX with the given, already resolved, MADX script.
    If log_file is given the MADX log will be written there.
    """
    if log_file is None:
        log_stream = sys.stdout
    else:
        log_stream = open(log_file, "w")
    return madxrunner.runForInputString(full_madx_script,
                                        stdout=log_stream,
                                        stderr=log_stream,
                                        madxPath=madx_path)
Example #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
Example #6
0
def run(full_madx_script, log_file=None, madx_path=MADX_PATH):
    """
    Runs MADX with the given, already resolved, MADX script.
    If log_file is given the MADX log will be written there.
    """
    if log_file is None:
        log_stream = sys.stdout
    else:
        log_stream = open(log_file, "w")
    if madx_path is None:
        madx_path = MADX_PATH
    return madxrunner.runForInputString(full_madx_script,
                                        stdout=log_stream,
                                        stderr=log_stream,
                                        madxPath=madx_path)