CORSIKA8  0.0.0
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>
13 #include <corsika/output/BaseOutput.hpp>
15 
16 namespace corsika {
17 
21  class OutputManager final {
22 
26  enum class OutputState {
27  NoInit,
28  LibraryReady,
29  ShowerInProgress,
30  LibraryFinished,
31  };
32 
33  OutputState state_{OutputState::NoInit};
34  std::string const name_;
35  boost::filesystem::path const root_;
36  int count_{0};
37  std::chrono::time_point<std::chrono::system_clock> const start_time{
38  std::chrono::system_clock::now()};
39  inline static auto logger{get_logger("output")};
40 
43  std::map<std::string, std::reference_wrapper<BaseOutput>> outputs_;
44 
48  void writeNode(YAML::Node const& node, boost::filesystem::path const& path) const;
49 
53  void writeTopLevelConfig() const;
54 
58  void initOutput(std::string const& name) const;
59 
63  void writeTopLevelSummary() const;
64 
65  public:
72  OutputManager(std::string const& name, boost::filesystem::path const& dir);
73 
78 
86  template <typename TOutput>
87  void add(std::string const& name, TOutput& output);
88 
94  void startOfLibrary();
95 
100  void startOfShower();
101 
106  void endOfShower();
107 
112  void endOfLibrary();
113 
114  }; // class OutputManager
115 
116 } // namespace corsika
117 
118 #include <corsika/detail/output/OutputManager.inl>
~OutputManager()
Handle graceful closure of the outputs upon destruction.
void add(std::string const &name, TOutput &output)
Register an existing output to this manager.
std::shared_ptr< spdlog::logger > get_logger(std::string const &name, bool const defaultlog=false)
Get a smart pointer to an existing logger.
void startOfShower()
Called at the start of each event/shower.
CORSIKA8 logging utilities.
OutputManager(std::string const &name, boost::filesystem::path const &dir)
Construct an OutputManager instance with a name in a given directory.
The cascade namespace assembles all objects needed to simulate full particles cascades.
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.