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, 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

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

Definition at line 115 of file DDValue.h.

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

Definition at line 119 of file DDValue.h.

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

Definition at line 123 of file DDValue.h.

Constructor & Destructor Documentation

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.

References name(), AlCaHLTBitMon_QueryRunRegistry::string, and heppy_batch::val.

25 : id_(0), vecPair_() { }
unsigned int id_
Definition: DDValue.h:122
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:124
DDValue::DDValue ( const std::string &  name)
explicit

create a named empty value

Definition at line 40 of file DDValue.cc.

References init().

41  : id_( 0 ),
42  vecPair_()
43 {
44  init( name );
45 }
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54
unsigned int id_
Definition: DDValue.h:122
void init(const std::string &)
Definition: DDValue.cc:11
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:124
DDValue::DDValue ( const char *  name)
explicit

create a named empty value

Definition at line 47 of file DDValue.cc.

References init().

48  : id_( 0 ),
49  vecPair_()
50 {
51  init( name );
52 }
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54
unsigned int id_
Definition: DDValue.h:122
void init(const std::string &)
Definition: DDValue.cc:11
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:124
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 54 of file DDValue.cc.

References init(), and vecPair_.

55  : id_( 0 )
56 {
57  init( name );
58 
59  auto it = v.begin();
60  std::vector<std::string> svec;
61  std::vector<double> dvec;
62  vecPair_.reset(new vecpair_type( false, std::make_pair( svec, dvec )));
63  for(; it != v.end(); ++it )
64  {
65  vecPair_->second.first.push_back( it->first );
66  vecPair_->second.second.push_back( it->second );
67  }
68 }
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54
unsigned int id_
Definition: DDValue.h:122
void init(const std::string &)
Definition: DDValue.cc:11
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:124
std::pair< bool, std::pair< std::vector< std::string >, std::vector< double >>> vecpair_type
Definition: DDValue.h:123
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 71 of file DDValue.cc.

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

72  : id_( 0 )
73 {
74  init( name );
75 
76  std::vector<std::string> svec( 1, "" );
77  std::vector<double> dvec( 1, val );
78 
79  vecPair_.reset( new vecpair_type( false, std::make_pair( svec, dvec )));
80  setEvalState( true );
81 }
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54
void setEvalState(bool newState)
set to true, if the double-values (method DDValue::doubles()) make sense
Definition: DDValue.cc:195
unsigned int id_
Definition: DDValue.h:122
void init(const std::string &)
Definition: DDValue.cc:11
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:124
std::pair< bool, std::pair< std::vector< std::string >, std::vector< double >>> vecpair_type
Definition: DDValue.h:123
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 83 of file DDValue.cc.

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

84  : id_( 0 )
85 {
86  init( name );
87 
88  std::vector<std::string> svec( 1, sval );
89  std::vector<double> dvec( 1, dval );
90  vecPair_.reset(new vecpair_type( false, std::make_pair( svec, dvec )));
91  setEvalState( true );
92 }
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54
void setEvalState(bool newState)
set to true, if the double-values (method DDValue::doubles()) make sense
Definition: DDValue.cc:195
unsigned int id_
Definition: DDValue.h:122
void init(const std::string &)
Definition: DDValue.cc:11
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:124
std::pair< bool, std::pair< std::vector< std::string >, std::vector< double >>> vecpair_type
Definition: DDValue.h:123
DDValue::DDValue ( const std::string &  name,
const std::string &  val 
)
explicit

creates a single std::string-valued named DDValue

Definition at line 94 of file DDValue.cc.

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

95  : id_( 0 )
96 {
97  init( name );
98 
99  std::vector<std::string> svec( 1, sval );
100  std::vector<double> dvec( 1, 0 );
101  vecPair_.reset(new vecpair_type( false, std::make_pair( svec, dvec )));
102  setEvalState( false );
103 }
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54
void setEvalState(bool newState)
set to true, if the double-values (method DDValue::doubles()) make sense
Definition: DDValue.cc:195
unsigned int id_
Definition: DDValue.h:122
void init(const std::string &)
Definition: DDValue.cc:11
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:124
std::pair< bool, std::pair< std::vector< std::string >, std::vector< double >>> vecpair_type
Definition: DDValue.h:123
DDValue::DDValue ( unsigned int  i)
explicit

Definition at line 105 of file DDValue.cc.

References mps_fire::i, id_, and lastIndex.

106  : id_( 0 ),
107  vecPair_()
108 {
109  if( lastIndex >= i )
110  id_ = i;
111 }
unsigned int id_
Definition: DDValue.h:122
static std::atomic< unsigned int > lastIndex
Definition: DDValue.cc:8
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:124

Member Function Documentation

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 137 of file DDValue.cc.

References Exception, python.rootplot.argparse::message, name(), AlCaHLTBitMon_QueryRunRegistry::string, and vecPair_.

