MarlinMT  0.1.0
marlinmt::book::BookStore Class Reference

Managed Access and creation of Objects. More...

#include <BookStore.h>

Classes

class  Identifier
 holds references for identify an entry. More...
 

Public Member Functions

 BookStore (bool allowMoving=false)
 
template<class T >
Handle< Entry< typename T::Object_t > > book (const std::filesystem::path &path, const std::string_view &name, const T &data)
 book new object. More...
 
template<typename T >
Handle< Entry< T > > entry (const EntryKey &key) const
 get access to entry from key. More...
 
Selection find (const Condition &cond) const
 select every Entry which matches the condition. More...
 
WeakEntry findFirst (const Condition &cond) const
 find first Entry which match the condition. More...
 
void remove (const EntryKey &key)
 removes an Entry from BookStore. More...
 
void remove (const Selection &selection)
 removes every Entry from the selection from the BookStore. More...
 
void clear ()
 clears the store. More...
 
void store (StoreWriter &writer) const
 saves all Objects in one Root-File. More...
 
template<typename Itr >
void storeList (StoreWriter &writer, Itr begin, Itr end) const
 stores only Objects which key is listed. More...
 
void storeSelection (StoreWriter &writer, const Selection &selection) const
 stores all objects from the selection. More...
 

Private Member Functions

std::shared_ptr< details::EntryaddEntry (const std::shared_ptr< EntryBase > &entry, EntryKey key)
 register Entry in store. More...
 
const std::shared_ptr< details::Entry > & getPtr (const EntryKey &key) const
 
template<class T , typename... Args_t>
std::shared_ptr< details::EntrybookSingle (std::filesystem::path path, Args_t... ctor_p)
 creates an Entry for a default Object. More...
 
template<class T , void(*)(const std::shared_ptr< T > &, const std::shared_ptr< T > &) MERGE, typename... Args_t>
std::shared_ptr< details::EntrybookMultiCopy (std::size_t n, std::filesystem::path path, Args_t... ctor_p)
 creates an Entry for parallel access. More...
 
template<class T , typename... Args_t>
std::shared_ptr< details::EntrybookMultiShared (std::size_t n, std::filesystem::path path, Args_t... ctor_p)
 creates an Entry for parallel access. More...
 
const details::Entryget (std::size_t const idx) const
 get Entry from key. More...
 
const details::Entryget (const EntryKey &key) const
 get Entry from key. More...
 
details::Entryget (std::size_t const idx)
 get Entry from key. More...
 
details::Entryget (const EntryKey &key)
 get Entry from key. More...
 

Static Private Member Functions

static std::filesystem::path normalizeDirPath (const std::filesystem::path &path)
 normalize and check path for internal usage. More...
 

Private Attributes

std::vector< std::shared_ptr< details::Entry > > _entries {}
 stores Entries created by BookStore. More...
 
std::unordered_map< Identifier, std::size_t, Identifier::Hash_idToEntry {}
 stores path+name -> Entry Id More...
 
std::thread::id _constructThread
 
const bool _allowMoving {false}
 when false only allow booking from construction thread. Avoid races. More...
 

Friends

template<typename , unsigned long long>
class EntryData
 

Detailed Description

Managed Access and creation of Objects.

Definition at line 96 of file BookStore.h.

Constructor & Destructor Documentation

◆ BookStore()

marlinmt::book::BookStore::BookStore ( bool  allowMoving = false)
inlineexplicit

Definition at line 232 of file BookStore.h.

Member Function Documentation

◆ addEntry()

std::shared_ptr< details::Entry > marlinmt::book::BookStore::addEntry ( const std::shared_ptr< EntryBase > &  entry,
EntryKey  key 
)
private

register Entry in store.

generate id for Entry.

Returns
shared pointer to new Entry

Definition at line 23 of file BookStore.cc.

References marlinmt::book::EntryKey::idx, MARLIN_BOOK_THROW, and marlinmt::book::EntryKey::path.

◆ book()

template<class T >
Handle< Entry< typename T::Object_t > > marlinmt::book::BookStore::book ( const std::filesystem::path &  path,
const std::string_view &  name,
const T &  data 
)

