From 329ca2806ca8346e4b4d5c6e116f1cb7f2546f45 Mon Sep 17 00:00:00 2001 From: vitor Date: Mon, 9 Dec 2024 12:30:21 -0300 Subject: [PATCH 1/3] first test: using T and R flags --- src/flat_file.cpp | 71 +++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/src/flat_file.cpp b/src/flat_file.cpp index 52ff4f3..c5585d8 100644 --- a/src/flat_file.cpp +++ b/src/flat_file.cpp @@ -28,8 +28,8 @@ static const int np = 17; // number precision static bool read_boolean_string(std::istringstream& ss); static int process_rad_property(std::istringstream& ss); static std::string get_boolean_string(bool value); -static bool has_t_vector(const double* t); -static bool has_r_matrix(const double* r); +// static bool has_t_vector(const double* t); +// static bool has_r_matrix(const double* r); static bool has_matrix66(const Matrix& r); static bool has_polynom(const std::vector& p); static void write_6d_vector(std::ostream& fp, const std::string& label, const double* t); @@ -129,9 +129,9 @@ void write_flat_file_trackcpp(std::ostream& fp, const Accelerator& accelerator) if (e.angle_in != 0) { fp << std::setw(pw) << "angle_in" << e.angle_in << '\n'; } if (e.angle_out != 0) { fp << std::setw(pw) << "angle_out" << e.angle_out << '\n'; } if (e.rescale_kicks != 1.0) { fp << std::setw(pw) << "rescale_kicks" << e.rescale_kicks << '\n'; } - if (has_t_vector(e.t_in)) write_6d_vector(fp, "t_in", e.t_in); - if (has_t_vector(e.t_out)) write_6d_vector(fp, "t_out", e.t_out); - if (has_r_matrix(e.r_in)) { + if (e.has_t_in) write_6d_vector(fp, "t_in", e.t_in); + if (e.has_t_out) write_6d_vector(fp, "t_out", e.t_out); + if (e.has_r_in) { write_6d_vector(fp, "rx|r_in", &e.r_in[6*0]); write_6d_vector(fp, "px|r_in", &e.r_in[6*1]); write_6d_vector(fp, "ry|r_in", &e.r_in[6*2]); @@ -139,7 +139,7 @@ void write_flat_file_trackcpp(std::ostream& fp, const Accelerator& accelerator) write_6d_vector(fp, "de|r_in", &e.r_in[6*4]); write_6d_vector(fp, "dl|r_in", &e.r_in[6*5]); } - if (has_r_matrix(e.r_out)) { + if (e.has_r_out) { write_6d_vector(fp, "rx|r_out", &e.r_out[6*0]); write_6d_vector(fp, "px|r_out", &e.r_out[6*1]); write_6d_vector(fp, "ry|r_out", &e.r_out[6*2]); @@ -309,6 +309,11 @@ Status::type read_flat_file_trackcpp(std::istream& fp, Accelerator& accelerator) return Status::flat_file_error; } + e.reflag_t_in(); + e.reflag_t_out(); + e.reflag_r_in(); + e.reflag_r_out(); + if (e.fam_name.compare("") != 0) { accelerator.lattice.push_back(e); } @@ -395,6 +400,12 @@ static Status::type read_flat_file_tracy(const std::string& filename, Accelerato e.r_out[2*6+0] = S; e.r_out[2*6+2] = C; e.r_out[1*6+1] = C; e.r_out[1*6+3] = -S; e.r_out[3*6+1] = S; e.r_out[3*6+3] = C; + + e.reflag_t_in(); + e.reflag_t_out(); + e.reflag_r_in(); + e.reflag_r_out(); + }; break; case FlatFileType::kicktable: { @@ -476,30 +487,30 @@ static std::string get_boolean_string(bool value) { return "false"; } -static bool has_t_vector(const double* t) { - for (int i=0; i<6; ++i) - if (t[i] != 0) - return true; - - return false; -} - -static bool has_r_matrix(const double* r) { - const double id[36] = { - 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 - }; - - for (int i=0; i<36; ++i) - if (r[i] != id[i]) - return true; - - return false; -} +// static bool has_t_vector(const double* t) { +// for (int i=0; i<6; ++i) +// if (t[i] != 0) +// return true; + +// return false; +// } + +// static bool has_r_matrix(const double* r) { +// const double id[36] = { +// 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, +// 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, +// 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, +// 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, +// 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, +// 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 +// }; + +// for (int i=0; i<36; ++i) +// if (r[i] != id[i]) +// return true; + +// return false; +// } static bool has_matrix66(const Matrix& m) { for (int i=0; i<6; ++i) From e28e62dcdc114fe9543f5c9bc0bd828317b175f6 Mon Sep 17 00:00:00 2001 From: vitor Date: Mon, 9 Dec 2024 12:49:51 -0300 Subject: [PATCH 2/3] new test --- src/flat_file.cpp | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/src/flat_file.cpp b/src/flat_file.cpp index c5585d8..4f40bf1 100644 --- a/src/flat_file.cpp +++ b/src/flat_file.cpp @@ -28,8 +28,6 @@ static const int np = 17; // number precision static bool read_boolean_string(std::istringstream& ss); static int process_rad_property(std::istringstream& ss); static std::string get_boolean_string(bool value); -// static bool has_t_vector(const double* t); -// static bool has_r_matrix(const double* r); static bool has_matrix66(const Matrix& r); static bool has_polynom(const std::vector& p); static void write_6d_vector(std::ostream& fp, const std::string& label, const double* t); @@ -229,19 +227,27 @@ Status::type read_flat_file_trackcpp(std::istream& fp, Accelerator& accelerator) if (cmd.compare("angle_out") == 0) { ss >> e.angle_out; continue; } if (cmd.compare("rescale_kicks") == 0) { ss >> e.rescale_kicks; continue; } if (cmd.compare("t_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.t_in[i]; continue; } + e.reflag_t_in(); + if (cmd.compare("t_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.t_out[i]; continue; } + e.reflag_t_out(); + if (cmd.compare("rx|r_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_in[0*6+i]; continue; } if (cmd.compare("px|r_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_in[1*6+i]; continue; } if (cmd.compare("ry|r_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_in[2*6+i]; continue; } if (cmd.compare("py|r_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_in[3*6+i]; continue; } if (cmd.compare("de|r_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_in[4*6+i]; continue; } if (cmd.compare("dl|r_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_in[5*6+i]; continue; } + e.reflag_r_in(); + if (cmd.compare("rx|r_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_out[0*6+i]; continue; } if (cmd.compare("px|r_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_out[1*6+i]; continue; } if (cmd.compare("ry|r_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_out[2*6+i]; continue; } if (cmd.compare("py|r_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_out[3*6+i]; continue; } if (cmd.compare("de|r_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_out[4*6+i]; continue; } if (cmd.compare("dl|r_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_out[5*6+i]; continue; } + e.reflag_r_out(); + if (cmd.compare("rx|matrix66") == 0) { for(auto i=0; i<6; ++i) ss >> e.matrix66[0][i]; continue; } if (cmd.compare("px|matrix66") == 0) { for(auto i=0; i<6; ++i) ss >> e.matrix66[1][i]; continue; } if (cmd.compare("ry|matrix66") == 0) { for(auto i=0; i<6; ++i) ss >> e.matrix66[2][i]; continue; } @@ -309,11 +315,6 @@ Status::type read_flat_file_trackcpp(std::istream& fp, Accelerator& accelerator) return Status::flat_file_error; } - e.reflag_t_in(); - e.reflag_t_out(); - e.reflag_r_in(); - e.reflag_r_out(); - if (e.fam_name.compare("") != 0) { accelerator.lattice.push_back(e); } @@ -487,31 +488,6 @@ static std::string get_boolean_string(bool value) { return "false"; } -// static bool has_t_vector(const double* t) { -// for (int i=0; i<6; ++i) -// if (t[i] != 0) -// return true; - -// return false; -// } - -// static bool has_r_matrix(const double* r) { -// const double id[36] = { -// 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -// 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, -// 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -// 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, -// 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -// 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 -// }; - -// for (int i=0; i<36; ++i) -// if (r[i] != id[i]) -// return true; - -// return false; -// } - static bool has_matrix66(const Matrix& m) { for (int i=0; i<6; ++i) for (int j=0; j<6; ++j) From 6b5a39daf715930d57c827266408f060478ffae9 Mon Sep 17 00:00:00 2001 From: Vitor Date: Thu, 17 Apr 2025 11:08:06 -0300 Subject: [PATCH 3/3] repositioning reflags --- src/flat_file.cpp | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/flat_file.cpp b/src/flat_file.cpp index 4f40bf1..a6ecc4b 100644 --- a/src/flat_file.cpp +++ b/src/flat_file.cpp @@ -226,28 +226,20 @@ Status::type read_flat_file_trackcpp(std::istream& fp, Accelerator& accelerator) if (cmd.compare("angle_in") == 0) { ss >> e.angle_in; continue; } if (cmd.compare("angle_out") == 0) { ss >> e.angle_out; continue; } if (cmd.compare("rescale_kicks") == 0) { ss >> e.rescale_kicks; continue; } - if (cmd.compare("t_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.t_in[i]; continue; } - e.reflag_t_in(); - - if (cmd.compare("t_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.t_out[i]; continue; } - e.reflag_t_out(); - - if (cmd.compare("rx|r_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_in[0*6+i]; continue; } - if (cmd.compare("px|r_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_in[1*6+i]; continue; } - if (cmd.compare("ry|r_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_in[2*6+i]; continue; } - if (cmd.compare("py|r_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_in[3*6+i]; continue; } - if (cmd.compare("de|r_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_in[4*6+i]; continue; } - if (cmd.compare("dl|r_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_in[5*6+i]; continue; } - e.reflag_r_in(); - - if (cmd.compare("rx|r_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_out[0*6+i]; continue; } - if (cmd.compare("px|r_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_out[1*6+i]; continue; } - if (cmd.compare("ry|r_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_out[2*6+i]; continue; } - if (cmd.compare("py|r_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_out[3*6+i]; continue; } - if (cmd.compare("de|r_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_out[4*6+i]; continue; } - if (cmd.compare("dl|r_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_out[5*6+i]; continue; } - e.reflag_r_out(); - + if (cmd.compare("t_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.t_in[i]; e.reflag_t_in(); continue; } + if (cmd.compare("t_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.t_out[i]; e.reflag_t_out(); continue; } + if (cmd.compare("rx|r_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_in[0*6+i]; e.reflag_r_in(); continue; } + if (cmd.compare("px|r_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_in[1*6+i]; e.reflag_r_in(); continue; } + if (cmd.compare("ry|r_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_in[2*6+i]; e.reflag_r_in(); continue; } + if (cmd.compare("py|r_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_in[3*6+i]; e.reflag_r_in(); continue; } + if (cmd.compare("de|r_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_in[4*6+i]; e.reflag_r_in(); continue; } + if (cmd.compare("dl|r_in") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_in[5*6+i]; e.reflag_r_in(); continue; } + if (cmd.compare("rx|r_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_out[0*6+i]; e.reflag_r_out(); continue; } + if (cmd.compare("px|r_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_out[1*6+i]; e.reflag_r_out(); continue; } + if (cmd.compare("ry|r_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_out[2*6+i]; e.reflag_r_out(); continue; } + if (cmd.compare("py|r_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_out[3*6+i]; e.reflag_r_out(); continue; } + if (cmd.compare("de|r_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_out[4*6+i]; e.reflag_r_out(); continue; } + if (cmd.compare("dl|r_out") == 0) { for(auto i=0; i<6; ++i) ss >> e.r_out[5*6+i]; e.reflag_r_out(); continue; } if (cmd.compare("rx|matrix66") == 0) { for(auto i=0; i<6; ++i) ss >> e.matrix66[0][i]; continue; } if (cmd.compare("px|matrix66") == 0) { for(auto i=0; i<6; ++i) ss >> e.matrix66[1][i]; continue; } if (cmd.compare("ry|matrix66") == 0) { for(auto i=0; i<6; ++i) ss >> e.matrix66[2][i]; continue; }