CMS 3D CMS Logo

Public Member Functions | Static Public Attributes | Private Types | Private Attributes

DEcompare< T > Class Template Reference

#include <DEcompare.h>

List of all members.

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 () const
std::string print (col_cit it) 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_type
cand_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 20 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 29 of file DEcompare.h.

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

Definition at line 27 of file DEcompare.h.

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

Definition at line 28 of file DEcompare.h.

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

Definition at line 23 of file DEcompare.h.

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

Definition at line 24 of file DEcompare.h.

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

Definition at line 22 of file DEcompare.h.

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

Definition at line 26 of file DEcompare.h.

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

Definition at line 25 of file DEcompare.h.

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

Definition at line 30 of file DEcompare.h.


Constructor & Destructor Documentation

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

Definition at line 34 of file DEcompare.h.

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

Definition at line 35 of file DEcompare.h.

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

Definition at line 37 of file DEcompare.h.

References DEcompare< T >::data_, DEcompare< T >::debug_, DEcompare< T >::deDigiColl_, DEcompare< T >::emul_, DEcompare< T >::get_ncand(), DEcompare< T >::GetName(), LogDebug, and DEcompare< T >::ncand_.

                                : 
    data_(dt), emul_(em), t_match(false){
    ncand_[0]=get_ncand(dt);
    ncand_[1]=get_ncand(em);
    deDigiColl_.clear();
    if(debug_)
      LogDebug("DEcompare") 
        << "DEcompare" 
        << ": creating instance of type: " << GetName(0)
        << ", data size:" << data_->size() << " ncand:" << ncand_[0] 
        << ", emul size:" << emul_->size() << " ncand:" << ncand_[1] 
        << ".\n" << std::flush;
  };

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 132 of file DEcompare.h.

References abs, gather_cfg::cout, i, and match().

                                                               {

  if(debug_)
    std::cout << " DEcompare::CompareCollections...\n"<< std::flush; 
  bool match = true;
  int ndata = get_ncand(0);
  int nemul = get_ncand(1);
  assert (ndata || nemul);

  cand_vec data_good, emul_good, data_bad, emul_bad; 
  data_good.reserve(data_->size());
  emul_good.reserve(emul_->size());
  data_bad .reserve(data_->size());
  emul_bad .reserve(emul_->size());

  // find matching candidates --  tbd report order match
  match &= SortCollections(data_good,emul_good,data_bad,emul_bad);  

  if(debug_)
    std::cout << "\tDEcompare stats2:" 
              << " data_bad:"  << data_bad .size()
              << " emul_bad:"  << emul_bad .size()
              << " data_good:" << data_good.size()
              << " emul_good:" << emul_good.size()
              << " data_:"     << data_->size()
              << " emul_:"     << emul_->size()
              << ".\n"         <<std::flush;
  
  if(dump==-1 || (dump==1 && !match)) {
    os << "  number of candidates: " << ndata;
    if(ndata!=nemul) {
      match &= false;
      os << " (data) " << nemul << " (emul) disagree";
    }
    os << std::endl;
  }
  

  col_cit itd, itm; 
  int prtmode=0;
  col_sz ndt=0, nem=0, nde=0;
  deDigiColl_.clear();


  ndt = data_bad.size();
  nem = emul_bad.size();
  nde = (ndt>nem)?ndt:nem;
  
  itd = data_bad.begin();
  itm = emul_bad.begin();

  if(dump==-1)
    os << "   un-matched (" << nde << ")\n";

  for (col_sz i=0; i<nde; i++) {

    if     (i< ndt && i< nem) prtmode=0; //dt+em
    else if(i< ndt && i>=nem) prtmode=1; //dt
    else if(i>=ndt && i< nem) prtmode=2; //em
    else assert(0);

    if(abs(dump)==1)
      DumpCandidate(itd,itm,os,prtmode);
    else if(prtmode==0) { 
      if( (dump==2 && !de_utils.de_equal_loc(*itd,*itm)) ||
          (dump==3 &&  de_utils.de_equal_loc(*itd,*itm)) )
        DumpCandidate(itd,itm,os,prtmode);
    }

    // Fill in DEdigi collection 
    if(prtmode==0) {
      if(de_utils.de_equal_loc(*itd,*itm)) {
        deDigiColl_.push_back( de_utils.DEDigi(itd,itm,1) );
      } else {
        deDigiColl_.push_back( de_utils.DEDigi(itd,itm,2) );
      }
    } else if (prtmode==1) {
      deDigiColl_.push_back(   de_utils.DEDigi(itd,itd,3) );
    } else if (prtmode==2) {
      deDigiColl_.push_back(   de_utils.DEDigi(itm,itm,4) );
    }

    itd++; itm++;
  }
  

  itd = data_good.begin();
  itm = emul_good.begin();

  assert(data_good.size()==emul_good.size());
  if(dump==-1)
    os << "   matched (" << data_good.size() << ")\n";

  for(col_sz i=0; i<data_good.size(); i++) {
    assert(de_utils.de_equal(*itd,*itm));
    if(dump==-1)
      DumpCandidate(itd,itm,os,prtmode);
    deDigiColl_.push_back( de_utils.DEDigi(itd,itm,0) );
    itd++; itm++;
  }  
  
  if(debug_)
    std::cout << "DEcompare<T>::CompareCollections end.\n"<< std::flush; 

  return match; 
}
template<typename T>
int DEcompare< T >::de_type ( ) const [inline]

