ODIN
measindex.h
1 /***************************************************************************
2  measindex.h - description
3  -------------------
4  begin : Mon Apr 2 2007
5  copyright : (C) 2000-2021 by Thies Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef RECOMEASINDEX_H
19 #define RECOMEASINDEX_H
20 
21 
22 #include "controller.h"
23 
24 
30 template<recoDim dim, class Ignore, class Separate=RecoDim<0> >
32 
33  public:
34 
38  bool init(const RecoCoord& coord, const RecoController& controller) {
39  Log<Reco> odinlog("RecoMeasIndex","init");
40  RecoCoord coord4count(coord);
41  prep_coord(coord4count);
42  coord4count.set_mode(RecoIndex::separate, dim);
43 
44  const CoordCountMap* countmap=controller.create_count_map(coord4count);
45  if(!countmap) return false;
46  init_countmap=(*countmap); // create deep copy because countmap may be deleted by controller after prep
47 
48  return create_measmap(init_countmap);
49  }
50 
51 
55  bool update(const CoordCountMap& extra) {
56  Log<Reco> odinlog("RecoMeasIndex","update");
57 
58  if(!extra.size()) return true;
59 
60  CoordCountMap countmap_copy(init_countmap);
61 
62  ODINLOG(odinlog,normalDebug) << "countmap_copy/extra.size()=" << countmap_copy.size() << "/" << extra.size() << STD_endl;
63 
64  for(CoordCountMap::const_iterator it=extra.begin(); it!=extra.end(); ++it) countmap_copy[it->first]+=it->second;
65 
66  return create_measmap(countmap_copy);
67  }
68 
69 
73  ivector get_indices(const RecoCoord& coord) const {
74  Log<Reco> odinlog("RecoMeasIndex","get_indices");
75  ivector result;
76  RecoCoord coord4meas(coord);
77  prep_coord(coord4meas);
78  coord4meas.set_mode(RecoIndex::ignore,dim);
79 
80  MeasMap::const_iterator it=measmap.find(coord4meas);
81  if(it==measmap.end()) {
82  ODINLOG(odinlog,normalDebug) << "<" << recoDimLabel[dim] << ">: No indices for coordinate " << coord4meas.print() << STD_endl;
83  } else {
84  result=it->second;
85  ODINLOG(odinlog,normalDebug) << "coord4meas/it=" << coord4meas.print() << "/" << it->first.print() << STD_endl;
86  ODINLOG(odinlog,normalDebug) << "result=" << result.printbody() << STD_endl;
87  }
88  return result;
89  }
90 
91 
92  private:
93 
94  static void prep_coord(RecoCoord& coord) {
95  Ignore::modify(RecoIndex::ignore, coord);
96  Separate::modify(RecoIndex::separate, coord);
97  }
98 
99 
100  bool create_measmap(const CoordCountMap& countmap) {
101  Log<Reco> odinlog("RecoMeasIndex","create_measmap");
102 
103  STD_map<RecoCoord, STD_list<int> > indexlist;
104  for(CoordCountMap::const_iterator it=countmap.begin(); it!=countmap.end(); ++it) {
105  RecoCoord coord4indexlist(it->first);
106  coord4indexlist.set_mode(RecoIndex::ignore, dim); // collapse index, indices will be stored in the index vectors of measmap
107  indexlist[coord4indexlist].push_back(it->first.index[dim]);
108  }
109 
110  for(STD_map<RecoCoord, STD_list<int> >::iterator lstit=indexlist.begin(); lstit!=indexlist.end(); ++lstit) {
111  STD_list<int>& lstref=lstit->second;
112  lstref.sort();
113  lstref.unique();
114  measmap[lstit->first]=list2vector(lstref);
115  }
116 
117  for(MeasMap::const_iterator mapit=measmap.begin(); mapit!=measmap.end(); ++mapit) {
118  ODINLOG(odinlog,normalDebug) << "measmap[" << mapit->first.print() << "]=" << mapit->second.printbody() << STD_endl;
119  }
120 
121  return true;
122  }
123 
124 
125  CoordCountMap init_countmap;
126 
127  typedef STD_map<RecoCoord, ivector> MeasMap;
128  MeasMap measmap; // will be initialized during init
129 
130 };
131 
132 
133 #endif
134 
Definition: tjlog.h:218
const CoordCountMap * create_count_map(const RecoCoord &mask) const
ivector get_indices(const RecoCoord &coord) const
Definition: measindex.h:73
bool update(const CoordCountMap &extra)
Definition: measindex.h:55
bool init(const RecoCoord &coord, const RecoController &controller)
Definition: measindex.h:38
STD_string printbody() const
STD_map< RecoCoord, UInt > CoordCountMap
Definition: index.h:364
STD_vector< T > list2vector(const STD_list< T > &src)
Definition: tjvector.h:500
RecoCoord & set_mode(RecoIndex::indexMode m, recoDim d1=n_recoDims, recoDim d2=n_recoDims, recoDim d3=n_recoDims, recoDim d4=n_recoDims, recoDim d5=n_recoDims, recoDim d6=n_recoDims, recoDim d7=n_recoDims, recoDim d8=n_recoDims)
Definition: index.h:238
STD_string print(RecoIndex::printMode printmode=RecoIndex::brief) const