def match(lhc_run, ip, sbs_data_b1_path, sbs_data_b2_path, match_temporary_path, use_errors, mode): print "+++ Starting Segment by Segment Match +++" beam1_temporary_path = os.path.join(match_temporary_path, "Beam1") beam2_temporary_path = os.path.join(match_temporary_path, "Beam2") iotools.create_dirs(os.path.join(beam1_temporary_path, "sbs")) iotools.create_dirs(os.path.join(beam2_temporary_path, "sbs")) if mode == "phase": run_genphases(ip, match_temporary_path, sbs_data_b1_path, sbs_data_b2_path) elif mode == "coupling": run_gen_f_terms(ip, match_temporary_path, sbs_data_b1_path, sbs_data_b2_path) print "Copying files into temporary folder..." iotools.copy_item(os.path.join(CURRENT_PATH, "dumpB1.gplot"), match_temporary_path) iotools.copy_item(os.path.join(CURRENT_PATH, "dumpB2.gplot"), match_temporary_path) _copy_beam1_temp_files(ip, sbs_data_b1_path, beam1_temporary_path) _copy_beam2_temp_files(ip, sbs_data_b2_path, beam2_temporary_path) print "Getting matching range..." ((range_beam1_start_s, range_beam1_start_name), (range_beam1_end_s, range_beam1_end_name)) = _get_match_bpm_range( os.path.join(beam1_temporary_path, "sbs", "sbsphasext_IP" + ip + ".out")) ((range_beam2_start_s, range_beam2_start_name), (range_beam2_end_s, range_beam2_end_name)) = _get_match_bpm_range( os.path.join(beam2_temporary_path, "sbs", "sbsphasext_IP" + ip + ".out")) print "Matching range for Beam 1:", range_beam1_start_name, range_beam1_end_name print "Matching range for Beam 2:", range_beam2_start_name, range_beam2_end_name print "Running MADX..." label = "IP" + str(ip) _prepare_script_and_run_madx(lhc_run, label, mode, beam1_temporary_path, beam2_temporary_path, match_temporary_path, range_beam1_start_name, range_beam1_end_name, range_beam2_start_name, range_beam2_end_name) print "Writting sbs files from MADX results..." _write_sbs_data(ip, beam1_temporary_path, beam2_temporary_path, range_beam1_start_name, range_beam2_start_name) print "Building changeparameters_match.madx..." _build_changeparameters_file(match_temporary_path) print "Running GNUPlot..." _prepare_and_run_gnuplot(ip, match_temporary_path, range_beam1_start_s, range_beam1_end_s, range_beam2_start_s, range_beam2_end_s) print "+++ Ended Segment by Segment Match +++" return 0
def _run_Segment_by_Segment_Match(self, output_path): print "Running Segment by Segment Match..." beam1path = "" beam2path = "" if "beam1" in output_path: beam1path = output_path beam2path = beam1path.replace("beam1", "beam2") if "beam2" in output_path: beam2path = output_path beam1path = beam2path.replace("beam2", "beam1") if os.path.isdir(os.path.join(beam1path, "sbs")) and os.path.isdir( os.path.join(beam2path, "sbs")): temp_dir = beam1path.replace("beam1", "match") iotools.create_dirs(temp_dir) self._sbs_match_output_paths.append(temp_dir) for ip in IP_SEGMENTS_TO_RUN: print "For IP" + str(ip) + "..." call_command = sys.executable + " " + os.path.abspath(self._path_to_sbs_match) + \ " --ip " + str(ip) + \ " --beam1 " + beam1path + \ " --beam2 " + beam2path + \ " --temp " + temp_dir self._run_outer_process(call_command, "Segment by Segment Match") iotools.copy_item( os.path.join(temp_dir, "match", "changeparameters.madx"), os.path.join(temp_dir, "changeparametersIP" + str(ip) + ".madx")) iotools.delete_item(os.path.join(temp_dir, "match")) else: print "No data for both beams yet."
def match(lhc_run, ip, sbs_data_b1_path, sbs_data_b2_path, match_temporary_path, use_errors, mode): print "+++ Starting Segment by Segment Match +++" beam1_temporary_path = os.path.join(match_temporary_path, "Beam1") beam2_temporary_path = os.path.join(match_temporary_path, "Beam2") iotools.create_dirs(os.path.join(beam1_temporary_path, "sbs")) iotools.create_dirs(os.path.join(beam2_temporary_path, "sbs")) if mode == "phase": run_genphases(ip, match_temporary_path, sbs_data_b1_path, sbs_data_b2_path) elif mode == "coupling": run_gen_f_terms(ip, match_temporary_path, sbs_data_b1_path, sbs_data_b2_path) print "Copying files into temporary folder..." iotools.copy_item(os.path.join(CURRENT_PATH, "dumpB1.gplot"), match_temporary_path) iotools.copy_item(os.path.join(CURRENT_PATH, "dumpB2.gplot"), match_temporary_path) _copy_beam1_temp_files(ip, sbs_data_b1_path, beam1_temporary_path) _copy_beam2_temp_files(ip, sbs_data_b2_path, beam2_temporary_path) print "Getting matching range..." ((range_beam1_start_s, range_beam1_start_name), (range_beam1_end_s, range_beam1_end_name)) = _get_match_bpm_range(os.path.join(beam1_temporary_path, "sbs", "sbsphasext_IP" + ip + ".out")) ((range_beam2_start_s, range_beam2_start_name), (range_beam2_end_s, range_beam2_end_name)) = _get_match_bpm_range(os.path.join(beam2_temporary_path, "sbs", "sbsphasext_IP" + ip + ".out")) print "Matching range for Beam 1:", range_beam1_start_name, range_beam1_end_name print "Matching range for Beam 2:", range_beam2_start_name, range_beam2_end_name print "Running MADX..." label = "IP" + str(ip) _prepare_script_and_run_madx(lhc_run, label, mode, beam1_temporary_path, beam2_temporary_path, match_temporary_path, range_beam1_start_name, range_beam1_end_name, range_beam2_start_name, range_beam2_end_name) print "Writting sbs files from MADX results..." _write_sbs_data(ip, beam1_temporary_path, beam2_temporary_path, range_beam1_start_name, range_beam2_start_name) print "Building changeparameters_match.madx..." _build_changeparameters_file(match_temporary_path) print "Running GNUPlot..." _prepare_and_run_gnuplot(ip, match_temporary_path, range_beam1_start_s, range_beam1_end_s, range_beam2_start_s, range_beam2_end_s) print "+++ Ended Segment by Segment Match +++" return 0
def _run_Segment_by_Segment_Match(self, output_path): print "Running Segment by Segment Match..." beam1path = "" beam2path = "" if "beam1" in output_path: beam1path = output_path beam2path = beam1path.replace("beam1", "beam2") if "beam2" in output_path: beam2path = output_path beam1path = beam2path.replace("beam2", "beam1") if os.path.isdir(os.path.join(beam1path, "sbs")) and os.path.isdir(os.path.join(beam2path, "sbs")): temp_dir = beam1path.replace("beam1", "match") iotools.create_dirs(temp_dir) self._sbs_match_output_paths.append(temp_dir) for ip in IP_SEGMENTS_TO_RUN: print "For IP" + str(ip) + "..." call_command = ( sys.executable + " " + os.path.abspath(self._path_to_sbs_match) + " --ip " + str(ip) + " --beam1 " + beam1path + " --beam2 " + beam2path + " --temp " + temp_dir ) self._run_outer_process(call_command, "Segment by Segment Match") iotools.copy_item( os.path.join(temp_dir, "match", "changeparameters.madx"), os.path.join(temp_dir, "changeparametersIP" + str(ip) + ".madx"), ) iotools.delete_item(os.path.join(temp_dir, "match")) else: print "No data for both beams yet."
def _copy_error_def_file(directory, options): new_err_def_path = os.path.join(directory, "error_deff.txt") iotools.copy_item(os.path.join( ERR_DEF_PATH, ERR_DEF_FILES[options.optics] ), new_err_def_path) return new_err_def_path