00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef RECOMEASINDEX_H
00019 #define RECOMEASINDEX_H
00020
00021
00022 #include "controller.h"
00023
00024
00030 template<recoDim dim, class Ignore, class Separate=RecoDim<0> >
00031 class RecoMeasIndex {
00032
00033 public:
00034
00038 bool init(const RecoCoord& coord, const RecoController& controller) {
00039 Log<Reco> odinlog("RecoMeasIndex","init");
00040 RecoCoord coord4count(coord);
00041 prep_coord(coord4count);
00042 coord4count.set_mode(RecoIndex::separate, dim);
00043
00044 const CoordCountMap* countmap=controller.create_count_map(coord4count);
00045 if(!countmap) return false;
00046 init_countmap=(*countmap);
00047
00048 return create_measmap(init_countmap);
00049 }
00050
00051
00055 bool update(const CoordCountMap& extra) {
00056 Log<Reco> odinlog("RecoMeasIndex","update");
00057
00058 if(!extra.size()) return true;
00059
00060 CoordCountMap countmap_copy(init_countmap);
00061
00062 ODINLOG(odinlog,normalDebug) << "countmap_copy/extra.size()=" << countmap_copy.size() << "/" << extra.size() << STD_endl;
00063
00064 for(CoordCountMap::const_iterator it=extra.begin(); it!=extra.end(); ++it) countmap_copy[it->first]+=it->second;
00065
00066 return create_measmap(countmap_copy);
00067 }
00068
00069
00073 ivector get_indices(const RecoCoord& coord) const {
00074 Log<Reco> odinlog("RecoMeasIndex","get_indices");
00075 ivector result;
00076 RecoCoord coord4meas(coord);
00077 prep_coord(coord4meas);
00078 coord4meas.set_mode(RecoIndex::ignore,dim);
00079
00080 MeasMap::const_iterator it=measmap.find(coord4meas);
00081 if(it==measmap.end()) {
00082 ODINLOG(odinlog,normalDebug) << "<" << recoDimLabel[dim] << ">: No indices for coordinate " << coord4meas.print() << STD_endl;
00083 } else {
00084 result=it->second;
00085 ODINLOG(odinlog,normalDebug) << "coord4meas/it=" << coord4meas.print() << "/" << it->first.print() << STD_endl;
00086 ODINLOG(odinlog,normalDebug) << "result=" << result.printbody() << STD_endl;
00087 }
00088 return result;
00089 }
00090
00091
00092 private:
00093
00094 static void prep_coord(RecoCoord& coord) {
00095 Ignore::modify(RecoIndex::ignore, coord);
00096 Separate::modify(RecoIndex::separate, coord);
00097 }
00098
00099
00100 bool create_measmap(const CoordCountMap& countmap) {
00101 Log<Reco> odinlog("RecoMeasIndex","create_measmap");
00102
00103 STD_map<RecoCoord, STD_list<int> > indexlist;
00104 for(CoordCountMap::const_iterator it=countmap.begin(); it!=countmap.end(); ++it) {
00105 RecoCoord coord4indexlist(it->first);
00106 coord4indexlist.set_mode(RecoIndex::ignore, dim);
00107 indexlist[coord4indexlist].push_back(it->first.index[dim]);
00108 }
00109
00110 for(STD_map<RecoCoord, STD_list<int> >::iterator lstit=indexlist.begin(); lstit!=indexlist.end(); ++lstit) {
00111 STD_list<int>& lstref=lstit->second;
00112 lstref.sort();
00113 lstref.unique();
00114 measmap[lstit->first]=list2vector(lstref);
00115 }
00116
00117 for(MeasMap::const_iterator mapit=measmap.begin(); mapit!=measmap.end(); ++mapit) {
00118 ODINLOG(odinlog,normalDebug) << "measmap[" << mapit->first.print() << "]=" << mapit->second.printbody() << STD_endl;
00119 }
00120
00121 return true;
00122 }
00123
00124
00125 CoordCountMap init_countmap;
00126
00127 typedef STD_map<RecoCoord, ivector> MeasMap;
00128 MeasMap measmap;
00129
00130 };
00131
00132
00133 #endif
00134