MarlinMT  0.1.0
BookStoreManager.h
Go to the documentation of this file.
1 #pragma once
2 
3 // -- marlinmt headers
5 #include <marlinmt/Component.h>
6 #include <marlinmt/Logging.h>
7 
8 // -- std includes
9 #include <unistd.h>
10 #include <set>
11 
12 namespace marlinmt {
13 
14  // forward declaration
15  class Application ;
16  class Processor ;
17 
21  class BookStoreManager : public Component {
22  public:
25 
26  BookStoreManager( const BookStoreManager & ) = delete ;
27  BookStoreManager &operator=( const BookStoreManager & ) = delete ;
28  BookStoreManager( BookStoreManager && ) = delete ;
30 
35  void writeToDisk() const ;
36 
38  void initialize() override ;
39 
50  template<typename HistT>
52  const std::filesystem::path &path,
53  const std::string_view &name,
54  const std::string_view &title,
55  const std::array<
57  HistT::Dimension> &axesconfig,
58  const BookFlag_t &flags ) ;
59 
63  void addToWrite(const book::EntryKey& key) ;
64 
68  void removeFromWrite(const book::EntryKey& key) ;
69 
73  struct ObjectNotFound : public std::exception {
74  ObjectNotFound(const std::string_view& msg)
75  : m_msg(msg) {}
76  const char* what() const noexcept override { return m_msg.c_str(); }
77  private:
78  const std::string m_msg;
79  };
80 
89  const book::EntryKey& getKey(
90  const std::filesystem::path &path,
91  const std::string_view &name) const ;
92 
93 
99  template<typename T>
100  [[nodiscard]] book::Handle<book::Entry<T>> getObject(
101  const book::EntryKey &key) const ;
102 
103 
104  private:
108  std::set<book::EntryKey> _entriesToWrite {} ;
110  StringParameter _outputFile {*this, "OutputFile", "The output file name for storage", "MarlinMT_"+details::convert<int>::to_string(::getpid())+".root"} ;
112  StringParameter _defaultMemLayout {*this, "DefaultMemoryLayout", "The memory layout for objects", "Default"} ;
116  };
117 
118 
119 }
static constexpr std::size_t Dimension
Dimension of the histogram.
Definition: Base.h:187
BookStoreManager & operator=(const BookStoreManager &)=delete
Data selection to identify and manage an Entry.
Definition: EntryData.h:21
StringParameter _defaultMemLayout
Output file name to store objects.
const std::string & name() const
Get the component name.
Definition: Component.cc:23
Managed Access and creation of Objects.
Definition: BookStore.h:96
book::Handle< book::Entry< HistT > > bookHist(const std::filesystem::path &path, const std::string_view &name, const std::string_view &title, const std::array< const AxisConfig< typename HistT::Precision_t > *, HistT::Dimension > &axesconfig, const BookFlag_t &flags)
Book a histogram 1D, float type.
BookStoreManager class.
const char * what() const noexcept override
Flag type for flags in marlinmt::book.
Definition: Flags.h:15
std::set< book::EntryKey > _entriesToWrite
List of entry keys for Entries which should be stored at end of lifetime.
void initialize() override
Initialize the book store manager.
void writeToDisk() const
reads output File from global StoreOutputFile.
book::Handle< book::Entry< T > > getObject(const book::EntryKey &key) const
access object managed by this store.
void removeFromWrite(const book::EntryKey &key)
remove entry key from write list.
Component class.
Definition: Component.h:22
collection for Axis Description
Definition: Base.h:23
thrown when try to access not existing object.
static std::string to_string(const T &value)
Definition: Utils.h:370
vanilla Handle.
Definition: Handle.h:54
const book::EntryKey & getKey(const std::filesystem::path &path, const std::string_view &name) const
receive key from Entry with given path and name.
void addToWrite(const book::EntryKey &key)
add entry key to write list.
ObjectNotFound(const std::string_view &msg)
BookFlag_t _defaultFlag
default flag, used if flag == BookFlags::Default.
book::BookStore _bookStore
The book store.
StringParameter _outputFile
Output file name to store objects.