PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
podio::EventStore Class Reference

#include <EventStore.h>

+ Inheritance diagram for podio::EventStore:

Public Types

typedef std::pair< std::string, CollectionBase * > CollPair
 Collection entry. Each collection is identified by a name.
 
typedef std::vector< CollPairCollContainer
 

Public Member Functions

 EventStore (const EventStore &)=delete
 Make non-copyable.
 
EventStoreoperator= (const EventStore &)=delete
 
 EventStore ()
 
 ~EventStore ()
 
template<typename T >
T & create (const std::string &name)
 create a new collection
 
void registerCollection (const std::string &name, podio::CollectionBase *coll)
 register an existing collection
 
template<typename T >
bool get (const std::string &name, const T *&collection)
 access a collection by name. returns true if successful
 
CollectionBasegetFast (int id) const
 fast access to cached collections
 
bool get (int id, CollectionBase *&coll) const final
 access a collection by ID. returns true if successful
 
template<typename T >
const T & get (const std::string &name)
 
void clearCollections ()
 empties collections.
 
void clear ()
 clears itself; deletes collections (use at end of event processing)
 
void clearCaches ()
 Clears only the cache containers (use at end of event if ownership of read objects is transferred)
 
void setReader (IReader *reader)
 set the reader
 
CollectionIDTablegetCollectionIDTable () const
 
virtual bool isValid () const final
 
GenericParametersgetEventMetaData () override
 return the event meta data for the current event
 
GenericParametersgetRunMetaData (int runID) override
 return the run meta data for the given runID
 
GenericParametersgetCollectionMetaData (int colID) override
 return the collection meta data for the given colID
 
RunMDMapgetRunMetaDataMap ()
 
ColMDMapgetColMetaDataMap ()
 
GenericParameterseventMetaDataPtr ()
 
- Public Member Functions inherited from podio::ICollectionProvider
virtual ~ICollectionProvider ()=default
 destructor
 
virtual bool get (int collectionID, CollectionBase *&collection) const =0
 access a collection by ID. returns true if successful
 
- Public Member Functions inherited from podio::IMetaDataProvider
virtual ~IMetaDataProvider ()=default
 destructor
 
virtual GenericParametersgetEventMetaData ()=0
 return the event meta data for the current event
 
virtual GenericParametersgetRunMetaData (int runID)=0
 return the run meta data for the given runID
 
virtual GenericParametersgetCollectionMetaData (int colID)=0
 return the collection meta data for the given colID
 

Detailed Description

Definition at line 37 of file EventStore.h.

Member Typedef Documentation

◆ CollContainer

Definition at line 45 of file EventStore.h.

◆ CollPair

typedef std::pair<std::string, CollectionBase*> podio::EventStore::CollPair

Collection entry. Each collection is identified by a name.

Definition at line 44 of file EventStore.h.

Constructor & Destructor Documentation

◆ EventStore() [1/2]

podio::EventStore::EventStore ( const EventStore )
delete

Make non-copyable.

◆ EventStore() [2/2]

podio::EventStore::EventStore ( )

Definition at line 9 of file EventStore.cc.

9 : m_table(new CollectionIDTable()) {
10 m_cachedCollections.resize(128); // allow for a sufficiently large initial number of collections
11}

◆ ~EventStore()

podio::EventStore::~EventStore ( )

Definition at line 13 of file EventStore.cc.

13 {
14 for (auto& coll : m_collections) {
15 delete coll.second;
16 }
17}

Member Function Documentation

◆ clear()

void podio::EventStore::clear ( )

clears itself; deletes collections (use at end of event processing)

Definition at line 126 of file EventStore.cc.

126 {
127 for (auto& coll : m_collections) {
128 coll.second->clear();
129 delete coll.second;
130 }
131
132 m_evtMD.clear();
133 clearCaches();
134}
void clearCaches()
Clears only the cache containers (use at end of event if ownership of read objects is transferred)
Definition: EventStore.cc:136
void clear()
erase all elements

Referenced by testWithIO().

◆ clearCaches()

void podio::EventStore::clearCaches ( )

Clears only the cache containers (use at end of event if ownership of read objects is transferred)

Definition at line 136 of file EventStore.cc.

