15 #include <boost/filesystem/fstream.hpp>
27 #include "smash/config.h"
45 void usage(
const int rc,
const std::string &progname) {
133 std::printf(
"\nUsage: %s [option]\n\n", progname.c_str());
135 " -h, --help usage information\n"
137 " -i, --inputfile <file> path to input configuration file\n"
138 " (default: ./config.yaml)\n"
139 " -d, --decaymodes <file> override default decay modes from file\n"
140 " -p, --particles <file> override default particles from file\n"
142 " -c, --config <YAML> specify config value overrides\n"
143 " (multiple -c arguments are supported)\n"
144 " -m, --modus <modus> shortcut for -c 'General: { Modus: <modus> "
146 " -e, --endtime <time> shortcut for -c 'General: { End_Time: <time> "
150 " -o, --output <dir> output directory (default: ./data/<runid>)\n"
151 " -l, --list-2-to-n list all possible 2->n reactions (with n>1)\n"
152 " -r, --resonance <pdg> dump width(m) and m*spectral function(m^2)"
153 " for resonance pdg\n"
154 " -s, --cross-sections <pdg1>,<pdg2>[,mass1,mass2[,plab1,...]] \n"
155 " dump all partial cross-sections of "
156 "pdg1 + pdg2 reactions versus sqrt(s).\n"
157 " -S, --cross-sections-fs <pdg1>,<pdg2>[,mass1,mass2[,plab1,...]] \n"
158 " dump an approximation of the final-state"
160 " of pdg1 + pdg2 reactions versus sqrt(s).\n"
161 " Contributions from strings are not considered"
162 " for the final state.\n"
163 " Masses are optional, by default pole masses"
165 " Note the required comma and no spaces.\n"
166 " -f, --force force overwriting files in the output "
169 " -x, --dump_iSS Dump particle table in iSS format\n"
170 " This format is used in MUSIC and CLVisc\n"
171 " relativistic hydro codes\n"
172 " -q, --quiet Supress disclaimer print-out\n"
173 " -n, --no-cache Don't cache integrals on disk\n"
174 " -v, --version\n\n");
181 <<
"###################################################################"
190 <<
" mss'.. ...s'm. sSA##As mAhh##hsh##s. .hA##ASa sS###As "
192 <<
" :a':'. .'':as sM#' .HHm''HMS''AMs mMA' .AMs aMA. "
194 <<
" .a:s'. ..''ss 'h#H#S. mMm 'M#' .HH. 'MH. :MA 'h#H#S. "
196 <<
" .::ss'. .... 'SMm .HH. SMa hMm sM#..mHMs 'AMa "
198 <<
" .s::' #SMASHh aMS .MH: HM: #MMMmMM. #SMASHh "
201 <<
"###################################################################"
204 <<
" This is SMASH version: " << SMASH_VERSION <<
"\n"
205 <<
" Simulating Many Accelerated Strongly-interacting Hadrons"
208 <<
" Distributed under the GNU General Public License 3.0"
209 <<
" (GPLv3 or later)."
211 <<
" See LICENSE for details."
213 <<
" For the full list of contributors see AUTHORS."
216 <<
" When using SMASH, please cite"
218 <<
" J. Weil et al., Phys.Rev. C94 (2016) no.5, 054905"
220 <<
" together with the software DOI for the specific code version "
223 <<
" https://doi.org/10.5281/zenodo.3484711."
225 <<
" In addition, if Pythia is used please cite"
227 <<
" T. Sjöstrand, S. Mrenna and P. Skands, JHEP05 (2006) 026,"
229 <<
" Comput. Phys. Comm. 178 (2008) 852."
232 <<
" Webpage: https://smash-transport.github.io"
235 <<
" Report issues at https://github.com/smash-transport/smash"
237 <<
" or contact us by email at elfner@itp.uni-frankfurt.de"
240 <<
"###################################################################"
252 using std::runtime_error::runtime_error;
261 using std::runtime_error::runtime_error;
266 const bf::path
p = bf::absolute(
"data");
267 if (!bf::exists(
p)) {
271 for (
int id = 0; id < std::numeric_limits<int>::max(); ++id) {
272 p2 =
p / std::to_string(
id);
273 if (!bf::exists(p2)) {
290 if (bf::exists(path)) {
291 if (!bf::is_directory(path)) {
293 ") exists, but it is not a directory.");
296 if (!bf::create_directories(path)) {
298 "Race condition detected: The directory " + path.native() +
299 " did not exist a few cycles ago, but was created in the meantime by "
300 "a different process.");
325 const std::string smash_version =
"1.8";
326 const std::set<std::string> compatible_config_versions = {
"1.8"};
330 if (compatible_config_versions.find(config_version) ==
331 compatible_config_versions.end()) {
332 std::stringstream err;
333 err <<
"The version of the configuration file (" << config_version
334 <<
") is not compatible with the SMASH version (" << smash_version
335 <<
").\nThe following config versions are supported:\n";
336 for (
auto it : compatible_config_versions) {
339 err <<
"\nPlease consider updating your config or using a compatible SMASH"
341 throw std::runtime_error(err.str());
351 if (report !=
"{}") {
352 throw std::runtime_error(
353 "The following configuration values were not used:\n" + report);
364 for (
const std::string s :
365 {
"Version",
"particles",
"decaymodes",
"Modi",
"General",
"Output",
366 "Lattice",
"Potentials",
"Forced_Thermalization"}) {
387 int main(
int argc,
char *argv[]) {
388 using namespace smash;
390 constexpr option longopts[] = {
391 {
"config", required_argument, 0,
'c'},
392 {
"decaymodes", required_argument, 0,
'd'},
393 {
"endtime", required_argument, 0,
'e'},
394 {
"force", no_argument, 0,
'f'},
395 {
"help", no_argument, 0,
'h'},
396 {
"inputfile", required_argument, 0,
'i'},
397 {
"modus", required_argument, 0,
'm'},
398 {
"particles", required_argument, 0,
'p'},
399 {
"output", required_argument, 0,
'o'},
400 {
"list-2-to-n", no_argument, 0,
'l'},
401 {
"resonance", required_argument, 0,
'r'},
402 {
"cross-sections", required_argument, 0,
's'},
403 {
"cross-sections-fs", required_argument, 0,
'S'},
404 {
"dump-iSS", no_argument, 0,
'x'},
405 {
"version", no_argument, 0,
'v'},
406 {
"no-cache", no_argument, 0,
'n'},
407 {
"quiet", no_argument, 0,
'q'},
411 const std::string progname = bf::path(argv[0]).filename().native();
414 bool force_overwrite =
false;
416 std::string input_path(
"./config.yaml"), particles, decaymodes;
417 std::vector<std::string> extra_config;
418 char *modus =
nullptr, *end_time =
nullptr, *pdg_string =
nullptr,
419 *cs_string =
nullptr;
420 bool list2n_activated =
false;
421 bool resonance_dump_activated =
false;
422 bool cross_section_dump_activated =
false;
423 bool final_state_cross_sections =
false;
424 bool particles_dump_iSS_format =
false;
425 bool cache_integrals =
true;
426 bool suppress_disclaimer =
false;
430 while ((opt = getopt_long(argc, argv,
"c:d:e:fhi:m:p:o:lr:s:S:xvnq",
431 longopts,
nullptr)) != -1) {
434 extra_config.emplace_back(optarg);
440 force_overwrite =
true;
446 usage(EXIT_SUCCESS, progname);
458 output_path = optarg;
461 list2n_activated =
true;
462 suppress_disclaimer =
true;
465 resonance_dump_activated =
true;
467 suppress_disclaimer =
true;
470 final_state_cross_sections =
true;
473 cross_section_dump_activated =
true;
475 suppress_disclaimer =
true;
478 particles_dump_iSS_format =
true;
479 suppress_disclaimer =
true;
487 "System : %s\nCompiler : %s %s\n"
488 "Build : %s\nDate : %s\n",
493 CMAKE_SYSTEM, CMAKE_CXX_COMPILER_ID, CMAKE_CXX_COMPILER_VERSION,
494 CMAKE_BUILD_TYPE, BUILD_DATE);
495 std::exit(EXIT_SUCCESS);
497 cache_integrals =
false;
500 suppress_disclaimer =
true;
503 usage(EXIT_FAILURE, progname);
509 std::cout << argv[0] <<
": invalid argument -- '" << argv[optind]
511 usage(EXIT_FAILURE, progname);
514 if (!suppress_disclaimer) {
519 decaymodes, extra_config);
526 std::string tabulations_path;
527 if (cache_integrals) {
528 tabulations_path = output_path.has_parent_path()
529 ? output_path.parent_path().string()
531 tabulations_path +=
"/tabulations";
533 tabulations_path =
"";
535 const std::string version(SMASH_VERSION);
537 if (list2n_activated) {
548 scat_finder.dump_reactions();
549 std::exit(EXIT_SUCCESS);
551 if (particles_dump_iSS_format) {
554 ParticleTypePtrList list;
556 for (
const auto &ptype : ParticleType::list_all()) {
557 list.push_back(&ptype);
559 std::sort(list.begin(), list.end(),
561 return a->mass() < b->mass();
564 if (ptype->pdgcode().is_lepton() || ptype->baryon_number() < 0) {
567 const auto &decay_modes = ptype->decay_modes();
568 const auto &modelist = decay_modes.decay_mode_list();
569 int ndecays = ptype->is_stable() ? 1 : modelist.size();
570 std::printf(
"%13i %s %10.5f %10.5f %5i %5i %5i %5i %5i %5i %5i %5i\n",
571 ptype->pdgcode().get_decimal(),
573 ptype->mass(), ptype->width_at_pole(),
574 ptype->pdgcode().spin_degeneracy(), ptype->baryon_number(),
575 ptype->strangeness(), ptype->pdgcode().charmness(),
576 ptype->pdgcode().bottomness(), ptype->isospin() + 1,
577 ptype->charge(), ndecays);
578 if (!ptype->is_stable()) {
579 for (
const auto &decay : modelist) {
580 auto ptypes = decay->particle_types();
581 std::printf(
"%13i %13i %20.5f %13i %13i %13i %13i %13i\n",
582 ptype->pdgcode().get_decimal(), 2, decay->weight(),
583 ptypes[0]->pdgcode().get_decimal(),
584 ptypes[1]->pdgcode().get_decimal(), 0, 0, 0);
587 std::printf(
"%13i %13i %20.5f %13i %13i %13i %13i %13i\n",
588 ptype->pdgcode().get_decimal(), 1, 1.0,
589 ptype->pdgcode().get_decimal(), 0, 0, 0, 0);
592 std::exit(EXIT_SUCCESS);
594 if (resonance_dump_activated) {
598 const auto _dummy = ExperimentBase::create(
configuration, output_path);
605 std::exit(EXIT_SUCCESS);
607 if (cross_section_dump_activated) {
610 std::string arg_string(cs_string);
611 std::vector<std::string> args =
split(arg_string,
',');
612 const unsigned int n_arg = args.size();
613 if (n_arg != 2 && n_arg != 4 && n_arg < 5) {
614 throw std::invalid_argument(
"-s usage: pdg1,pdg2[,m1,m2[,sqrts1,...]]");
616 PdgCode pdg_a(args[0]), pdg_b(args[1]);
620 for (
unsigned int i = 0; i < 4 - n_arg; i++) {
624 double ma = (args[2] ==
"") ? a.
mass() : std::stod(args[2]);
625 double mb = (args[3] ==
"") ? b.
mass() : std::stod(args[3]);
626 if (a.
is_stable() && args[2] !=
"" && std::stod(args[2]) != a.
mass()) {
628 std::cerr <<
"Warning: pole mass is used for stable particle "
629 << a.
name() <<
" instead of " << args[2] << std::endl;
631 if (b.
is_stable() && args[3] !=
"" && std::stod(args[3]) != b.
mass()) {
633 std::cerr <<
"Warning: pole mass is used for stable particle "
634 << b.
name() <<
" instead of " << args[3] << std::endl;
636 const size_t plab_size = n_arg <= 4 ? 0 : n_arg - 4;
637 std::vector<double> plab;
638 plab.reserve(plab_size);
639 for (
size_t i = 4; i < n_arg; i++) {
640 plab.push_back(std::stod(args.at(i)));
647 scat_finder.dump_cross_sections(a, b, ma, mb, final_state_cross_sections,
649 std::exit(EXIT_SUCCESS);
655 configuration[
"General"][
"End_Time"] = std::abs(std::atof(end_time));
664 const bf::path lock_path = output_path /
"smash.lock";
667 throw std::runtime_error(
668 "Another instance of SMASH is already writing to the specified "
669 "output directory. If you are sure this is not the case, remove \"" +
670 lock_path.native() +
"\".");
672 logg[
LMain].debug(
"output path: ", output_path);
673 if (!force_overwrite && bf::exists(output_path /
"config.yaml")) {
674 throw std::runtime_error(
675 "Output directory would get overwritten. Select a different output "
676 "directory, clean up, or tell SMASH to ignore existing files.");
681 bf::ofstream(output_path /
"config.yaml")
682 <<
"# " << SMASH_VERSION <<
'\n'
684 <<
"# Branch : " << GIT_BRANCH <<
'\n'
686 <<
"# System : " << CMAKE_SYSTEM <<
'\n'
687 <<
"# Compiler : " << CMAKE_CXX_COMPILER_ID <<
' '
688 << CMAKE_CXX_COMPILER_VERSION <<
'\n'
689 <<
"# Build : " << CMAKE_BUILD_TYPE <<
'\n'
690 <<
"# Date : " << BUILD_DATE <<
'\n'
708 }
catch (std::exception &e) {
709 logg[
LMain].fatal() <<
"SMASH failed with the following error:\n"
Interface to the SMASH configuration files.
bool has_value(std::initializer_list< const char * > keys) const
Returns whether there is a non-empty value behind the requested keys.
void merge_yaml(const std::string &yaml)
Merge the configuration in yaml into the existing tree.
std::string to_string() const
Returns a YAML string of the current tree.
std::string unused_values_report() const
Returns a string listing the key/value pairs that have not been taken yet.
Value take(std::initializer_list< const char * > keys)
The default interface for SMASH to read configuration values.
Value read(std::initializer_list< const char * > keys) const
Additional interface for SMASH to read configuration values without removing them.
Guard to create a file lock.
bool acquire()
Try to acquire the file lock.
A pointer-like interface to global references to ParticleType objects.
Particle type contains the static properties of a particle species.
void dump_width_and_spectral_function() const
Prints out width and spectral function versus mass to the standard output.
const std::string & name() const
PdgCode stores a Particle Data Group Particle Numbering Scheme particle type number.
A simple scatter finder: Just loops through all particles and checks each pair for a collision.
#define SMASH_SOURCE_LOCATION
Hackery that is required to output the location in the source code where the log statement occurs.
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Configuration configuration(std::string overrides={})
Return a configuration object filled with data from src/config.yaml.
std::unique_ptr< ExperimentBase > experiment(const Configuration &c=configuration())
Create an experiment.
void ignore_simulation_config_values(Configuration &configuration)
Remove all config values that are only needed for simulations.
bf::path default_output_path()
ScatterActionsFinder actions_finder_for_dump(Configuration configuration)
Prepares ActionsFinder for cross-section and reaction dumps.
void check_for_unused_config_values(const Configuration &configuration)
Checks if there are unused config values.
void ensure_path_is_valid(const bf::path &path)
Ensures the output path is valid.
void print_disclaimer()
Print the disclaimer.
void check_config_version_is_compatible(Configuration configuration)
Checks if the SMASH version is compatible with the version of the configuration file.
int64_t generate_63bit_seed()
Generates a seed with a truly random 63-bit value, if possible.
std::string fill_left(const std::string &s, size_t width, char fill=' ')
Fill string with characters to the left until the given width is reached.
std::vector< std::string > split(const std::string &s, char delim)
Split string by delimiter.
void initialize_particles_decays_and_tabulations(Configuration &configuration, const std::string &version, const std::string &tabulations_dir={})
Initialize the particles and decays from the given configuration, plus tabulate the resonance integra...
Configuration setup_config_and_logging(const std::string &config_file, const std::string &particles_file={}, const std::string &decaymodes_file={}, const std::vector< std::string > &extra_config={})
Set up configuration and logging from input files and extra config.
void setup_default_float_traps()
Setup the floating-point traps used throughout SMASH.
static constexpr int LMain
ExperimentParameters create_experiment_parameters(Configuration config)
Gathers all general Experiment parameters.
int main(int argc, char *argv[])
Main program Smashes Many Accelerated Strongly-Interacting Hadrons :-)
Helper structure for Experiment.
Exception class that is thrown, if the requested output directory already exists and -f was not speci...
Exception class that is thrown, if no new output path can be generated (there is a directory name for...