CMS 3D CMS Logo

DDValue.h
Go to the documentation of this file.
1 #ifndef DetectorDescription_Core_DDValue_h
2 #define DetectorDescription_Core_DDValue_h
3 
4 #include <atomic>
5 #include <iostream>
6 #include <memory>
7 #include <string>
8 #include <utility>
9 #include <vector>
10 
12 #include "oneapi/tbb/concurrent_unordered_map.h"
13 #include "oneapi/tbb/concurrent_vector.h"
15 
22 class DDValue {
23 public:
25  DDValue(void) : id_(0), vecPair_() {}
26 
28  explicit DDValue(const std::string&);
29 
31  explicit DDValue(const char*);
32 
34  explicit DDValue(const std::string&, const std::vector<DDValuePair>&);
35 
37  explicit DDValue(const std::string&, double);
38 
40  explicit DDValue(const std::string&, const std::string&, double);
41 
43  explicit DDValue(const std::string& name, const std::string& val);
44 
45  explicit DDValue(unsigned int);
46 
48  unsigned int id(void) const { return id_; }
49 
51  operator unsigned int(void) const { return id_; }
52 
54  const std::string& name(void) const { return *(names()[id_].string_); }
55 
58  DDValuePair operator[](unsigned int i) const;
59 
61  const std::vector<std::string>& strings() const { return vecPair_->second.first; }
62 
64  const std::vector<double>& doubles() const;
65  //const DDValuePair & operator[](unsigned int i) const { return (*valPairs_)[i] ; }
66 
68  unsigned int size() const { return vecPair_ ? vecPair_->second.first.size() : 0; }
69 
71  void setEvalState(bool newState);
72 
74 
76  bool isEvaluated(void) const;
77 
79 
81  bool operator==(const DDValue& v) const;
82 
84  bool operator<(const DDValue&) const;
85 
86 private:
88  struct StringHolder {
90  explicit StringHolder(std::string iString) : string_(new std::string{std::move(iString)}) {}
91  explicit StringHolder(StringHolder const& iOther) : string_(new std::string{*(iOther.string_)}) {}
92  StringHolder& operator=(const StringHolder&) = delete;
93  ~StringHolder() { delete string_.load(); }
94 
95  std::atomic<std::string*> string_;
96  };
97  struct AtomicUInt {
98  AtomicUInt(unsigned int iValue) : value_(iValue) {}
100  AtomicUInt(const AtomicUInt& iOther) : value_(iOther.value_.load()) {}
101  AtomicUInt& operator=(const AtomicUInt& iOther) {
102  value_ = iOther.value_.load();
103  return *this;
104  }
105 
106  std::atomic<unsigned int> value_;
107  };
108 
109  void init(const std::string&);
110 
111  using Names = tbb::concurrent_vector<StringHolder, edm::zero_allocator<StringHolder>>;
112  static Names& names();
113  static Names initializeNames();
114 
115  using NamesToIndicies = tbb::concurrent_unordered_map<std::string, AtomicUInt>;
116  static NamesToIndicies& indexer();
117 
118  unsigned int id_;
119  using vecpair_type = std::pair<bool, std::pair<std::vector<std::string>, std::vector<double>>>;
120  std::shared_ptr<vecpair_type> vecPair_;
121 };
122 
123 std::ostream& operator<<(std::ostream& o, const DDValue& v);
124 
125 #endif // DetectorDescription_Core_DDValue_h
std::pair< bool, std::pair< std::vector< std::string >, std::vector< double > >> vecpair_type
Definition: DDValue.h:119
bool operator<(const DDValue &) const
A DDValue a is smaller than a DDValue b if (a.id()<b.id()) OR (a.id()==b.id() and value(a)<value(b)) ...
Definition: DDValue.cc:168
DDValue(void)
create a unnamed emtpy value. One can assing a named DDValue to it.
Definition: DDValue.h:25
AtomicUInt(const AtomicUInt &iOther)
Definition: DDValue.h:100
bool isEvaluated(void) const
true, if values are numerical evaluated; else false.
Definition: DDValue.cc:152
unsigned int size() const
the size of the stored value-pairs (std::string,double)
Definition: DDValue.h:68
Only used internally.
Definition: DDValue.h:88
std::ostream & operator<<(std::ostream &o, const DDValue &v)
Definition: DDValue.cc:121
static Names & names()
Definition: DDValue.cc:106
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:111
StringHolder(StringHolder const &iOther)
Definition: DDValue.h:91
tbb::concurrent_vector< StringHolder, edm::zero_allocator< StringHolder > > Names
Definition: DDValue.h:111
void setEvalState(bool newState)
set to true, if the double-values (method DDValue::doubles()) make sense
Definition: DDValue.cc:150
const std::vector< std::string > & strings() const
a reference to the std::string-valued values stored in the given instance of DDValue ...
Definition: DDValue.h:61
StringHolder(std::string iString)
Definition: DDValue.h:90
AtomicUInt & operator=(const AtomicUInt &iOther)
Definition: DDValue.h:101
DDValuePair operator[](unsigned int i) const
Definition: DDValue.cc:140
tbb::concurrent_unordered_map< std::string, AtomicUInt > NamesToIndicies
Definition: DDValue.h:115
std::atomic< std::string * > string_
Definition: DDValue.h:95
unsigned int id(void) const
returns the ID of the DDValue
Definition: DDValue.h:48
static Names initializeNames()
Definition: DDValue.cc:97
unsigned int id_
Definition: DDValue.h:118
static NamesToIndicies & indexer()
Definition: DDValue.cc:92
void init(const std::string &)
Definition: DDValue.cc:14
AtomicUInt(unsigned int iValue)
Definition: DDValue.h:98
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:120
StringHolder & operator=(const StringHolder &)=delete
def load(fileName)
Definition: svgfig.py:547
std::atomic< unsigned int > value_
Definition: DDValue.h:106
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54
def move(src, dest)
Definition: eostools.py:511
bool operator==(const DDValue &v) const
Two DDValues are equal only if their id() is equal AND their values are equal.
Definition: DDValue.cc:154