CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDsvalues.cc
Go to the documentation of this file.
2 
3 #include<iostream>
4 namespace {
5 
6  struct Counter {
7  int empty;
8  int begin;
9  int end;
10  int middle;
11  int mixed;
12  ~Counter() {
13  }
14 
15  };
16 
17 
18 }
19 
20 
21 void merge(DDsvalues_type & target, DDsvalues_type const & sv, bool sortit /* =true */) {
22  static Counter counter = {0,0,0,0,0};
23  if (target.empty()) {
24  ++counter.empty;
25  target = sv;
26  return;
27  }
28  DDsvalues_type::const_iterator sit = sv.begin();
29  DDsvalues_type::const_iterator sed = sv.end();
30  // fast merge
31  if (target.back()<sv.front()) {
32  ++counter.end;
33  target.insert(target.end(),sit,sed);
34  return;
35  }
36  if (sv.back()<target.front()) {
37  ++counter.begin;
38  target.insert(target.begin(),sit,sed);
39  return;
40  }
41  {
42  DDsvalues_type::iterator it = std::lower_bound(target.begin(),target.end(),sv.front());
43  if (it == std::lower_bound(target.begin(),target.end(),sv.back())) {
44  ++counter.middle;
45  target.insert(it,sit,sed);
46  return;
47  }
48  }
49  // it nevers arrives here...
50  ++counter.mixed;
51  target.reserve(target.size()+sv.size());
52  DDsvalues_type::const_iterator ted = target.end();
53  for (; sit != sed; ++sit) {
54  DDsvalues_type::const_iterator it = find(target.begin(),ted, (*sit).first);
55  if (it!=ted) const_cast<DDsvalues_Content_type&>(*it).second = (*sit).second;
56  else target.push_back(*sit);
57  }
58  if (sortit) std::sort(target.begin(),target.end());
59 }
60 
61 
62 std::ostream & operator<<(std::ostream & os , const DDsvalues_type & s)
63 {
64  DDsvalues_type::const_iterator it = s.begin();
65  for(; it != s.end(); ++it) {
66  os << it->second;
67  /*
68  os << DDValue(it->first).name() << " = ";
69  for (unsigned int i=0; i<it->second.size(); ++i) {
70  os << it->second[i] << ' ';
71  }
72  os << std::endl;
73  */
74  }
75  return os;
76 }
77 
78 
79 std::ostream & operator<<(std::ostream & os , const std::vector<const DDsvalues_type*> & v)
80 {
81  for (unsigned int i=0; i<v.size() ; ++i) {
82  os << *(v[i]); // << std::endl;
83  }
84 
85  return os;
86 }
87 
102 bool DDfetch(const DDsvalues_type * p, DDValue & v)
103 {
104  bool result = false;
105  DDsvalues_type::const_iterator it = find(*p, v);
106  if (it != p->end()) {
107  result = true;
108  v = it->second;
109  }
110  return result;
111 }
112 
113 
114 unsigned int DDfetch(const std::vector<const DDsvalues_type *> & sp, DDValue & toFetch, std::vector<DDValue> & result)
115 {
116  unsigned int count = 0;
117  std::vector<const DDsvalues_type *>::const_iterator it(sp.begin()), ed(sp.end());
118  for (; it != ed; ++it) {
119  if (DDfetch(*it, toFetch)) {
120  result.push_back(toFetch);
121  ++count;
122  }
123  }
124  return count;
125 }
126 
127 /*
128 DDValue DDsvalues_type::operator[](const unsigned int& i) const
129 {
130  return DDValue(i);
131 }
132 */
int i
Definition: DBlmapReader.cc:9
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:102
unsigned int(* Counter)(align::ID, const TrackerTopology *)
Definition: Counters.h:27
tuple result
Definition: query.py:137
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
std::maps an index to a DDValue. The index corresponds to the index assigned to the name of the std::...
Definition: DDsvalues.h:19
#define end
Definition: vmac.h:37
#define begin
Definition: vmac.h:30
static std::atomic< unsigned int > counter
DDsvalues_type::value_type DDsvalues_Content_type
Definition: DDsvalues.h:20