Go to the documentation of this file.00001 #ifndef DataReducer_h
00002 #define DataReducer_h
00003
00004 #include "OnlineDB/EcalCondDB/interface/EcalLogicID.h"
00005 #include "OnlineDB/EcalCondDB/interface/Tm.h"
00006
00007
00008
00009 #include <vector>
00010 #include <string>
00011 #include <map>
00012 #include <iostream>
00013 #include <list>
00014 #include <cctype>
00015
00016
00017
00018
00019
00020
00021
00022 template < typename T >
00023 class DataReducer
00024 {
00025
00026 public:
00027
00028 typedef DataReducer<T> self;
00029 typedef typename std::pair< EcalLogicID, T > DataItem;
00030 typedef typename std::map< EcalLogicID, T > DataMap ;
00031 typedef typename std::list< std::pair< Tm, DataMap > >::iterator list_iterator;
00032 typedef typename std::map< EcalLogicID, T >::iterator map_iterator;
00033
00034
00035 template < typename U >
00036 class MyData
00037 {
00038 public:
00039 typedef MyData<U> self;
00040 bool operator < (const MyData& rhs)
00041 {
00042 Tm t1=m_iData.first;
00043 Tm t2=rhs.m_iData.first;
00044 long long diff_time= (t1.microsTime() - t2.microsTime()) ;
00045 return ( diff_time<0 );
00046 };
00047
00048 std::pair< Tm, std::pair< EcalLogicID, U > > m_iData;
00049
00050 };
00051
00052 typedef typename std::list< MyData<T> >::iterator iterator;
00053
00054
00055 DataReducer() { m_printout=false; };
00056 ~DataReducer() {};
00057
00058 static const int TIMELIMIT=60;
00059
00060 void setDataList( std::list< MyData<T> > _list ){
00061
00062 m_list = _list;
00063 m_list.sort();
00064
00065 };
00066
00067 void getReducedDataList(std::list< std::pair< Tm, DataMap > >* my_new_list) {
00068
00069
00070
00071
00072 std::cout << " we are in getReducedDataList "<< std::endl;
00073
00074 iterator i;
00075 std::cout << " created iterator "<< std::endl;
00076
00077 bool firstpass=true;
00078 unsigned int s_old=0;
00079 for ( i=m_list.begin(); i!=m_list.end(); i++){
00080
00081 Tm t = (*i).m_iData.first;
00082 DataItem d = (*i).m_iData.second;
00083 bool new_time_change=true;
00084
00085 DataMap the_data;
00086 list_iterator it_good=my_new_list->end();
00087
00088
00089 if(!firstpass) {
00090
00091 list_iterator it;
00092 int last_state=-1;
00093 for(it =my_new_list->begin(); it!= my_new_list->end(); ++it) {
00094
00095
00096
00097
00098 std::pair< Tm, DataMap > pair_new_list = *it;
00099
00100 Tm t_l = pair_new_list.first;
00101 DataMap dd = pair_new_list.second;
00102 map_iterator ip;
00103 for(ip =dd.begin(); ip!= dd.end(); ++ip) {
00104 EcalLogicID ecid = ip->first;
00105 T dcs_dat = ip->second;
00106 if(ecid.getLogicID()==d.first.getLogicID() ) last_state= dcs_dat.getStatus();
00107 }
00108
00109 long long diff_time= (t.microsTime() - t_l.microsTime()) /1000000 ;
00110 if(diff_time<0) diff_time=-diff_time;
00111 if( diff_time < TIMELIMIT ) {
00112
00113
00114
00115 new_time_change=false;
00116
00117 the_data = pair_new_list.second;
00118 it_good=it;
00119
00120 }
00121
00122 }
00123
00124 if(last_state != d.second.getStatus()){
00125 if(!new_time_change ) {
00126 std::pair< Tm, DataMap > pair_new_list = *it_good;
00127 Tm t_good = pair_new_list.first;
00128 the_data = pair_new_list.second;
00129 the_data.insert(d);
00130 std::pair< Tm, DataMap > pair_new_good;
00131 pair_new_good.first=t_good;
00132 pair_new_good.second=the_data;
00133
00134 my_new_list->erase(it_good);
00135 my_new_list->push_back(pair_new_good);
00136
00137
00138 } else if(new_time_change) {
00139
00140 std::pair< Tm, DataMap > p_new;
00141 p_new.first=t;
00142 DataMap a_map;
00143 a_map.insert( d );
00144 p_new.second=a_map;
00145 my_new_list->push_back(p_new);
00146
00147 }
00148 }
00149 list_iterator it3;
00150 if(my_new_list->size() > s_old) {
00151 s_old=my_new_list->size();
00152 if(m_printout){
00153 std::cout << "************"<< std::endl;
00154 for(it3 =my_new_list->begin(); it3!= my_new_list->end(); ++it3) {
00155 std::pair< Tm, DataMap > pair_new_list3 = *it3;
00156 Tm t3 = pair_new_list3.first;
00157 std::cout << " T =" << t3.str()<< std::endl;
00158 }
00159 std::cout << "************"<< std::endl;
00160 }
00161 }
00162
00163
00164 } else {
00165
00166 std::pair< Tm, DataMap > p_new;
00167 p_new.first=t;
00168 DataMap a_map;
00169 a_map.insert( d );
00170 p_new.second=a_map;
00171 my_new_list->insert(my_new_list->begin(),p_new);
00172 firstpass=false;
00173
00174 }
00175
00176 }
00177
00178
00179 if(m_printout) {
00180 list_iterator it3;
00181 for(it3 =my_new_list->begin(); it3!= my_new_list->end(); ++it3) {
00182 std::pair< Tm, DataMap > pair_new_list3 = *it3;
00183 Tm t3 = pair_new_list3.first;
00184 std::cout << " T =" << t3.str()<< std::endl;
00185 }
00186 }
00187
00188 };
00189
00190
00191 private:
00192
00193 std::list< MyData<T> > m_list;
00194 bool m_printout;
00195 };
00196
00197
00198 #endif
00199