book new object.

Parameters
pathto store object.
nameof object.
Note
path + name must be unique in the store.
Parameters
datadescribing access and construction of object.
Exceptions
BookStoreExceptionwhen:
  • object with same path + name already exist
  • book was constructed in different thread.
See also
{_allowMoving}

Definition at line 389 of file BookStore.h.

References MARLIN_BOOK_THROW.

Referenced by marlinmt::BookStoreManager::bookHist().

◆ bookMultiCopy()

template<class T , void(*)(const std::shared_ptr< T > &, const std::shared_ptr< T > &) MERGE, typename... Args_t>
std::shared_ptr< details::Entry > marlinmt::book::BookStore::bookMultiCopy ( std::size_t  n,
std::filesystem::path  path,
Args_t...  ctor_p 
)
private

creates an Entry for parallel access.

Creates Multiple copy's of the object to avoid locks.

See also
BookStore::book
Note
getting the results is triggers a merging → expensive.
Parameters
nnumber of instances which should be created. (max level of pluralism)

Definition at line 352 of file BookStore.h.

References marlinmt::book::Flags::Book::MultiCopy(), and marlinmt::book::EntryKey::path.

Referenced by marlinmt::book::EntryMultiShared< types::HistT< Config > >::handle().

◆ bookMultiShared()

template<class T , typename... Args_t>
std::shared_ptr< details::Entry > marlinmt::book::BookStore::bookMultiShared ( std::size_t  n,
std::filesystem::path  path,
Args_t...  ctor_p 
)
private

creates an Entry for parallel access.

Creates one object in Memory and modifiers.

Parameters
nnumber of Static Modifiers

Definition at line 370 of file BookStore.h.

References marlinmt::book::Flags::Book::MultiShared(), and marlinmt::book::EntryKey::path.

Referenced by marlinmt::book::EntryMultiShared< types::HistT< Config > >::handle().

◆ bookSingle()

template<class T , typename... Args_t>
std::shared_ptr< details::Entry > marlinmt::book::BookStore::bookSingle ( std::filesystem::path  path,
Args_t...  ctor_p 
)
private

creates an Entry for a default Object.

Template Parameters
Tobject which should be booked.
Args_ttypes of parameters to construct T.
Parameters
pathlocation to store the Entry.
namename of the Entry.
ctor_pparameters to construct the object.

Definition at line 332 of file BookStore.h.

References marlinmt::book::EntryKey::path, and marlinmt::book::Flags::Book::Single().

Referenced by marlinmt::book::EntryMultiShared< types::HistT< Config > >::handle().

◆ clear()

void marlinmt::book::BookStore::clear ( )

clears the store.

the handles keep a reference to the result.

Attention
modifying removed objects results in undefined behavior.

Definition at line 81 of file BookStore.cc.

◆ entry()

template<typename T >
Handle< Entry< T > > marlinmt::book::BookStore::entry ( const EntryKey key) const

get access to entry from key.

Definition at line 491 of file BookStore.h.

Referenced by marlinmt::BookStoreManager::getObject().

◆ find()

Selection marlinmt::book::BookStore::find ( const Condition cond) const

select every Entry which matches the condition.

Returns
Selection with matches Entries.

Definition at line 57 of file BookStore.cc.

◆ findFirst()

WeakEntry marlinmt::book::BookStore::findFirst ( const Condition cond) const

find first Entry which match the condition.

Returns
WeakEntry which is not valid if no Entry was found.

Definition at line 63 of file BookStore.cc.

Referenced by marlinmt::BookStoreManager::getKey().

◆ get() [1/4]

const details::Entry& marlinmt::book::BookStore::get ( std::size_t const  idx) const
inlineprivate

get Entry from key.

Exceptions
BookStoreExceptionkey not exist in Store.

Definition at line 197 of file BookStore.h.

References MARLIN_BOOK_THROW.

◆ get() [2/4]

const details::Entry& marlinmt::book::BookStore::get ( const EntryKey key) const
inlineprivate

get Entry from key.

Exceptions
BookStoreExceptionkey not exist in Store.

Definition at line 209 of file BookStore.h.

