EventAnalysis  1.3.0
Classes | Public Member Functions | Private Types | Private Attributes | List of all members
EA::EventDataCache Class Reference

A cache for event data object. More...

#include <EventDataCache.h>

Classes

struct  ObjCache
 

Public Member Functions

 EventDataCache (EventDataStore &evStore)
 Constructor. More...
 
bool BookObject (const std::string &objName, unsigned int sizeHint=1000)
 Books an object for caching. More...
 
bool CacheValues ()
 Caches the value of the booked objects for the current event. More...
 
bool Unbook (const std::string &objName="")
 Unbooks the given object. More...
 
bool SetCurrentEvent (unsigned int event)
 Sets the current event. More...
 
RetrievalResult GetCachedValue (const std::string &objName, ObjectWrapper &wrapper)
 Retrieves the cached value for the given object. More...
 
bool Clean (const std::string &objName="")
 Cleans the cache of the given object. More...
 
std::string GetStoreName ()
 Returns the name of the event store to which the cache is attached. More...
 

Private Types

using Cache = std::vector< ObjectWrapper >
 
using ObjCacheMap = std::unordered_map< std::string, ObjCache >
 

Private Attributes

EventDataStore_evStore
 
unsigned int _currEv
 
ObjCacheMap _cacheMap
 

Detailed Description

A cache for event data object.

This class caches the values of event objects taken from a given event data store in memory. Objects can be booked for caching, and the object values are retrieved from store and cached by the CacheValues method event by event. Cached values can then provided on a per-event basis on subsequent analysis passes.

Member Typedef Documentation

◆ Cache

using EA::EventDataCache::Cache = std::vector<ObjectWrapper>
private

◆ ObjCacheMap

using EA::EventDataCache::ObjCacheMap = std::unordered_map<std::string, ObjCache>
private

Constructor & Destructor Documentation

◆ EventDataCache()

EA::EventDataCache::EventDataCache ( EventDataStore evStore)

Constructor.

Constructs the cache and attaches it to the given data store. If the data store already has a cache then an exception is thrown.

Parameters
evStoreThe event store containing data objects to be cached.
Exceptions
std::runtime_errorif the given data store already has a cache.

Member Function Documentation

◆ BookObject()

bool EA::EventDataCache::BookObject ( const std::string &  objName,
unsigned int  sizeHint = 1000 
)

Books an object for caching.

Books an object for being cached. This method must be called before the beginning of the event loop. The given object must not have already been booked or cached in a previous analysis pass, otherwise the false value is returned.

Parameters
objNameThe object to be cached.
sizeHintHint about the total number of values to be cached.
Returns
true if no other object with the same name has been booked for caching and if the object has not been cached in a previous pass.

◆ CacheValues()

bool EA::EventDataCache::CacheValues ( )

Caches the value of the booked objects for the current event.

This method retrieves the booked objects from the event store and saves their value in the cache. It must be called at the end of event processing in order to save the object value after all the processing done by the algorithms. Calling this method for an already-booked object will generate an error, and the false value will be returned.

Returns
true if all the booked objects have been cached, false in case of errors.

◆ Clean()

bool EA::EventDataCache::Clean ( const std::string &  objName = "")

Cleans the cache of the given object.

This method unbooks the given object and deletes all its cached values. In case no object name is given then all the booked objects and cached values are removed.

Returns
false if the given object is not cached or if an error occurs, true otherwise.

◆ GetCachedValue()

RetrievalResult EA::EventDataCache::GetCachedValue ( const std::string &  objName,
ObjectWrapper wrapper 
)

Retrieves the cached value for the given object.

This method retrieves the cached value of the given object for the current event. If the retrieval operation is successful then the #wrapper argument is set to wrap the object value and RetrievalResult::SUCCESS is returned. The #wrapper argument will wrap nothing in case the retrieval operation is not successful. In this case, possible return values are:

RetrievalResult::NOTFOUND if the object is not present in the cache RetrievalResult::NOTAVAILABLE if the object is present in the cache but no cached value for the current event is available RetrievalResult::ERROR if any error occurs

Parameters
objNameThe name of the desired cached object.
wrapperReference to a wrapper for the return value.
Returns
a RetrievalResult code with the result of the retrieval operation.

◆ GetStoreName()

std::string EA::EventDataCache::GetStoreName ( )

Returns the name of the event store to which the cache is attached.

Returns
The name of the event store.

◆ SetCurrentEvent()

bool EA::EventDataCache::SetCurrentEvent ( unsigned int  event)

Sets the current event.

To be called before #EndOfEvent.

Parameters
eventThe number of the current event.
Returns
true if the current event has been correctly set.

◆ Unbook()

bool EA::EventDataCache::Unbook ( const std::string &  objName = "")

Unbooks the given object.

At the end of the processing pass the data caching is complete, so on subsequent passes the caching must be disabled for the already-cached objects. This method disables the caching for the given booked object (for all the objects if no object name is given), but preserves the cached values that can be accessed in subsequent analysis passes. If this method is called twice for the same event (e.g. in two iterations of a loop) then the cached values are updated.

Parameters
objNameThe name of the object to unbook.
Returns
true if the unbooking is successful.

Member Data Documentation

◆ _cacheMap

ObjCacheMap EA::EventDataCache::_cacheMap
private

◆ _currEv

unsigned int EA::EventDataCache::_currEv
private

◆ _evStore

EventDataStore& EA::EventDataCache::_evStore
private

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