Belle II Software  release-05-02-19
StoreAccessorBase.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Heck *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <framework/datastore/DataStore.h>
13 
14 #include <string>
15 #include <utility>
16 
17 class TClass;
18 
19 namespace Belle2 {
25  typedef std::pair<std::string, DataStore::EDurability>
30  public:
31 
39  StoreAccessorBase(const std::string& name, DataStore::EDurability durability, TClass* objClass, bool isArray):
40  m_name(name), m_durability(durability), m_class(objClass), m_isArray(isArray) {}
41 
46  virtual ~StoreAccessorBase() {}
47 
55  {
57  }
58 
66  bool registerInDataStore(const std::string& name, DataStore::EStoreFlags storeFlags = DataStore::c_WriteOut)
67  {
68  if (!name.empty())
69  m_name = name;
71  }
72 
80  bool isRequired(const std::string& name = "")
81  {
82  if (!name.empty())
83  m_name = name;
84  return DataStore::Instance().requireInput(*this);
85  }
86 
95  bool isOptional(const std::string& name = "")
96  {
97  if (!name.empty())
98  m_name = name;
99  return DataStore::Instance().optionalInput(*this);
100  }
101 
109  bool create(bool replace = false)
110  {
111  return DataStore::Instance().createObject(0, replace, *this);
112  }
113 
120  bool assign(TObject* object, bool replace = false);
121 
123  virtual void clear()
124  {
125  create(true);
126  }
127 
128 
130  const std::string& getName() const { return m_name; }
131 
134 
136  AccessorParams getAccessorParams() const { return make_pair(m_name, m_durability);}
137 
139  virtual bool operator==(const StoreAccessorBase& other) const
140  {
141  return getAccessorParams() == other.getAccessorParams();
142  }
143 
145  virtual bool operator!=(const StoreAccessorBase& other) const
146  {
147  return !(*this == other);
148  }
149 
151  TClass* getClass() const { return m_class; }
152 
154  bool isArray() const { return m_isArray; }
155 
157  bool notWrittenOut() const;
158 
159 
164  std::string readableName() const;
165 
166  protected:
168  std::string m_name;
169 
172 
174  TClass* m_class;
175 
177  bool m_isArray;
178 
179  };
181 }
Belle2::StoreAccessorBase::getDurability
DataStore::EDurability getDurability() const
Return durability with which the object is saved in the DataStore.
Definition: StoreAccessorBase.h:133
Belle2::StoreAccessorBase::getClass
TClass * getClass() const
The underlying object's type.
Definition: StoreAccessorBase.h:151
Belle2::DataStore::Instance
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
Belle2::StoreAccessorBase::readableName
std::string readableName() const
Convert this acessor into a readable string (for messages).
Definition: StoreAccessorBase.cc:20
Belle2::StoreAccessorBase::~StoreAccessorBase
virtual ~StoreAccessorBase()
Destructor.
Definition: StoreAccessorBase.h:46
Belle2::StoreAccessorBase::getAccessorParams
AccessorParams getAccessorParams() const
Return pair of name and durability under which stored object is saved.
Definition: StoreAccessorBase.h:136
Belle2::StoreAccessorBase::assign
bool assign(TObject *object, bool replace=false)
Assign 'object' to this accessor.
Definition: StoreAccessorBase.cc:35
Belle2::DataStore::EStoreFlags
EStoreFlags
Flags describing behaviours of objects etc.
Definition: DataStore.h:71
Belle2::StoreAccessorBase::notWrittenOut
bool notWrittenOut() const
Returns true if this object/array should not be saved by output modules.
Definition: StoreAccessorBase.cc:55
Belle2::StoreAccessorBase::clear
virtual void clear()
Clear contents of this object.
Definition: StoreAccessorBase.h:123
Belle2::StoreAccessorBase::isOptional
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
Definition: StoreAccessorBase.h:95
Belle2::StoreAccessorBase::getName
const std::string & getName() const
Return name under which the object is saved in the DataStore.
Definition: StoreAccessorBase.h:130
Belle2::StoreAccessorBase
Base class for StoreObjPtr and StoreArray for easier common treatment.
Definition: StoreAccessorBase.h:29
Belle2::StoreAccessorBase::registerInDataStore
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Definition: StoreAccessorBase.h:54
Belle2::DataStore::optionalInput
bool optionalInput(const StoreAccessorBase &accessor)
Register the given object/array as an optional input.
Definition: DataStore.cc:713
Belle2::StoreAccessorBase::m_name
std::string m_name
Store name under which this object/array is saved.
Definition: StoreAccessorBase.h:168
Belle2::StoreAccessorBase::registerInDataStore
bool registerInDataStore(const std::string &name, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Definition: StoreAccessorBase.h:66
Belle2::StoreAccessorBase::m_class
TClass * m_class
The underlying object's type.
Definition: StoreAccessorBase.h:174
Belle2::DataStore::c_WriteOut
@ c_WriteOut
Object/array should be saved by output modules.
Definition: DataStore.h:72
Belle2::StoreAccessorBase::m_isArray
bool m_isArray
Is this an accessor for an array?
Definition: StoreAccessorBase.h:177
Belle2::AccessorParams
std::pair< std::string, DataStore::EDurability > AccessorParams
Pair of parameters needed to find an object in the DataStore.
Definition: StoreAccessorBase.h:26
Belle2::StoreAccessorBase::isRequired
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Definition: StoreAccessorBase.h:80
Belle2::StoreAccessorBase::m_durability
DataStore::EDurability m_durability
Store durability under which the object/array is saved.
Definition: StoreAccessorBase.h:171
Belle2::StoreAccessorBase::create
bool create(bool replace=false)
Create a default object in the data store.
Definition: StoreAccessorBase.h:109
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreAccessorBase::operator!=
virtual bool operator!=(const StoreAccessorBase &other) const
Check if two store accessors point to a different object/array.
Definition: StoreAccessorBase.h:145
Belle2::StoreAccessorBase::isArray
bool isArray() const
Is this an accessor for an array?
Definition: StoreAccessorBase.h:154
Belle2::DataStore::registerEntry
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
Belle2::DataStore::createObject
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
Belle2::StoreAccessorBase::operator==
virtual bool operator==(const StoreAccessorBase &other) const
Check if two store accessors point to the same object/array.
Definition: StoreAccessorBase.h:139
Belle2::StoreAccessorBase::StoreAccessorBase
StoreAccessorBase(const std::string &name, DataStore::EDurability durability, TClass *objClass, bool isArray)
Constructor to access an object or array in the DataStore.
Definition: StoreAccessorBase.h:39
Belle2::DataStore::requireInput
bool requireInput(const StoreAccessorBase &accessor)
Produce ERROR message if no entry of the given type is registered in the DataStore.
Definition: DataStore.cc:696
Belle2::DataStore::EDurability
EDurability
Durability types.
Definition: DataStore.h:60