ATLAS Offline Software
TIDAAssociator.h
Go to the documentation of this file.
1 /* emacs: this is -*- c++ -*- */
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 
21 namespace TIDA {
22 
23 template<typename T, typename S=T>
24 class Associator {
25 
26 public:
27 
28  typedef std::map<T*, S*> map_type;
29  typedef std::map<S*, T*> rmap_type;
30 
31 public:
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 
69 protected:
70 
71  std::string mname;
72 
75 
76 };
77 
78 }
79 
80 
81 
82 
83 template<typename T, typename S>
84 inline 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 
TIDA::Associator
Definition: TIDAAssociator.h:24
TIDA
Test for xAOD.
Definition: Filter_AcceptAll.h:22
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
TIDA::Associator::~Associator
virtual ~Associator()
Definition: TIDAAssociator.h:37
TIDA::Associator::matched
const map_type & matched() const
Definition: TIDAAssociator.h:59
TIDA::Associator::mmatched
map_type mmatched
Definition: TIDAAssociator.h:73
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
JetTiledMap::S
@ S
Definition: TiledEtaPhiMap.h:44
TIDA::Associator::matched
virtual const S * matched(T *t)
Definition: TIDAAssociator.h:45
TIDA::Associator::rmap_type
std::map< S *, T * > rmap_type
Definition: TIDAAssociator.h:29
TIDA::Associator::clone
virtual Associator * clone()=0
TIDA::Associator::clear
void clear()
Definition: TIDAAssociator.h:63
TIDA::Associator::revmatched
const rmap_type & revmatched() const
Definition: TIDAAssociator.h:60
TIDA::Associator::map_type
std::map< T *, S * > map_type
Definition: TIDAAssociator.h:28
TIDA::Associator::revmatched
virtual const T * revmatched(S *t)
Definition: TIDAAssociator.h:52
TIDA::Associator::mname
std::string mname
Definition: TIDAAssociator.h:71
operator<<
std::ostream & operator<<(std::ostream &s, const TIDA::Associator< T, S > &a)
Definition: TIDAAssociator.h:84
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
a
TList * a
Definition: liststreamerinfos.cxx:10
ReadCellNoiseFromCoolCompare.s2
s2
Definition: ReadCellNoiseFromCoolCompare.py:379
TIDA::Associator::Associator
Associator(const std::string &name)
Definition: TIDAAssociator.h:33
TIDA::Associator::mrevmatched
rmap_type mrevmatched
Definition: TIDAAssociator.h:74
TIDA::Associator::match
virtual void match(const std::vector< T * > &s1, const std::vector< S * > &s2)=0
TIDA::Associator::size
unsigned size() const
Definition: TIDAAssociator.h:66