CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/DetectorDescription/Core/src/DDsvalues.cc

Go to the documentation of this file.
00001 #include "DetectorDescription/Core/interface/DDsvalues.h"
00002 
00003 #include<iostream>
00004 namespace {
00005 
00006   struct Counter {
00007     int empty;
00008     int begin;
00009     int end;
00010     int middle;
00011     int mixed;
00012     ~Counter() {
00013     }
00014 
00015   };
00016 
00017 
00018 }
00019 
00020 
00021 void merge(DDsvalues_type & target, DDsvalues_type const & sv, bool sortit /* =true */) {
00022   static Counter counter = {0,0,0,0,0};
00023   if (target.empty()) {
00024     ++counter.empty;
00025     target = sv; 
00026     return;
00027   }
00028   DDsvalues_type::const_iterator sit = sv.begin();
00029   DDsvalues_type::const_iterator sed = sv.end();
00030   // fast merge
00031   if (target.back()<sv.front()) {
00032     ++counter.end;
00033     target.insert(target.end(),sit,sed);
00034     return;
00035   }
00036   if (sv.back()<target.front()) {
00037     ++counter.begin;
00038     target.insert(target.begin(),sit,sed);
00039     return;
00040   }
00041   {
00042     DDsvalues_type::iterator it = std::lower_bound(target.begin(),target.end(),sv.front()); 
00043     if (it == std::lower_bound(target.begin(),target.end(),sv.back())) {
00044       ++counter.middle; 
00045       target.insert(it,sit,sed);
00046       return;
00047     }
00048   }
00049   // it nevers arrives here...
00050   ++counter.mixed;
00051   target.reserve(target.size()+sv.size());
00052   DDsvalues_type::const_iterator ted = target.end();
00053   for (; sit != sed; ++sit) {
00054     DDsvalues_type::const_iterator it = find(target.begin(),ted, (*sit).first);
00055     if (it!=ted) const_cast<DDsvalues_Content_type&>(*it).second = (*sit).second;
00056     else target.push_back(*sit);
00057   }
00058   if (sortit) std::sort(target.begin(),target.end());
00059 }
00060 
00061 
00062 std::ostream & operator<<(std::ostream & os , const DDsvalues_type & s)
00063 {
00064   DDsvalues_type::const_iterator it = s.begin();
00065   for(; it != s.end(); ++it)  {
00066     os << it->second; 
00067     /*
00068     os << DDValue(it->first).name() << " = ";
00069     for (unsigned int i=0; i<it->second.size(); ++i) {
00070        os << it->second[i] << ' ';
00071     }    
00072     os << std::endl;
00073     */
00074   }  
00075   return os;
00076 }
00077 
00078 
00079 std::ostream & operator<<(std::ostream & os , const std::vector<const DDsvalues_type*> & v)
00080 {
00081    for (unsigned int i=0; i<v.size() ; ++i) {
00082      os << *(v[i]); // << std::endl;
00083    }
00084    
00085    return os;
00086 }
00087 
00102 bool DDfetch(const DDsvalues_type * p, DDValue & v)
00103 {
00104   bool result = false;
00105   DDsvalues_type::const_iterator it = find(*p, v);
00106   if (it != p->end()) {
00107     result = true;
00108     v = it->second;
00109   }
00110   return result;
00111 }
00112 
00113 
00114 unsigned int DDfetch(const std::vector<const DDsvalues_type *> & sp, DDValue & toFetch, std::vector<DDValue> & result)
00115 {
00116    unsigned int count = 0;
00117    std::vector<const DDsvalues_type *>::const_iterator it(sp.begin()), ed(sp.end());
00118    for (; it != ed; ++it) {
00119      if (DDfetch(*it, toFetch)) {
00120        result.push_back(toFetch);
00121        ++count;
00122      }
00123    }    
00124    return count;
00125 }
00126 
00127 /*
00128 DDValue DDsvalues_type::operator[](const unsigned int& i) const
00129 {
00130     return DDValue(i);
00131 }
00132 */