diff --git a/corsika/detail/output/OutputManager.inl b/corsika/detail/output/OutputManager.inl index af813534ea6761f502ab2f9ac33a5a8fc7ef3433..172afe3aea2df9bde4f47ad466670c4e9ef49dd2 100644 --- a/corsika/detail/output/OutputManager.inl +++ b/corsika/detail/output/OutputManager.inl @@ -23,11 +23,12 @@ namespace corsika { inline OutputManager::OutputManager( - std::string const& name, + std::string const& name, const long& vseed = 0, boost::filesystem::path const& dir = boost::filesystem::current_path()) : root_(dir / name) , name_(name) - , count_(0) { + , count_(0) + , seed_(vseed) { // check if this directory already exists if (boost::filesystem::exists(root_)) { @@ -112,6 +113,8 @@ namespace corsika { // the total number of showers contained in the library summary["showers"] = count_; + summary["seed"] = seed_; + // this next section handles writing some time and duration information // create a quick lambda function to convert a time-instance to a string diff --git a/corsika/output/OutputManager.hpp b/corsika/output/OutputManager.hpp index 8cc9a63600355507d6a9c2188a19b41a1a50c70a..f8be5cd575d4e2161d0d03b78abefb3697e38fdb 100644 --- a/corsika/output/OutputManager.hpp +++ b/corsika/output/OutputManager.hpp @@ -38,7 +38,8 @@ namespace corsika { * @param name The name of this output collection. * @param dir The directory where the output directory will be stored. */ - OutputManager(std::string const& name, boost::filesystem::path const& dir); + OutputManager(std::string const& name, const long& vseed, + boost::filesystem::path const& dir); /** * Handle graceful closure of the outputs upon destruction. @@ -107,6 +108,7 @@ namespace corsika { OutputState state_{OutputState::NoInit}; ///< The current state of this manager. std::string const name_; ///< The name of this simulation file. int count_{0}; ///< The current ID of this shower. + long seed_{0}; std::chrono::time_point<std::chrono::system_clock> const start_time{ std::chrono::system_clock::now()}; ///< The time the manager is created. inline static auto logger_{get_logger("output")}; ///< A custom logger. diff --git a/examples/corsika.cpp b/examples/corsika.cpp index 76f8a194b8278c34f78c744ce145c2881fd98bbf..a0c097f691439ea426ddcdff3806be3b65cffca0 100644 --- a/examples/corsika.cpp +++ b/examples/corsika.cpp @@ -90,7 +90,7 @@ using EnvType = Environment<EnvironmentInterface>; using Particle = setup::Stack<EnvType>::particle_type; -void registerRandomStreams(long seed) { +long registerRandomStreams(long seed) { RNGManager<>::getInstance().registerRandomStream("cascade"); RNGManager<>::getInstance().registerRandomStream("qgsjet"); RNGManager<>::getInstance().registerRandomStream("sibyll"); @@ -103,11 +103,12 @@ void registerRandomStreams(long seed) { if (seed == 0) { std::random_device rd; seed = rd(); - CORSIKA_LOG_INFO("random seed (auto) {} ", seed); + std::cout << "random seed (auto) " << seed << std::endl; } else { - CORSIKA_LOG_INFO("random seed {} ", seed); + std::cout << "random seed " << seed << std::endl; } RNGManager<>::getInstance().setSeed(seed); + return seed; } template <typename T> @@ -242,7 +243,7 @@ int main(int argc, char** argv) { } // initialize random number sequence(s) - registerRandomStreams(app["--seed"]->as<long>()); + auto seed = registerRandomStreams(app["--seed"]->as<long>()); /* === START: SETUP ENVIRONMENT AND ROOT COORDINATE SYSTEM === */ EnvType env; @@ -333,7 +334,7 @@ int main(int argc, char** argv) { EMThinning thinning{emthinfrac * E0, maxWeight, !multithin}; // create the output manager that we then register outputs with - OutputManager output(app["--filename"]->as<std::string>()); + OutputManager output(app["--filename"]->as<std::string>(), seed); // register energy losses as output EnergyLossWriter dEdX{showerAxis, 10_g / square(1_cm), 200}; diff --git a/tests/output/testOutputManager.cpp b/tests/output/testOutputManager.cpp index ee886f526bda289f3ddbd352682cab341852a696..b9680004346afac3f9d63ecbe1a9235e5c40d928 100644 --- a/tests/output/testOutputManager.cpp +++ b/tests/output/testOutputManager.cpp @@ -67,7 +67,7 @@ TEST_CASE("OutputManager") { } // output manager performs nothing, no action, just interface - OutputManager output("check", "./out_test"); + OutputManager output("check", 0, "./out_test"); CHECK(boost::filesystem::is_directory("./out_test/check")); @@ -105,7 +105,7 @@ TEST_CASE("OutputManager") { } // output manager performs nothing, no action, just interface - OutputManager* output = new OutputManager("check", "./out_test"); + OutputManager* output = new OutputManager("check", 0, "./out_test"); CHECK(boost::filesystem::is_directory("./out_test/check")); @@ -136,8 +136,8 @@ TEST_CASE("OutputManager") { } // output manager performs nothing, no action, just interface - OutputManager output("check", "./out_test"); - CHECK_THROWS(new OutputManager("check", "./out_test")); + OutputManager output("check", 0, "./out_test"); + CHECK_THROWS(new OutputManager("check", 0, "./out_test")); CHECK_THROWS(output.endOfLibrary());