 |
Belle II Software
release-05-02-19
|
12 #include <framework/datastore/StoreArray.h>
13 #include <framework/datastore/RelationArray.h>
15 #include <boost/multi_index_container.hpp>
16 #include <boost/multi_index/ordered_index.hpp>
17 #include <boost/multi_index/member.hpp>
32 class RelationIndexBase {
82 typedef boost::multi_index::multi_index_container <
84 boost::multi_index::indexed_by <
85 boost::multi_index::ordered_non_unique <
86 boost::multi_index::member<Element, const FROM*, &Element::from>
88 boost::multi_index::ordered_non_unique <
89 boost::multi_index::member<Element, const TO*, &Element::to>
95 operator bool()
const {
return m_valid; }
132 void rebuild(
bool force =
false);
159 m_valid = m_storeRel.isValid();
161 B2DEBUG(100,
"Relation " << m_storeRel.getName() <<
" does not exist, cannot build index");
170 if (!force && !m_storeRel.getModified())
return;
172 B2DEBUG(100,
"Building index for " << m_storeRel.getName());
175 m_storeRel.setModified(
false);
180 m_storeFrom = m_storeRel.getFromAccessorParams();
181 m_storeTo = m_storeRel.getToAccessorParams();
188 const unsigned int nRel = m_storeRel.getEntries();
191 for (
unsigned int i = 0; i < nRel; ++i) {
194 if (idxFrom >= nFrom)
195 B2FATAL(
"Relation " << m_storeRel.getName() <<
" is inconsistent: from-index (" << idxFrom <<
") out of range");
196 const FROM* from = storeFrom[idxFrom];
199 const auto& indices = r.getToIndices();
200 const auto& weights = r.getWeights();
201 auto itIdx = indices.begin();
202 auto itWgt = weights.begin();
203 const auto& idxEnd = indices.end();
204 for (; itIdx != idxEnd; ++itIdx, ++itWgt) {
207 B2FATAL(
"Relation " << m_storeRel.getName() <<
" is inconsistent: to-index (" << idxTo <<
") out of range");
208 const TO* to = storeTo[idxTo];
209 m_index.insert(Element(idxFrom, idxTo, from, to, *itWgt));
RelationElement::weight_type weight
weight of the relation.
Baseclass for all RelationIndexContainers.
Low-level class to create/modify relations between StoreArrays.
AccessorParams m_storeFrom
AccessorParams of the StoreArray the relation points from.
RelationElement::index_type indexTo
index of the element to which the relation points.
ElementIndex m_index
Instance of the index.
virtual ~RelationIndexBase()
Virtual destructor to create vtable.
AccessorParams getAccessorParams() const
Return pair of name and durability under which stored object is saved.
RelationElement::index_type indexFrom
index of the element from which the relation points.
Manager to keep a cache of existing RelationIndexContainers.
const FROM * from
pointer of the element from which the relation points.
RelationIndexContainer & operator=(const RelationIndexContainer &)=delete
Restrict copies.
const TO * to
pointer of the element to which the relation points.
const AccessorParams & getFromAccessorParams() const
Get the AccessorParams of the StoreArray the relation points from.
virtual void clear() override
Clear the index (at the end of an event)
void rebuild(bool force=false)
Rebuild the index.
Class to store a single element of a relation.
std::pair< std::string, DataStore::EDurability > AccessorParams
Pair of parameters needed to find an object in the DataStore.
Element type for the index.
RelationIndexContainer(const RelationArray &relArray)
Constructor to create a new IndexContainer.
Element(RelationElement::index_type indexFrom_, RelationElement::index_type indexTo_, const FROM *from_, const TO *to_, RelationElement::weight_type weight_)
Create a new element.
AccessorParams m_storeTo
AccessorParams of the StoreArray the relation points to.
RelationArray m_storeRel
the underlying relation.
Abstract base class for different kinds of events.
unsigned int index_type
type used for indices.
virtual void clear()=0
Clear the index (at the end of the event)
AccessorParams getAccessorParams() const
Get the AccessorParams of the underlying relation.
Class to store a bidirectional index between two StoreArrays.
boost::multi_index::multi_index_container< Element, boost::multi_index::indexed_by< boost::multi_index::ordered_non_unique< boost::multi_index::member< Element, const FROM *, &Element::from > >, boost::multi_index::ordered_non_unique< boost::multi_index::member< Element, const TO *, &Element::to > > > > ElementIndex
Boost MultiIndex container to keep the bidirectional index.
const ElementIndex & index() const
Get the index.
Accessor to arrays stored in the data store.
const AccessorParams & getToAccessorParams() const
Get the AccessorParams of the StoreArray the relation points to.
float weight_type
type used for weights.
bool m_valid
Indicate wether the relation is valid.