136 {
137 m_collections.clear();
138 m_cachedCollections.clear();
139 m_cachedCollections.resize(128);
140 m_retrievedIDs.clear();
141}

Referenced by clear().

◆ clearCollections()

void podio::EventStore::clearCollections ( )

empties collections.

Definition at line 119 of file EventStore.cc.

119 {
120 for (auto& coll : m_collections) {
121 coll.second->clear();
122 }
123 m_evtMD.clear();
124}

Referenced by testWithIO(), and write().

◆ create()

template<typename T >
T & podio::EventStore::create ( const std::string &  name)

create a new collection

Definition at line 133 of file EventStore.h.

133 {
134 static_assert(std::is_base_of<podio::CollectionBase, T>::value,
135 "DataStore only accepts types inheriting from CollectionBase");
136 // TODO: add check for existence
137 T* coll = new T();
138 registerCollection(name, coll);
139 return *coll;
140}
void registerCollection(const std::string &name, podio::CollectionBase *coll)
register an existing collection
Definition: EventStore.cc:48

Referenced by testWithIO(), and write().

◆ eventMetaDataPtr()

GenericParameters * podio::EventStore::eventMetaDataPtr ( )
inline

Definition at line 107 of file EventStore.h.

107 {
108 return &m_evtMD;
109 }

Referenced by podio::ROOTWriter::ROOTWriter(), and podio::SIOWriter::SIOWriter().

◆ get() [1/3]

template<typename T >
const T & podio::EventStore::get ( const std::string &  name)

access a collection by name returns a collection w/ setting isValid to true if successful

Definition at line 156 of file EventStore.h.

156 {
157 const T* tmp(0);
158 auto success = this->get(name, tmp);
159 if (!success) {
160 throw std::runtime_error("No collection \'" + name + "\' is present in the EventStore");
161 }
162 return *tmp;
163}
bool get(const std::string &name, const T *&collection)
access a collection by name. returns true if successful
Definition: EventStore.h:143

◆ get() [2/3]

template<typename T >
bool podio::EventStore::get ( const std::string &  name,
const T *&  collection 
)

access a collection by name. returns true if successful

Definition at line 143 of file EventStore.h.

143 {
144 // static_assert(std::is_base_of<podio::CollectionBase,T>::value,
145 // "DataStore only contains types inheriting from CollectionBase");
146 CollectionBase* tmp{nullptr};
147 doGet(name, tmp);
148 collection = static_cast<T*>(tmp);
149 if (collection != nullptr) {
150 return true;
151 }
152 return false;
153}

Referenced by podio::ROOTWriter::finish(), get(), podio::ASCIIWriter::registerForWrite(), podio::ROOTWriter::registerForWrite(), podio::SIOWriter::registerForWrite(), podio::SIOCollectionIDTableBlock::SIOCollectionIDTableBlock(), testWithIO(), and podio::ROOTWriter::writeEvent().

◆ get() [3/3]

bool podio::EventStore::get ( int  id,
CollectionBase *&  coll 
) const
finalvirtual

access a collection by ID. returns true if successful

Implements podio::ICollectionProvider.

Definition at line 19 of file EventStore.cc.

19 {
20 // see if we have a cached collection
21 if ((collection = getFast(id)) != nullptr) {
22 return true;
23 }
24
25 auto val = m_retrievedIDs.insert(id);
26 bool success = false;
27 if (val.second == true) {
28 // collection not yet retrieved in recursive-call
29 auto name = m_table->name(id);
30 success = doGet(name, collection, true);
31 if (collection != nullptr) { // cache the collection for faster retreaval later
32 if (m_cachedCollections.size() < (unsigned)id + 1) {
33 m_cachedCollections.resize(id + 1);
34 }
35 m_cachedCollections[id] = collection;
36 }
37 } else {
38 // collection already requested in recursive call
39 // do not set the references to break collection dependency-cycle
40 auto name = m_table->name(id);
41 success = doGet(name, collection, false);
42 }
43 // fg: the set should only be cleared at the end of event (in clear() ) ...
44 // m_retrievedIDs.erase(id);
45 return success;
46}
CollectionBase * getFast(int id) const
fast access to cached collections
Definition: EventStore.h:62

◆ getCollectionIDTable()

CollectionIDTable * podio::EventStore::getCollectionIDTable ( ) const
inline

Definition at line 86 of file EventStore.h.

