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 
5 void merge(DDsvalues_type & target, DDsvalues_type const & sv, bool sortit /* =true */) {
6  if (target.empty()) {
7  target = sv;
8  return;
9  }
10  DDsvalues_type::const_iterator sit = sv.begin();
11  DDsvalues_type::const_iterator sed = sv.end();
12  // fast merge
13  if (target.back()<sv.front()) {
14  target.insert(target.end(),sit,sed);
15  return;
16  }
17  if (sv.back()<target.front()) {
18  target.insert(target.begin(),sit,sed);
19  return;
20  }
21  {
22  DDsvalues_type::iterator it = std::lower_bound(target.begin(),target.end(),sv.front());
23  if (it == std::lower_bound(target.begin(),target.end(),sv.back())) {
24  target.insert(it,sit,sed);
25  return;
26  }
27  }
28  // it nevers arrives here...
29  target.reserve(target.size()+sv.size());
30  DDsvalues_type::const_iterator ted = target.end();
31  for (; sit != sed; ++sit) {
32  DDsvalues_type::const_iterator it = find(target.begin(),ted, (*sit).first);
33  if (it!=ted) const_cast<DDsvalues_Content_type&>(*it).second = (*sit).second;
34  else target.push_back(*sit);
35  }
36  if (sortit) std::sort(target.begin(),target.end());
37 }
38 
39 
40 std::ostream & operator<<(std::ostream & os , const DDsvalues_type & s)
41 {
42  DDsvalues_type::const_iterator it = s.begin();
43  for(; it != s.end(); ++it) {
44  os << it->second;
45  /*
46  os << DDValue(it->first).name() << " = ";
47  for (unsigned int i=0; i<it->second.size(); ++i) {
48  os << it->second[i] << ' ';
49  }
50  os << std::endl;
51  */
52  }
53  return os;
54 }
55 
56 
57 std::ostream & operator<<(std::ostream & os , const std::vector<const DDsvalues_type*> & v)
58 {
59  for (unsigned int i=0; i<v.size() ; ++i) {
60  os << *(v[i]); // << std::endl;
61  }
62 
63  return os;
64 }
65 
80 bool DDfetch(const DDsvalues_type * p, DDValue & v)
81 {
82  bool result = false;
83  DDsvalues_type::const_iterator it = find(*p, v);
84  if (it != p->end()) {
85  result = true;
86  v = it->second;
87  }
88  return result;
89 }
90 
91 
92 unsigned int DDfetch(const std::vector<const DDsvalues_type *> & sp, DDValue & toFetch, std::vector<DDValue> & result)
93 {
94  unsigned int count = 0;
95  std::vector<const DDsvalues_type *>::const_iterator it(sp.begin()), ed(sp.end());
96  for (; it != ed; ++it) {
97  if (DDfetch(*it, toFetch)) {
98  result.push_back(toFetch);
99  ++count;
100  }
101  }
102  return count;
103 }
104 
105 /*
106 DDValue DDsvalues_type::operator[](const unsigned int& i) const
107 {
108  return DDValue(i);
109 }
110 */
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:80
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
DDsvalues_type::value_type DDsvalues_Content_type
Definition: DDsvalues.h:20