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

References init().

45  : id_( 0 ),
46  vecPair_()
47 {
48  init( name );
49 }
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:15
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:124
DDValue::DDValue ( const char *  name)
explicit

create a named empty value

Definition at line 51 of file DDValue.cc.

References init().

52  : id_( 0 ),
53  vecPair_()
54 {
55  init( name );
56 }
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:15
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 58 of file DDValue.cc.

References init(), and vecPair_.

59  : id_( 0 )
60 {
61  init( name );
62 
63  auto it = v.begin();
64  std::vector<std::string> svec;
65  std::vector<double> dvec;
66  vecPair_.reset(new vecpair_type( false, std::make_pair( svec, dvec )));
67  for(; it != v.end(); ++it )
68  {
69  vecPair_->second.first.emplace_back( it->first );
70  vecPair_->second.second.emplace_back( it->second );
71  }
72 }
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:15
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 74 of file DDValue.cc.

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

75  : id_( 0 )
76 {
77  init( name );
78 
79  std::vector<std::string> svec( 1, "" );
80  std::vector<double> dvec( 1, val );
81 
82  vecPair_.reset( new vecpair_type( false, std::make_pair( svec, dvec )));
83  setEvalState( true );
84 }
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:198
unsigned int id_
Definition: DDValue.h:122
void init(const std::string &)
Definition: DDValue.cc:15
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 86 of file DDValue.cc.

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

87  : id_( 0 )
88 {
89  init( name );
90 
91  std::vector<std::string> svec( 1, sval );
92  std::vector<double> dvec( 1, dval );
93  vecPair_.reset(new vecpair_type( false, std::make_pair( svec, dvec )));
94  setEvalState( true );
95 }
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:198
unsigned int id_
Definition: DDValue.h:122
void init(const std::string &)
Definition: DDValue.cc:15
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 97 of file DDValue.cc.

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

98  : id_( 0 )
99 {
100  init( name );
101 
102  std::vector<std::string> svec( 1, sval );
103  std::vector<double> dvec( 1, 0 );
104  vecPair_.reset(new vecpair_type( false, std::make_pair( svec, dvec )));
105  setEvalState( false );
106 }
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:198
unsigned int id_
Definition: DDValue.h:122
void init(const std::string &)
Definition: DDValue.cc:15
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 108 of file DDValue.cc.

References mps_fire::i, id_, and lastIndex.

109  : id_( 0 ),
110  vecPair_()
111 {
112  if( lastIndex >= i )
113  id_ = i;
114 }
unsigned int id_
Definition: DDValue.h:122
static std::atomic< unsigned int > lastIndex
Definition: DDValue.cc:12
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 140 of file DDValue.cc.

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

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

141 {
142  if( vecPair_->first )
143  {
144  return vecPair_->second.second;
145  }
146  else
147  {
148  std::string message = "DDValue " + name() + " is not numerically evaluated! Use DDValue::std::strings()!";
149  edm::LogError("DDValue") << message << std::endl;
150  throw cms::Exception("DDException") << message;
151  }
152 }
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 117 of file DDValue.cc.

Referenced by init().

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

Definition at line 15 of file DDValue.cc.

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

Referenced by DDValue().

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

Definition at line 123 of file DDValue.cc.

References names(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by names().

123  {
124  //Make sure memory is zeroed before allocating StringHolder
125  // this allows us to check the value of the held std::atomic
126  // as the object is being added to the container
128  names.emplace_back(StringHolder(std::string{}));
129  return names;
130 }
static Names & names()
Definition: DDValue.cc:133
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 204 of file DDValue.cc.

References vecPair_.

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

205 {
206  return vecPair_->first;
207 }
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 133 of file DDValue.cc.

References initializeNames().

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

134 {
135  static Names names_{ initializeNames() };
136  return names_;
137 }
tbb::concurrent_vector< StringHolder, tbb::zero_allocator< StringHolder >> Names
Definition: DDValue.h:115
static Names initializeNames()
Definition: DDValue.cc:123
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 228 of file DDValue.cc.

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

Referenced by size().

229 {
230  bool result( false );
231  if( id() < v.id())
232  {
233  result = true;
234  }
235  else
236  {
237  if( id() == v.id())
238  {
239  assert( vecPair_ );
240  assert( v.vecPair_ );
241  if( vecPair_->first && v.vecPair_->first ) { // numerical values
242  result = ( vecPair_->second.second < v.vecPair_->second.second );
243  }
244  else { // std::string values
245  result = ( vecPair_->second.first < v.vecPair_->second.first );
246  }
247  }
248  }
249  return result;
250 }
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 210 of file DDValue.cc.

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

Referenced by size().

211 {
212  bool result( false );
213  if( id() == v.id())
214  {
215  assert( vecPair_ );
216  assert( v.vecPair_ );
217  if( vecPair_->first ) { // numerical values
218  result = ( vecPair_->second.second == v.vecPair_->second.second );
219  }
220  else { // std::string values
221  result = ( vecPair_->second.first == v.vecPair_->second.first );
222  }
223  }
224  return result;
225 }
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 183 of file DDValue.cc.

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

Referenced by name().

184 {
185  if( vecPair_->first )
186  {
187  return DDValuePair( vecPair_->second.first[i], vecPair_->second.second[i] );
188  }
189  else
190  {
191  std::string message = "DDValue " + name() + " is not numerically evaluated! Use DDValue::std::strings()!";
192  edm::LogError( "DDValue" ) << message;
193  throw cms::Exception("DDException") << message;
194  }
195 }
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 198 of file DDValue.cc.

References vecPair_.

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

199 {
200  vecPair_->first = newState;
201 }
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