CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DetGroupMerger.cc
Go to the documentation of this file.
1 #include "DetGroupMerger.h"
3 
4 using namespace std;
5 
6 
7 void
8 DetGroupMerger::orderAndMergeTwoLevels( const vector<DetGroup>& one,
9  const vector<DetGroup>& two,
10  std::vector<DetGroup>& result,
11  int firstIndex,
12  int firstCrossed) {
13  if (one.empty() && two.empty()) return;
14 
15 
16  if (one.empty()) {
17  result = two;
18  if (firstIndex == firstCrossed) incrementAndDoubleSize(result);
19  else doubleIndexSize(result);
20  }
21  else if (two.empty()) {
22  result = one;
23  if (firstIndex == firstCrossed) doubleIndexSize(result);
24  else incrementAndDoubleSize(result);
25  }
26  else { // both are not empty
27  if (firstIndex == firstCrossed) mergeTwoLevels( one, two,result);
28  else mergeTwoLevels( two, one, result);
29  }
30 }
31 
32 
33 void
34 DetGroupMerger::mergeTwoLevels( const vector<DetGroup>& one, const vector<DetGroup>& two, std::vector<DetGroup>& result) {
35 
36  result.reserve( one.size() + two.size());
37 
38  int indSize1 = one.front().indexSize();
39  int indSize2 = two.front().indexSize();
40 
41  for (vector<DetGroup>::const_iterator i=one.begin(); i!=one.end(); i++) {
42  result.push_back(*i);
43  result.back().setIndexSize(indSize1+indSize2);
44  }
45  for (vector<DetGroup>::const_iterator j=two.begin(); j!=two.end(); j++) {
46  result.push_back(*j);
47  result.back().incrementIndex(indSize1);
48  }
49 }
50 
51 void
52 DetGroupMerger::addSameLevel( const vector<DetGroup>& gvec, vector<DetGroup>& result) {
53  for (vector<DetGroup>::const_iterator ig=gvec.begin(); ig != gvec.end(); ig++) {
54  int gSize = ig->indexSize();
55  int index = ig->index(); // at which level it should be inserted
56  bool found = false;
57  for (vector<DetGroup>::iterator ires=result.begin(); ires!=result.end(); ires++) {
58  int resSize = ires->indexSize();
59  if (gSize != resSize) {
60  LogDebug("TkDetLayers") << "DetGroupMerger::addSameLevel called with groups of different index sizes";
61  // throw something appropriate...or handle it properly (may happen in petals?)
62  }
63 
64  int resIndex = ires->index();
65  if (index == resIndex) {
66  ires->insert(ires->end(), ig->begin(), ig->end()); // insert in group with same index
67  found = true;
68  break;
69  }
70  else if (index < resIndex) {
71  // result has no group at index level yet
72  result.insert( ires, *ig); // insert a new group, invalidates the iterator ires
73  found = true;
74  break;
75  }
76  } // end of loop over result groups
77  if (!found) result.insert( result.end(), *ig); // in case the ig index is bigger than any in result
78  }
79 }
80 
81 void
82 DetGroupMerger::doubleIndexSize( vector<DetGroup>& vec) {
83  int indSize = vec.front().indexSize();
84  for (vector<DetGroup>::iterator i=vec.begin(); i!=vec.end(); i++) {
85  i->setIndexSize( 2*indSize);
86  }
87 }
88 
89 void
90 DetGroupMerger::incrementAndDoubleSize( vector<DetGroup>& vec) {
91  int indSize = vec.front().indexSize();
92  for (vector<DetGroup>::iterator i=vec.begin(); i!=vec.end(); i++) {
93  i->incrementIndex( indSize);
94  }
95 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
static void orderAndMergeTwoLevels(const std::vector< DetGroup > &one, const std::vector< DetGroup > &two, std::vector< DetGroup > &result, int firstIndex, int firstCrossed)
static void incrementAndDoubleSize(std::vector< DetGroup > &vec)
int ires[2]
static void mergeTwoLevels(const std::vector< DetGroup > &one, const std::vector< DetGroup > &two, std::vector< DetGroup > &result)
static void doubleIndexSize(std::vector< DetGroup > &vec)
tuple result
Definition: query.py:137
int j
Definition: DBlmapReader.cc:9
static void addSameLevel(const std::vector< DetGroup > &gvec, std::vector< DetGroup > &result)