BOSS 7.0.2
BESIII Offline Software System
Loading...
Searching...
No Matches
InstallArea/include/RelTable/RelTable/Relation.h
Go to the documentation of this file.
1
2#ifndef RELATION_H
3#define RELATION_H
4
5#include "RelKey.h"
6#include "GaudiKernel/ClassID.h"
7#include "GaudiKernel/ContainedObject.h"
8#include <vector>
9#include <string>
10#include <iostream>
11
12
13
14/**
15 * @class Relation
16 *
17 * @brief This class is used to relate pair of objets.
18 *
19 * The Relation class build a relation between two objects. It can be an m to n
20 * relation and it stores additional information as a vector of strings
21 *
22 */
23
24static const CLID CLID_Relation = 5100;
25
26
27namespace Event {
28
29template <class T1, class T2>
30class RelTable;
31
32
33
34template <class T1, class T2>
35class Relation: public ContainedObject {
36
37public:
38
39 virtual const CLID& clID() const { return Relation::classID(); }
40 static const CLID& classID() { return CLID_Relation; }
41
42
43 Relation(T1* obj1, T2* obj2): m_first(obj1), m_second(obj2) {}
44 Relation(T1* obj1, T2* obj2, std::string info);
45 Relation(T1* obj1, T2* obj2, std::vector<std::string> infos);
46
47 const T1* getFirst() const {return m_first.getData();}
48 T1* getFirst() { return m_first.getData();}
49
50 const T2* getSecond() const {return m_second.getData();}
51 T2* getSecond() { return m_second.getData();}
52
53 /// Add additional information (as a string) to the relation
54 void addInfo(std::string inf);
55 std::vector<std::string> getInfos() const;
56
57 /// Fill the ASCII output stream
58 std::ostream& fillStream( std::ostream& s ) const;
59
60 friend class RelTable<T1,T2>;
61
62private:
63
64 /// Key associated to the first object to be related
65 RelKey<T1,T1,T2> m_first;
66 /// Key associated to the second object to be related
67 RelKey<T2,T1,T2> m_second;
68 /// Additional information associated to the relation
69 std::vector<std::string> m_infos;
70
71 void setFirst(T1* obj) {m_first.setData(obj);}
72 void setSecond(T2 *obj) {m_second.setData(obj);}
73
74};
75
76
77
78template <class T1, class T2>
79inline Relation<T1,T2>::Relation(T1* obj1, T2* obj2, std::string info):
80 m_first(obj1), m_second(obj2), m_infos(1,info) {}
81
82
83template <class T1, class T2>
84inline Relation<T1,T2>::Relation(T1* obj1, T2* obj2, std::vector<std::string> infos):
85 m_first(obj1), m_second(obj2), m_infos(infos) {}
86
87
88
89template <class T1, class T2>
90void Relation<T1,T2>::addInfo(std::string inf) {
91 // Purpose and Method: This routine add additional information to the relation.
92 // Inputs: inf is the information to be added.
93
94 m_infos.push_back(inf);
95
96}
97
98template <class T1, class T2>
99std::vector<std::string> Relation<T1,T2>::getInfos() const {
100 // Purpose and Method: This routine get the additional information
101 // associated to the relation.
102 // Outputs: a vector of strings
103
104 return m_infos;
105}
106
107
108template <class T1, class T2>
109inline std::ostream& Relation<T1,T2>::fillStream( std::ostream& s ) const {
110 // Fill the ASCII output stream
111 s << " Base class Relation"
112 << "\n First Column: ";
113 m_first.toStream(s);
114 s << "\n Second Column: ";
115 m_second.toStream(s);
116 s << "\n Additional Information: ";
117
118 std::vector<std::string>::const_iterator i;
119 for(i = m_infos.begin(); i != m_infos.end(); i++)
120 {
121 s << "\n " << *i;
122 }
123 return s;
124}
125
126}
127
128#endif // RELATION_H
129
XmlRpcServer s
Definition: HelloServer.cpp:11
void toStream(std::ostream &s) const
Fill the ASCII output stream.
void addInfo(std::string inf)
Add additional information (as a string) to the relation.
std::ostream & fillStream(std::ostream &s) const
Fill the ASCII output stream.
Relation(T1 *obj1, T2 *obj2, std::vector< std::string > infos)
std::vector< std::string > getInfos() const
std::vector< std::string > getInfos() const
void addInfo(std::string inf)
Add additional information (as a string) to the relation.
Relation(T1 *obj1, T2 *obj2, std::string info)
std::ostream & fillStream(std::ostream &s) const
Fill the ASCII output stream.
This class is used to wrap a collection of Relations.
This class is used to relate pair of objets.