Belle II Software development
RelationVectorBase Class Reference

base class for RelationVector<T> More...

#include <RelationVector.h>

Inheritance diagram for RelationVectorBase:
RelationVector< T >

Public Member Functions

 RelationVectorBase ()
 Construct empty set.
 
 RelationVectorBase (const std::string &name, int index, const std::vector< Belle2::RelationEntry > &relations, const std::vector< std::string > &names)
 Constructor.
 

Protected Member Functions

void add (const RelationVectorBase &other)
 add another list of relations.
 
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.
 

Protected Attributes

std::string m_name
 entry name of array containing object these relations belong to.
 
int m_index { -1}
 index of object these relations belong to.
 
std::vector< RelationEntrym_relations
 The vector of relation entries.
 
std::vector< std::string > m_relationNames
 Names of associated relations.
 

Friends

class DataStore
 

Detailed Description

base class for RelationVector<T>

Definition at line 24 of file RelationVector.h.

Constructor & Destructor Documentation

◆ RelationVectorBase() [1/2]

RelationVectorBase ( )
inline

Construct empty set.

Definition at line 27 of file RelationVector.h.

27{ }

◆ RelationVectorBase() [2/2]

RelationVectorBase ( const std::string &  name,
int  index,
const std::vector< Belle2::RelationEntry > &  relations,
const std::vector< std::string > &  names 
)
inline

Constructor.


Definition at line 30 of file RelationVector.h.

31 : m_name(name), m_index(index), m_relations(relations), m_relationNames(names) {}
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.

Member Function Documentation

◆ add()

void add ( const RelationVectorBase other)
protected

add another list of relations.

(internal use)

Definition at line 59 of file RelationVector.cc.

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}

◆ apply()

void apply ( int  index,
const std::function< void(std::vector< unsigned int > &, std::vector< float > &, size_t)> &  f 
)
protected

apply function to the relation associated with the RelationEntry at given index.

Definition at line 13 of file RelationVector.cc.

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}
@ 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
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

Friends And Related Function Documentation

◆ DataStore

friend class DataStore
friend

Definition at line 44 of file RelationVector.h.

Member Data Documentation

◆ m_index

int m_index { -1}
protected

index of object these relations belong to.

Definition at line 41 of file RelationVector.h.

◆ m_name

std::string m_name
protected

entry name of array containing object these relations belong to.

Definition at line 40 of file RelationVector.h.

◆ m_relationNames

std::vector<std::string> m_relationNames
protected

Names of associated relations.

Definition at line 43 of file RelationVector.h.

◆ m_relations

std::vector<RelationEntry> m_relations
protected

The vector of relation entries.

Definition at line 42 of file RelationVector.h.


The documentation for this class was generated from the following files: