CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes
DDValue Class Reference

#include <DDValue.h>

Classes

struct  AtomicUInt
 
struct  StringHolder
 Only used internally. More...
 

Public Member Functions

 DDValue (void)
 create a unnamed emtpy value. One can assing a named DDValue to it. More...
 
 DDValue (const std::string &)
 create a named empty value More...
 
 DDValue (const char *)
 create a named empty value More...
 
 DDValue (const std::string &, const std::vector< DDValuePair > &)
 creates a named DDValue initialized with a std::vector of values More...
 
 DDValue (const std::string &, double)
 creates a single double valued named DDValue. The corresponding std::string-value is an empty std::string More...
 
 DDValue (const std::string &, const std::string &, double)
 
 DDValue (const std::string &name, const std::string &val)
 
 DDValue (unsigned int)
 
const std::vector< double > & doubles () const
 a reference to the double-valued values stored in the given instance of DDValue More...
 
unsigned int id (void) const
 returns the ID of the DDValue More...
 
bool isEvaluated (void) const
 true, if values are numerical evaluated; else false. More...
 
const std::string & name (void) const
 the name of the DDValue More...
 
 operator unsigned int (void) const
 converts a DDValue object into its ID More...
 
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)) More...
 
bool operator== (const DDValue &v) const
 Two DDValues are equal only if their id() is equal AND their values are equal. More...
 
DDValuePair operator[] (unsigned int i) const
 
void setEvalState (bool newState)
 set to true, if the double-values (method DDValue::doubles()) make sense More...
 
unsigned int size () const
 the size of the stored value-pairs (std::string,double) More...
 
const std::vector< std::string > & strings () const
 a reference to the std::string-valued values stored in the given instance of DDValue More...
 

Private Types

using Names = tbb::concurrent_vector< StringHolder, edm::zero_allocator< StringHolder > >
 
using NamesToIndicies = tbb::concurrent_unordered_map< std::string, AtomicUInt >
 
using vecpair_type = std::pair< bool, std::pair< std::vector< std::string >, std::vector< double > >>
 

Private Member Functions

void init (const std::string &)
 

Static Private Member Functions

static NamesToIndiciesindexer ()
 
static Names initializeNames ()
 
static Namesnames ()
 

Private Attributes

unsigned int id_
 
std::shared_ptr< vecpair_typevecPair_
 

Detailed Description

A DDValue std::maps a std::vector of DDValuePair (std::string,double) to a name. Names of DDValues are stored transiently. Furthermore, an ID is assigned std::mapping to the name. Use DDValue::setEvalState(true) to indicate whether the double numbers stored in the DDValuePair make sense, otherwise an exception will be thrown when trying to get access to these values via DDValue::doubles() or DDValue::operator[].

Definition at line 22 of file DDValue.h.

Member Typedef Documentation

◆ Names

using DDValue::Names = tbb::concurrent_vector<StringHolder, edm::zero_allocator<StringHolder> >
private

Definition at line 111 of file DDValue.h.

◆ NamesToIndicies

using DDValue::NamesToIndicies = tbb::concurrent_unordered_map<std::string, AtomicUInt>
private

Definition at line 115 of file DDValue.h.

◆ vecpair_type

using DDValue::vecpair_type = std::pair<bool, std::pair<std::vector<std::string>, std::vector<double> >>
private

Definition at line 119 of file DDValue.h.

Constructor & Destructor Documentation

◆ DDValue() [1/8]

DDValue::DDValue ( void  )
inline

create a unnamed emtpy value. One can assing a named DDValue to it.

Definition at line 25 of file DDValue.h.

25 : id_(0), vecPair_() {}
unsigned int id_
Definition: DDValue.h:118
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:120

◆ DDValue() [2/8]

DDValue::DDValue ( const std::string &  name)
explicit

create a named empty value

Definition at line 42 of file DDValue.cc.

References init(), and name().

42 : id_(0), vecPair_() { init(name); }
unsigned int id_
Definition: DDValue.h:118
void init(const std::string &)
Definition: DDValue.cc:14
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:120
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54

◆ DDValue() [3/8]

DDValue::DDValue ( const char *  name)
explicit

create a named empty value

Definition at line 44 of file DDValue.cc.

References init(), and name().

44 : id_(0), vecPair_() { init(name); }
unsigned int id_
Definition: DDValue.h:118
void init(const std::string &)
Definition: DDValue.cc:14
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:120
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54

◆ DDValue() [4/8]

