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

Data store class. More...

#include <DataStore.h>

Inheritance diagram for EA::DataStore:
EA::Info EA::ObjectMap EA::EventDataStore EA::OwningDataStore EA::PassDataStore EA::GlobalDataStore

Classes

struct  KnownObject
 Descriptor for a known object. More...
 

Public Member Functions

 DataStore (const std::string &name, ObjectCategory category)
 
template<class DataType >
void AddObject (const std::string &name, DataType &obj, const observer_ptr< ObjectProducer > &producer=nullptr)
 Adds an object to the map, storing also the producer. More...
 
template<class DataType >
void AddObject (const std::string &name, observer_ptr< DataType > obj, const observer_ptr< ObjectProducer > &producer=nullptr)
 Adds an object to the map, storing also the producer. More...
 
void AddObject (const std::string &name, const char *obj, const observer_ptr< ObjectProducer > &=nullptr)
 Adds a string literal to the map. More...
 
template<class DataType >
void AddObject (const std::string &name, std::shared_ptr< DataType > obj, const observer_ptr< ObjectProducer > &producer=nullptr)
 Adds an object to the map, storing also the producer. More...
 
template<class DataType >
void AddObject (const std::string &name, std::unique_ptr< DataType > obj, const observer_ptr< ObjectProducer > &=nullptr)
 Adds an object to the map. More...
 
void SetAlias (const std::string &objName, const std::string &objAlias)
 Set an alias for the given object. More...
 
template<class DataType >
observer_ptr< DataType > GetObject (const std::string &name)
 Provides a data object. More...
 
bool RemoveObject (const std::string &name, bool removeAliased=false)
 Removes an object or an alias from the map. More...
 
std::vector< std::string > GetObjects () const
 Returns the names of the objects in the store. More...
 
bool IsPresent (const std::string &nameOrAlias)
 Checks if an object is present in the map. More...
 
const std::vector< KnownObject > & GetKnownObjects ()
 Returns a list of all the objects that are known to the store. More...
 
std::vector< std::string > GetAliases (const std::string &name="") const
 Returns the aliases of the objects in the store. More...
 
bool Clean ()
 Removes all the objects and aliases from the store. More...
 
bool CleanAliases ()
 Removes all the aliases from the store. More...
 
bool IsAlias (const std::string &objName)
 Checks if an object name is actually an alias. More...
 
const std::string & GetNameOfAliasedObject (const std::string &aliasName)
 Gets the name of the object corresponding to an alias. More...
 
ObjectWrapper GetObjectWrapper (const std::string &objName)
 Provides a data object wrapper. More...
 
bool AddProvider (observer_ptr< DataProvider > provider)
 Adds a data provider in the data store. More...
 
const std::vector< observer_ptr< DataProvider > > GetAttachedProviders ()
 Gets all the providers attached to the data store. More...
 
void TrackRemovedObjects (bool track=true)
 Enables the tracking of removed objects. More...
 
bool IsTrackingRemovedObjects ()
 Checks whether the data store is tracking removed objects or not. More...
 
bool FreeRemoved (Memory::Status memStatus)
 Release the memory allocated for removed objects. More...
 
bool SetAlgoProducedObjects (const AlgoSequence &seq)
 Notify the data store about objects that are produced by the algorithms. More...
 
bool IsAlgoProducedObject (const std::string nameOrAlias)
 Checks if a given object is produced by an algorithm. More...
 
- Public Member Functions inherited from EA::Info
 Info (const std::string &name)
 Constructor. More...
 
virtual ~Info ()
 Destructor. More...
 
virtual const std::string GetType () const
 
virtual const std::string GetName () const
 The type (i.e. class) of the object. More...
 
virtual const std::string GetVersion () const
 The name of the object. More...
 

Protected Member Functions

template<class DataType >
ObjPtr< DataType > GetFromMap (const std::string &name)
 Retrieves an object from the internal ObjectMap. More...
 
RetrievalResult GetFromProvider (const std::string &name, ObjectWrapper &wrapper, std::string &actualName, observer_ptr< ObjectProducer > &provider)
 Retrieves an object from the registered providers. More...
 
