CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/DetectorDescription/Core/src/DDComparator.cc

Go to the documentation of this file.
00001 #include "DetectorDescription/Core/interface/DDComparator.h"
00002 //#include "DetectorDescription/Core/interface/DDPartSelection.h"
00003 //#include "DetectorDescription/Base/interface/DDException.h"
00004 
00005 #include<map>
00006 #include<iostream>
00007 
00008 namespace {
00009 
00010   struct Counter {
00011     int old;
00012     int diff;
00013     int t;
00014     int f;
00015     std::map<int,int> res;
00016     std::map<int,int> siz;
00017     Counter() :old(0),diff(0),t(0),f(0){}
00018     ~Counter() {
00019       for (std::map<int,int>::const_iterator p=res.begin();p!=res.end(); ++p)
00020         std::cout << (*p).first <<","<<(*p).second <<" "; 
00021       if (!res.empty()) std::cout << std::endl;
00022        for (std::map<int,int>::const_iterator p=siz.begin();p!=siz.end(); ++p)
00023         std::cout << (*p).first <<","<<(*p).second <<" "; 
00024        if (!siz.empty()) std::cout << std::endl;
00025     }
00026     void add(bool r, int /*id*/, int /*im*/) {
00027       if(r) {
00028         ++t;
00029         return;
00030       }
00031       else ++f;
00032       /*
00033       std::map<int,int>::iterator p;
00034       p= res.find(im-id);
00035       if (p==res.end()) res[im-id]=1;
00036       else ++(*p).second;
00037       p= siz.find(id);
00038       if (p==siz.end()) siz[id]=1;
00039       else ++(*p).second;
00040       */
00041     }
00042 
00043   };
00044 
00045   inline Counter & counter() {
00046     static Counter local;
00047     return local;
00048   }
00049 
00050 }
00051 
00052 // reason for the ctor: reference initialization at construction.
00053 // FIXME: DDCompareEqual: use pointers instead of references, initialize to 0 and 
00054 // FIXME: do the check in operator() instead of in the ctor
00055 
00056 bool DDCompareEqual::operator() (const DDGeoHistory &, const DDPartSelection &) 
00057 {
00058   return (*this)();
00059 }
00060 
00061 bool DDCompareEqual::operator() () 
00062 {
00063 
00064   // don't compare, if history or partsel is empty! (see ctor) 
00065   bool result(absResult_);
00066   
00067   /*
00068      sIndex_  =  running index in the part-selection-std::vector
00069      sMax_    =  max. value + 1 of sIndex_
00070      hIndex_  =  runninig index in the geo-history-std::vector
00071      hMax_    =  max. value + 1 of hIndex_
00072      sLp_     =  current LogicalPart (the redir-ptr!) in the part-selection-std::vector
00073      hLp_     =  current LogicalPart (the redir-ptr!) in the geo-history-std::vector
00074      sCopyno_ =  current copy-no in the part-selection-std::vector
00075   */
00076   //DCOUT('U', "DDCompareEqual: comparing");
00077     
00078   while(result && sIndex_ < sMax_) {
00079     sLp_ = partsel_[sIndex_].lp_;
00080     sCopyno_ = partsel_[sIndex_].copyno_;
00081     ddselection_type stype = partsel_[sIndex_].selectionType_; 
00082     switch (stype) {
00083    
00084      case ddanylogp:
00085         result=nextAnylogp(); 
00086         break;
00087    
00088      case ddanyposp:
00089         result=nextAnyposp();
00090         break;
00091          
00092      case ddchildlogp:
00093         result=nextChildlogp();
00094         break;
00095         
00096      case ddchildposp:
00097         result=nextChildposp();
00098         break;
00099         
00100      case ddanychild:
00101         ++sIndex_;
00102         ++hIndex_;
00103         result=true;
00104         break;
00105      
00106      // ddanynode IS NOT SUPPORTED IN PROTOTYPE SW !!!!
00107      case ddanynode:
00108         result=false;
00109         break;
00110                 
00111      default:
00112       result=false;
00113       //throw DDException("DDCompareEqual: undefined state!");
00114     }
00115     ++sIndex_;
00116   }
00117   counter().add(result,sIndex_, sMax_);
00118   return result;
00119 }
00120 
00121 
00122 bool DDCompareEqual::nextAnylogp()
00123 {
00124   /* does not help, most of the time is spent when FALSE....
00125   static size_t hIndexOld=0;
00126   // hope same position that previous
00127   {
00128     size_t oldH = hIndexOld; // thread safe??? 
00129     if (oldH<hMax_ && sLp_== hist_[oldH].logicalPart()) {
00130       hIndex_ = oldH+1;
00131       ++counter.old;
00132       return true;
00133     }
00134   }
00135   */
00136   register size_t hi = hIndex_;
00137   while (hi < hMax_) {
00138     if (sLp_==hist_[hi].logicalPart()) {
00139       // hIndexOld=hIndex_;
00140       // ++counter.diff;
00141       hIndex_ = hi+1;
00142       return true;
00143     }
00144     ++hi;  
00145   }
00146   hIndex_ = hi;
00147   return false;
00148 }
00149 
00150 
00151 bool DDCompareEqual::nextAnyposp()
00152 {
00153   bool result(false);
00154   while (hIndex_ < hMax_) {
00155     if (sLp_ == hist_[hIndex_].logicalPart() && 
00156         sCopyno_ == hist_[hIndex_].copyno() ) 
00157      { result=true;
00158        ++hIndex_; 
00159        break; 
00160      }
00161     ++hIndex_;
00162   }    
00163   return result;
00164 }
00165 
00166 
00167 bool DDCompareEqual::nextChildlogp()
00168 {
00169   bool result(false);
00170   if (hIndex_ < hMax_) {
00171     if (sLp_ == hist_[hIndex_].logicalPart()) {
00172       ++hIndex_;
00173       result=true;
00174     }
00175   }
00176   return result;
00177 }
00178 
00179 
00180 bool DDCompareEqual::nextChildposp()
00181 {
00182   bool result(false);
00183   if (hIndex_ < hMax_) {
00184     if (sLp_ == hist_[hIndex_].logicalPart() &&
00185         sCopyno_ == hist_[hIndex_].copyno() ) {
00186       ++hIndex_;
00187       result=true;
00188     }
00189   }
00190   return result;
00191 }