◆ get() [3/4]

details::Entry& marlinmt::book::BookStore::get ( std::size_t const  idx)
inlineprivate

get Entry from key.

Exceptions
BookStoreExceptionkey not exist in Store.

Definition at line 215 of file BookStore.h.

References MARLIN_BOOK_THROW.

◆ get() [4/4]

details::Entry& marlinmt::book::BookStore::get ( const EntryKey key)
inlineprivate

get Entry from key.

Exceptions
BookStoreExceptionkey not exist in Store.

Definition at line 227 of file BookStore.h.

◆ getPtr()

const std::shared_ptr<details::Entry>& marlinmt::book::BookStore::getPtr ( const EntryKey key) const
inlineprivate
Parameters
keyfor Entry which is demanded.
Exceptions
BookStoreExceptionkey not exist in Store
Returns
shared pointer to details::Entry with given key.

Definition at line 136 of file BookStore.h.

References marlinmt::book::EntryKey::idx, and MARLIN_BOOK_THROW.

◆ normalizeDirPath()

std::filesystem::path marlinmt::book::BookStore::normalizeDirPath ( const std::filesystem::path &  path)
staticprivate

normalize and check path for internal usage.

Exceptions
BookStoreExceptionif path is no absolute path to a directory.
Parameters
pathabsolute directory path.

Definition at line 92 of file BookStore.cc.

References MARLIN_BOOK_THROW.

◆ remove() [1/2]

void marlinmt::book::BookStore::remove ( const EntryKey key)

removes an Entry from BookStore.

the handles are keeping a reference to the result.

Attention
modifying removed objects results in undefined behavior.

Definition at line 69 of file BookStore.cc.

◆ remove() [2/2]

void marlinmt::book::BookStore::remove ( const Selection selection)

removes every Entry from the selection from the BookStore.

calls BookStore::remove(const Entry &e) for every Entry in Selection.

Definition at line 73 of file BookStore.cc.

◆ store()

void marlinmt::book::BookStore::store ( StoreWriter writer) const

saves all Objects in one Root-File.

Parameters
writerused to serialize objects.
Exceptions
BookStoreExceptionwhen: Sere kisser
  • directory to store not exist.

Definition at line 39 of file BookStore.cc.

References marlinmt::book::StoreWriter::writeSelection().

◆ storeList()

template<typename Itr >
void marlinmt::book::BookStore::storeList ( StoreWriter writer,
Itr  begin,
Itr  end 
) const

stores only Objects which key is listed.

Parameters
writerused to serialize objects.
beginof list with keys
endof list with keys (not included)
Template Parameters
ItrIterator type used for traversing keys

Definition at line 471 of file BookStore.h.

References marlinmt::book::Selection::find().

Referenced by marlinmt::BookStoreManager::writeToDisk().

◆ storeSelection()

void marlinmt::book::BookStore::storeSelection ( StoreWriter writer,
const Selection selection 
) const

stores all objects from the selection.

Parameters
writerused to serialize objects.
selectionwhich includes objects to write.

Definition at line 50 of file BookStore.cc.

References marlinmt::book::StoreWriter::writeSelection().

Friends And Related Function Documentation

◆ EntryData

template<typename , unsigned long long>
friend class EntryData
friend

Definition at line 98 of file BookStore.h.

Member Data Documentation

◆ _allowMoving

const bool marlinmt::book::BookStore::_allowMoving {false}
private

when false only allow booking from construction thread. Avoid races.

Definition at line 325 of file BookStore.h.

◆ _constructThread

std::thread::id marlinmt::book::BookStore::_constructThread
private

Definition at line 323 of file BookStore.h.

◆ _entries

std::vector< std::shared_ptr< details::Entry > > marlinmt::book::BookStore::_entries {}
private

stores Entries created by BookStore.

Definition at line 319 of file BookStore.h.

◆ _idToEntry

std::unordered_map< Identifier, std::size_t, Identifier::Hash > marlinmt::book::BookStore::_idToEntry {}
private

stores path+name -> Entry Id

Definition at line 322 of file BookStore.h.


The documentation for this class was generated from the following files: