CMS 3D CMS Logo

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