template<class DataType >
ObjPtr< DataType > CastAndWrap (const std::string &name, const std::string &actualName, ObjectWrapper &&wrapper, observer_ptr< ObjectProducer > provider)
 Casts the wrapper to the template type, registers the object in the store and wraps it inside the return ObjPtr. More...
 
void AddKnownObjects (const ObjectProducer &producer)
 
- Protected Member Functions inherited from EA::Info
 Info (const std::shared_ptr< Representation > &impl)
 
std::shared_ptr< Representation > & GetRepresentation ()
 

Private Attributes

std::vector< observer_ptr< DataProvider > > _providers
 
ObjectCategory _category
 
std::vector< KnownObject_knownObjects
 
bool _providersCheckedForProducedObjects
 
std::unique_ptr< RemovedObjectsTracker_remObjTracker
 
std::list< std::string > _algoProdObjects
 
std::list< std::string > _algoProdAliases
 

Additional Inherited Members

- Private Member Functions inherited from EA::ObjectMap
 ~ObjectMap ()
 Destructor. More...
 
template<class DataType >
InsertionResult AddObject (const std::string &name, DataType &obj)
 Adds an object to the map. More...
 
template<class DataType >
InsertionResult AddObject (const std::string &name, observer_ptr< DataType > obj)
 Adds an object to the map. More...
 
InsertionResult AddObject (const std::string &name, const char *obj)
 Adds a string literal to the map. More...
 
template<class DataType >
InsertionResult AddObject (const std::string &name, std::shared_ptr< DataType > obj)
 Adds an object to the map. More...
 
template<class DataType >
InsertionResult AddObject (const std::string &name, std::unique_ptr< DataType > obj)
 Adds an object to the map. More...
 
InsertionResult SetAlias (const std::string &objName, const std::string &objAlias)
 Set an alias for the given object. More...
 
template<class DataType >
ObjPtr< DataType > GetObject (const std::string &name)
 Retrieves an object given its name. More...
 
ObjectWrapper GetObjectWrapper (const std::string &objName)
 Get a wrapper for a given object. More...
 
const std::string & GetNameOfAliasedObject (const std::string &aliasName)
 Gets the name of the object corresponding to an alias. More...
 
bool RemoveObject (const std::string &name, bool removeAliased=false)
 Removes an object or an alias from the map. More...
 
std::vector< std::string > GetObjects () const
 Returns the names of the objects in the map. More...
 
bool IsPresent (const std::string &nameOrAlias) const
 Checks if an object is present in the map. More...
 
std::vector< std::string > GetAliases (const std::string &name="") const
 Returns the aliases of the objects in the map. More...
 
bool Clean ()
 Removes all the objects and aliases from the map. More...
 
bool CleanAliases ()
 Removes all the aliases from the map. More...
 
std::string GetObjectClass (const std::string &objName)
 Get the class name of an object in the store. More...
 
bool IsAlias (const std::string &objName)
 Checks if an object name is actually an alias. More...
 
InsertionResult AddObject (const std::string &name, ObjectWrapper &&wrapper)
 Add an already wrapped object. More...
 

Detailed Description

Data store class.

The data store is simply a #DataMap, i.e. a correspondence between strings and data objects. It serves as a data publisher/retriever for producer/consumer objects. The DataStore can register data providers from which the store will try to retrieve requested objects.

When adding objects to a data store it is also possible to specify the object producer: this producer will be asked to clean the memory used by produced objects that are no longer needed in case of memory pressure. If no producer is specified then the memory clean request for that object will not be made. This functionality is disabled by default, and have to be enabled by calling #ManageRemoved.

Constructor & Destructor Documentation

◆ DataStore()

EA::DataStore::DataStore ( const std::string &  name,
ObjectCategory  category 
)

Constructor.

Parameters
nameThe name of the data store object.
categoryThe category of stored objects.

Member Function Documentation

◆ AddKnownObjects()

void EA::DataStore::AddKnownObjects ( const ObjectProducer producer)
protected

Adds the objects produced by a producer to the list of objects known to the store.

Parameters
producerThe object producer

◆ AddObject() [1/5]

template<class DataType >
void EA::DataStore::AddObject ( const std::string &  name,
DataType &  obj,
const observer_ptr< ObjectProducer > &  producer = nullptr 
)

Adds an object to the map, storing also the producer.

