Version: SMASH-3.4
smash::anonymous_namespace{smash.cc} Namespace Reference

Classes

struct  OutputDirectoryExists
 Exception class that is thrown, if the requested output directory already exists and -f was not specified on the command line. More...
 
struct  OutputDirectoryOutOfIds
 Exception class that is thrown, if no new output path can be generated (there is a directory name for each positive integer value) More...
 

Functions

void usage (const int rc, const std::string &progname)
 Prints usage information and exits the program. More...
 
void print_disclaimer ()
 Print the disclaimer. More...
 
std::filesystem::path default_output_path ()
 
void ensure_path_is_valid (const std::filesystem::path &path)
 Ensures the output path is valid. More...
 
ScatterActionsFinder actions_finder_for_dump (Configuration &configuration)
 Prepares ActionsFinder for cross-section and reaction dumps. More...
 
void check_for_unused_config_values (const Configuration &configuration)
 Checks if there are unused config values. More...
 
void ignore_simulation_config_values (Configuration &configuration)
 Remove all config values that are only needed for simulations. More...
 

Function Documentation

◆ usage()

void smash::anonymous_namespace{smash.cc}::usage ( const int  rc,
const std::string &  progname 
)

Prints usage information and exits the program.

Parameters
[out]rcExit status to return
[in]prognameName of the program

usage() is called when either the --help or -h command line options are given to the program; in this case, the exit status is EXIT_SUCCESS, or when an unknown option is given; in this case, the exit status is EXIT_FAIL.

Definition at line 153 of file smash.cc.

153  {
154  // Implement some tools to format helper using Einhard colors
155  const auto colorize = [](const auto &color,
156  const std::string s) -> std::string {
157  return color + s + einhard::NoColor_t_::ANSI();
158  };
159  const auto print_option = [&colorize](
160  const std::string &short_option,
161  const std::string &long_option,
162  std::optional<std::string> value_placeholder,
163  const std::string &description) {
164  const auto option_color = std::string{einhard::Cyan_t_::ANSI()};
165  const auto value_color = std::string{einhard::DCyan_t_::ANSI()};
166  const auto default_color = std::string{einhard::NoColor_t_::ANSI()};
167  const int indentation = 2;
168  const int effective_option_column_width = 29;
169  /* Calculate the width of the option column including the bytes from the
170  * ANSI color code which don't appear on screen but are "eaten up" by
171  * std::printf and thus must be added here. */
172  const int option_column_width =
173  effective_option_column_width +
174  3 * (option_color.length() + default_color.length());
175  const int padding = indentation + effective_option_column_width;
176  const int raw_option_length =
177  short_option.length() + 2 + long_option.length() +
178  ((value_placeholder) ? (1 + value_placeholder->length()) : 0);
179  const std::string option{
180  colorize(option_color, short_option) + ", " +
181  colorize(option_color, long_option) + (value_placeholder ? " " : "") +
182  colorize(value_color, value_placeholder.value_or(""))};
183  std::printf("%*s%-*s", indentation, "", option_column_width,
184  option.c_str());
185  bool skip_padding = true;
186  if (raw_option_length >= effective_option_column_width) {
187  std::printf("\n");
188  skip_padding = false;
189  }
190  for (const auto &line : smash::split(description, '\n')) {
191  std::printf("%*s%s\n", (skip_padding) ? 0 : padding, "", line.c_str());
192  skip_padding = false;
193  }
194  };
195 
196  // Print synopsis
197  std::printf(
198  "\n Usage: %s\n\n",
199  colorize(einhard::Yellow_t_::ANSI(), progname + " [option]").c_str());
200 
201  // Print options
202  print_option("-h", "--help", std::nullopt, "Print usage information");
203  print_option("-v", "--version", std::nullopt, "Print version");
204  std::printf("\n");
205  print_option("-i", "--inputfile", "<file>",
206  "Path to input configuration file (default: ./config.yaml)");
207  print_option("-o", "--output", "<dir>",
208  "Output directory (default: ./data/<runid>)");
209  print_option("-f", "--force", std::nullopt,
210  "Force overwriting files in the output directory");
211  print_option("-d", "--decaymodes", "<file>",
212  "Override default decay modes from file");
213  print_option("-p", "--particles", "<file>",
214  "Override default particles from file");
215  print_option("-t", "--tabulations", "<dir>",
216  "Tabulations cache directory (default: ./data/tabulations)");
217  print_option("-q", "--quiet", std::nullopt, "Suppress disclaimer printout");
218  print_option("-n", "--no-cache", std::nullopt,
219  "Disable caching integrals on disk");
220  std::printf("\n");
221  print_option(
222  "-c", "--config", "<YAML string>",
223  "Specify config value overrides (multiple -c arguments are supported)");
224  print_option("-m", "--modus", "<modus>",
225  "Shortcut for -c 'General: { Modus: <modus> }'");
226  print_option("-e", "--endtime", "<time>",
227  "Shortcut for -c 'General: { End_Time: <time> }'");
228  std::printf("\n");
229  print_option("-l", "--list-2-to-n", std::nullopt,
230  "Print list of all possible 2->n reactions (with n>1)");
231  print_option("-r", "--resonance", "<pdg>",
232  "Print width(m) and m*spectral function(m^2) for resonance pdg");
233  print_option(
234  "-s", "--cross-sections", "<pdg1>,<pdg2>[,mass1,mass2[,plab1,...]]",
235  "Print all partial cross-sections of pdg1 + pdg2 reactions versus "
236  "sqrt(s)");
237  print_option("-S", "--cross-sections-fs",
238  "<pdg1>,<pdg2>[,mass1,mass2[,plab1,...]]",
239  "Print an approximation of the final-state cross-sections of "
240  "pdg1 + pdg2\nreactions versus sqrt(s). Contributions from "
241  "strings are not considered\nfor the final state. Masses are "
242  "optional, by default pole masses are used.\nNote the required "
243  "comma and no spaces");
244  print_option("-x", "--dump_iSS", std::nullopt,
245  "Print particles table in iSS format. This format is used in "
246  "MUSIC and\nCLVisc relativistic hydro codes");
247  std::printf("\n");
248  std::exit(rc);
249 }
std::vector< std::string > split(const std::string &s, char delim)
Split string by delimiter.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_disclaimer()

