CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/RecoTracker/TkDetLayers/src/DetGroupMerger.cc

Go to the documentation of this file.
00001 #include "DetGroupMerger.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 
00004 using namespace std;
00005 
00006 
00007 void
00008 DetGroupMerger::orderAndMergeTwoLevels( vector<DetGroup>&& one,  
00009                                         vector<DetGroup>&& two,
00010                                         std::vector<DetGroup>& result,
00011                                         int firstIndex, 
00012                                         int firstCrossed) {
00013   if (one.empty() && two.empty()) return;
00014 
00015 
00016   if (one.empty()) {
00017     result = std::move(two);
00018     if (firstIndex == firstCrossed) incrementAndDoubleSize(result); 
00019     else                            doubleIndexSize(result);
00020   }
00021   else if (two.empty()) {
00022     result = std::move(one);
00023     if (firstIndex == firstCrossed) doubleIndexSize(result);
00024     else                            incrementAndDoubleSize(result);
00025   }
00026   else { // both are not empty
00027     if (firstIndex == firstCrossed) mergeTwoLevels( std::move(one), std::move(two), result);
00028     else                            mergeTwoLevels( std::move(two), std::move(one), result);
00029   }
00030 }
00031 
00032 
00033 void
00034 DetGroupMerger::mergeTwoLevels( vector<DetGroup>&& one,  vector<DetGroup>&& two, std::vector<DetGroup>& result) {
00035 
00036   result.reserve( one.size() + two.size());
00037 
00038   int indSize1 = one.front().indexSize();
00039   int indSize2 = two.front().indexSize();
00040 
00041   for (auto && dg : one) {
00042     result.push_back(std::move(dg));
00043     result.back().setIndexSize(indSize1+indSize2);
00044   }
00045   for (auto && dg : two) {
00046     result.push_back(std::move(dg));
00047     result.back().incrementIndex(indSize1);
00048   }
00049 }
00050 
00051 void 
00052 DetGroupMerger::addSameLevel(vector<DetGroup>&& gvec, vector<DetGroup>& result) {
00053   for (auto && ig : gvec) {
00054     int gSize = ig.indexSize();
00055     int index = ig.index(); // at which level it should be inserted
00056     bool found = false;
00057     for (vector<DetGroup>::iterator ires=result.begin(); ires!=result.end(); ires++) {
00058       int resSize = ires->indexSize();
00059       if (gSize != resSize) {
00060         LogDebug("TkDetLayers") << "DetGroupMerger::addSameLevel called with groups of different index sizes";
00061         // throw something appropriate...or handle it properly (may happen in petals?)
00062       }
00063 
00064       int resIndex = ires->index();
00065       if (index == resIndex) {
00066         ires->insert(ires->end(), ig.begin(), ig.end()); // insert in group with same index
00067         found = true;
00068         break;
00069       }
00070       else if (index < resIndex) {
00071         // result has no group at index level yet
00072         result.insert( ires, ig); // insert a new group, invalidates the iterator ires
00073         found = true;
00074         break;
00075       }
00076     } // end of loop over result groups
00077     if (!found) result.insert( result.end(), ig); // in case the ig index is bigger than any in result
00078   }
00079 }
00080 
00081 void 
00082 DetGroupMerger::doubleIndexSize( vector<DetGroup>& vec) {
00083   int indSize = vec.front().indexSize();
00084   for (vector<DetGroup>::iterator i=vec.begin(); i!=vec.end(); i++) {
00085     i->setIndexSize( 2*indSize);
00086   }
00087 }
00088 
00089 void 
00090 DetGroupMerger::incrementAndDoubleSize( vector<DetGroup>& vec) {
00091   int indSize = vec.front().indexSize();
00092   for (vector<DetGroup>::iterator i=vec.begin(); i!=vec.end(); i++) {
00093     i->incrementIndex( indSize);
00094   }
00095 }