The object referenced by #obj is added to the map. The map will not own the object. If the object producer is non-null then the producer will be asked to clean the object in cases of memory pressure.

Parameters
nameThe name of the object.
objReference to the object.
producerThe object producer.
Exceptions
anEA::Insertion::Exception if an error occurred while adding the object.

◆ AddObject() [2/5]

template<class DataType >
void EA::DataStore::AddObject ( const std::string &  name,
observer_ptr< DataType >  obj,
const observer_ptr< ObjectProducer > &  producer = nullptr 
)

Adds an object to the map, storing also the producer.

The object pointed by #obj is added to the map. The map will not own the object. If the object producer is non-null then the producer will be asked to clean the object in cases of memory pressure.

Parameters
nameThe name of the object.
objPointer to the object.
producerThe object producer.
Exceptions
anEA::Insertion::Exception if an error occurred while adding the object.

◆ AddObject() [3/5]

void EA::DataStore::AddObject ( const std::string &  name,
const char *  obj,
const observer_ptr< ObjectProducer > &  = nullptr 
)

Adds a string literal to the map.

Specialization for string literals. Stores the literal as an std::string, so when retrieving it with GetObject the template type std::string must be used. The ObjectProducer parameter is ignored since there's no need to ask for cleanup of a string literal.

Parameters
nameThe name of the object.
objThe string literal.
Exceptions
anEA::Insertion::Exception if an error occurred while adding the object.

◆ AddObject() [4/5]

template<class DataType >
void EA::DataStore::AddObject ( const std::string &  name,
std::shared_ptr< DataType >  obj,
const observer_ptr< ObjectProducer > &  producer = nullptr 
)

Adds an object to the map, storing also the producer.

The object pointed by obj is added to the map. The map will share the object ownership with the producer. If the object producer is non-null then the producer will be asked to clean the object in cases of memory pressure.

Parameters
nameThe name of the object.
objPointer to the object.
producerThe object producer.
Exceptions
anEA::Insertion::Exception if an error occurred while adding the object.

◆ AddObject() [5/5]

template<class DataType >
void EA::DataStore::AddObject ( const std::string &  name,
std::unique_ptr< DataType >  obj,
const observer_ptr< ObjectProducer > &  = nullptr 
)

Adds an object to the map.

The object pointed by #obj is added to the map. The map will own the object. The ObjectProducer parameter is ignored since the memory will be automatically cleaned when the object is removed from the store.

Parameters
nameThe name of the object.
objPointer to the object.
Exceptions
anEA::Insertion::Exception if an error occurred while adding the object.

◆ AddProvider()

bool EA::DataStore::AddProvider ( observer_ptr< DataProvider provider)

Adds a data provider in the data store.

Registered data provider will be queried for data objects. The DataStore will not own the registered providers. If provider provides the same objects of an already added provider the a false value is returned and the provider is not added.

Parameters
providerThe data provider to be registered.
Returns
true if registration succeeds.

◆ CastAndWrap()

template<class DataType >
ObjPtr< DataType > EA::DataStore::CastAndWrap ( const std::string &  name,
const std::string &  actualName,
ObjectWrapper &&  wrapper,
observer_ptr< ObjectProducer provider 
)
protected

Casts the wrapper to the template type, registers the object in the store and wraps it inside the return ObjPtr.

This method is called by GetObject for objects which have just been retrieved from a data provider. It checks the type and if the type check is successful then it moves the wrapper to the internal object map. An #ObjPtr is returned, with the result of the type check and a pointer to the object (if the type check has been successful, nullptr otherwise).

Parameters
nameThe requested object
actualNameThe actual object name in case name is an alias.
wrapperWrapper containing the object.
providerThe data provider that provided the object.
Returns
an ObjPtr with the cast result and the object pointer.

◆ Clean()

bool EA::DataStore::Clean ( )

Removes all the objects and aliases from the store.

Owned object will be deleted. The list of removed object is cleaned, so that an eventual subsequent call to FreeRemoved does not actually free any memory.

Returns
true if clean-up succeeded.

◆ CleanAliases()

bool EA::DataStore::CleanAliases ( )
inline

Removes all the aliases from the store.

See also
ObjectMap::CleanAliases.
Returns
true if clean-up succeeded.

