ATLAS Offline Software
Loading...
Searching...
No Matches
TIDAAssociator.h
Go to the documentation of this file.
1/* emacs: this is -*- c++ -*- */
10
11
12#ifndef TIDA_ASSOCIATOR_H
13#define TIDA_ASSOCIATOR_H
14
15#include <iostream>
16#include <vector>
17#include <string>
18#include <cmath>
19#include <map>
20
21namespace TIDA {
22
23template<typename T, typename S=T>
25
26public:
27
28 typedef std::map<T*, S*> map_type;
29 typedef std::map<S*, T*> rmap_type;
30
31public:
32
33 Associator(const std::string& name)
34 : mname(name)
35 { }
36
37 virtual ~Associator() { }
38
39 virtual Associator* clone() = 0;
40
41 virtual void match(const std::vector<T*>& s1,
42 const std::vector<S*>& s2 ) = 0;
43
44 // get matched track from map
45 virtual const S* matched( T* t) {
46 typename map_type::const_iterator titr = mmatched.find(t);
47 if ( titr != mmatched.end() ) return titr->second;
48 else return 0;
49 }
50
51 // get matched track from reverse map
52 virtual const T* revmatched( S* t) {
53 typename rmap_type::const_iterator titr = mrevmatched.find(t);
54 if ( titr != mrevmatched.end() ) return titr->second;
55 else return 0;
56 }
57
58 // get the lookup tables
59 const map_type& matched() const { return mmatched; }
60 const rmap_type& revmatched() const { return mrevmatched; }
61
62 // clear the match lookup tables
63 void clear() { mmatched.clear(); mrevmatched.clear(); }
64
65 // how many items were matched
66 unsigned size() const { return mmatched.size(); }
67
68
69protected:
70
71 std::string mname;
72
75
76};
77
78}
79
80
81
82
83template<typename T, typename S>
84inline std::ostream& operator<<(std::ostream& s, const TIDA::Associator<T,S>& a ) {
85 typename TIDA::Associator<T,S>::map_type::const_iterator mitr = a.matched().begin();
86 typename TIDA::Associator<T,S>::map_type::const_iterator mend = a.matched().end();
87
88 std::cout << "TIDA::Associator size() " << a.size() << std::endl;
89
90 while ( mitr!=mend ) {
91 s << "\t[ ";
92 if ( mitr->first ) s << *(mitr->first) << "\t";
93 else s << "-------\t\t";
94
95 if ( mitr->second ) s << *(mitr->second);
96 else s << "-------";
97
98 s << " ]" << std::endl;
99
100 ++mitr;
101 }
102
103 return s;
104}
105
106
107#endif // TIDA_ASSOCIATOR_H
108
109
110
111
112
113
114
115
116
117
static Double_t a
std::ostream & operator<<(std::ostream &s, const TIDA::Associator< T, S > &a)
std::map< T *, S * > map_type
std::map< S *, T * > rmap_type
virtual const T * revmatched(S *t)
const map_type & matched() const
virtual Associator * clone()=0
unsigned size() const
virtual const S * matched(T *t)
const rmap_type & revmatched() const
virtual void match(const std::vector< T * > &s1, const std::vector< S * > &s2)=0
virtual ~Associator()
Associator(const std::string &name)
Test for xAOD.