86 {
87 return m_table.get();
88 }

Referenced by podio::ROOTWriter::finish(), and podio::SIOCollectionIDTableBlock::SIOCollectionIDTableBlock().

◆ getCollectionMetaData()

GenericParameters & podio::EventStore::getCollectionMetaData ( int  colID)
overridevirtual

return the collection meta data for the given colID

Implements podio::IMetaDataProvider.

Definition at line 109 of file EventStore.cc.

109 {
110
111 if (m_colMDMap.empty() && m_reader != nullptr) {
112 ColMDMap* tmp = m_reader->readCollectionMetaData();
113 m_colMDMap = std::move(*tmp);
114 delete tmp;
115 }
116 return m_colMDMap[colID];
117}
virtual std::map< int, GenericParameters > * readCollectionMetaData()=0
std::map< int, GenericParameters > ColMDMap
Definition: EventStore.h:35

Referenced by write().

◆ getColMetaDataMap()

ColMDMap * podio::EventStore::getColMetaDataMap ( )
inline

Definition at line 104 of file EventStore.h.

104 {
105 return &m_colMDMap;
106 }

Referenced by podio::ROOTWriter::finish(), and podio::SIOWriter::SIOWriter().

◆ getEventMetaData()

GenericParameters & podio::EventStore::getEventMetaData ( )
overridevirtual

return the event meta data for the current event

Implements podio::IMetaDataProvider.

Definition at line 89 of file EventStore.cc.

89 {
90
91 if (m_evtMD.empty() && m_reader != nullptr) {
92 GenericParameters* tmp = m_reader->readEventMetaData();
93 m_evtMD = std::move(*tmp);
94 delete tmp;
95 }
96 return m_evtMD;
97}
bool empty() const
Check if no parameter is stored (i.e. if all internal maps are empty)
virtual GenericParameters * readEventMetaData()=0
read event meta data from file

Referenced by write().

◆ getFast()

CollectionBase * podio::EventStore::getFast ( int  id) const
inline

fast access to cached collections

Definition at line 62 of file EventStore.h.

62 {
63 return (m_cachedCollections.size() > (unsigned)id ? m_cachedCollections[id] : nullptr);
64 }

Referenced by get().

◆ getRunMetaData()

GenericParameters & podio::EventStore::getRunMetaData ( int  runID)
overridevirtual

return the run meta data for the given runID

Implements podio::IMetaDataProvider.

Definition at line 99 of file EventStore.cc.

99 {
100
101 if (m_runMDMap.empty() && m_reader != nullptr) {
102 RunMDMap* tmp = m_reader->readRunMetaData();
103 m_runMDMap = std::move(*tmp);
104 delete tmp;
105 }
106 return m_runMDMap[runID];
107}
virtual std::map< int, GenericParameters > * readRunMetaData()=0
std::map< int, GenericParameters > RunMDMap
Definition: EventStore.h:34

◆ getRunMetaDataMap()

RunMDMap * podio::EventStore::getRunMetaDataMap ( )
inline

Definition at line 101 of file EventStore.h.

101 {
102 return &m_runMDMap;
103 }

Referenced by podio::ROOTWriter::finish(), and podio::SIOWriter::SIOWriter().

◆ isValid()

bool podio::EventStore::isValid ( ) const
finalvirtual

Definition at line 54 of file EventStore.cc.

54 {
55 return m_reader->isValid();
56}
virtual bool isValid() const =0
Check if reader is valid.

◆ operator=()

EventStore & podio::EventStore::operator= ( const EventStore )
delete

◆ registerCollection()

void podio::EventStore::registerCollection ( const std::string &  name,
podio::CollectionBase coll 
)

register an existing collection

Definition at line 48 of file EventStore.cc.

48 {
49 m_collections.push_back({name, coll});
50 auto id = m_table->add(name);
51 coll->setID(id);
52}
virtual void setID(unsigned id)=0
set collection ID

Referenced by create().

◆ setReader()

void podio::EventStore::setReader ( IReader reader)

set the reader

Definition at line 149 of file EventStore.cc.

149 {
150 m_reader = reader;
151 setCollectionIDTable(reader->getCollectionIDTable());
152}

Referenced by podio::PythonEventStore::PythonEventStore(), and testWithIO().


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