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#include <memory>
21#include <stdexcept>
22
23namespace TIDA {
24
25template<typename T, typename S=T>
27
28public:
29
30 typedef std::map<const T*, const S*> map_type;
31 typedef std::map<const S*, const T*> rmap_type;
32
33public:
34
35 Associator(const std::string& name)
36 : mname(name)
37 { }
38
39 virtual ~Associator() { }
40
41 virtual std::unique_ptr<Associator> uclone() const = 0;
42
43 virtual void match(const std::vector<T*>& s1,
44 const std::vector<S*>& s2 ) = 0;
45
46 // get matched track from map
47 virtual const S* matched( T* t) const {
48 typename map_type::const_iterator titr = mmatched.find(t);
49 if ( titr != mmatched.end() ) return titr->second;
50 else return 0;
51 }
52
53 // get matched track from reverse map
54 virtual const T* revmatched( S* t) const {
55 typename rmap_type::const_iterator titr = mrevmatched.find(t);
56 if ( titr != mrevmatched.end() ) return titr->second;
57 else return 0;
58 }
59
60 // get the lookup tables
61 const map_type& matched() const { return mmatched; }
62 const rmap_type& revmatched() const { return mrevmatched; }
63
64 // clear the match lookup tables
65 void clear() { mmatched.clear(); mrevmatched.clear(); }
66
67 // how many items were matched
68 unsigned size() const { return mmatched.size(); }
69
70
71protected:
72
73 std::string mname;
74
77
78};
79
80}
81
82
83
84
85template<typename T, typename S>
86inline std::ostream& operator<<(std::ostream& s, const TIDA::Associator<T,S>& a ) {
87 typename TIDA::Associator<T,S>::map_type::const_iterator mitr = a.matched().begin();
88 typename TIDA::Associator<T,S>::map_type::const_iterator mend = a.matched().end();
89
90 std::cout << "TIDA::Associator size() " << a.size() << std::endl;
91
92 while ( mitr!=mend ) {
93 s << "\t[ ";
94 if ( mitr->first ) s << *(mitr->first) << "\t";
95 else s << "-------\t\t";
96
97 if ( mitr->second ) s << *(mitr->second);
98 else s << "-------";
99
100 s << " ]" << std::endl;
101
102 ++mitr;
103 }
104
105 return s;
106}
107
108
109#endif // TIDA_ASSOCIATOR_H
110
111
112
113
114
115
116
117
118
119
static Double_t a
std::ostream & operator<<(std::ostream &s, const TIDA::Associator< T, S > &a)
virtual const T * revmatched(S *t) const
std::map< const T *, const S * > map_type
const map_type & matched() const
virtual std::unique_ptr< Associator > uclone() const =0
virtual const S * matched(T *t) const
unsigned size() const
const rmap_type & revmatched() const
virtual void match(const std::vector< T * > &s1, const std::vector< S * > &s2)=0
std::map< const S *, const T * > rmap_type
virtual ~Associator()
Associator(const std::string &name)
Test for xAOD.