DDValue::DDValue ( const std::string &  name,
const std::vector< DDValuePair > &  v 
)
explicit

creates a named DDValue initialized with a std::vector of values

Definition at line 46 of file DDValue.cc.

References init(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, name(), findQualityFiles::v, and vecPair_.

46  : id_(0) {
47  init(name);
48 
49  auto it = v.begin();
50  std::vector<std::string> svec;
51  std::vector<double> dvec;
52  vecPair_.reset(new vecpair_type(false, std::make_pair(svec, dvec)));
53  for (; it != v.end(); ++it) {
54  vecPair_->second.first.emplace_back(it->first);
55  vecPair_->second.second.emplace_back(it->second);
56  }
57 }
std::pair< bool, std::pair< std::vector< std::string >, std::vector< double > >> vecpair_type
Definition: DDValue.h:119
unsigned int id_
Definition: DDValue.h:118
void init(const std::string &)
Definition: DDValue.cc:14
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:120
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54

◆ DDValue() [5/8]

DDValue::DDValue ( const std::string &  name,
double  val 
)
explicit

creates a single double valued named DDValue. The corresponding std::string-value is an empty std::string

Definition at line 59 of file DDValue.cc.

References init(), name(), setEvalState(), heppy_batch::val, and vecPair_.

59  : id_(0) {
60  init(name);
61 
62  std::vector<std::string> svec(1, "");
63  std::vector<double> dvec(1, val);
64 
65  vecPair_.reset(new vecpair_type(false, std::make_pair(svec, dvec)));
66  setEvalState(true);
67 }
std::pair< bool, std::pair< std::vector< std::string >, std::vector< double > >> vecpair_type
Definition: DDValue.h:119
void setEvalState(bool newState)
set to true, if the double-values (method DDValue::doubles()) make sense
Definition: DDValue.cc:150
unsigned int id_
Definition: DDValue.h:118
void init(const std::string &)
Definition: DDValue.cc:14
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:120
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54

◆ DDValue() [6/8]

DDValue::DDValue ( const std::string &  name,
const std::string &  sval,
double  dval 
)
explicit

creates a single std::string & numerical-valued named DDValue.

Definition at line 69 of file DDValue.cc.

References init(), name(), setEvalState(), and vecPair_.

69  : id_(0) {
70  init(name);
71 
72  std::vector<std::string> svec(1, sval);
73  std::vector<double> dvec(1, dval);
74  vecPair_.reset(new vecpair_type(false, std::make_pair(svec, dvec)));
75  setEvalState(true);
76 }
std::pair< bool, std::pair< std::vector< std::string >, std::vector< double > >> vecpair_type
Definition: DDValue.h:119
void setEvalState(bool newState)
set to true, if the double-values (method DDValue::doubles()) make sense
Definition: DDValue.cc:150
unsigned int id_
Definition: DDValue.h:118
void init(const std::string &)
Definition: DDValue.cc:14
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:120
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54

◆ DDValue() [7/8]

DDValue::DDValue ( const std::string &  name,
const std::string &  val 
)
explicit

creates a single std::string-valued named DDValue

Definition at line 78 of file DDValue.cc.

References init(), name(), setEvalState(), and vecPair_.

78  : id_(0) {
79  init(name);
80 
81  std::vector<std::string> svec(1, sval);
82  std::vector<double> dvec(1, 0);
83  vecPair_.reset(new vecpair_type(false, std::make_pair(svec, dvec)));
84  setEvalState(false);
85 }
std::pair< bool, std::pair< std::vector< std::string >, std::vector< double > >> vecpair_type
Definition: DDValue.h:119
void setEvalState(bool newState)
set to true, if the double-values (method DDValue::doubles()) make sense
Definition: DDValue.cc:150
unsigned int id_
Definition: DDValue.h:118
void init(const std::string &)
Definition: DDValue.cc:14
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:120
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54

◆ DDValue() [8/8]

DDValue::DDValue ( unsigned int  i)
explicit

Definition at line 87 of file DDValue.cc.

References mps_fire::i, id_, and lastIndex.

87  : id_(0), vecPair_() {
88  if (lastIndex >= i)
89  id_ = i;
90 }
unsigned int id_
Definition: DDValue.h:118
static std::atomic< unsigned int > lastIndex
Definition: DDValue.cc:12
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:120

Member Function Documentation

◆ doubles()

const std::vector< double > & DDValue::doubles ( void  ) const

a reference to the double-valued values stored in the given instance of DDValue

Definition at line 111 of file DDValue.cc.

References Exception, name(), AlCaHLTBitMon_QueryRunRegistry::string, and vecPair_.

Referenced by ME0GeometryParsFromDD::buildEtaPartition(), GEMGeometryParsFromDD::buildEtaPartition(), ME0GeometryBuilder::buildEtaPartition(), GEMGeometryBuilder::buildEtaPartition(), RPCGeometryBuilder::buildGeometry(), and RPCGeometryParsFromDD::buildGeometry().

111  {
112  if (vecPair_->first) {
113  return vecPair_->second.second;
114  } else {
115  std::string message = "DDValue " + name() + " is not numerically evaluated! Use DDValue::std::strings()!";
116  edm::LogError("DDValue") << message << std::endl;
117  throw cms::Exception("DDException") << message;
118  }
119 }
Log< level::Error, false > LogError
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:120
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54

◆ id()

unsigned int DDValue::id ( void  ) const
inline

returns the ID of the DDValue

Definition at line 48 of file DDValue.h.

References id_.

Referenced by DDSpecificsHasNamedValueFilter::accept(), and DDSpecificsMatchesValueFilter::accept().

48 { return id_; }
unsigned int id_
Definition: DDValue.h:118

◆ indexer()

DDValue::NamesToIndicies & DDValue::indexer ( void  )
staticprivate

Definition at line 92 of file DDValue.cc.

Referenced by init().

92  {
93  static NamesToIndicies indexer_;
94  return indexer_;
95 }
tbb::concurrent_unordered_map< std::string, AtomicUInt > NamesToIndicies
Definition: DDValue.h:115

◆ init()

void DDValue::init ( const std::string &  name)
private

Definition at line 14 of file DDValue.cc.

References id_, indexer(), lastIndex, name(), names(), mps_merge::newName, callgraph::previous, mps_fire::result, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by DDValue().

14  {
15  auto result = indexer().insert({name, 0});
16 
17  auto& indexToUse = result.first->second;
18 
19  //A 0 index means either
20  // 1) this result was just added or
21  // 2) another thread just added this but has not yet assigned an index
22  if (0 == indexToUse.value_) {
23  auto newIndex = ++lastIndex;
24  unsigned int previous = 0;
25  indexToUse.value_.compare_exchange_strong(previous, newIndex);
26  }
27  id_ = indexToUse.value_.load();
28 
29  //Make sure the name is recorded at the proper index
30  auto& allNames = names();
31  allNames.grow_to_at_least(id_ + 1);
32  auto& storedName = allNames[id_];
33  if (not storedName.string_) {
34  std::unique_ptr<std::string> newName(new std::string{name});
35  std::string* previous = nullptr;
36  if (storedName.string_.compare_exchange_strong(previous, newName.get())) {
37  newName.release();
38  }
39  }
40 }
static Names & names()
Definition: DDValue.cc:106
string newName
Definition: mps_merge.py:86
unsigned int id_
Definition: DDValue.h:118
static NamesToIndicies & indexer()
Definition: DDValue.cc:92
static std::atomic< unsigned int > lastIndex
Definition: DDValue.cc:12
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54

◆ initializeNames()

DDValue::Names DDValue::initializeNames ( )
staticprivate

Definition at line 97 of file DDValue.cc.

References names(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by names().

97  {
98  //Make sure memory is zeroed before allocating StringHolder
99  // this allows us to check the value of the held std::atomic
100  // as the object is being added to the container
102  names.emplace_back(StringHolder(std::string{}));
103  return names;
104 }
static Names & names()
Definition: DDValue.cc:106
tbb::concurrent_vector< StringHolder, edm::zero_allocator< StringHolder > > Names
Definition: DDValue.h:111

◆ isEvaluated()

bool DDValue::isEvaluated ( void  ) const

true, if values are numerical evaluated; else false.

in case of a 'true' return value, the method DDValue::doubles() and the operator DDValue::operator[] can be used

Definition at line 152 of file DDValue.cc.

References vecPair_.

152 { return vecPair_->first; }
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:120

◆ name()

const std::string& DDValue::name ( void  ) const
inline

the name of the DDValue

Definition at line 54 of file DDValue.h.

References id_, and names().

Referenced by config.CFG::__str__(), DDValue(), validation.Sample::digest(), doubles(), init(), VIDSelectorBase.VIDSelectorBase::initialize(), and operator[]().

54 { return *(names()[id_].string_); }
static Names & names()
Definition: DDValue.cc:106
unsigned int id_
Definition: DDValue.h:118

◆ names()

DDValue::Names & DDValue::names ( void  )
staticprivate

Definition at line 106 of file DDValue.cc.

References initializeNames().

Referenced by init(), initializeNames(), and name().

106  {
107  static Names names_{initializeNames()};
108  return names_;
109 }
tbb::concurrent_vector< StringHolder, edm::zero_allocator< StringHolder > > Names
Definition: DDValue.h:111
static Names initializeNames()
Definition: DDValue.cc:97

◆ operator unsigned int()

DDValue::operator unsigned int ( void  ) const
inline

converts a DDValue object into its ID

Definition at line 51 of file DDValue.h.

References id_.

51 { return id_; }
unsigned int id_
Definition: DDValue.h:118

◆ operator<()

bool DDValue::operator< ( const DDValue v) 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 at line 168 of file DDValue.cc.

References cms::cuda::assert(), mps_fire::result, findQualityFiles::v, and vecPair_.

168  {
169  bool result(false);
170  if (id() < v.id()) {
171  result = true;
172  } else {
173  if (id() == v.id()) {
174  assert(vecPair_);
175  assert(v.vecPair_);
176  if (vecPair_->first && v.vecPair_->first) { // numerical values
177  result = (vecPair_->second.second < v.vecPair_->second.second);
178  } else { // std::string values
179  result = (vecPair_->second.first < v.vecPair_->second.first);
180  }
181  }
182  }
183  return result;
184 }
assert(be >=bs)
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:120

◆ operator==()

bool DDValue::operator== ( const DDValue v) const

Two DDValues are equal only if their id() is equal AND their values are equal.

If the DDValue::isEvalued() == true, the numerical representation is taken for comparison, else the std::string representation

Definition at line 154 of file DDValue.cc.

References cms::cuda::assert(), mps_fire::result, findQualityFiles::v, and vecPair_.

154  {
155  bool result(false);
156  if (id() == v.id()) {
157  assert(vecPair_);
158  assert(v.vecPair_);
159  if (vecPair_->first) { // numerical values
160  result = (vecPair_->second.second == v.vecPair_->second.second);
161  } else { // std::string values
162  result = (vecPair_->second.first == v.vecPair_->second.first);
163  }
164  }
165  return result;
166 }
assert(be >=bs)
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:120

◆ operator[]()

DDValuePair DDValue::operator[] ( unsigned int  i) const

access to the values stored in DDValue by an index. Note, that the index is not checked for bounds excess!

Definition at line 140 of file DDValue.cc.

References Exception, mps_fire::i, name(), AlCaHLTBitMon_QueryRunRegistry::string, and vecPair_.

140  {
141  if (vecPair_->first) {
142  return DDValuePair(vecPair_->second.first[i], vecPair_->second.second[i]);
143  } else {
144  std::string message = "DDValue " + name() + " is not numerically evaluated! Use DDValue::std::strings()!";
145  edm::LogError("DDValue") << message;
146  throw cms::Exception("DDException") << message;
147  }
148 }
Log< level::Error, false > LogError
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:120
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54

◆ setEvalState()

void DDValue::setEvalState ( bool  newState)

set to true, if the double-values (method DDValue::doubles()) make sense

Definition at line 150 of file DDValue.cc.

References vecPair_.

Referenced by DDValue().

150 { vecPair_->first = newState; }
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:120

◆ size()

unsigned int DDValue::size ( void  ) const
inline

the size of the stored value-pairs (std::string,double)

Definition at line 68 of file DDValue.h.

References vecPair_.

Referenced by ntupleDataFormat._Collection::__iter__(), and ntupleDataFormat._Collection::__len__().

68 { return vecPair_ ? vecPair_->second.first.size() : 0; }
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:120

◆ strings()

const std::vector<std::string>& DDValue::strings ( ) const
inline

a reference to the std::string-valued values stored in the given instance of DDValue

Definition at line 61 of file DDValue.h.

References vecPair_.

Referenced by DDSpecificsMatchesValueFilter::accept().

61 { return vecPair_->second.first; }
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:120

Member Data Documentation

◆ id_

unsigned int DDValue::id_
private

Definition at line 118 of file DDValue.h.

Referenced by DDValue(), id(), init(), name(), and operator unsigned int().

◆ vecPair_

std::shared_ptr<vecpair_type> DDValue::vecPair_
private