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 (const char *)
 create a named empty value More...
 
 DDValue (const std::string &)
 create a named empty value More...
 
 DDValue (const std::string &, const std::string &, double)
 
 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 &name, const std::string &val)
 
 DDValue (unsigned int)
 
 DDValue (void)
 create a unnamed emtpy value. One can assing a named DDValue to it. More...
 
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, tbb::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 21 of file DDValue.h.

Member Typedef Documentation

◆ Names

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

Definition at line 110 of file DDValue.h.

◆ NamesToIndicies

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

Definition at line 114 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 118 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 24 of file DDValue.h.

24 : id_(0), vecPair_() {}

◆ DDValue() [2/8]

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

create a named empty value

Definition at line 42 of file DDValue.cc.

42 : id_(0), vecPair_() { init(name); }

References init(), and name().

◆ DDValue() [3/8]

DDValue::DDValue ( const char *  name)
explicit

create a named empty value

Definition at line 44 of file DDValue.cc.

44 : id_(0), vecPair_() { init(name); }

References init(), and name().

◆ 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.

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 }

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

◆ 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.

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 }

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

◆ 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.

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 }

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

◆ 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.

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 }

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

◆ DDValue() [8/8]

DDValue::DDValue ( unsigned int  i)
explicit

Definition at line 87 of file DDValue.cc.

87  : id_(0), vecPair_() {
88  if (lastIndex >= i)
89  id_ = i;
90 }

References mps_fire::i, id_, and lastIndex.

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.

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 }

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

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

◆ id()

unsigned int DDValue::id ( void  ) const
inline

returns the ID of the DDValue

Definition at line 47 of file DDValue.h.

47 { return id_; }

References id_.

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

◆ indexer()

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

Definition at line 92 of file DDValue.cc.

92  {
93  static NamesToIndicies indexer_;
94  return indexer_;
95 }

Referenced by init().

◆ init()

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

Definition at line 14 of file DDValue.cc.

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 }

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

Referenced by DDValue().

◆ initializeNames()

DDValue::Names DDValue::initializeNames ( )
staticprivate

Definition at line 97 of file DDValue.cc.

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 }

References names(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by names().

◆ 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.

152 { return vecPair_->first; }

References vecPair_.

◆ name()

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

the name of the DDValue

Definition at line 53 of file DDValue.h.

53 { return *(names()[id_].string_); }

References id_, and names().

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

◆ names()

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

Definition at line 106 of file DDValue.cc.

106  {
107  static Names names_{initializeNames()};
108  return names_;
109 }

References initializeNames().

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

◆ operator unsigned int()

DDValue::operator unsigned int ( void  ) const
inline

converts a DDValue object into its ID

Definition at line 50 of file DDValue.h.

50 { return id_; }

References id_.

◆ 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.

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 }

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

◆ 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.

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 }

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

◆ 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.

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 }

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

◆ 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.

150 { vecPair_->first = newState; }

References vecPair_.

Referenced by DDValue().

◆ size()

unsigned int DDValue::size ( void  ) const
inline

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

Definition at line 67 of file DDValue.h.

67 { return vecPair_ ? vecPair_->second.first.size() : 0; }

References vecPair_.

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

◆ 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 60 of file DDValue.h.

60 { return vecPair_->second.first; }

References vecPair_.

Referenced by DDSpecificsMatchesValueFilter::accept().

Member Data Documentation

◆ id_

unsigned int DDValue::id_
private

Definition at line 117 of file DDValue.h.

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

◆ vecPair_

std::shared_ptr<vecpair_type> DDValue::vecPair_
private
DDValue::init
void init(const std::string &)
Definition: DDValue.cc:14
mps_fire.i
i
Definition: mps_fire.py:428
DDValuePair
Definition: DDValuePair.h:8
callgraph.previous
previous
Definition: callgraph.py:62
cms::cuda::assert
assert(be >=bs)
findQualityFiles.v
v
Definition: findQualityFiles.py:179
DDValue::id_
unsigned int id_
Definition: DDValue.h:117
DDValue::indexer
static NamesToIndicies & indexer()
Definition: DDValue.cc:92
lastIndex
static std::atomic< unsigned int > lastIndex
Definition: DDValue.cc:12
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::NamesToIndicies
tbb::concurrent_unordered_map< std::string, AtomicUInt > NamesToIndicies
Definition: DDValue.h:114
DDValue::initializeNames
static Names initializeNames()
Definition: DDValue.cc:97
DDValue::names
static Names & names()
Definition: DDValue.cc:106
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
mps_merge.newName
string newName
Definition: mps_merge.py:86
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
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
Exception
Definition: hltDiff.cc:245
mps_fire.result
result
Definition: mps_fire.py:311
DDValue::name
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:53