Definition at line 76 of file DEcompare.h.

Referenced by L1Comparator::process().

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

Definition at line 106 of file DEcompare.h.

References gather_cfg::cout, and convertSQLiteXML::ok.

Referenced by L1Comparator::process().

                                                       {
  if(debug_)
    std::cout << " DEcompare::do_compare... " 
              << GetName() << "\n" << std::flush;
  t_match = CompareCollections(os,dump);
  char ok[10];
  if(t_match) sprintf(ok,"successful");
  else        sprintf(ok,"failed");
  if(dump==-1 || (dump==1 && !t_match))
    os << "  ..." << GetName() 
       << " data and emulator comparison: " << ok << std::endl;
  return t_match;
}
template<typename T >
bool DEcompare< T >::DumpCandidate ( col_cit  itd,
col_cit  itm,
std::ofstream &  os,
int  mode = 0 
)

Definition at line 311 of file DEcompare.h.

References reco::print().

                                                                                    {
  if(mode!=2)
    os << "   data: " << print(itd);
  if(mode!=1)
    os << "   emul: " << print(itm) << std::endl;
  if(mode==0) 
    if( !de_utils.de_equal(*itd,*itm) ) 
      return false;
  return true;
}
template<typename T>
bool DEcompare< T >::get_match ( ) const [inline]

Definition at line 77 of file DEcompare.h.

References DEcompare< T >::t_match.

{return t_match;}
template<typename T >
int DEcompare< T >::get_ncand ( typeT  col) const

Definition at line 121 of file DEcompare.h.

References utils::is_empty().

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

                                           {
  int ncand=0;
  for (col_cit it = col->begin(); it!=col->end(); it++) {
    if(!is_empty(it)) {
      ncand++;
    }
  }
  return ncand;
}
template<typename T>
int DEcompare< T >::get_ncand ( int  i) const [inline]

Definition at line 66 of file DEcompare.h.

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

                             {
    if(debug_ && (i<0 || i>2) )
      LogDebug("DEcompare") 
        << "DEcompare illegal number of candidates request flag:"<<i<<"\n";
    return ncand_[i];
  }
template<typename T>
L1DEDigiCollection DEcompare< T >::getDEDigis ( ) const [inline]

Definition at line 79 of file DEcompare.h.

References DEcompare< T >::deDigiColl_.

Referenced by L1Comparator::process().

{return deDigiColl_;}
template<typename T>
std::string DEcompare< T >::GetName ( int  i = 0) const [inline]

Definition at line 73 of file DEcompare.h.

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

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

{return de_utils.GetName(i);}
template<typename T>
bool DEcompare< T >::is_empty ( col_cit  it) const [inline]

Definition at line 75 of file DEcompare.h.

References DEcompare< T >::de_utils.

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

{return de_utils.is_empty(it);}
template<typename T>
std::string DEcompare< T >::print ( col_cit  it) const [inline]

