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 
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 private:
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:104
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:90
static Names & names()
Definition: DDValue.cc:132
StringHolder(StringHolder const &iOther)
Definition: DDValue.h:93
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:92
unsigned int id(void) const
returns the ID of the DDValue
Definition: DDValue.h:49
AtomicUInt & operator=(const AtomicUInt &iOther)
Definition: DDValue.h:105
~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:99
static Names initializeNames()
Definition: DDValue.cc:122
unsigned int id_
Definition: DDValue.h:123
def move
Definition: eostools.py:508
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: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: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:110
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