CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Attributes | Private Types | Private Attributes
DEcompare< T > Class Template Reference

#include <DEcompare.h>

Public Member Functions

bool CompareCollections (std::ofstream &, int dump=0)
 
int de_type () const
 
 DEcompare ()
 
 DEcompare (typeT dt, typeT em)
 
bool do_compare (std::ofstream &, int dump=0)
 
bool DumpCandidate (col_cit itd, col_cit itm, std::ofstream &, int mode=0)
 
bool get_match () const
 
int get_ncand (typeT) const
 
int get_ncand (int i) const
 
L1DEDigiCollection getDEDigis () const
 
std::string GetName (int i=0) const
 
bool is_empty (col_cit it) const
 
std::string print (col_cit it) const
 
std::string print () const
 
bool SortCollections (cand_vec &dg, cand_vec &eg, cand_vec &db, cand_vec &eb)
 
 ~DEcompare ()
 

Static Public Attributes

static const int debug_ =0
 

Private Types

typedef std::pair< cand_type, cand_typecand_pair
 
typedef de_trait::cand_type cand_type
 
typedef std::vector< cand_typecand_vec
 
typedef T::const_iterator col_cit
 
typedef T::iterator col_it
 
typedef T::size_type col_sz
 
typedef de_trait::coll_type coll_type
 
typedef DEtrait< Tde_trait
 
typedef de_trait::coll_type const * typeT
 

Private Attributes

typeT data_
 
DEutils< Tde_utils
 
L1DEDigiCollection deDigiColl_
 
typeT emul_
 
int ncand_ [2]
 
bool t_match
 

Detailed Description

template<typename T>
class DEcompare< T >

Definition at line 22 of file DEcompare.h.

Member Typedef Documentation

template<typename T>
typedef std::pair<cand_type,cand_type> DEcompare< T >::cand_pair
private

Definition at line 31 of file DEcompare.h.

template<typename T>
typedef de_trait::cand_type DEcompare< T >::cand_type
private

Definition at line 29 of file DEcompare.h.

template<typename T>
typedef std::vector<cand_type> DEcompare< T >::cand_vec
private

Definition at line 30 of file DEcompare.h.

template<typename T>
typedef T::const_iterator DEcompare< T >::col_cit
private

Definition at line 25 of file DEcompare.h.

template<typename T>
typedef T::iterator DEcompare< T >::col_it
private

Definition at line 26 of file DEcompare.h.

template<typename T>
typedef T::size_type DEcompare< T >::col_sz
private

Definition at line 24 of file DEcompare.h.

template<typename T>
typedef de_trait::coll_type DEcompare< T >::coll_type
private

Definition at line 28 of file DEcompare.h.

template<typename T>
typedef DEtrait<T> DEcompare< T >::de_trait
private

Definition at line 27 of file DEcompare.h.

template<typename T>
typedef de_trait::coll_type const* DEcompare< T >::typeT
private

Definition at line 32 of file DEcompare.h.

Constructor & Destructor Documentation

template<typename T>
DEcompare< T >::DEcompare ( )
inline

Definition at line 36 of file DEcompare.h.

36 {};
template<typename T>
DEcompare< T >::~DEcompare ( )
inline

Definition at line 37 of file DEcompare.h.

37 {};
template<typename T>
DEcompare< T >::DEcompare ( typeT  dt,
typeT  em 
)
inline

Definition at line 39 of file DEcompare.h.

References DEcompare< T >::CompareCollections(), DEcompare< T >::data_, DEcompare< T >::debug_, DEcompare< T >::deDigiColl_, DEcompare< T >::do_compare(), DEcompare< T >::DumpCandidate(), DEcompare< T >::emul_, DEcompare< T >::get_ncand(), DEcompare< T >::GetName(), LogDebug, ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, DEcompare< T >::ncand_, and DEcompare< T >::SortCollections().

