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 {
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 {
69  return vecPair_ ? vecPair_->second.first.size() : 0 ;
70  }
71 
73  void setEvalState( bool newState );
74 
76 
78  bool isEvaluated( void ) const;
79 
81 
83  bool operator==( const DDValue & v ) const;
84 
86  bool operator<( const DDValue & ) const;
87 
88 private:
90  struct StringHolder {
92  explicit StringHolder(std::string iString): string_(new std::string{std::move(iString)}) {}
93  explicit StringHolder(StringHolder const& iOther): string_(new std::string{*(iOther.string_)}) {
94  }
95  StringHolder& operator=(const StringHolder&) = delete;
96  ~StringHolder() { delete string_.load();}
97 
98 
99  std::atomic<std::string*> string_;
100  };
101  struct AtomicUInt {
102  AtomicUInt(unsigned int iValue): value_(iValue) {}
104  AtomicUInt( const AtomicUInt& iOther) : value_(iOther.value_.load()) {}
105  AtomicUInt& operator=(const AtomicUInt& iOther) {
106  value_ = iOther.value_.load();
107  return *this;
108  }
109 
110  std::atomic<unsigned int> value_;
111  };
112 
113  void init( const std::string & );
114 
115  using Names = tbb::concurrent_vector<StringHolder,tbb::zero_allocator<StringHolder>>;
116  static Names& names();
117  static Names initializeNames();
118 
119  using NamesToIndicies = tbb::concurrent_unordered_map<std::string,AtomicUInt>;
120  static NamesToIndicies& indexer();
121 
122  unsigned int id_;
123  using vecpair_type = std::pair<bool, std::pair<std::vector<std::string>, std::vector<double>>>;
124  std::shared_ptr<vecpair_type> vecPair_;
125 };
126 
127 std::ostream & operator<<(std::ostream & o, const DDValue & v);
128 
129 #endif // DetectorDescription_Core_DDValue_h
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54
int i
Definition: DBlmapReader.cc:9
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:104
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:137
Only used internally.
Definition: DDValue.h:90
std::ostream & operator<<(std::ostream &o, const DDValue &v)
Definition: DDValue.cc:151
static Names & names()
Definition: DDValue.cc:130
StringHolder(StringHolder const &iOther)
Definition: DDValue.h:93
tbb::concurrent_vector< StringHolder, tbb::zero_allocator< StringHolder >> Names
Definition: DDValue.h:115
void setEvalState(bool newState)
set to true, if the double-values (method DDValue::doubles()) make sense
Definition: DDValue.cc:195
StringHolder(std::string iString)
Definition: DDValue.h:92
unsigned int id(void) const
returns the ID of the DDValue
Definition: DDValue.h:48
AtomicUInt & operator=(const AtomicUInt &iOther)
Definition: DDValue.h:105
bool isEvaluated(void) const
true, if values are numerical evaluated; else false.
Definition: DDValue.cc:201
std::atomic< std::string * > string_
Definition: DDValue.h:99
static Names initializeNames()
Definition: DDValue.cc:120
unsigned int id_
Definition: DDValue.h:122
static NamesToIndicies & indexer()
Definition: DDValue.cc:114
void init(const std::string &)
Definition: DDValue.cc:11
AtomicUInt(unsigned int iValue)
Definition: DDValue.h:102
bool operator==(const DDValue &v) const
Two DDValues are equal only if their id() is equal AND their values are equal.
Definition: DDValue.cc:207
tbb::concurrent_unordered_map< std::string, AtomicUInt > NamesToIndicies
Definition: DDValue.h:119
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
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:124
StringHolder & operator=(const StringHolder &)=delete
DDValuePair operator[](unsigned int i) const
Definition: DDValue.cc:180
def load(fileName)
Definition: svgfig.py:546
std::atomic< unsigned int > value_
Definition: DDValue.h:110
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:225
unsigned int size() const
the size of the stored value-pairs (std::string,double)
Definition: DDValue.h:68
std::pair< bool, std::pair< std::vector< std::string >, std::vector< double >>> vecpair_type
Definition: DDValue.h:123
def move(src, dest)
Definition: eostools.py:510