11#include <framework/datastore/StoreArray.h>
12#include <framework/datastore/RelationArray.h>
14#include <boost/multi_index_container.hpp>
15#include <boost/multi_index/ordered_index.hpp>
16#include <boost/multi_index/member.hpp>
81 typedef boost::multi_index::multi_index_container <
83 boost::multi_index::indexed_by <
84 boost::multi_index::ordered_non_unique <
85 boost::multi_index::member<Element, const FROM*, &Element::from>
87 boost::multi_index::ordered_non_unique <
88 boost::multi_index::member<Element, const TO*, &Element::to>
131 void rebuild(
bool force =
false);
158 m_valid = m_storeRel.isValid();
160 B2DEBUG(100,
"Relation " << m_storeRel.getName() <<
" does not exist, cannot build index");
169 if (!force && !m_storeRel.getModified())
return;
171 B2DEBUG(100,
"Building index for " << m_storeRel.getName());
174 m_storeRel.setModified(
false);
179 m_storeFrom = m_storeRel.getFromAccessorParams();
180 m_storeTo = m_storeRel.getToAccessorParams();
187 const unsigned int nRel = m_storeRel.getEntries();
190 for (
unsigned int i = 0; i < nRel; ++i) {
193 if (idxFrom >= nFrom)
194 B2FATAL(
"Relation " << m_storeRel.getName() <<
" is inconsistent: from-index (" << idxFrom <<
") out of range");
195 const FROM* from = storeFrom[idxFrom];
198 const auto& indices = r.getToIndices();
199 const auto& weights = r.getWeights();
200 auto itIdx = indices.begin();
201 auto itWgt = weights.begin();
202 const auto& idxEnd = indices.end();
203 for (; itIdx != idxEnd; ++itIdx, ++itWgt) {
206 B2FATAL(
"Relation " << m_storeRel.getName() <<
" is inconsistent: to-index (" << idxTo <<
") out of range");
207 const TO* to = storeTo[idxTo];
208 m_index.insert(
Element(idxFrom, idxTo, from, to, *itWgt));
Low-level class to create/modify relations between StoreArrays.
Class to store a single element of a relation.
unsigned int index_type
type used for indices.
float weight_type
type used for weights.
Baseclass for all RelationIndexContainers.
virtual void clear()=0
Clear the index (at the end of the event)
virtual ~RelationIndexBase()
Virtual destructor to create vtable.
Class to store a bidirectional index between two StoreArrays.
const AccessorParams & getFromAccessorParams() const
Get the AccessorParams of the StoreArray the relation points from.
RelationIndexContainer(const RelationIndexContainer &)=delete
Restrict copies.
RelationArray m_storeRel
the underlying relation.
AccessorParams m_storeFrom
AccessorParams of the StoreArray the relation points from.
RelationIndexContainer(const RelationArray &relArray)
Constructor to create a new IndexContainer.
ElementIndex & index()
Get the index.
const AccessorParams & getToAccessorParams() const
Get the AccessorParams of the StoreArray the relation points to.
const ElementIndex & index() const
Get the index.
bool m_valid
Indicate wether the relation is valid.
virtual void clear() override
Clear the index (at the end of an event)
RelationIndexContainer & operator=(const RelationIndexContainer &)=delete
Restrict copies.
AccessorParams getAccessorParams() const
Get the AccessorParams of the underlying relation.
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.
ElementIndex m_index
Instance of the index.
AccessorParams m_storeTo
AccessorParams of the StoreArray the relation points to.
Manager to keep a cache of existing RelationIndexContainers.
AccessorParams getAccessorParams() const
Return pair of name and durability under which stored object is saved.
Accessor to arrays stored in the data store.
int getEntries() const
Get the number of objects in the array.
void rebuild(bool force=false)
Rebuild the index.
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.
Element type for the index.
const FROM * from
pointer of the element from which the relation points.
const TO * to
pointer of the element to which the relation points.
RelationElement::index_type indexTo
index of the element to which the relation points.
RelationElement::index_type indexFrom
index of the element from which the relation points.
RelationElement::weight_type weight
weight of the relation.
Element(RelationElement::index_type indexFrom_, RelationElement::index_type indexTo_, const FROM *from_, const TO *to_, RelationElement::weight_type weight_)
Create a new element.