CMS 3D CMS Logo

DetGroupMerger.cc

Go to the documentation of this file.
00001 #include "RecoTracker/TkDetLayers/interface/DetGroupMerger.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 
00004 using namespace std;
00005 
00006 
00007 void
00008 DetGroupMerger::orderAndMergeTwoLevels( const vector<DetGroup>& one,  
00009                                         const 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 = two;
00018     if (firstIndex == firstCrossed) incrementAndDoubleSize(result); 
00019     else                            doubleIndexSize(result);
00020   }
00021   else if (two.empty()) {
00022     result = one;
00023     if (firstIndex == firstCrossed) doubleIndexSize(result);
00024     else                            incrementAndDoubleSize(result);
00025   }
00026   else { // both are not empty
00027     if (firstIndex == firstCrossed) mergeTwoLevels( one, two,result);
00028     else                            mergeTwoLevels( two, one, result);
00029   }
00030 }
00031 
00032 
00033 void
00034 DetGroupMerger::mergeTwoLevels( const vector<DetGroup>& one,  const 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 (vector<DetGroup>::const_iterator i=one.begin(); i!=one.end(); i++) {
00042     result.push_back(*i);
00043     result.back().setIndexSize(indSize1+indSize2);
00044   }
00045   for (vector<DetGroup>::const_iterator j=two.begin(); j!=two.end(); j++) {
00046     result.push_back(*j);
00047     result.back().incrementIndex(indSize1);
00048   }
00049 }
00050 
00051 void 
00052 DetGroupMerger::addSameLevel( const vector<DetGroup>& gvec, vector<DetGroup>& result) {
00053   for (vector<DetGroup>::const_iterator ig=gvec.begin(); ig != gvec.end(); ig++) {
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 }

Generated on Tue Jun 9 17:45:46 2009 for CMSSW by  doxygen 1.5.4