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 }
mps_fire.i
i
Definition: mps_fire.py:428
SiPixelPI::one
Definition: SiPixelPayloadInspectorHelper.h:39
MessageLogger.h
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
ires
int ires[2]
Definition: CascadeWrapper.h:19
DetGroupMerger::doubleIndexSize
static void doubleIndexSize(std::vector< DetGroup > &vec)
Definition: DetGroupMerger.cc:76
DetGroupMerger.h
DetGroupMerger::orderAndMergeTwoLevels
static void orderAndMergeTwoLevels(std::vector< DetGroup > &&one, std::vector< DetGroup > &&two, std::vector< DetGroup > &result, int firstIndex, int firstCrossed)
Definition: DetGroupMerger.cc:6
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
DetGroupMerger::mergeTwoLevels
static void mergeTwoLevels(std::vector< DetGroup > &&one, std::vector< DetGroup > &&two, std::vector< DetGroup > &result)
Definition: DetGroupMerger.cc:31
DetGroupMerger::incrementAndDoubleSize
static void incrementAndDoubleSize(std::vector< DetGroup > &vec)
Definition: DetGroupMerger.cc:83
SiPixelPI::two
Definition: SiPixelPayloadInspectorHelper.h:39
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
mps_fire.result
result
Definition: mps_fire.py:311
DetGroupMerger::addSameLevel
static void addSameLevel(std::vector< DetGroup > &&gvec, std::vector< DetGroup > &result)
Definition: DetGroupMerger.cc:47