CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDComparator.cc
Go to the documentation of this file.
2 //#include "DetectorDescription/Core/interface/DDPartSelection.h"
3 //#include "DetectorDescription/Base/interface/DDException.h"
4 
5 #include<map>
6 #include<iostream>
7 
8 namespace {
9 
10  struct Counter {
11  int old;
12  int diff;
13  int t;
14  int f;
15  std::map<int,int> res;
16  std::map<int,int> siz;
17  Counter() :old(0),diff(0),t(0),f(0){}
18  ~Counter() {
19  for (std::map<int,int>::const_iterator p=res.begin();p!=res.end(); ++p)
20  std::cout << (*p).first <<","<<(*p).second <<" ";
21  if (!res.empty()) std::cout << std::endl;
22  for (std::map<int,int>::const_iterator p=siz.begin();p!=siz.end(); ++p)
23  std::cout << (*p).first <<","<<(*p).second <<" ";
24  if (!siz.empty()) std::cout << std::endl;
25  }
26  void add(bool r, int /*id*/, int /*im*/) {
27  if(r) {
28  ++t;
29  return;
30  }
31  else ++f;
32  /*
33  std::map<int,int>::iterator p;
34  p= res.find(im-id);
35  if (p==res.end()) res[im-id]=1;
36  else ++(*p).second;
37  p= siz.find(id);
38  if (p==siz.end()) siz[id]=1;
39  else ++(*p).second;
40  */
41  }
42 
43  };
44 
45  inline Counter & counter() {
46  static Counter local;
47  return local;
48  }
49 
50 }
51 
52 // reason for the ctor: reference initialization at construction.
53 // FIXME: DDCompareEqual: use pointers instead of references, initialize to 0 and
54 // FIXME: do the check in operator() instead of in the ctor
55 
57 {
58  return (*this)();
59 }
60 
62 {
63 
64  // don't compare, if history or partsel is empty! (see ctor)
65  bool result(absResult_);
66 
67  /*
68  sIndex_ = running index in the part-selection-std::vector
69  sMax_ = max. value + 1 of sIndex_
70  hIndex_ = runninig index in the geo-history-std::vector
71  hMax_ = max. value + 1 of hIndex_
72  sLp_ = current LogicalPart (the redir-ptr!) in the part-selection-std::vector
73  hLp_ = current LogicalPart (the redir-ptr!) in the geo-history-std::vector
74  sCopyno_ = current copy-no in the part-selection-std::vector
75  */
76  //DCOUT('U', "DDCompareEqual: comparing");
77 
78  while(result && sIndex_ < sMax_) {
79  sLp_ = partsel_[sIndex_].lp_;
80  sCopyno_ = partsel_[sIndex_].copyno_;
81  ddselection_type stype = partsel_[sIndex_].selectionType_;
82  switch (stype) {
83 
84  case ddanylogp:
85  result=nextAnylogp();
86  break;
87 
88  case ddanyposp:
89  result=nextAnyposp();
90  break;
91 
92  case ddchildlogp:
93  result=nextChildlogp();
94  break;
95 
96  case ddchildposp:
97  result=nextChildposp();
98  break;
99 
100  case ddanychild:
101  ++sIndex_;
102  ++hIndex_;
103  result=true;
104  break;
105 
106  // ddanynode IS NOT SUPPORTED IN PROTOTYPE SW !!!!
107  case ddanynode:
108  result=false;
109  break;
110 
111  default:
112  result=false;
113  //throw DDException("DDCompareEqual: undefined state!");
114  }
115  ++sIndex_;
116  }
117  counter().add(result,sIndex_, sMax_);
118  return result;
119 }
120 
121 
123 {
124  /* does not help, most of the time is spent when FALSE....
125  static size_t hIndexOld=0;
126  // hope same position that previous
127  {
128  size_t oldH = hIndexOld; // thread safe???
129  if (oldH<hMax_ && sLp_== hist_[oldH].logicalPart()) {
130  hIndex_ = oldH+1;
131  ++counter.old;
132  return true;
133  }
134  }
135  */
136  register size_t hi = hIndex_;
137  while (hi < hMax_) {
138  if (sLp_==hist_[hi].logicalPart()) {
139  // hIndexOld=hIndex_;
140  // ++counter.diff;
141  hIndex_ = hi+1;
142  return true;
143  }
144  ++hi;
145  }
146  hIndex_ = hi;
147  return false;
148 }
149 
150 
152 {
153  bool result(false);
154  while (hIndex_ < hMax_) {
155  if (sLp_ == hist_[hIndex_].logicalPart() &&
156  sCopyno_ == hist_[hIndex_].copyno() )
157  { result=true;
158  ++hIndex_;
159  break;
160  }
161  ++hIndex_;
162  }
163  return result;
164 }
165 
166 
168 {
169  bool result(false);
170  if (hIndex_ < hMax_) {
171  if (sLp_ == hist_[hIndex_].logicalPart()) {
172  ++hIndex_;
173  result=true;
174  }
175  }
176  return result;
177 }
178 
179 
181 {
182  bool result(false);
183  if (hIndex_ < hMax_) {
184  if (sLp_ == hist_[hIndex_].logicalPart() &&
185  sCopyno_ == hist_[hIndex_].copyno() ) {
186  ++hIndex_;
187  result=true;
188  }
189  }
190  return result;
191 }
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
DDPartSelection::size_type sIndex_
Definition: DDComparator.h:48
bool nextChildposp()
DDPartSelection::size_type const sMax_
Definition: DDComparator.h:47
ddselection_type
unsigned int(* Counter)(align::ID, const TrackerTopology *)
Definition: Counters.h:27
tuple result
Definition: query.py:137
double f[11][100]
DDLogicalPart sLp_
Definition: DDComparator.h:49
std::vector< DDExpandedNode > DDGeoHistory
Geometrical &#39;path&#39; of the current node up to the root-node.
const DDPartSelection & partsel_
Definition: DDComparator.h:44
DDGeoHistory::size_type hIndex_
Definition: DDComparator.h:46
static std::atomic< unsigned int > counter
tuple cout
Definition: gather_cfg.py:121
DDGeoHistory::size_type const hMax_
Definition: DDComparator.h:45
if(conf.exists("allCellsPositionCalc"))
bool nextChildlogp()
const DDGeoHistory & hist_
Definition: DDComparator.h:43