15 #include <boost/filesystem/fstream.hpp>
27 #include "smash/config.h"
43 void usage(
const int rc,
const std::string &progname) {
131 std::printf(
"\nUsage: %s [option]\n\n", progname.c_str());
133 " -h, --help usage information\n"
135 " -i, --inputfile <file> path to input configuration file\n"
136 " (default: ./config.yaml)\n"
137 " -d, --decaymodes <file> override default decay modes from file\n"
138 " -p, --particles <file> override default particles from file\n"
140 " -c, --config <YAML> specify config value overrides\n"
141 " (multiple -c arguments are supported)\n"
142 " -m, --modus <modus> shortcut for -c 'General: { Modus: <modus> "
144 " -e, --endtime <time> shortcut for -c 'General: { End_Time: <time> "
148 " -o, --output <dir> output directory (default: ./data/<runid>)\n"
149 " -l, --list-2-to-n list all possible 2->n reactions (with n>1)\n"
150 " -r, --resonance <pdg> dump width(m) and m*spectral function(m^2)"
151 " for resonance pdg\n"
152 " -s, --cross-sections <pdg1>,<pdg2>[,mass1,mass2[,plab1,...]] \n"
153 " dump all partial cross-sections of "
154 "pdg1 + pdg2 reactions versus sqrt(s).\n"
155 " -S, --cross-sections-fs <pdg1>,<pdg2>[,mass1,mass2[,plab1,...]] \n"
156 " dump an approximation of the final-state"
158 " of pdg1 + pdg2 reactions versus sqrt(s).\n"
159 " Contributions from strings are not considered"
160 " for the final state.\n"
161 " Masses are optional, by default pole masses"
163 " Note the required comma and no spaces.\n"
164 " -f, --force force overwriting files in the output "
167 " -x, --dump_iSS Dump particle table in iSS format\n"
168 " This format is used in MUSIC and CLVisc\n"
169 " relativistic hydro codes\n"
170 " -q, --quiet Supress disclaimer print-out\n"
171 " -n, --no-cache Don't cache integrals on disk\n"
172 " -v, --version\n\n");
179 <<
"###################################################################"
188 <<
" mss'.. ...s'm. sSA##As mAhh##hsh##s. .hA##ASa sS###As "
190 <<
" :a':'. .'':as sM#' .HHm''HMS''AMs mMA' .AMs aMA. "
192 <<
" .a:s'. ..''ss 'h#H#S. mMm 'M#' .HH. 'MH. :MA 'h#H#S. "
194 <<
" .::ss'. .... 'SMm .HH. SMa hMm sM#..mHMs 'AMa "
196 <<
" .s::' #SMASHh aMS .MH: HM: #MMMmMM. #SMASHh "
199 <<
"###################################################################"
202 <<
" This is SMASH version: " << VERSION_MAJOR <<
"\n"
203 <<
" Simulating Many Accelerated Strongly-interacting Hadrons"
206 <<
" Distributed under the GNU General Public License 3.0"
207 <<
" (GPLv3 or later)."
209 <<
" See LICENSE for details."
211 <<
" For the full list of contributors see AUTHORS."
214 <<
" When using SMASH, please cite"
216 <<
" J. Weil et al., Phys.Rev. C94 (2016) no.5, 054905"
218 <<
" together with the software DOI for the specific code version "
221 <<
" https://doi.org/10.5281/zenodo.3484711."
223 <<
" In addition, if Pythia is used please cite"
225 <<
" T. Sjöstrand, S. Mrenna and P. Skands, JHEP05 (2006) 026,"
227 <<
" Comput. Phys. Comm. 178 (2008) 852."
230 <<
" Webpage: https://smash-transport.github.io"
233 <<
" Report issues at https://github.com/smash-transport/smash"
235 <<
" or contact us by email at elfner@itp.uni-frankfurt.de"
238 <<
"###################################################################"
250 using std::runtime_error::runtime_error;
259 using std::runtime_error::runtime_error;
264 const bf::path
p = bf::absolute(
"data");
265 if (!bf::exists(
p)) {
269 for (
int id = 0; id < std::numeric_limits<int>::max(); ++id) {
270 p2 =
p / std::to_string(
id);
271 if (!bf::exists(p2)) {
288 if (bf::exists(path)) {
289 if (!bf::is_directory(path)) {
291 ") exists, but it is not a directory.");
294 if (!bf::create_directories(path)) {
296 "Race condition detected: The directory " + path.native() +
297 " did not exist a few cycles ago, but was created in the meantime by "
298 "a different process.");
323 const std::string smash_version =
"1.8";
324 const std::set<std::string> compatible_config_versions = {
"1.8"};
328 if (compatible_config_versions.find(config_version) ==
329 compatible_config_versions.end()) {
330 std::stringstream err;
331 err <<
"The version of the configuration file (" << config_version
332 <<
") is not compatible with the SMASH version (" << smash_version
333 <<
").\nThe following config versions are supported:\n";
334 for (
auto it : compatible_config_versions) {
337 err <<
"\nPlease consider updating your config or using a compatible SMASH"
339 throw std::runtime_error(err.str());
349 if (report !=
"{}") {
350 throw std::runtime_error(
351 "The following configuration values were not used:\n" + report);
362 for (
const std::string s :
363 {
"Version",
"particles",
"decaymodes",
"Modi",
"General",
"Output",
364 "Lattice",
"Potentials",
"Forced_Thermalization"}) {
383 bf::path tabulations_path) {
385 logg[
LMain].info(
"Tabulating cross section integrals...");
403 int main(
int argc,
char *argv[]) {
404 using namespace smash;
406 constexpr option longopts[] = {
407 {
"config", required_argument, 0,
'c'},
408 {
"decaymodes", required_argument, 0,
'd'},
409 {
"endtime", required_argument, 0,
'e'},
410 {
"force", no_argument, 0,
'f'},
411 {
"help", no_argument, 0,
'h'},
412 {
"inputfile", required_argument, 0,
'i'},
413 {
"modus", required_argument, 0,
'm'},
414 {
"particles", required_argument, 0,
'p'},
415 {
"output", required_argument, 0,
'o'},
416 {
"list-2-to-n", no_argument, 0,
'l'},
417 {
"resonance", required_argument, 0,
'r'},
418 {
"cross-sections", required_argument, 0,
's'},
419 {
"cross-sections-fs", required_argument, 0,
'S'},
420 {
"dump-iSS", no_argument, 0,
'x'},
421 {
"version", no_argument, 0,
'v'},
422 {
"no-cache", no_argument, 0,
'n'},
423 {
"quiet", no_argument, 0,
'q'},
427 const std::string progname = bf::path(argv[0]).filename().native();
430 bool force_overwrite =
false;
432 std::vector<std::string> extra_config;
433 char *particles =
nullptr, *decaymodes =
nullptr, *modus =
nullptr,
434 *end_time =
nullptr, *pdg_string =
nullptr, *cs_string =
nullptr;
435 bool list2n_activated =
false;
436 bool resonance_dump_activated =
false;
437 bool cross_section_dump_activated =
false;
438 bool final_state_cross_sections =
false;
439 bool particles_dump_iSS_format =
false;
440 bool cache_integrals =
true;
444 bool suppress_disclaimer =
false;
445 while ((opt = getopt_long(argc, argv,
"c:d:e:fhi:m:p:o:lr:s:S:xvnq",
446 longopts,
nullptr)) != -1) {
449 extra_config.emplace_back(optarg);
455 force_overwrite =
true;
461 usage(EXIT_SUCCESS, progname);
473 output_path = optarg;
476 list2n_activated =
true;
477 suppress_disclaimer =
true;
480 resonance_dump_activated =
true;
482 suppress_disclaimer =
true;
485 final_state_cross_sections =
true;
488 cross_section_dump_activated =
true;
490 suppress_disclaimer =
true;
493 particles_dump_iSS_format =
true;
494 suppress_disclaimer =
true;
499 "Branch : %s\nSystem : %s\nCompiler : %s %s\n"
500 "Build : %s\nDate : %s\n",
501 VERSION_MAJOR, GIT_BRANCH, CMAKE_SYSTEM, CMAKE_CXX_COMPILER_ID,
502 CMAKE_CXX_COMPILER_VERSION, CMAKE_BUILD_TYPE, BUILD_DATE);
503 std::exit(EXIT_SUCCESS);
505 cache_integrals =
false;
508 suppress_disclaimer =
true;
511 usage(EXIT_FAILURE, progname);
517 std::cout << argv[0] <<
": invalid argument -- '" << argv[optind]
519 usage(EXIT_FAILURE, progname);
522 if (!suppress_disclaimer) {
528 input_path.filename());
530 for (
const auto &config : extra_config) {
545 " create ParticleType and DecayModes");
547 auto particles_and_decays =
554 "Ambiguity: particles from external file ", particles,
555 " requested, but there is also particle list in the config."
556 " Using particles from ",
565 "Ambiguity: decaymodes from external file ", decaymodes,
566 " requested, but there is also decaymodes list in the config."
567 " Using decaymodes from",
575 const std::string version(VERSION_MAJOR);
579 hash_context.
update(version);
580 hash_context.
update(particle_string);
581 hash_context.
update(decay_string);
582 const auto hash = hash_context.
finalize();
585 bf::path tabulations_path;
586 if (cache_integrals) {
587 tabulations_path = output_path.parent_path() /
"tabulations";
588 bf::create_directories(tabulations_path);
589 logg[
LMain].info() <<
"Tabulations path: " << tabulations_path;
591 tabulations_path =
"";
593 if (list2n_activated) {
597 logg[
LMain].info() <<
"Tabulations path: " << tabulations_path;
604 scat_finder.dump_reactions();
605 std::exit(EXIT_SUCCESS);
607 if (particles_dump_iSS_format) {
609 ParticleTypePtrList list;
611 for (
const auto &ptype : ParticleType::list_all()) {
612 list.push_back(&ptype);
614 std::sort(list.begin(), list.end(),
616 return a->mass() < b->mass();
619 if (ptype->pdgcode().is_lepton() || ptype->baryon_number() < 0) {
622 const auto &decay_modes = ptype->decay_modes();
623 const auto &modelist = decay_modes.decay_mode_list();
624 int ndecays = ptype->is_stable() ? 1 : modelist.size();
625 std::printf(
"%13i %s %10.5f %10.5f %5i %5i %5i %5i %5i %5i %5i %5i\n",
626 ptype->pdgcode().get_decimal(),
628 ptype->mass(), ptype->width_at_pole(),
629 ptype->pdgcode().spin_degeneracy(), ptype->baryon_number(),
630 ptype->strangeness(), ptype->pdgcode().charmness(),
631 ptype->pdgcode().bottomness(), ptype->isospin() + 1,
632 ptype->charge(), ndecays);
633 if (!ptype->is_stable()) {
634 for (
const auto &decay : modelist) {
635 auto ptypes = decay->particle_types();
636 std::printf(
"%13i %13i %20.5f %13i %13i %13i %13i %13i\n",
637 ptype->pdgcode().get_decimal(), 2, decay->weight(),
638 ptypes[0]->pdgcode().get_decimal(),
639 ptypes[1]->pdgcode().get_decimal(), 0, 0, 0);
642 std::printf(
"%13i %13i %20.5f %13i %13i %13i %13i %13i\n",
643 ptype->pdgcode().get_decimal(), 1, 1.0,
644 ptype->pdgcode().get_decimal(), 0, 0, 0, 0);
647 std::exit(EXIT_SUCCESS);
649 if (resonance_dump_activated) {
652 const auto _dummy = ExperimentBase::create(
configuration,
"");
659 std::exit(EXIT_SUCCESS);
661 if (cross_section_dump_activated) {
663 std::string arg_string(cs_string);
664 std::vector<std::string> args =
split(arg_string,
',');
665 const unsigned int n_arg = args.size();
666 if (n_arg != 2 && n_arg != 4 && n_arg < 5) {
667 throw std::invalid_argument(
"-s usage: pdg1,pdg2[,m1,m2[,sqrts1,...]]");
669 PdgCode pdg_a(args[0]), pdg_b(args[1]);
673 for (
unsigned int i = 0; i < 4 - n_arg; i++) {
677 double ma = (args[2] ==
"") ? a.
mass() : std::stod(args[2]);
678 double mb = (args[3] ==
"") ? b.
mass() : std::stod(args[3]);
679 if (a.
is_stable() && args[2] !=
"" && std::stod(args[2]) != a.
mass()) {
681 std::cerr <<
"Warning: pole mass is used for stable particle "
682 << a.
name() <<
" instead of " << args[2] << std::endl;
684 if (b.
is_stable() && args[3] !=
"" && std::stod(args[3]) != b.
mass()) {
686 std::cerr <<
"Warning: pole mass is used for stable particle "
687 << b.
name() <<
" instead of " << args[3] << std::endl;
689 const size_t plab_size = n_arg <= 4 ? 0 : n_arg - 4;
690 std::vector<double> plab;
691 plab.reserve(plab_size);
692 for (
size_t i = 4; i < n_arg; i++) {
693 plab.push_back(std::stod(args.at(i)));
700 scat_finder.dump_cross_sections(a, b, ma, mb, final_state_cross_sections,
702 std::exit(EXIT_SUCCESS);
708 configuration[
"General"][
"End_Time"] = std::abs(std::atof(end_time));
718 const bf::path lock_path = output_path /
"smash.lock";
721 throw std::runtime_error(
722 "Another instance of SMASH is already writing to the specified "
723 "output directory. If you are sure this is not the case, remove \"" +
724 lock_path.native() +
"\".");
726 logg[
LMain].debug(
"output path: ", output_path);
727 if (!force_overwrite && bf::exists(output_path /
"config.yaml")) {
728 throw std::runtime_error(
729 "Output directory would get overwritten. Select a different output "
730 "directory, clean up, or tell SMASH to ignore existing files.");
735 bf::ofstream(output_path /
"config.yaml")
736 <<
"# " << VERSION_MAJOR <<
'\n'
737 <<
"# Branch : " << GIT_BRANCH <<
'\n'
738 <<
"# System : " << CMAKE_SYSTEM <<
'\n'
739 <<
"# Compiler : " << CMAKE_CXX_COMPILER_ID <<
' '
740 << CMAKE_CXX_COMPILER_VERSION <<
'\n'
741 <<
"# Build : " << CMAKE_BUILD_TYPE <<
'\n'
742 <<
"# Date : " << BUILD_DATE <<
'\n'
745 " create ParticleType and DecayModes");
760 }
catch (std::exception &e) {
761 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.
static void load_decaymodes(const std::string &input)
Loads the DecayModes map as described in the input string.
Guard to create a file lock.
bool acquire()
Try to acquire the file lock.
static void tabulate_integrals(sha256::Hash hash, const bf::path &tabulations_path)
Tabulate all relevant integrals.
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.
static void check_consistency()
const std::string & name() const
static void create_type_list(const std::string &particles)
Initialize the global ParticleType list (list_all) from the given input data.
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.
void update(uint8_t const *buffer, size_t buffer_size)
Add data to the SHA256 context.
Hash finalize()
Performs the final calculation of the hash and returns the digest (32 byte buffer containing 256bit h...
#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.
void set_default_loglevel(einhard::LogLevel level)
Set the default log level (what will be returned from subsequent default_loglevel calls).
void create_all_loggers(Configuration config)
Called from main() right after the Configuration object is fully set up to create all 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 initialize_particles_and_decays(Configuration &configuration, sha256::Hash hash, bf::path tabulations_path)
Initialize the particles and decays from the configuration, the hash and the path to the cashed reson...
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::array< uint8_t, HASH_SIZE > Hash
A SHA256 hash.
std::string hash_to_string(Hash hash)
Convert a SHA256 hash to a hexadecimal string.
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.
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.
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...