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