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 "tbb/concurrent_unordered_map.h"
13 #include "tbb/concurrent_vector.h"
14 
21 class DDValue {
22 public:
24  DDValue(void) : id_(0), vecPair_() {}
25 
27  explicit DDValue(const std::string&);
28 
30  explicit DDValue(const char*);
31 
33  explicit DDValue(const std::string&, const std::vector<DDValuePair>&);
34 
36  explicit DDValue(const std::string&, double);
37 
39  explicit DDValue(const std::string&, const std::string&, double);
40 
42  explicit DDValue(const std::string& name, const std::string& val);
43 
44  explicit DDValue(unsigned int);
45 
47  unsigned int id(void) const { return id_; }
48 
50  operator unsigned int(void) const { return id_; }
51 
53  const std::string& name(void) const { return *(names()[id_].string_); }
54 
57  DDValuePair operator[](unsigned int i) const;
58 
60  const std::vector<std::string>& strings() const { return vecPair_->second.first; }
61 
63  const std::vector<double>& doubles() const;
64  //const DDValuePair & operator[](unsigned int i) const { return (*valPairs_)[i] ; }
65 
67  unsigned int size() const { return vecPair_ ? vecPair_->second.first.size() : 0; }
68 
70  void setEvalState(bool newState);
71 
73 
75  bool isEvaluated(void) const;
76 
78 
80  bool operator==(const DDValue& v) const;
81 
83  bool operator<(const DDValue&) const;
84 
85 private:
87  struct StringHolder {
89  explicit StringHolder(std::string iString) : string_(new std::string{std::move(iString)}) {}
90  explicit StringHolder(StringHolder const& iOther) : string_(new std::string{*(iOther.string_)}) {}
91  StringHolder& operator=(const StringHolder&) = delete;
92  ~StringHolder() { delete string_.load(); }
93 
94  std::atomic<std::string*> string_;
95  };
96  struct AtomicUInt {
97  AtomicUInt(unsigned int iValue) : value_(iValue) {}
99  AtomicUInt(const AtomicUInt& iOther) : value_(iOther.value_.load()) {}
100  AtomicUInt& operator=(const AtomicUInt& iOther) {
101  value_ = iOther.value_.load();
102  return *this;
103  }
104 
105  std::atomic<unsigned int> value_;
106  };
107 
108  void init(const std::string&);
109 
110  using Names = tbb::concurrent_vector<StringHolder, tbb::zero_allocator<StringHolder>>;
111  static Names& names();
112  static Names initializeNames();
113 
114  using NamesToIndicies = tbb::concurrent_unordered_map<std::string, AtomicUInt>;
115  static NamesToIndicies& indexer();
116 
117  unsigned int id_;
118  using vecpair_type = std::pair<bool, std::pair<std::vector<std::string>, std::vector<double>>>;
119  std::shared_ptr<vecpair_type> vecPair_;
120 };
121 
122 std::ostream& operator<<(std::ostream& o, const DDValue& v);
123 
124 #endif // DetectorDescription_Core_DDValue_h
DDValuePair.h
DDValue::init
void init(const std::string &)
Definition: DDValue.cc:14
mps_fire.i
i
Definition: mps_fire.py:428
DDValue::StringHolder::operator=
StringHolder & operator=(const StringHolder &)=delete
DDValuePair
Definition: DDValuePair.h:8
DDValue::operator==
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
DDValue::StringHolder::~StringHolder
~StringHolder()
Definition: DDValue.h:92
DDValue::AtomicUInt::AtomicUInt
AtomicUInt()
Definition: DDValue.h:98
DDValue::StringHolder::StringHolder
StringHolder()
Definition: DDValue.h:88
findQualityFiles.v
v
Definition: findQualityFiles.py:179
operator<<
std::ostream & operator<<(std::ostream &o, const DDValue &v)
Definition: DDValue.cc:121
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:36
DDValue::operator[]
DDValuePair operator[](unsigned int i) const
Definition: DDValue.cc:140
DDValue::id_
unsigned int id_
Definition: DDValue.h:117
DDValue::DDValue
DDValue(void)
create a unnamed emtpy value. One can assing a named DDValue to it.
Definition: DDValue.h:24
DDValue::AtomicUInt::value_
std::atomic< unsigned int > value_
Definition: DDValue.h:105
DDValue::indexer
static NamesToIndicies & indexer()
Definition: DDValue.cc:92
DDValue::StringHolder
Only used internally.
Definition: DDValue.h:87
svgfig.load
def load(fileName)
Definition: svgfig.py:547
DDValue::Names
tbb::concurrent_vector< StringHolder, tbb::zero_allocator< StringHolder > > Names
Definition: DDValue.h:110
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DDValue::AtomicUInt
Definition: DDValue.h:96
DDValue::isEvaluated
bool isEvaluated(void) const
true, if values are numerical evaluated; else false.
Definition: DDValue.cc:152
DDValue::operator<
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::NamesToIndicies
tbb::concurrent_unordered_map< std::string, AtomicUInt > NamesToIndicies
Definition: DDValue.h:114
DDValue::size
unsigned int size() const
the size of the stored value-pairs (std::string,double)
Definition: DDValue.h:67
DDValue::initializeNames
static Names initializeNames()
Definition: DDValue.cc:97
createfilelist.int
int
Definition: createfilelist.py:10
DDValue::names
static Names & names()
Definition: DDValue.cc:106
DDValue::StringHolder::StringHolder
StringHolder(std::string iString)
Definition: DDValue.h:89
DDValue::AtomicUInt::operator=
AtomicUInt & operator=(const AtomicUInt &iOther)
Definition: DDValue.h:100
DDValue::AtomicUInt::AtomicUInt
AtomicUInt(const AtomicUInt &iOther)
Definition: DDValue.h:99
DDValue::vecpair_type
std::pair< bool, std::pair< std::vector< std::string >, std::vector< double > >> vecpair_type
Definition: DDValue.h:118
heppy_batch.val
val
Definition: heppy_batch.py:351
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
DDValue::setEvalState
void setEvalState(bool newState)
set to true, if the double-values (method DDValue::doubles()) make sense
Definition: DDValue.cc:150
DDValue::vecPair_
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:119
DDValue
Definition: DDValue.h:21
DDValue::id
unsigned int id(void) const
returns the ID of the DDValue
Definition: DDValue.h:47
DDValue::StringHolder::StringHolder
StringHolder(StringHolder const &iOther)
Definition: DDValue.h:90
DDValue::doubles
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:111
DDValue::StringHolder::string_
std::atomic< std::string * > string_
Definition: DDValue.h:94
DDValue::AtomicUInt::AtomicUInt
AtomicUInt(unsigned int iValue)
Definition: DDValue.h:97
DDValue::name
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:53
DDValue::strings
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:60