CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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...
 
 ~DDValue (void)
 

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

Member Typedef Documentation

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

Definition at line 116 of file DDValue.h.

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

Definition at line 120 of file DDValue.h.

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

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

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

create a named empty value

Definition at line 39 of file DDValue.cc.

References init().

40  : id_( 0 ),
41  vecPair_()
42 {
43  init( name );
44 }
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:55
unsigned int id_
Definition: DDValue.h:123
void init(const std::string &)
Definition: DDValue.cc:10
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:125
DDValue::DDValue ( const char *  name)
explicit

create a named empty value

Definition at line 46 of file DDValue.cc.

References init().

47  : id_( 0 ),
48  vecPair_()
49 {
50  init( name );
51 }
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:55
unsigned int id_
Definition: DDValue.h:123
void init(const std::string &)
Definition: DDValue.cc:10
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:125
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 53 of file DDValue.cc.

References init(), and vecPair_.

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

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

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

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

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

creates a single std::string-valued named DDValue

Definition at line 93 of file DDValue.cc.

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

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

Definition at line 104 of file DDValue.cc.

References i, id_, and lastIndex.

105  : id_( 0 ),
106  vecPair_()
107 {
108  if( lastIndex >= i )
109  id_ = i;
110 }
int i
Definition: DBlmapReader.cc:9
unsigned int id_
Definition: DDValue.h:123
static std::atomic< unsigned int > lastIndex
Definition: DDValue.cc:7
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:125
DDValue::~DDValue ( void  )

Definition at line 112 of file DDValue.cc.

113 {}

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

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

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

140 {
141  if( vecPair_->first )
142  {
143  return vecPair_->second.second;
144  }
145  else
146  {
147  std::string message = "DDValue " + name() + " is not numerically evaluated! Use DDValue::std::strings()!";
148  edm::LogError("DDValue") << message << std::endl;
149  throw cms::Exception("DDException") << message;
150  }
151 }
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:55
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:125
unsigned int DDValue::id ( void  ) const
inline

returns the ID of the DDValue

Definition at line 49 of file DDValue.h.

References id_.

Referenced by DDI::LogicalPart::hasDDValue(), operator<(), and operator==().

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

Definition at line 116 of file DDValue.cc.

Referenced by init().

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

Definition at line 10 of file DDValue.cc.

References id_, indexer(), lastIndex, name(), names(), query::result, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by DDValue().

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

Definition at line 122 of file DDValue.cc.

References names(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by names().

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

References vecPair_.

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

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

Definition at line 132 of file DDValue.cc.

References initializeNames().

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

133 {
134  static Names names_{ initializeNames() };
135  return names_;
136 }
tbb::concurrent_vector< StringHolder, tbb::zero_allocator< StringHolder >> Names
Definition: DDValue.h:116
static Names initializeNames()
Definition: DDValue.cc:122
DDValue::operator unsigned int ( void  ) const
inline

converts a DDValue object into its ID

Definition at line 52 of file DDValue.h.

References id_.

52 { return id_; }
unsigned int id_
Definition: DDValue.h:123
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 227 of file DDValue.cc.

References assert(), id(), query::result, and vecPair_.

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

References assert(), id(), query::result, and vecPair_.

210 {
211  bool result( false );
212  if( id() == v.id())
213  {
214  assert( vecPair_ );
215  assert( v.vecPair_ );
216  if( vecPair_->first ) { // numerical values
217  result = ( vecPair_->second.second == v.vecPair_->second.second );
218  }
219  else { // std::string values
220  result = ( vecPair_->second.first == v.vecPair_->second.first );
221  }
222  }
223  return result;
224 }
assert(m_qm.get())
unsigned int id(void) const
returns the ID of the DDValue
Definition: DDValue.h:49
tuple result
Definition: query.py:137
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:125
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 182 of file DDValue.cc.

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

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

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

Definition at line 197 of file DDValue.cc.

References vecPair_.

Referenced by DDValue(), DDLSpecPar::processElement(), and DDStreamer::specs_read().

198 {
199  vecPair_->first = newState;
200 }
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:125
unsigned int DDValue::size ( void  ) const
inline

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

Definition at line 69 of file DDValue.h.

References vecPair_.

Referenced by DDMapper< KeyType, ValueType >::noSpecifics(), operator<<(), DDCoreToDDXMLOutput::specpar(), DDStreamer::specs_write(), DDI::Specific::stream(), DDMapper< KeyType, ValueType >::toDouble(), and DDMapper< KeyType, ValueType >::toString().

69  {
70  return vecPair_ ? vecPair_->second.first.size() : 0 ;
71  }
std::shared_ptr< vecpair_type > vecPair_
Definition: DDValue.h:125
const std::vector<std::string>& DDValue::strings ( ) const
inline

Member Data Documentation

unsigned int DDValue::id_
private

Definition at line 123 of file DDValue.h.

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

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