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