39  :
40  data_(dt), emul_(em), t_match(false){
41  ncand_[0]=get_ncand(dt);
42  ncand_[1]=get_ncand(em);
43  deDigiColl_.clear();
44  if(debug_)
45  LogDebug("DEcompare")
46  << "DEcompare"
47  << ": creating instance of type: " << GetName(0)
48  << ", data size:" << data_->size() << " ncand:" << ncand_[0]
49  << ", emul size:" << emul_->size() << " ncand:" << ncand_[1]
50  << ".\n" << std::flush;
51  };
#define LogDebug(id)
float dt
Definition: AMPTWrapper.h:126
static const int debug_
Definition: DEcompare.h:94
typeT data_
Definition: DEcompare.h:98
int get_ncand(typeT) const
Definition: DEcompare.h:123
std::string GetName(int i=0) const
Definition: DEcompare.h:75
int ncand_[2]
Definition: DEcompare.h:102
bool t_match
Definition: DEcompare.h:101
typeT emul_
Definition: DEcompare.h:99
L1DEDigiCollection deDigiColl_
Definition: DEcompare.h:103

Member Function Documentation

template<typename T >
bool DEcompare< T >::CompareCollections ( std::ofstream &  os,
int  dump = 0 
)

-— treat NON-AGREEING candidates -—

-— treat AGREEING candidates -—

Definition at line 134 of file DEcompare.h.

References funct::abs(), gather_cfg::cout, DEcompare< T >::data_, DEcompare< T >::de_utils, DEcompare< T >::debug_, DEcompare< T >::deDigiColl_, DEcompare< T >::DumpCandidate(), DEcompare< T >::emul_, DEcompare< T >::get_ncand(), mps_fire::i, match(), and DEcompare< T >::SortCollections().

Referenced by DEcompare< T >::DEcompare(), and DEcompare< T >::do_compare().

134  {
135 
136  if(debug_)
137  std::cout << " DEcompare::CompareCollections...\n"<< std::flush;
138  bool match = true;
139  int ndata = get_ncand(0);
140  int nemul = get_ncand(1);
141  assert (ndata || nemul);
142 
143  cand_vec data_good, emul_good, data_bad, emul_bad;
144  data_good.reserve(data_->size());
145  emul_good.reserve(emul_->size());
146  data_bad .reserve(data_->size());
147  emul_bad .reserve(emul_->size());
148 
149  // find matching candidates -- tbd report order match
150  match &= SortCollections(data_good,emul_good,data_bad,emul_bad);
151 
152  if(debug_)
153  std::cout << "\tDEcompare stats2:"
154  << " data_bad:" << data_bad .size()
155  << " emul_bad:" << emul_bad .size()
156  << " data_good:" << data_good.size()
157  << " emul_good:" << emul_good.size()
158  << " data_:" << data_->size()
159  << " emul_:" << emul_->size()
160  << ".\n" <<std::flush;
161 
162  if(dump==-1 || (dump==1 && !match)) {
163  os << " number of candidates: " << ndata;
164  if(ndata!=nemul) {
165  match &= false;
166  os << " (data) " << nemul << " (emul) disagree";
167  }
168  os << std::endl;
169  }
170 
171 
172  col_cit itd, itm;
173  int prtmode=0;
174  col_sz ndt=0, nem=0, nde=0;
175  deDigiColl_.clear();
176 
178 
179  ndt = data_bad.size();
180  nem = emul_bad.size();
181  nde = (ndt>nem)?ndt:nem;
182 
183  itd = data_bad.begin();
184  itm = emul_bad.begin();
185 
186  if(dump==-1)
187  os << " un-matched (" << nde << ")\n";
188 
189  for (col_sz i=0; i<nde; i++) {
190 
191  if (i< ndt && i< nem) prtmode=0; //dt+em
192  else if(i< ndt && i>=nem) prtmode=1; //dt
193  else if(i>=ndt && i< nem) prtmode=2; //em
194  else assert(0);
195 
196  if(abs(dump)==1)
197  DumpCandidate(itd,itm,os,prtmode);
198  else if(prtmode==0) {
199  if( (dump==2 && !de_utils.de_equal_loc(*itd,*itm)) ||
200  (dump==3 && de_utils.de_equal_loc(*itd,*itm)) )
201  DumpCandidate(itd,itm,os,prtmode);
202  }
203 
204  // Fill in DEdigi collection
205  if(prtmode==0) {
206  if(de_utils.de_equal_loc(*itd,*itm)) {
207  deDigiColl_.push_back( de_utils.DEDigi(itd,itm,1) );
208  } else {
209  deDigiColl_.push_back( de_utils.DEDigi(itd,itm,2) );
210  }
211  } else if (prtmode==1) {
212  deDigiColl_.push_back( de_utils.DEDigi(itd,itd,3) );
213  } else if (prtmode==2) {
214  deDigiColl_.push_back( de_utils.DEDigi(itm,itm,4) );
215  }
216 
217  itd++; itm++;
218  }
219 
221 
222  itd = data_good.begin();
223  itm = emul_good.begin();
224 
225  assert(data_good.size()==emul_good.size());
226  if(dump==-1)
227  os << " matched (" << data_good.size() << ")\n";
228 
229  for(col_sz i=0; i<data_good.size(); i++) {
230  assert(de_utils.de_equal(*itd,*itm));
231  if(dump==-1)
232  DumpCandidate(itd,itm,os,prtmode);
233  deDigiColl_.push_back( de_utils.DEDigi(itd,itm,0) );
234  itd++; itm++;
235  }
236 
237  if(debug_)
238  std::cout << "DEcompare<T>::CompareCollections end.\n"<< std::flush;
239 
240  return match;
241 }
static const int debug_
Definition: DEcompare.h:94
typeT data_
Definition: DEcompare.h:98
int get_ncand(typeT) const
Definition: DEcompare.h:123
bool SortCollections(cand_vec &dg, cand_vec &eg, cand_vec &db, cand_vec &eb)
Definition: DEcompare.h:245
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< cand_type > cand_vec
Definition: DEcompare.h:30
Definition: dump.py:1
T::size_type col_sz
Definition: DEcompare.h:24
bool DumpCandidate(col_cit itd, col_cit itm, std::ofstream &, int mode=0)
Definition: DEcompare.h:313
T::const_iterator col_cit
Definition: DEcompare.h:25
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
DEutils< T > de_utils
Definition: DEcompare.h:100
typeT emul_
Definition: DEcompare.h:99
L1DEDigiCollection deDigiColl_
Definition: DEcompare.h:103
template<typename T>
int DEcompare< T >::de_type ( ) const
inline