void smash::anonymous_namespace{smash.cc}::print_disclaimer ( )

Print the disclaimer.

Definition at line 252 of file smash.cc.

252  {
253  std::cout
254  << "###################################################################"
255  << "############"
256  << "\n"
257  << "\n"
258  << " :::s.\n"
259  << " .... ''ss:: "
260  "ah:\n"
261  << " a::''. ..:sss "
262  ".HH.\n"
263  << " mss'.. ...s'm. sSA##As mAhh##hsh##s. .hA##ASa sS###As "
264  "hMAh##h.\n"
265  << " :a':'. .'':as sM#' .HHm''HMS''AMs mMA' .AMs aMA. "
266  "'HHa..HM:\n"
267  << " .a:s'. ..''ss 'h#H#S. mMm 'M#' .HH. 'MH. :MA 'h#H#S. "
268  "hMm :M#\n"
269  << " .::ss'. .... 'SMm .HH. SMa hMm sM#..mHMs 'AMa "
270  "'MH. SMa\n"
271  << " .s::' #SMASHh aMS .MH: HM: #MMMmMM. #SMASHh "
272  "aMS .MM.\n"
273  << "\n"
274  << "###################################################################"
275  << "############"
276  << "\n"
277  << " This is SMASH version: " << SMASH_VERSION << "\n"
278  << " Simulating Many Accelerated Strongly-interacting Hadrons"
279  << "\n"
280  << "\n"
281  << " Distributed under the GNU General Public License 3.0"
282  << " (GPLv3 or later)."
283  << "\n"
284  << " See LICENSE for details."
285  << "\n"
286  << " For the full list of contributors see the AUTHORS.md file."
287  << "\n"
288  << "\n"
289  << " When using SMASH, please cite"
290  << "\n"
291  << " J. Weil et al., Phys.Rev. C94 (2016) no.5, 054905"
292  << "\n"
293  << " together with the software DOI for the specific code version "
294  << "employed:"
295  << "\n"
296  << " https://doi.org/10.5281/zenodo.3484711"
297  << "\n"
298  << " In addition, if Pythia is used please cite"
299  << "\n"
300  << " C. Bierlich et al, SciPost Phys. Codebases 8 (2022)"
301  << "\n"
302  << " together with the Codebase release you used:"
303  << "\n"
304  << " https://doi.org/10.21468/SciPostPhysCodeb.8-r8.3"
305  << "\n"
306  << "\n"
307  << " Webpage: https://smash-transport.github.io"
308  << "\n"
309  << "\n"
310  << " Report issues at https://github.com/smash-transport/smash"
311  << "\n"
312  << " or contact us by email at elfner@itp.uni-frankfurt.de"
313  << "\n"
314  << "\n"
315  << "###################################################################"
316  << "############"
317  << "\n"
318  << "\n";
319 }
Here is the caller graph for this function:

◆ default_output_path()

std::filesystem::path smash::anonymous_namespace{smash.cc}::default_output_path ( )
Returns
the default path for output.

