Belle II Software light-2406-ragdoll
StoreAccessorBase.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <framework/datastore/DataStore.h>
11
12#include <string>
13#include <utility>
14
15class TClass;
16
17namespace Belle2 {
23 typedef std::pair<std::string, DataStore::EDurability>
28 public:
29
37 StoreAccessorBase(const std::string& name, DataStore::EDurability durability, TClass* objClass, bool isArray):
38 m_name(name), m_durability(durability), m_class(objClass), m_isArray(isArray) {}
39
44 virtual ~StoreAccessorBase() {}
45
53 {
55 }
56
64 bool registerInDataStore(const std::string& name, DataStore::EStoreFlags storeFlags = DataStore::c_WriteOut)
65 {
66 if (!name.empty())
67 m_name = name;
69 }
70
78 bool isRequired(const std::string& name = "")
79 {
80 if (!name.empty())
81 m_name = name;
82 return DataStore::Instance().requireInput(*this);
83 }
84
93 bool isOptional(const std::string& name = "")
94 {
95 if (!name.empty())
96 m_name = name;
97 return DataStore::Instance().optionalInput(*this);
98 }
99
107 bool create(bool replace = false)
108 {
109 return DataStore::Instance().createObject(0, replace, *this);
110 }
111
118 bool assign(TObject* object, bool replace = false);
119
121 virtual void clear()
122 {
123 create(true);
124 }
125
126
128 const std::string& getName() const { return m_name; }
129
132
135
137 virtual bool operator==(const StoreAccessorBase& other) const
138 {
139 return getAccessorParams() == other.getAccessorParams();
140 }
141
143 virtual bool operator!=(const StoreAccessorBase& other) const
144 {
145 return !(*this == other);
146 }
147
149 TClass* getClass() const { return m_class; }
150
152 bool isArray() const { return m_isArray; }
153
155 bool notWrittenOut() const;
156
157
162 std::string readableName() const;
163
164 protected:
166 std::string m_name;
167
170
172 TClass* m_class;
173
176
177 };
179}
EStoreFlags
Flags describing behaviours of objects etc.
Definition: DataStore.h:69
@ c_WriteOut
Object/array should be saved by output modules.
Definition: DataStore.h:70
bool requireInput(const StoreAccessorBase &accessor)
Produce ERROR message if no entry of the given type is registered in the DataStore.
Definition: DataStore.cc:722
EDurability
Durability types.
Definition: DataStore.h:58
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
bool createObject(TObject *object, bool replace, const StoreAccessorBase &accessor)
Create a new object/array in the DataStore or add an existing one.
Definition: DataStore.cc:316
bool registerEntry(const std::string &name, EDurability durability, TClass *objClass, bool array, EStoreFlags storeFlags)
Register an entry in the DataStore map.
Definition: DataStore.cc:190
bool optionalInput(const StoreAccessorBase &accessor)
Register the given object/array as an optional input.
Definition: DataStore.cc:739
Base class for StoreObjPtr and StoreArray for easier common treatment.
StoreAccessorBase(const std::string &name, DataStore::EDurability durability, TClass *objClass, bool isArray)
Constructor to access an object or array in the DataStore.
DataStore::EDurability getDurability() const
Return durability with which the object is saved in the DataStore.
DataStore::EDurability m_durability
Store durability under which the object/array is saved.
virtual bool operator!=(const StoreAccessorBase &other) const
Check if two store accessors point to a different object/array.
virtual bool operator==(const StoreAccessorBase &other) const
Check if two store accessors point to the same object/array.
const std::string & getName() const
Return name under which the object is saved in the DataStore.
bool registerInDataStore(const std::string &name, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool notWrittenOut() const
Returns true if this object/array should not be saved by output modules.
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
bool m_isArray
Is this an accessor for an array?
std::string readableName() const
Convert this acessor into a readable string (for messages).
AccessorParams getAccessorParams() const
Return pair of name and durability under which stored object is saved.
virtual void clear()
Clear contents of this object.
bool assign(TObject *object, bool replace=false)
Assign 'object' to this accessor.
TClass * getClass() const
The underlying object's type.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
bool create(bool replace=false)
Create a default object in the data store.
virtual ~StoreAccessorBase()
Destructor.
std::string m_name
Store name under which this object/array is saved.
bool isArray() const
Is this an accessor for an array?
TClass * m_class
The underlying object's type.
std::pair< std::string, DataStore::EDurability > AccessorParams
Pair of parameters needed to find an object in the DataStore.
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24