Referenced by DDMapper< KeyType, ValueType >::all(), ME0GeometryBuilderFromDDD10EtaPart::buildEtaPartition(), GEMGeometryBuilderFromDDD::buildEtaPartition(), GEMGeometryParsFromDD::buildGeometry(), RPCGeometryBuilderFromDDD::buildGeometry(), RPCGeometryParsFromDD::buildGeometry(), FastTimeParametersFromDD::getDDDArray(), HFShowerFibreBundle::getDDDArray(), HFShowerPMT::getDDDArray(), HFFibre::getDDDArray(), MaterialBudgetHcalHistos::getDDDArray(), ECalSD::getDDDArray(), HFShower::getDDDArray(), HFShowerParam::getDDDArray(), HCalSD::getDDDArray(), HFShowerLibrary::getDDDArray(), HGCalGeomParameters::getDDDArray(), FastTimerSD::getDDDArray(), MuonDDDNumbering::getInt(), DDG4Builder::getInt(), CaloTrkProcessing::getNumbers(), CocoaAnalyzer::myFetchDbl(), strings(), and DDMapper< KeyType, ValueType >::toDouble().

138 {
139  if( vecPair_->first )
140  {
141  return vecPair_->second.second;
142  }
143  else
144  {
145  std::string message = "DDValue " + name() + " is not numerically evaluated! Use DDValue::std::strings()!";
146  edm::LogError("DDValue") << message << std::endl;
147  throw cms::Exception("DDException") << message;
148  }
149 }
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:124
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 DDI::LogicalPart::hasDDValue(), operator<(), and operator==().

48 { return id_; }
unsigned int id_
Definition: DDValue.h:122
DDValue::NamesToIndicies & DDValue::indexer ( void  )
staticprivate

Definition at line 114 of file DDValue.cc.

Referenced by init().

115 {
116  static NamesToIndicies indexer_;
117  return indexer_;
118 }
tbb::concurrent_unordered_map< std::string, AtomicUInt > NamesToIndicies
Definition: DDValue.h:119
void DDValue::init ( const std::string &  name)
private

Definition at line 11 of file DDValue.cc.

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

Referenced by DDValue().

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

Definition at line 120 of file DDValue.cc.

References names(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by names().

120  {
121  //Make sure memory is zeroed before allocating StringHolder
122  // this allows us to check the value of the held std::atomic
123  // as the object is being added to the container
125  names.push_back(StringHolder(std::string{}));
126  return names;
127 }
static Names & names()
Definition: DDValue.cc:130
tbb::concurrent_vector< StringHolder, tbb::zero_allocator< StringHolder >> Names
Definition: DDValue.h:115
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 201 of file DDValue.cc.

References vecPair_.

Referenced by operator<<(), size(), DDCoreToDDXMLOutput::specpar(), and DDI::Specific::stream().

202 {
203  return vecPair_->first;
204 }
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:124
const std::string& DDValue::name ( void  ) const
inline
DDValue::Names & DDValue::names ( void  )
staticprivate

Definition at line 130 of file DDValue.cc.

References initializeNames().

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

131 {
132  static Names names_{ initializeNames() };
133  return names_;
134 }
tbb::concurrent_vector< StringHolder, tbb::zero_allocator< StringHolder >> Names
Definition: DDValue.h:115
static Names initializeNames()
Definition: DDValue.cc:120
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:122
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 225 of file DDValue.cc.

References id(), mps_fire::result, and vecPair_.

Referenced by size().

226 {
227  bool result( false );
228  if( id() < v.id())
229  {
230  result = true;
231  }
232  else
233  {
234  if( id() == v.id())
235  {
236  assert( vecPair_ );
237  assert( v.vecPair_ );
238  if( vecPair_->first && v.vecPair_->first ) { // numerical values
239  result = ( vecPair_->second.second < v.vecPair_->second.second );
240  }
241  else { // std::string values
242  result = ( vecPair_->second.first < v.vecPair_->second.first );
243  }
244  }
245  }
246  return result;
247 }
unsigned int id(void) const
returns the ID of the DDValue
Definition: DDValue.h:48
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:124
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 207 of file DDValue.cc.

References id(), mps_fire::result, and vecPair_.

Referenced by size().

208 {
209  bool result( false );
210  if( id() == v.id())
211  {
212  assert( vecPair_ );
213  assert( v.vecPair_ );
214  if( vecPair_->first ) { // numerical values
215  result = ( vecPair_->second.second == v.vecPair_->second.second );
216  }
217  else { // std::string values
218  result = ( vecPair_->second.first == v.vecPair_->second.first );
219  }
220  }
221  return result;
222 }
unsigned int id(void) const
returns the ID of the DDValue
Definition: DDValue.h:48
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:124
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 180 of file DDValue.cc.

References Exception, python.rootplot.argparse::message, name(), AlCaHLTBitMon_QueryRunRegistry::string, and vecPair_.

Referenced by name().

181 {
182  if( vecPair_->first )
183  {
184  return DDValuePair( vecPair_->second.first[i], vecPair_->second.second[i] );
185  }
186  else
187  {
188  std::string message = "DDValue " + name() + " is not numerically evaluated! Use DDValue::std::strings()!";
189  edm::LogError( "DDValue" ) << message;
190  throw cms::Exception("DDException") << message;
191  }
192 }
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:124
void DDValue::setEvalState ( bool  newState)

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

Definition at line 195 of file DDValue.cc.

References vecPair_.

Referenced by DDValue(), DDLSpecPar::processElement(), and size().

196 {
197  vecPair_->first = newState;
198 }
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:124
unsigned int DDValue::size ( void  ) const
inline
const std::vector<std::string>& DDValue::strings ( ) const
inline

Member Data Documentation

unsigned int DDValue::id_
private

Definition at line 122 of file DDValue.h.

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

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