◆ FreeRemoved()

bool EA::DataStore::FreeRemoved ( Memory::Status  memStatus)

Release the memory allocated for removed objects.

This method asks the object producers to free the memory allocated for removed objects. The memStatus code is passed to the producers, which are free to decide whether to actually free the memory or not and to which degree, based on the memory status code. However, with a value of Memory::Status::EXHAUSTED all the producers are required to free all the removed objects they handle.

Parameters
memStatusThe memory status code.
Returns
true if no error occurs

◆ GetAliases()

std::vector<std::string> EA::DataStore::GetAliases ( const std::string &  name = "") const
inline

Returns the aliases of the objects in the store.

Returns a list of aliases for the given object. If no object name is specified then a list of all the currently defined aliases for all the objects in the store will be returned.

See also
ObjectMap::GetAliases
Parameters
nameThe name of the object.
Returns
The aliases of the object, or an empty vector if the given object has no alias.
a vector with the aliases of the objects in the store, or of all the objects if name is not given.

◆ GetAttachedProviders()

const std::vector<observer_ptr<DataProvider> > EA::DataStore::GetAttachedProviders ( )
inline

Gets all the providers attached to the data store.

Returns
A list of providers attached to the data store with AddProvider.

◆ GetFromMap()

template<class DataType >
ObjPtr< DataType > EA::DataStore::GetFromMap ( const std::string &  name)
protected

Retrieves an object from the internal ObjectMap.

Parameters
nameThe requested object
Returns
an ObjPtr with the retrieve result and the wrapper

◆ GetFromProvider()

RetrievalResult EA::DataStore::GetFromProvider ( const std::string &  name,
ObjectWrapper wrapper,
std::string &  actualName,
observer_ptr< ObjectProducer > &  provider 
)
protected

Retrieves an object from the registered providers.

Parameters
nameThe requested object
wrapperFor returning the object wrapper
actualNameThe actual name of the object, in case name was identified as an alias.
providerPointer to the data provider that provided the object (non-null only for successful retrieval).
Returns
the retrieve result.

◆ GetKnownObjects()

const std::vector< DataStore::KnownObject > & EA::DataStore::GetKnownObjects ( )

Returns a list of all the objects that are known to the store.

This method returns a list of all the objects that can be accessed by algorithms and persistence services through the data store. The list is the union of the list of objects provided by the data providers attached to the store and of the list of objects provided by the algorithms as set by SetAlgoProducedObjects.

These lists are retrieved by querying the #ObjectProducer interface of algorithms and data providers, meaning that only those objects that have been declared with ObjectProducer::DeclareProducedObject in the implementations of the algorithms and the data providers will be included in the returned list.

Notice also that eventual objects that are already present on the data store but which are not declared by their producers will not be present in the list. Similarly, a data object that is not on the store but is declared by its producer (including the eventual event objects that are not available for the current event) will be present in the list.

See also
GetObjects
Returns
a vector with the objects that can be obtained through the data store.

◆ GetNameOfAliasedObject()

const std::string& EA::DataStore::GetNameOfAliasedObject ( const std::string &  aliasName)
inline

Gets the name of the object corresponding to an alias.

See also
ObjectMap::GetNameOfAliasedObject
Parameters
aliasNameThe alias.
Returns
The name of the aliased object or a empty string if the alias does not exists or is currently not associated to any object.

◆ GetObject()

template<class DataType >
observer_ptr< DataType > EA::DataStore::GetObject ( const std::string &  name)

Provides a data object.

This method returns a pointer to the requested object. If the object is not present in the store, i.e. it has not been published yet or it has been removed, then the registered data providers will be queried for the object. If the object is not found, or if other errors occur, a #Retrieval::Exception is thrown, the exact class depending on the kind of error.

Parameters
namethe name of the requested object.
Returns
a pointer to the requested object.
See also
AddProvider
Retrieval::Exception

◆ GetObjects()

std::vector<std::string> EA::DataStore::GetObjects ( ) const
inline

Returns the names of the objects in the store.

See also
ObjectMap::GetObjects
GetAvailableObjects
Returns
a vector with the names of the objects in the store.

◆ GetObjectWrapper()

