Belle II Software light-2406-ragdoll
RelationVector.cc
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#include <framework/datastore/RelationVector.h>
9#include <framework/datastore/RelationArray.h>
10
11using namespace Belle2;
12
14 const std::function<void(std::vector<RelationElement::index_type>&, std::vector<RelationElement::weight_type>&, size_t)>& f)
15{
16 const TObject* obj = m_relations.at(index).object;
17 float objweight = m_relations.at(index).weight;
18
19 for (const auto& name : m_relationNames) {
21
22 //fill fromIndex, toIndex the rght way around
23 unsigned int fromIndex, toIndex;
24 StoreEntry* entry = nullptr;
25 int otherIndex = -1;
26 if (!DataStore::Instance().findStoreEntry(obj, entry, otherIndex))
27 B2FATAL("RelationVectorBase points to object not in DataStore?");
28
29 if (m_name == rel.getFromAccessorParams().first and entry->name == rel.getToAccessorParams().first) {
30 fromIndex = m_index;
31 toIndex = otherIndex;
32 } else if (entry->name == rel.getFromAccessorParams().first and m_name == rel.getToAccessorParams().first) {
33 toIndex = m_index;
34 fromIndex = otherIndex;
35 } else {
36 continue;
37 }
38
39 //go through rel, see if we can find fromIndex and toIndex
40 for (int i = 0; i < rel.getEntries(); i++) {
41 if (rel[i].getFromIndex() == fromIndex) {
42 auto& toIndices = const_cast<std::vector<RelationElement::index_type>&>(rel[i].getToIndices());
43 auto& toWeights = const_cast<std::vector<RelationElement::weight_type>&>(rel[i].getWeights());
44 for (size_t j = 0; j < toIndices.size(); j++) {
45 //we also compare the weight here to handle duplicate relations properly
46 if (toIndices[j] == toIndex and toWeights[j] == objweight) {
47 f(toIndices, toWeights, j);
48 rel.setModified(true);
49 return;
50 }
51 }
52 }
53 }
54 }
55
56 B2FATAL("RelationVectorBase and DataStore differ!??");
57}
58
60{
61 if ((other.m_name != m_name) or (other.m_index != m_index))
62 B2FATAL("Trying to add RelationVectorBase for " << m_name << m_index << " and " << other.m_name << other.m_index << "!");
63
64 m_relations.insert(m_relations.end(), other.m_relations.begin(), other.m_relations.end());
65 if (!other.m_relations.empty())
66 m_relationNames.insert(m_relationNames.end(), other.m_relationNames.begin(), other.m_relationNames.end());
67}
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Definition: DataStore.h:59
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
Low-level class to create/modify relations between StoreArrays.
Definition: RelationArray.h:62
const AccessorParams & getFromAccessorParams() const
Return the AccessorParams the attached relation points from.
const AccessorParams & getToAccessorParams() const
Return the AccessorParams the attached relation points to.
void setModified(bool modified)
Set modified flag of underlying container.
int getEntries() const
Get the number of elements.
base class for RelationVector<T>
void apply(int index, const std::function< void(std::vector< unsigned int > &, std::vector< float > &, size_t)> &f)
apply function to the relation associated with the RelationEntry at given index.
void add(const RelationVectorBase &other)
add another list of relations.
std::vector< RelationEntry > m_relations
The vector of relation entries.
int m_index
index of object these relations belong to.
std::string m_name
entry name of array containing object these relations belong to.
std::vector< std::string > m_relationNames
Names of associated relations.
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
Wraps a stored array/object, stored under unique (name, durability) key.
Definition: StoreEntry.h:22
std::string name
Name of the entry.
Definition: StoreEntry.h:53