EventAnalysis  1.0.0
DataStore.h
Go to the documentation of this file.
1 /*
2  * DataStore.h
3  *
4  * Created on: 03 Jan 2017
5  * Author: Nicola Mori
6  */
7 
10 #ifndef DATASTORE_H_
11 #define DATASTORE_H_
12 
13 #include "core/Info.h"
14 #include "core/ObjectMap.h"
15 #include "core/ObserverPtr.h"
16 #include "core/RetrievalResult.h"
17 #include "data/DataProvider.h"
18 #include "data/EventDataCache.h"
20 #include "data/ObjectCategory.h"
23 
24 #include <vector>
25 
26 namespace EA {
27 
28 class AlgoSequence;
29 
41 class DataStore : public Info, private ObjectMap {
42 public:
43  // Constructors/destructor
44 
50  DataStore(const std::string &name, ObjectCategory category);
51 
52  // ObjectMap interface
53 
64  template <class DataType>
65  void AddObject(const std::string &name, DataType &obj, const observer_ptr<ObjectProducer> &producer = nullptr);
66 
77  template <class DataType>
78  void AddObject(const std::string &name, observer_ptr<DataType> obj,
79  const observer_ptr<ObjectProducer> &producer = nullptr);
80 
91  void AddObject(const std::string &name, const char *obj, const observer_ptr<ObjectProducer> & = nullptr);
92 
103  template <class DataType>
104  void AddObject(const std::string &name, std::shared_ptr<DataType> obj,
105  const observer_ptr<ObjectProducer> &producer = nullptr);
106 
117  template <class DataType>
118  void AddObject(const std::string &name, std::unique_ptr<DataType> obj,
119  const observer_ptr<ObjectProducer> & = nullptr);
120 
128  void SetAlias(const std::string &objName, const std::string &objAlias);
129 
136  std::string GetAlias(const std::string &name) const { return ObjectMap::GetAlias(name); }
137 
151  template <class DataType> observer_ptr<DataType> GetObject(const std::string &name);
152 
163  bool RemoveObject(const std::string &name, bool removeAliased = false);
164 
170  std::vector<observer_ptr<const std::string>> &GetListOfObjects() { return ObjectMap::GetListOfObjects(); }
171 
179  bool Clean();
180 
187 
194  bool IsAlias(const std::string &objName) { return ObjectMap::IsAlias(objName); }
195 
203  const std::string &GetNameOfAliasedObject(const std::string &aliasName) {
204  return ObjectMap::GetNameOfAliasedObject(aliasName);
205  }
206 
219  ObjectWrapper GetObjectWrapper(const std::string &objName);
220 
221  // DataStore interface
232 
237  const std::vector<observer_ptr<DataProvider>> GetAttachedProviders() { return _providers; }
238 
246  void TrackRemovedObjects(bool track = true);
247 
252  bool IsTrackingRemovedObjects() { return (bool)_remObjTracker; }
253 
264  bool FreeRemoved(Memory::Status memStatus);
265 
276  bool SetAlgoProducedObjects(const AlgoSequence &seq);
277 
283  bool IsAlgoProducedObject(const std::string nameOrAlias);
284 
285 protected:
291  template <class DataType> ObjPtr<DataType> GetFromMap(const std::string &name);
292 
301  RetrievalResult GetFromProvider(const std::string &name, ObjectWrapper &wrapper, std::string &actualName,
302  observer_ptr<ObjectProducer> &provider);
303 
318  template <class DataType>
319  ObjPtr<DataType> CastAndWrap(const std::string &name, const std::string &actualName, ObjectWrapper &&wrapper,
321 
322 private:
323  std::vector<observer_ptr<DataProvider>> _providers;
325 
326  std::unique_ptr<RemovedObjectsTracker> _remObjTracker;
327 
328  // The following two containers are kept ordered
329  std::list<std::string> _algoProdObjects;
330  std::list<std::string> _algoProdAliases;
331 };
332 
338 class OwningDataStore : public DataStore {
339 public:
340  OwningDataStore(const std::string &name, ObjectCategory category) : DataStore(name, category) {}
341 
342  template <class DataType> void AddObject(const std::string &name, std::shared_ptr<DataType> obj) {
343  DataStore::AddObject(name, obj);
344  }
345 };
346 
348 public:
349  GlobalDataStore(const std::string &name) : OwningDataStore(name, ObjectCategory::GLOBAL) {}
350 };
351 
352 class PassDataStore : public DataStore {
353 public:
354  PassDataStore(const std::string &name) : DataStore(name, ObjectCategory::PASS) {}
355 };
356 
357 class EventDataStore : public DataStore {
358 public:
359  EventDataStore(const std::string &name) : DataStore(name, ObjectCategory::EVENT) {}
360 
369  bool AddEventCache(observer_ptr<EventDataCache> cache);
370 
383  template <class DataType> observer_ptr<DataType> GetObject(const std::string &name);
384 
385 private:
387 };
388 
389 #include "data/DataStore.hpp"
390 
391 } // namespace EA
392 
393 #endif /* DATASTORE_H_ */
bool AddProvider(observer_ptr< DataProvider > provider)
Adds a data provider in the data store.
Definition: DataStore.cpp:96
std::string GetAlias(const std::string &name) const
Get the alias of an object.
Definition: DataStore.h:136
bool IsAlias(const std::string &objName)
Checks if an object name is actually an alias.
Definition: DataStore.h:194
Objects with values defined on a per-event basis.
Class describing a pointer to an object retrieved from an ObjectMap.
Definition: ObjPtr.h:31
std::unique_ptr< RemovedObjectsTracker > _remObjTracker
Definition: DataStore.h:326
Definition: DataStore.h:352
bool CleanAliases()
Removes all the aliases from the map.
Definition: ObjectMap.cpp:121
bool CleanAliases()
Removes all the aliases from the store.
Definition: DataStore.h:186
bool SetAlgoProducedObjects(const AlgoSequence &seq)
Notify the data store about objects that are produced by the algorithms.
Definition: DataStore.cpp:51
void TrackRemovedObjects(bool track=true)
Enables the tracking of removed objects.
Definition: DataStore.cpp:121
EventDataStore(const std::string &name)
Definition: DataStore.h:359
bool Clean()
Removes all the objects and aliases from the store.
Definition: DataStore.cpp:86
std::list< std::string > _algoProdAliases
Definition: DataStore.h:330
std::vector< observer_ptr< const std::string > > & GetListOfObjects()
Returns a list of the objects in the store.
Definition: DataStore.h:170
OwningDataStore(const std::string &name, ObjectCategory category)
Definition: DataStore.h:340
ObjPtr< DataType > GetFromMap(const std::string &name)
Retrieves an object from the internal ObjectMap.
observer_ptr< EventDataCache > _eventCache
Definition: DataStore.h:386
A smart pointer not owning the wrapped object.
Definition: ObserverPtr.h:28
GlobalDataStore(const std::string &name)
Definition: DataStore.h:349
const std::vector< observer_ptr< DataProvider > > GetAttachedProviders()
Gets all the providers attached to the data store.
Definition: DataStore.h:237
const std::string & GetNameOfAliasedObject(const std::string &aliasName)
Gets the name of the object corresponding to an alias.
Definition: ObjectMap.cpp:62
Interface for retrieving informations about an object.
Definition: Info.h:18
bool IsAlgoProducedObject(const std::string nameOrAlias)
Checks if a given object is produced by an algorithm.
Definition: DataStore.cpp:78
RetrievalResult
Definition: RetrievalResult.h:16
bool IsAlias(const std::string &objName)
Checks if an object name is actually an alias.
Definition: ObjectMap.cpp:177
Algorithm made by multiple basic algorithms.
Definition: AlgoSequence.h:37
IncludeFileExc.h IncludeFileExc class declaration.
Definition: Algorithm.h:21
A map between strings and objects of ObjectWrapper kind.
Definition: ObjectMap.h:32
bool RemoveObject(const std::string &name, bool removeAliased=false)
Removes an object or an alias from the map.
Definition: DataStore.cpp:27
void SetAlias(const std::string &objName, const std::string &objAlias)
Set an alias for the given object.
Definition: DataStore.cpp:37
A data store owning all of the contained objects.
Definition: DataStore.h:338
std::string GetAlias(const std::string &name) const
Get the alias of an object.
Definition: ObjectMap.cpp:167
Objects with values defined on a per-pass basis.
RetrievalResult GetFromProvider(const std::string &name, ObjectWrapper &wrapper, std::string &actualName, observer_ptr< ObjectProducer > &provider)
Retrieves an object from the registered providers.
Definition: DataStore.cpp:163
observer_ptr< DataType > GetObject(const std::string &name)
Provides a data object.
ObjectCategory
Category of objects.
Definition: ObjectCategory.h:17
Generic wrapper class.
Definition: ObjectWrapper.h:28
void AddObject(const std::string &name, DataType &obj, const observer_ptr< ObjectProducer > &producer=nullptr)
Adds an object to the map, storing also the producer.
Definition: DataStore.h:357
PassDataStore(const std::string &name)
Definition: DataStore.h:354
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 ret...
std::list< std::string > _algoProdObjects
Definition: DataStore.h:329
DataStore(const std::string &name, ObjectCategory category)
Definition: DataStore.cpp:17
Status
Aliases for memory occupation levels.
Definition: Memory.h:23
bool IsTrackingRemovedObjects()
Checks whether the data store is tracking removed objects or not.
Definition: DataStore.h:252
std::vector< observer_ptr< DataProvider > > _providers
Definition: DataStore.h:323
Undefined value (for default initialization).
std::vector< observer_ptr< const std::string > > & GetListOfObjects()
Returns a list of the objects in the map.
Definition: ObjectMap.cpp:112
void AddObject(const std::string &name, std::shared_ptr< DataType > obj)
Definition: DataStore.h:342
Definition: DataStore.h:347
Data store class.
Definition: DataStore.h:41
ObjectWrapper GetObjectWrapper(const std::string &objName)
Provides a data object wrapper.
Definition: DataStore.cpp:129
bool FreeRemoved(Memory::Status memStatus)
Release the memory allocated for removed objects.
Definition: DataStore.cpp:44
const std::string & GetNameOfAliasedObject(const std::string &aliasName)
Gets the name of the object corresponding to an alias.
Definition: DataStore.h:203
ObjectCategory _category
Definition: DataStore.h:324