ObjectWrapper EA::DataStore::GetObjectWrapper ( const std::string &  objName)

Provides a data object wrapper.

This method provides wrapped data objects. It is useful to retrieve an object when the type is unknown; in order to effectively use the wrapper object it is necessary to cast the wrapper using wrapper_cast, so the type must be known in the end. If the object is not found, or if other errors occur, a #Retrieval::Exception is thrown, the exact class depending on the kind of error.

Parameters
objNameThe name of the desired object.
Returns
A wrapper containing a pointer to the desired object (wraps nothing if the object is not found neither in store nor in data providers).

◆ IsAlgoProducedObject()

bool EA::DataStore::IsAlgoProducedObject ( const std::string  nameOrAlias)

Checks if a given object is produced by an algorithm.

Parameters
nameOrAliasThe name or the alias of the object.
Returns
true if the specified object is produced by an algorithm.

◆ IsAlias()

bool EA::DataStore::IsAlias ( const std::string &  objName)
inline

Checks if an object name is actually an alias.

See also
ObjectMap::IsAlias.
Parameters
objNameThe name to be checked.
Returns
true if the given name is a currently defined alias.

◆ IsPresent()

bool EA::DataStore::IsPresent ( const std::string &  nameOrAlias)
inline

Checks if an object is present in the map.

Parameters
nameOrAliasThe name or the alias of the object.
Returns
true if the object is in the map, false otherwise

◆ IsTrackingRemovedObjects()

bool EA::DataStore::IsTrackingRemovedObjects ( )
inline

Checks whether the data store is tracking removed objects or not.

Returns
true if the data store is tracking removed objects, false otherwise.

◆ RemoveObject()

bool EA::DataStore::RemoveObject ( const std::string &  name,
bool  removeAliased = false 
)

Removes an object or an alias from the map.

If the object is owned by the map then it is also deleted. If #name is an alias then the aliased object is removed together with the alias only if #removeAliased is set to true. The memory of removed objects can eventually be released by #FreeMemory.

Parameters
nameThe name of the object to be deleted.
removeAliasedif name is an alias then the aliased object will be removed if this parameter is set to true.
Returns
true if the object has been removed from the map, false if the object is not present in the map

◆ SetAlgoProducedObjects()

bool EA::DataStore::SetAlgoProducedObjects ( const AlgoSequence seq)

Notify the data store about objects that are produced by the algorithms.

This method sets the objects produced by the algorithms in the given. These objects, when requested and not found on the store nor provided by any of the attached providers, will be considered as NOTAVAILABLE instead of NOTFOUND.

Only the produced objects declared by the algorithms in the sequence will be considered (

See also
ObjectProducer).
Parameters
seqThe sequence of algorithms whose produced objects will be notified to the data store.
Returns
true.

◆ SetAlias()

void EA::DataStore::SetAlias ( const std::string &  objName,
const std::string &  objAlias 
)

Set an alias for the given object.

See also
ObjectMap::SetAlias
Parameters
objNameThe aliased object.
objAliasThe alias to assign to the aliased object.
Exceptions
anEA::Insertion::Exception if an error occurred while setting the alias.

◆ TrackRemovedObjects()

void EA::DataStore::TrackRemovedObjects ( bool  track = true)

Enables the tracking of removed objects.

Calling this method the tracking of removed objects is enabled. Objects removed from the data store and their producers will be tracked and the memory of tracked removed objects can be freed by FreeRemoved.

Parameters
trackIf true then the tracking of the removed objects will be enabled, otherwise it will be disabled.

Member Data Documentation

◆ _algoProdAliases

std::list<std::string> EA::DataStore::_algoProdAliases
private

◆ _algoProdObjects

std::list<std::string> EA::DataStore::_algoProdObjects
private

◆ _category

ObjectCategory EA::DataStore::_category
private

◆ _knownObjects

std::vector<KnownObject> EA::DataStore::_knownObjects
private

◆ _providers

std::vector<observer_ptr<DataProvider> > EA::DataStore::_providers
private

◆ _providersCheckedForProducedObjects

bool EA::DataStore::_providersCheckedForProducedObjects
private

◆ _remObjTracker

std::unique_ptr<RemovedObjectsTracker> EA::DataStore::_remObjTracker
private

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