Definition at line 78 of file DEcompare.h.

Referenced by L1Comparator::process().

78 {return de_trait::de_type();}
template<typename T >
bool DEcompare< T >::do_compare ( std::ofstream &  os,
int  dump = 0 
)

Definition at line 108 of file DEcompare.h.

References DEcompare< T >::CompareCollections(), gather_cfg::cout, DEcompare< T >::debug_, DEcompare< T >::GetName(), convertSQLiteXML::ok, AlCaHLTBitMon_QueryRunRegistry::string, and DEcompare< T >::t_match.

Referenced by DEcompare< T >::DEcompare(), and L1Comparator::process().

108  {
109  if(debug_)
110  std::cout << " DEcompare::do_compare... "
111  << GetName() << "\n" << std::flush;
113  std::string ok;
114  if(t_match) ok="successful";
115  else ok="failed";
116  if(dump==-1 || (dump==1 && !t_match))
117  os << " ..." << GetName()
118  << " data and emulator comparison: " << ok.c_str() << std::endl;
119  return t_match;
120 }
bool CompareCollections(std::ofstream &, int dump=0)
Definition: DEcompare.h:134
static const int debug_
Definition: DEcompare.h:94
std::string GetName(int i=0) const
Definition: DEcompare.h:75
Definition: dump.py:1
bool t_match
Definition: DEcompare.h:101
template<typename T >
bool DEcompare< T >::DumpCandidate ( col_cit  itd,
col_cit  itm,
std::ofstream &  os,
int  mode = 0 
)

Definition at line 313 of file DEcompare.h.

References DEcompare< T >::de_utils, and DEcompare< T >::print().

Referenced by DEcompare< T >::CompareCollections(), and DEcompare< T >::DEcompare().

313  {
314  if(mode!=2)
315  os << " data: " << print(itd);
316  if(mode!=1)
317  os << " emul: " << print(itm) << std::endl;
318  if(mode==0)
319  if( !de_utils.de_equal(*itd,*itm) )
320  return false;
321  return true;
322 }
std::string print() const
Definition: DEcompare.h:83
DEutils< T > de_utils
Definition: DEcompare.h:100
template<typename T>
bool DEcompare< T >::get_match ( ) const
inline