Definition at line 340 of file smash.cc.

340  {
341  const std::filesystem::path p = std::filesystem::absolute("data");
342  if (!std::filesystem::exists(p)) {
343  return p / "0";
344  }
345  std::filesystem::path p2;
346  for (int id = 0; id < std::numeric_limits<int>::max(); ++id) {
347  p2 = p / std::to_string(id);
348  if (!std::filesystem::exists(p2)) {
349  break;
350  }
351  }
352  if (p == p2) {
353  throw OutputDirectoryOutOfIds("no unique data subdir ID left");
354  }
355  return p2;
356 }
constexpr int p
Proton.
std::string to_string(ThermodynamicQuantity quantity)
Convert a ThermodynamicQuantity enum value to its corresponding string.
Definition: stringify.cc:26
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ensure_path_is_valid()

void smash::anonymous_namespace{smash.cc}::ensure_path_is_valid ( const std::filesystem::path &  path)

Ensures the output path is valid.

Exceptions
OutputDirectoryExistsif the Output directory already exists.
Parameters
[in]pathThe output path to be written to

Definition at line 364 of file smash.cc.

364  {
365  if (std::filesystem::exists(path)) {
366  if (!std::filesystem::is_directory(path)) {
367  throw OutputDirectoryExists("The given path (" + path.native() +
368  ") exists, but it is not a directory.");
369  }
370  } else {
371  if (!std::filesystem::create_directories(path)) {
372  throw OutputDirectoryExists(
373  "Race condition detected: The directory " + path.native() +
374  " did not exist a few cycles ago, but was created in the meantime by "
375  "a different process.");
376  }
377  }
378 }
Here is the caller graph for this function:

◆ actions_finder_for_dump()

ScatterActionsFinder smash::anonymous_namespace{smash.cc}::actions_finder_for_dump ( Configuration configuration)

Prepares ActionsFinder for cross-section and reaction dumps.

Parameters
[in,out]configurationNecessary parameters to switch reactions on/off
Returns
The constructed ScatterActionsFinder .

Definition at line 386 of file smash.cc.

386  {
387  ExperimentParameters params = create_experiment_parameters(configuration);
388  return ScatterActionsFinder(configuration, params);
389 }
A simple scatter finder: Just loops through all particles and checks each pair for a collision.
ExperimentParameters create_experiment_parameters(Configuration &config)
Gathers all general Experiment parameters.
Definition: experiment.cc:135
Helper structure for Experiment.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_for_unused_config_values()

void smash::anonymous_namespace{smash.cc}::check_for_unused_config_values ( const Configuration configuration)

Checks if there are unused config values.

Definition at line 394 of file smash.cc.

394  {
395  if (!configuration.is_empty()) {
396  throw std::runtime_error(
397  "The following configuration values were not used:\n" +
398  configuration.to_string());
399  }
400 }
std::string to_string() const
Return a string of the current YAML tree.
bool is_empty() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ignore_simulation_config_values()

void smash::anonymous_namespace{smash.cc}::ignore_simulation_config_values ( Configuration configuration)

Remove all config values that are only needed for simulations.

This is useful when checking for unused config value when SMASH only outputs cross sections, resonance properties or possible reactions.

Definition at line 408 of file smash.cc.

408  {
409  for (const auto &key : {InputKeys::particles, InputKeys::decaymodes}) {
410  if (configuration.has_value(key)) {
411  configuration.take(key);
412  }
413  }
414  for (const auto &section :
418  if (configuration.has_section(section)) {
419  configuration.extract_sub_configuration(section).clear();
420  }
421  }
422 }
Configuration extract_sub_configuration(KeyLabels section, Configuration::GetEmpty empty_if_not_existing=Configuration::GetEmpty::No)
Create a new configuration from a then-removed section of the present object.
bool has_value(const Key< T > &key) const
Return whether there is a non-empty value behind the requested key (which is supposed not to refer to...
void clear()
Erase the Configuration content.
bool has_section(const KeyLabels &labels) const
Return whether there is a (possibly empty) section with the given labels.
T take(const Key< T > &key)
The default interface for SMASH to read configuration values.
constexpr Section output
Section for the output information.
Definition: input_keys.h:205
constexpr Section general
General section.
Definition: input_keys.h:143
constexpr Section forcedThermalization
Section for the forced thermalization.
Definition: input_keys.h:140
constexpr Section potentials
Section for the potentials information.
Definition: input_keys.h:228
constexpr Section lattice
Section for the lattice.
Definition: input_keys.h:149
constexpr Section modi
Section for the modus specific information.
Definition: input_keys.h:155
Here is the call graph for this function:
Here is the caller graph for this function: