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