Definition at line 79 of file DEcompare.h.

References DEcompare< T >::t_match.

79 {return t_match;}
bool t_match
Definition: DEcompare.h:101
template<typename T >
int DEcompare< T >::get_ncand ( typeT  col) const

Definition at line 123 of file DEcompare.h.

References DEcompare< T >::is_empty().

Referenced by DEcompare< T >::CompareCollections(), DEcompare< T >::DEcompare(), L1Comparator::process(), and DEcompare< T >::SortCollections().

123  {
124  int ncand=0;
125  for (col_cit it = col->begin(); it!=col->end(); it++) {
126  if(!is_empty(it)) {
127  ncand++;
128  }
129  }
130  return ncand;
131 }
bool is_empty(col_cit it) const
Definition: DEcompare.h:77
T::const_iterator col_cit
Definition: DEcompare.h:25
col
Definition: cuy.py:1008
template<typename T>
int DEcompare< T >::get_ncand ( int  i) const
inline

Definition at line 68 of file DEcompare.h.

References DEcompare< T >::debug_, mps_fire::i, LogDebug, and DEcompare< T >::ncand_.

68  {
69  if(debug_ && (i<0 || i>2) )
70  LogDebug("DEcompare")
71  << "DEcompare illegal number of candidates request flag:"<<i<<"\n";
72  return ncand_[i];
73  }
#define LogDebug(id)
static const int debug_
Definition: DEcompare.h:94
int ncand_[2]
Definition: DEcompare.h:102
template<typename T>
L1DEDigiCollection DEcompare< T >::getDEDigis ( ) const
inline

Definition at line 81 of file DEcompare.h.

References DEcompare< T >::deDigiColl_.

Referenced by L1Comparator::process().

81 {return deDigiColl_;}
L1DEDigiCollection deDigiColl_
Definition: DEcompare.h:103
template<typename T>
std::string DEcompare< T >::GetName ( int  i = 0) const
inline

Definition at line 75 of file DEcompare.h.

References DEcompare< T >::de_utils, and mps_fire::i.

Referenced by DEcompare< T >::DEcompare(), DEcompare< T >::do_compare(), and L1Comparator::process().

75 {return de_utils.GetName(i);}
DEutils< T > de_utils
Definition: DEcompare.h:100
template<typename T>
bool DEcompare< T >::is_empty ( col_cit  it) const
inline
template<typename T>
std::string DEcompare< T >::print ( col_cit  it) const
inline

Definition at line 76 of file DEcompare.h.

References DEcompare< T >::de_utils.

Referenced by L1Comparator::process().

76 {return de_utils.print(it);}
DEutils< T > de_utils
Definition: DEcompare.h:100
template<typename T>
std::string DEcompare< T >::print ( void  ) const
inline

Definition at line 83 of file DEcompare.h.

References DEcompare< T >::data_, DEcompare< T >::emul_, and DEcompare< T >::is_empty().

Referenced by DEcompare< T >::DumpCandidate().

83  {
84  std::stringstream ss("");
85  for(col_cit itd=data_->begin();itd!=data_->end();itd++)
86  if(!is_empty(itd)) ss << " data: " << print(itd);
87  for(col_cit itm=emul_->begin();itm!=emul_->end();itm++)
88  if(!is_empty(itm)) ss << " emul: " << print(itm);
89  return ss.str();
90  }
typeT data_
Definition: DEcompare.h:98
std::string print() const
Definition: DEcompare.h:83
bool is_empty(col_cit it) const
Definition: DEcompare.h:77
T::const_iterator col_cit
Definition: DEcompare.h:25
typeT emul_
Definition: DEcompare.h:99
template<typename T >
bool DEcompare< T >::SortCollections ( cand_vec dg,
cand_vec eg,
cand_vec db,
cand_vec eb 
)

Definition at line 245 of file DEcompare.h.

References gather_cfg::cout, DEcompare< T >::data_, DEcompare< T >::de_utils, DEcompare< T >::debug_, DEcompare< T >::emul_, DEcompare< T >::get_ncand(), DEcompare< T >::is_empty(), and match().

