CORSIKA  @c8_version@
The framework to simulate particle cascades for astroparticle physics
OutputManager.hpp
1 /*
2  * (c) Copyright 2021 CORSIKA Project, corsika-project@lists.kit.edu
3  *
4  * This software is distributed under the terms of the GNU General Public
5  * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
6  * the license.
7  */
8 #pragma once
9 
10 #include <chrono>
11 #include <string>
12 #include <boost/filesystem.hpp>
14 #include <corsika/output/BaseOutput.hpp>
15 #include <corsika/output/YAMLStreamer.hpp>
16 
17 namespace corsika {
18 
22  class OutputManager : public YAMLStreamer {
23 
27  enum class OutputState {
28  NoInit,
29  LibraryReady,
30  ShowerInProgress,
31  LibraryFinished,
32  };
33 
34  public:
41  OutputManager(std::string const& name, const long& vseed,
42  std::string const& input_args, boost::filesystem::path const& dir);
43 
48 
49  template <typename TOutput>
50  void add(std::string const& name, TOutput& output);
51 
57  YAML::Node getSummary() const;
58 
64  YAML::Node getConfig() const;
65 
66  private:
70  void writeConfig() const;
71 
75  void writeSummary() const;
76 
77  public:
81  void startOfLibrary();
82 
87  void startOfShower();
88 
93  void endOfShower();
94 
99  void endOfLibrary();
100 
104  int getEventId() const;
105 
106  private:
107  boost::filesystem::path root_;
108  OutputState state_{OutputState::NoInit};
109  std::string const name_;
110  std::string const cmnd_line_args_;
111  int count_{0};
112  long seed_{0};
113  std::chrono::time_point<std::chrono::system_clock> const start_time{
114  std::chrono::system_clock::now()};
115  inline static auto logger_{get_logger("output")};
116 
119  std::map<std::string, std::reference_wrapper<BaseOutput>> outputs_;
120 
121  }; // class OutputManager
122 
123 } // namespace corsika
124 
125 #include <corsika/detail/output/OutputManager.inl>
YAML::Node getConfig() const
Produces the config YAML.
OutputManager(std::string const &name, const long &vseed, std::string const &input_args, boost::filesystem::path const &dir)
Construct an OutputManager instance with a name in a given directory.
~OutputManager()
Handle graceful closure of the outputs upon destruction.
This class automates the construction of simple tabular YAML files using the YAML::StreamWriter.
std::shared_ptr< spdlog::logger > get_logger(std::string const &name, bool const defaultlog=false)
Get a smart pointer to an existing logger.
int getEventId() const
Return current event number.
void startOfShower()
Called at the start of each event/shower.
CORSIKA8 logging utilities.
`, since they are used everywhere as integral part of the framework.
YAML::Node getSummary() const
Produces the summary YAML.
void endOfLibrary()
Called at the end of each library.
void endOfShower()
Called at the end of each event/shower.
void startOfLibrary()
Called at the start of each library.