Definition at line 74 of file DEcompare.h.

References DEcompare< T >::de_utils.

Referenced by L1Comparator::process().

{return de_utils.print(it);}
template<typename T>
std::string DEcompare< T >::print ( void  ) const [inline]

Definition at line 81 of file DEcompare.h.

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

                          {
    std::stringstream ss("");
    for(col_cit itd=data_->begin();itd!=data_->end();itd++)
      if(!is_empty(itd)) ss << "  data: " << print(itd);      
    for(col_cit itm=emul_->begin();itm!=emul_->end();itm++)
      if(!is_empty(itm)) ss << "  emul: " << print(itm);      
    return ss.str();
  }
template<typename T >
bool DEcompare< T >::SortCollections ( cand_vec dg,
cand_vec eg,
cand_vec db,
cand_vec eb 
)

Definition at line 243 of file DEcompare.h.

References gather_cfg::cout, utils::is_empty(), match(), and python::multivaluedict::sort().

                                                                             {
  if(debug_)
    std::cout << " DEcompare::SortCollections...\n"<< std::flush; 

  bool match = true;
  cand_vec data_tmp, emul_tmp;
  
  data_good.clear();
  emul_good.clear();
  data_bad .clear();
  emul_bad .clear();
  data_tmp .clear();
  emul_tmp .clear();

  for(col_cit ite = emul_->begin(); ite != emul_->end(); ite++) {
    if(!is_empty(ite)) {
      emul_tmp.push_back(*ite);
    }
  }
  
  for(col_cit itd = data_->begin(); itd != data_->end(); itd++) {
    if(is_empty(itd)) continue;
    col_it ite = emul_tmp.end();
    ite = de_utils.de_find(emul_tmp.begin(),emul_tmp.end(),*itd);
    if(ite!=emul_tmp.end()) {
      data_good.push_back(*itd);
      emul_good.push_back(*ite);
      ite=emul_tmp.erase(ite);
    } else {
      data_tmp.push_back(*itd);
      match &= false;
    }
  }

  for(col_it itd = data_tmp.begin(); itd != data_tmp.end(); itd++) {
    for(col_it ite = emul_tmp.begin(); ite != emul_tmp.end(); ite++) {
      if(de_utils.de_equal_loc(*itd,*ite)) {
        data_bad.push_back(*itd);
        emul_bad.push_back(*ite);
        itd = data_tmp.erase(itd)-1;
        ite = emul_tmp.erase(ite)-1;
        break;
      }  
    }
  }

  sort(data_tmp.begin(), data_tmp.end(),de_rank<coll_type>());
  sort(emul_tmp.begin(), emul_tmp.end(),de_rank<coll_type>());

  data_bad.insert(data_bad.end(),data_tmp.begin(),data_tmp.end());
  emul_bad.insert(emul_bad.end(),emul_tmp.begin(),emul_tmp.end());

  if(debug_)
    std::cout << "\tDEcompare stats1:" 
              << " data_bad:"  << data_bad .size()
              << " emul_bad:"  << emul_bad .size()
              << " data_good:" << data_good.size()
              << " emul_good:" << emul_good.size()
              << " data: "     << get_ncand(data_)
              << " emul: "     << get_ncand(emul_)
              << "\n" << std::flush;
  if(debug_)  
    std::cout << "DEcompare<T>::SortCollections end.\n"<< std::flush; 
  return match;
}

Member Data Documentation

template<typename T>
typeT DEcompare< T >::data_ [private]

Definition at line 96 of file DEcompare.h.

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

template<typename T>
DEutils<T> DEcompare< T >::de_utils [private]
template<typename T>
const int DEcompare< T >::debug_ = 0 [static]

Definition at line 92 of file DEcompare.h.

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

template<typename T>
L1DEDigiCollection DEcompare< T >::deDigiColl_ [private]

Definition at line 101 of file DEcompare.h.

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

template<typename T>
typeT DEcompare< T >::emul_ [private]

Definition at line 97 of file DEcompare.h.

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

template<typename T>
int DEcompare< T >::ncand_[2] [private]

Definition at line 100 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 99 of file DEcompare.h.

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