Referenced by DEcompare< T >::CompareCollections(), and DEcompare< T >::DEcompare().

246  {
247  if(debug_)
248  std::cout << " DEcompare::SortCollections...\n"<< std::flush;
249 
250  bool match = true;
251  cand_vec data_tmp, emul_tmp;
252 
253  data_good.clear();
254  emul_good.clear();
255  data_bad .clear();
256  emul_bad .clear();
257  data_tmp .clear();
258  emul_tmp .clear();
259 
260  for(col_cit ite = emul_->begin(); ite != emul_->end(); ite++) {
261  if(!is_empty(ite)) {
262  emul_tmp.push_back(*ite);
263  }
264  }
265 
266  for(col_cit itd = data_->begin(); itd != data_->end(); itd++) {
267  if(is_empty(itd)) continue;
268  col_it ite = emul_tmp.end();
269  ite = de_utils.de_find(emul_tmp.begin(),emul_tmp.end(),*itd);
270  if(ite!=emul_tmp.end()) {
271  data_good.push_back(*itd);
272  emul_good.push_back(*ite);
273  ite=emul_tmp.erase(ite);
274  } else {
275  data_tmp.push_back(*itd);
276  match &= false;
277  }
278  }
279 
280  for(col_it itd = data_tmp.begin(); itd != data_tmp.end(); itd++) {
281  for(col_it ite = emul_tmp.begin(); ite != emul_tmp.end(); ite++) {
282  if(de_utils.de_equal_loc(*itd,*ite)) {
283  data_bad.push_back(*itd);
284  emul_bad.push_back(*ite);
285  itd = data_tmp.erase(itd)-1;
286  ite = emul_tmp.erase(ite)-1;
287  break;
288  }
289  }
290  }
291 
292  sort(data_tmp.begin(), data_tmp.end(),de_rank<coll_type>());
293  sort(emul_tmp.begin(), emul_tmp.end(),de_rank<coll_type>());
294 
295  data_bad.insert(data_bad.end(),data_tmp.begin(),data_tmp.end());
296  emul_bad.insert(emul_bad.end(),emul_tmp.begin(),emul_tmp.end());
297 
298  if(debug_)
299  std::cout << "\tDEcompare stats1:"
300  << " data_bad:" << data_bad .size()
301  << " emul_bad:" << emul_bad .size()
302  << " data_good:" << data_good.size()
303  << " emul_good:" << emul_good.size()
304  << " data: " << get_ncand(data_)
305  << " emul: " << get_ncand(emul_)
306  << "\n" << std::flush;
307  if(debug_)
308  std::cout << "DEcompare<T>::SortCollections end.\n"<< std::flush;
309  return match;
310 }
— order candidates —
Definition: DEcompare.h:17
static const int debug_
Definition: DEcompare.h:94
typeT data_
Definition: DEcompare.h:98
int get_ncand(typeT) const
Definition: DEcompare.h:123
std::vector< cand_type > cand_vec
Definition: DEcompare.h:30
bool is_empty(col_cit it) const
Definition: DEcompare.h:77
T::const_iterator col_cit
Definition: DEcompare.h:25
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
DEutils< T > de_utils
Definition: DEcompare.h:100
T::iterator col_it
Definition: DEcompare.h:26
typeT emul_
Definition: DEcompare.h:99

Member Data Documentation

template<typename T>
typeT DEcompare< T >::data_
private
template<typename T>
DEutils<T> DEcompare< T >::de_utils
private
template<typename T>
const int DEcompare< T >::debug_ =0
static
template<typename T>
L1DEDigiCollection DEcompare< T >::deDigiColl_
private
template<typename T>
typeT DEcompare< T >::emul_
private
template<typename T>
int DEcompare< T >::ncand_[2]
private

Definition at line 102 of file DEcompare.h.

Referenced by DEcompare< T >::DEcompare(), and DEcompare< T >::get_ncand().

template<typename T>
bool DEcompare< T >::t_match
private

Definition at line 101 of file DEcompare.h.

Referenced by DEcompare< T >::do_compare(), and DEcompare< T >::get_match().