File indexing completed on 2024-09-07 04:37:15
0001 #ifndef DataReducer_h
0002 #define DataReducer_h
0003
0004 #include "OnlineDB/EcalCondDB/interface/EcalLogicID.h"
0005 #include "OnlineDB/EcalCondDB/interface/Tm.h"
0006
0007
0008
0009 #include <vector>
0010 #include <string>
0011 #include <map>
0012 #include <iostream>
0013 #include <list>
0014 #include <cctype>
0015
0016
0017
0018
0019 template <typename T>
0020 class DataReducer {
0021 public:
0022 typedef DataReducer<T> self;
0023 typedef typename std::pair<EcalLogicID, T> DataItem;
0024 typedef typename std::map<EcalLogicID, T> DataMap;
0025 typedef typename std::list<std::pair<Tm, DataMap> >::iterator list_iterator;
0026 typedef typename std::map<EcalLogicID, T>::iterator map_iterator;
0027
0028 template <typename U>
0029 class MyData {
0030 public:
0031 typedef MyData<U> self;
0032 bool operator<(const MyData& rhs) {
0033 Tm t1 = m_iData.first;
0034 Tm t2 = rhs.m_iData.first;
0035 long long diff_time = (t1.microsTime() - t2.microsTime());
0036 return (diff_time < 0);
0037 };
0038
0039 std::pair<Tm, std::pair<EcalLogicID, U> > m_iData;
0040 };
0041
0042 typedef typename std::list<MyData<T> >::iterator iterator;
0043
0044 DataReducer() { m_printout = false; };
0045 ~DataReducer() {}
0046
0047 static const int TIMELIMIT = 60;
0048
0049 void setDataList(std::list<MyData<T> > _list) {
0050 m_list = _list;
0051 m_list.sort();
0052 };
0053
0054 void getReducedDataList(std::list<std::pair<Tm, DataMap> >* my_new_list) {
0055
0056
0057
0058
0059 std::cout << " we are in getReducedDataList " << std::endl;
0060
0061 iterator i;
0062 std::cout << " created iterator " << std::endl;
0063
0064 bool firstpass = true;
0065 unsigned int s_old = 0;
0066 for (i = m_list.begin(); i != m_list.end(); i++) {
0067 Tm t = (*i).m_iData.first;
0068 DataItem d = (*i).m_iData.second;
0069 bool new_time_change = true;
0070
0071 DataMap the_data;
0072 list_iterator it_good = my_new_list->end();
0073
0074 if (!firstpass) {
0075 list_iterator it;
0076 int last_state = -1;
0077 for (it = my_new_list->begin(); it != my_new_list->end(); ++it) {
0078
0079
0080 std::pair<Tm, DataMap> pair_new_list = *it;
0081
0082 Tm t_l = pair_new_list.first;
0083 DataMap dd = pair_new_list.second;
0084 map_iterator ip;
0085 for (ip = dd.begin(); ip != dd.end(); ++ip) {
0086 EcalLogicID ecid = ip->first;
0087 T dcs_dat = ip->second;
0088 if (ecid.getLogicID() == d.first.getLogicID())
0089 last_state = dcs_dat.getStatus();
0090 }
0091
0092 long long diff_time = (t.microsTime() - t_l.microsTime()) / 1000000;
0093 if (diff_time < 0)
0094 diff_time = -diff_time;
0095 if (diff_time < TIMELIMIT) {
0096
0097
0098 new_time_change = false;
0099
0100 the_data = pair_new_list.second;
0101 it_good = it;
0102 }
0103 }
0104
0105 if (last_state != d.second.getStatus()) {
0106 if (!new_time_change) {
0107 std::pair<Tm, DataMap> pair_new_list = *it_good;
0108 Tm t_good = pair_new_list.first;
0109 the_data = pair_new_list.second;
0110 the_data.insert(d);
0111 std::pair<Tm, DataMap> pair_new_good;
0112 pair_new_good.first = t_good;
0113 pair_new_good.second = the_data;
0114
0115 my_new_list->erase(it_good);
0116 my_new_list->push_back(pair_new_good);
0117
0118 } else if (new_time_change) {
0119 std::pair<Tm, DataMap> p_new;
0120 p_new.first = t;
0121 DataMap a_map;
0122 a_map.insert(d);
0123 p_new.second = a_map;
0124 my_new_list->push_back(p_new);
0125 }
0126 }
0127 list_iterator it3;
0128 if (my_new_list->size() > s_old) {
0129 s_old = my_new_list->size();
0130 if (m_printout) {
0131 std::cout << "************" << std::endl;
0132 for (it3 = my_new_list->begin(); it3 != my_new_list->end(); ++it3) {
0133 std::pair<Tm, DataMap> pair_new_list3 = *it3;
0134 Tm t3 = pair_new_list3.first;
0135 std::cout << " T =" << t3.str() << std::endl;
0136 }
0137 std::cout << "************" << std::endl;
0138 }
0139 }
0140
0141 } else {
0142
0143 std::pair<Tm, DataMap> p_new;
0144 p_new.first = t;
0145 DataMap a_map;
0146 a_map.insert(d);
0147 p_new.second = a_map;
0148 my_new_list->insert(my_new_list->begin(), p_new);
0149 firstpass = false;
0150 }
0151 }
0152
0153 if (m_printout) {
0154 list_iterator it3;
0155 for (it3 = my_new_list->begin(); it3 != my_new_list->end(); ++it3) {
0156 std::pair<Tm, DataMap> pair_new_list3 = *it3;
0157 Tm t3 = pair_new_list3.first;
0158 std::cout << " T =" << t3.str() << std::endl;
0159 }
0160 }
0161 };
0162
0163 private:
0164
0165 std::list<MyData<T> > m_list;
0166 bool m_printout;
0167 };
0168
0169 #endif