CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDValue.h
Go to the documentation of this file.
1 #ifndef DetectorDescription_Core_DDValue_h
2 #define DetectorDescription_Core_DDValue_h
3 
4 #include <iostream>
5 #include <string>
6 #include <vector>
7 #include <memory>
8 #include <atomic>
9 #include "tbb/concurrent_vector.h"
10 #include "tbb/concurrent_unordered_map.h"
11 
13 
20 class DDValue
21 {
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 
46  ~DDValue( void );
47 
49  unsigned int id( void ) const { return id_; }
50 
52  operator unsigned int( void ) const { return id_; }
53 
55  const std::string & name( void ) const { return *(names()[id_].string_); }
56 
59  DDValuePair operator[]( unsigned int i ) const;
60 
62  const std::vector<std::string> & strings() const { return vecPair_->second.first; }
63 
65  const std::vector<double> & doubles() const;
66  //const DDValuePair & operator[](unsigned int i) const { return (*valPairs_)[i] ; }
67 
69  unsigned int size() const {
70  return vecPair_ ? vecPair_->second.first.size() : 0 ;
71  }
72 
74  void setEvalState( bool newState );
75 
77 
79  bool isEvaluated( void ) const;
80 
82 
84  bool operator==( const DDValue & v ) const;
85 
87  bool operator<( const DDValue & ) const;
88 
89 private:
91  struct StringHolder {
93  explicit StringHolder(std::string iString): string_(new std::string{std::move(iString)}) {}
94  explicit StringHolder(StringHolder const& iOther): string_(new std::string{*(iOther.string_)}) {
95  }
96  StringHolder& operator=(const StringHolder&) = delete;
97  ~StringHolder() { delete string_.load();}
98 
99 
100  std::atomic<std::string*> string_;
101  };
102  struct AtomicUInt {
103  AtomicUInt(unsigned int iValue): value_(iValue) {}
105  AtomicUInt( const AtomicUInt& iOther) : value_(iOther.value_.load()) {}
106  AtomicUInt& operator=(const AtomicUInt& iOther) {
107  value_ = iOther.value_.load();
108  return *this;
109  }
110 
111  std::atomic<unsigned int> value_;
112  };
113 
114  void init( const std::string & );
115 
116  using Names = tbb::concurrent_vector<StringHolder,tbb::zero_allocator<StringHolder>>;
117  static Names& names();
118  static Names initializeNames();
119 
120  using NamesToIndicies = tbb::concurrent_unordered_map<std::string,AtomicUInt>;
121  static NamesToIndicies& indexer();
122 
123  unsigned int id_;
124  using vecpair_type = std::pair<bool, std::pair<std::vector<std::string>, std::vector<double>>>;
125  std::shared_ptr<vecpair_type> vecPair_;
126 };
127 
128 std::ostream & operator<<(std::ostream & o, const DDValue & v);
129 
130 #endif // DetectorDescription_Core_DDValue_h
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:55
int i
Definition: DBlmapReader.cc:9
DDValue(void)
create a unnamed emtpy value. One can assing a named DDValue to it.
Definition: DDValue.h:24
AtomicUInt(const AtomicUInt &iOther)
Definition: DDValue.h:105
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:139
Only used internally.
Definition: DDValue.h:91
static Names & names()
Definition: DDValue.cc:132
StringHolder(StringHolder const &iOther)
Definition: DDValue.h:94
tbb::concurrent_vector< StringHolder, tbb::zero_allocator< StringHolder >> Names
Definition: DDValue.h:116
void setEvalState(bool newState)
set to true, if the double-values (method DDValue::doubles()) make sense
Definition: DDValue.cc:197
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
StringHolder(std::string iString)
Definition: DDValue.h:93
unsigned int id(void) const
returns the ID of the DDValue
Definition: DDValue.h:49
AtomicUInt & operator=(const AtomicUInt &iOther)
Definition: DDValue.h:106
~DDValue(void)
Definition: DDValue.cc:112
bool isEvaluated(void) const
true, if values are numerical evaluated; else false.
Definition: DDValue.cc:203
std::atomic< std::string * > string_
Definition: DDValue.h:100
static Names initializeNames()
Definition: DDValue.cc:122
unsigned int id_
Definition: DDValue.h:123
def move
Definition: eostools.py:510
def load
Definition: svgfig.py:546
static NamesToIndicies & indexer()
Definition: DDValue.cc:116
void init(const std::string &)
Definition: DDValue.cc:10
AtomicUInt(unsigned int iValue)
Definition: DDValue.h:103
bool operator==(const DDValue &v) const
Two DDValues are equal only if their id() is equal AND their values are equal.
Definition: DDValue.cc:209
tbb::concurrent_unordered_map< std::string, AtomicUInt > NamesToIndicies
Definition: DDValue.h:120
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:62
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:125
StringHolder & operator=(const StringHolder &)=delete
DDValuePair operator[](unsigned int i) const
Definition: DDValue.cc:182
std::atomic< unsigned int > value_
Definition: DDValue.h:111
bool operator<(const DDValue &) const
A DDValue a is smaller than a DDValue b if (a.id()&lt;b.id()) OR (a.id()==b.id() and value(a)&lt;value(b)) ...
Definition: DDValue.cc:227
unsigned int size() const
the size of the stored value-pairs (std::string,double)
Definition: DDValue.h:69
std::pair< bool, std::pair< std::vector< std::string >, std::vector< double >>> vecpair_type
Definition: DDValue.h:124