CMS 3D CMS Logo

DetGroupMerger.cc
Go to the documentation of this file.
1 #include "DetGroupMerger.h"
3 
4 using namespace std;
5 
6 
7 void
9  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 = std::move(two);
18  if (firstIndex == firstCrossed) incrementAndDoubleSize(result);
19  else doubleIndexSize(result);
20  }
21  else if (two.empty()) {
22  result = std::move(one);
23  if (firstIndex == firstCrossed) doubleIndexSize(result);
24  else incrementAndDoubleSize(result);
25  }
26  else { // both are not empty
27  if (firstIndex == firstCrossed) mergeTwoLevels( std::move(one), std::move(two), result);
28  else mergeTwoLevels( std::move(two), std::move(one), result);
29  }
30 }
31 
32 
33 void
34 DetGroupMerger::mergeTwoLevels( vector<DetGroup>&& one, 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 (auto && dg : one) {
42  result.push_back(std::move(dg));
43  result.back().setIndexSize(indSize1+indSize2);
44  }
45  for (auto && dg : two) {
46  result.push_back(std::move(dg));
47  result.back().incrementIndex(indSize1);
48  }
49 }
50 
51 void
52 DetGroupMerger::addSameLevel(vector<DetGroup>&& gvec, vector<DetGroup>& result) {
53  for (auto && ig : gvec) {
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)
static void incrementAndDoubleSize(std::vector< DetGroup > &vec)
int ires[2]
static void mergeTwoLevels(std::vector< DetGroup > &&one, std::vector< DetGroup > &&two, std::vector< DetGroup > &result)
static void addSameLevel(std::vector< DetGroup > &&gvec, std::vector< DetGroup > &result)
static void doubleIndexSize(std::vector< DetGroup > &vec)
static void orderAndMergeTwoLevels(std::vector< DetGroup > &&one, std::vector< DetGroup > &&two, std::vector< DetGroup > &result, int firstIndex, int firstCrossed)
def move(src, dest)
Definition: eostools.py:510