EventAnalysis
1.3.0
|
Data store class. More...
#include <DataStore.h>
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... | |
![]() | |
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) |
![]() | |
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 | |
![]() | |
~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... | |
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.
EA::DataStore::DataStore | ( | const std::string & | name, |
ObjectCategory | category | ||
) |
Constructor.
name | The name of the data store object. |
category | The category of stored objects. |
|
protected |
Adds the objects produced by a producer to the list of objects known to the store.
producer | The object producer |
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.
name | The name of the object. |
obj | Reference to the object. |
producer | The object producer. |
an | EA::Insertion::Exception if an error occurred while adding the object. |
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.
name | The name of the object. |
obj | Pointer to the object. |
producer | The object producer. |
an | EA::Insertion::Exception if an error occurred while adding the object. |
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.
name | The name of the object. |
obj | The string literal. |
an | EA::Insertion::Exception if an error occurred while adding the object. |
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.
name | The name of the object. |
obj | Pointer to the object. |
producer | The object producer. |
an | EA::Insertion::Exception if an error occurred while adding the object. |
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.
name | The name of the object. |
obj | Pointer to the object. |
an | EA::Insertion::Exception if an error occurred while adding the object. |
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.
provider | The data provider to be registered. |
|
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).
name | The requested object |
actualName | The actual object name in case name is an alias. |
wrapper | Wrapper containing the object. |
provider | The data provider that provided the object. |
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.
|
inline |
Removes all the aliases from the store.
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.
memStatus | The memory status code. |
|
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.
name | The name of the object. |
name
is not given.
|
inline |
Gets all the providers attached to the data store.
|
protected |
|
protected |
Retrieves an object from the registered providers.
name | The requested object |
wrapper | For returning the object wrapper |
actualName | The actual name of the object, in case name was identified as an alias. |
provider | Pointer to the data provider that provided the object (non-null only for successful retrieval). |
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.
|
inline |
Gets the name of the object corresponding to an alias.
aliasName | The alias. |
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.
name | the name of the requested object. |
|
inline |
Returns the names of the objects in the store.
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.
objName | The name of the desired object. |
bool EA::DataStore::IsAlgoProducedObject | ( | const std::string | nameOrAlias | ) |
Checks if a given object is produced by an algorithm.
nameOrAlias | The name or the alias of the object. |
|
inline |
Checks if an object name is actually an alias.
objName | The name to be checked. |
|
inline |
Checks if an object is present in the map.
nameOrAlias | The name or the alias of the object. |
|
inline |
Checks whether the data store is tracking removed objects or not.
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.
name | The name of the object to be deleted. |
removeAliased | if name is an alias then the aliased object will be removed if this parameter is set to true. |
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 (
seq | The sequence of algorithms whose produced objects will be notified to the data store. |
void EA::DataStore::SetAlias | ( | const std::string & | objName, |
const std::string & | objAlias | ||
) |
Set an alias for the given object.
objName | The aliased object. |
objAlias | The alias to assign to the aliased object. |
an | EA::Insertion::Exception if an error occurred while setting the alias. |
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.
track | If true then the tracking of the removed objects will be enabled, otherwise it will be disabled. |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |