EventAnalysis  1.3.0
EventDataCache.h
Go to the documentation of this file.
1 /*
2  * EventDataCache.h
3  *
4  * Created on: 11 Dec 2017
5  * Author: Nicola Mori
6  */
7 
10 #ifndef EVENTDATACACHE_H_
11 #define EVENTDATACACHE_H_
12 
13 #include "core/ObjectWrapper.h"
14 #include "core/RetrievalResult.h"
15 #include <unordered_map>
16 #include <vector>
17 
18 namespace EA {
19 
20 class EventDataStore;
21 
31 public:
41 
53  bool BookObject(const std::string &objName, unsigned int sizeHint = 1000);
54 
65  bool CacheValues();
66 
79  bool Unbook(const std::string &objName = "");
80 
88  bool SetCurrentEvent(unsigned int event);
89 
105  RetrievalResult GetCachedValue(const std::string &objName, ObjectWrapper &wrapper);
106 
114  bool Clean(const std::string &objName = "");
115 
120  std::string GetStoreName();
121 
122 private:
124  unsigned int _currEv;
125 
126  // Cache structure: vector of wrappers, the vector index corresponds to the event ID. If the object is
127  // missing for an event then for that event the wrapper wraps nothing.
128  // This data structure is optimized for these hypotheses: the object is present for almost all the events
129  // (i.e. there are almost no holes), first event is event 0 (i.e. we don't waste space at the beginning of
130  // the container), event processing is done sequentially (i.e. we need efficient
131  using Cache = std::vector<ObjectWrapper>;
132 
133  struct ObjCache {
134  bool booked;
136  ObjCache(unsigned int sizeHint) : booked(true) { cache.reserve(sizeHint); }
137  };
138 
139  using ObjCacheMap = std::unordered_map<std::string, ObjCache>;
141 };
142 
143 } // namespace EA
144 
145 #endif /* EVENTDATACACHE_H_ */
bool CacheValues()
Caches the value of the booked objects for the current event.
Definition: EventDataCache.cpp:38
bool BookObject(const std::string &objName, unsigned int sizeHint=1000)
Books an object for caching.
Definition: EventDataCache.cpp:26
A cache for event data object.
Definition: EventDataCache.h:30
bool SetCurrentEvent(unsigned int event)
Sets the current event.
Definition: EventDataCache.cpp:77
bool Clean(const std::string &objName="")
Cleans the cache of the given object.
Definition: EventDataCache.cpp:99
std::unordered_map< std::string, ObjCache > ObjCacheMap
Definition: EventDataCache.h:139
Definition: EventDataCache.h:133
bool Unbook(const std::string &objName="")
Unbooks the given object.
Definition: EventDataCache.cpp:60
RetrievalResult
Definition: RetrievalResult.h:16
IncludeFileExc.h IncludeFileExc class declaration.
Definition: Algorithm.h:21
std::vector< ObjectWrapper > Cache
Definition: EventDataCache.h:131
RetrievalResult GetCachedValue(const std::string &objName, ObjectWrapper &wrapper)
Retrieves the cached value for the given object.
Definition: EventDataCache.cpp:82
EventDataStore & _evStore
Definition: EventDataCache.h:123
Cache cache
Definition: EventDataCache.h:135
Generic wrapper class.
Definition: ObjectWrapper.h:28
Definition: DataStore.h:422
ObjCacheMap _cacheMap
Definition: EventDataCache.h:140
unsigned int _currEv
Definition: EventDataCache.h:124
ObjCache(unsigned int sizeHint)
Definition: EventDataCache.h:136
std::string GetStoreName()
Returns the name of the event store to which the cache is attached.
Definition: EventDataCache.cpp:112
bool booked
Definition: EventDataCache.h:134
EventDataCache(EventDataStore &evStore)
Constructor.
Definition: EventDataCache.cpp:18