Version: SMASH-3.1
setup_particles_decaymodes.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2019,2022
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
11 
12 #include "smash/decaymodes.h"
13 #include "smash/inputfunctions.h"
14 
15 namespace {
16 #ifndef DOXYGEN
17 namespace particles_txt {
18 #include <particles.txt.h>
19 } // namespace particles_txt
20 namespace decaymodes_txt {
21 #include <decaymodes.txt.h>
22 } // namespace decaymodes_txt
23 #endif
24 } // unnamed namespace
25 
26 namespace smash {
27 
28 std::pair<std::string, std::string> load_particles_and_decaymodes(
29  const std::filesystem::path &particles_file,
30  const std::filesystem::path &decaymodes_file) {
31  std::string particle_string, decay_string;
32  if (!particles_file.empty()) {
33  if (!std::filesystem::exists(particles_file)) {
34  std::stringstream err;
35  err << "The particles file was expected at '" << particles_file
36  << "', but the file does not exist.";
37  throw std::runtime_error(err.str());
38  }
39  particle_string = read_all(std::ifstream{particles_file});
40  if (has_crlf_line_ending(particle_string)) {
41  std::stringstream err;
42  err << "The particles file has CR LF line endings. Please use LF"
43  " line endings.";
44  throw std::runtime_error(err.str());
45  }
46  } else {
47  particle_string = particles_txt::data;
48  }
49 
50  if (!decaymodes_file.empty()) {
51  if (!std::filesystem::exists(decaymodes_file)) {
52  std::stringstream err;
53  err << "The decay modes file was expected at '" << decaymodes_file
54  << "', but the file does not exist.";
55  throw std::runtime_error(err.str());
56  }
57  decay_string = read_all(std::ifstream{decaymodes_file});
58  if (has_crlf_line_ending(decay_string)) {
59  std::stringstream err;
60  err << "The decay mode file has CR LF line endings. Please use LF"
61  " line endings.";
62  throw std::runtime_error(err.str());
63  }
64  } else {
65  decay_string = decaymodes_txt::data;
66  }
67  return std::make_pair(particle_string, decay_string);
68 }
69 
71  const auto pd = load_particles_and_decaymodes({}, {});
73  DecayModes::load_decaymodes(pd.second);
75 }
76 
77 } // namespace smash
static void load_decaymodes(const std::string &input)
Loads the DecayModes map as described in the input string.
Definition: decaymodes.cc:163
static void check_consistency()
static void create_type_list(const std::string &particles)
Initialize the global ParticleType list (list_all) from the given input data.
Definition: action.h:24
void initialize_default_particles_and_decaymodes()
Loads default smash particle list and decaymodes.
std::pair< std::string, std::string > load_particles_and_decaymodes(const std::filesystem::path &particles_file, const std::filesystem::path &decaymodes_file)
Loads particles and decaymodes from provided files particles_file and decaymodes_file.
bool has_crlf_line_ending(const std::string in)
Check if a line in the string ends with \r\n.
std::string read_all(std::istream &&input)
Utility function to read a complete input stream (e.g.