CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
DDMapper< KeyType, ValueType > Class Template Reference

#include <DDMapper.h>

Public Types

typedef std::pair< KeyType, ValueType > Pair
 usefull typedef More...
 
typedef std::vector< PairVector
 usefull typedef More...
 

Public Member Functions

Vector all (const std::string &name, const std::string &value) const
 get all std::mapped instances which have a specific 'name' with value 'value' More...
 
Vector all (const std::string &name, const double &value) const
 get all std::mapped instances which have a specific 'name' with value 'value' More...
 
Vector all (const std::string &name) const
 get all std::mapped instances which have a specific 'name' More...
 
void insert (const KeyType &, const ValueType &)
 insert a new key-value-pair More...
 
unsigned int noSpecifics (const KeyType &key, const std::string &name) const
 fetch a key given a value More...
 
unsigned int toDouble (const std::string &name, const KeyType &key, double &value, unsigned int pos=0) const
 returns the number specific parameters named 'name' and the corrsponding double More...
 
unsigned int toDouble (const std::string &name, const ValueType &key, double &value, unsigned int pos=0) const
 
unsigned int toString (const std::string &name, const KeyType &key, std::string &value, unsigned int pos=0) const
 same as toDouble but for std::string-valued values of named parameters More...
 
unsigned int toString (const std::string &name, const ValueType &key, std::string &value, unsigned int pos=0) const
 same as toDouble but for std::string-valued values of named parameters More...
 
bool value (const KeyType &key, ValueType &result)
 removes a key-value pair More...
 

Private Attributes

std::map< KeyType, ValueType > keyToValue_
 
std::multimap< ValueType, KeyType > valueToKey_
 

Detailed Description

template<class KeyType, class ValueType>
class DDMapper< KeyType, ValueType >

Definition at line 13 of file DDMapper.h.

Member Typedef Documentation

◆ Pair

template<class KeyType, class ValueType>
typedef std::pair<KeyType, ValueType> DDMapper< KeyType, ValueType >::Pair

usefull typedef

Definition at line 16 of file DDMapper.h.

◆ Vector

template<class KeyType, class ValueType>
typedef std::vector<Pair> DDMapper< KeyType, ValueType >::Vector

usefull typedef

Definition at line 19 of file DDMapper.h.

Member Function Documentation

◆ all() [1/3]

template<class K , class V >
std::vector< std::pair< K, V > > DDMapper< K, V >::all ( const std::string &  name,
const std::string &  value 
) const

get all std::mapped instances which have a specific 'name' with value 'value'

Definition at line 199 of file DDMapper.h.

Referenced by DDG4ProductionCuts::initialize().

199  {
200  std::vector<std::pair<K, V> > result;
201  typedef std::vector<const DDsvalues_type *> sv_type;
202  typename std::map<V, K>::const_iterator it = valueToKey_.begin();
203  typename std::map<V, K>::const_iterator ed = valueToKey_.end();
204 
205  // loop over all registered ValueTypes
206  for (; it != ed; ++it) {
207  sv_type sv = it->first.specifics();
208  //std::cout << "now at: " << it->first.name() << std::endl;
209  sv_type::const_iterator svIt = sv.begin();
210  sv_type::const_iterator svEd = sv.end();
211  DDValue v(name);
212  for (; svIt != svEd; ++svIt) {
213  if (DDfetch(*svIt, v)) {
214  //std::cout << "found: ";
215  const std::vector<std::string> &s = v.strings();
216  if (!s.empty()) {
217  //std::cout << s[0];
218  if (s[0] == value) {
219  result.emplace_back(std::make_pair(it->second, it->first));
220  break;
221  }
222  }
223  //std::cout << std::endl;
224  }
225  }
226  }
227  return result;
228 }
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
Definition: value.py:1
std::multimap< ValueType, KeyType > valueToKey_
Definition: DDMapper.h:70

◆ all() [2/3]

template<class K , class V >
std::vector< std::pair< K, V > > DDMapper< K, V >::all ( const std::string &  name,
const double &  value 
) const

get all std::mapped instances which have a specific 'name' with value 'value'

Definition at line 231 of file DDMapper.h.

231  {
232  std::vector<std::pair<K, V> > result;
233  typedef std::vector<const DDsvalues_type *> sv_type;
234  typename std::map<V, K>::const_iterator it = valueToKey_.begin();
235  typename std::map<V, K>::const_iterator ed = valueToKey_.end();
236 
237  // loop over all registered ValueTypes
238  for (; it != ed; ++it) {
239  sv_type sv = it->first.specifics();
240  //std::cout << "now at: " << it->first.name() << std::endl;
241  sv_type::const_iterator svIt = sv.begin();
242  sv_type::const_iterator svEd = sv.end();
243  DDValue v(name);
244  for (; svIt != svEd; ++svIt) {
245  if (DDfetch(*svIt, v)) {
246  //std::cout << "found: ";
247  const std::vector<double> &s = v.doubles();
248  if (!s.empty()) {
249  //std::cout << s[0];
250  if (s[0] == value) {
251  result.emplace_back(std::make_pair(it->second, it->first));
252  break;
253  }
254  }
255  //std::cout << std::endl;
256  }
257  }
258  }
259  return result;
260 }
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
Definition: value.py:1
std::multimap< ValueType, KeyType > valueToKey_
Definition: DDMapper.h:70

◆ all() [3/3]

template<class K , class V >
std::vector< std::pair< K, V > > DDMapper< K, V >::all ( const std::string &  name) const

get all std::mapped instances which have a specific 'name'

Definition at line 263 of file DDMapper.h.

263  {
264  std::vector<std::pair<K, V> > result;
265  typedef std::vector<const DDsvalues_type *> sv_type;
266  typename std::map<V, K>::const_iterator it = valueToKey_.begin();
267  typename std::map<V, K>::const_iterator ed = valueToKey_.end();
268 
269  // loop over all registered ValueTypes
270  for (; it != ed; ++it) {
271  sv_type sv = it->first.specifics();
272  //std::cout << "now at: " << it->first.name() << std::endl;
273  sv_type::const_iterator svIt = sv.begin();
274  sv_type::const_iterator svEd = sv.end();
275  DDValue v(name);
276  for (; svIt != svEd; ++svIt) {
277  if (DDfetch(*svIt, v)) {
278  result.emplace_back(std::make_pair(it->second, it->first));
279  break;
280  }
281  }
282  }
283  return result;
284 }
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
std::multimap< ValueType, KeyType > valueToKey_
Definition: DDMapper.h:70

◆ insert()

template<class K, class V>
void DDMapper< K, V >::insert ( const K &  key,
const V &  value 
)

insert a new key-value-pair

any existing entry will be overridden

Definition at line 74 of file DDMapper.h.

Referenced by SequenceTypes.Schedule::_replaceIfHeldDirectly(), DDG4Builder::BuildGeometry(), and DDG4Builder::convertLV().

74  {
76  valueToKey_.insert(std::make_pair(value, key));
77  // valueToKey_[value] = key;
78 }
bool value(const KeyType &key, ValueType &result)
removes a key-value pair
Definition: DDMapper.h:81
std::map< KeyType, ValueType > keyToValue_
Definition: DDMapper.h:69
key
prepare the HTCondor submission files and eventually submit them
Definition: value.py:1
std::multimap< ValueType, KeyType > valueToKey_
Definition: DDMapper.h:70

◆ noSpecifics()

template<class K, class V >
unsigned int DDMapper< K, V >::noSpecifics ( const K &  key,
const std::string &  name 
) const

fetch a key given a value

the number of specific parameters which are named 'name'

Definition at line 92 of file DDMapper.h.

92  {
93  typedef std::vector<const DDsvalues_type *> sv_type;
94  unsigned int result = 0;
95  typename std::map<K, V>::const_iterator it = keyToValue_.find(key);
96  if (it != keyToValue_.end()) {
97  sv_type sv = it->second.specifics();
98  sv_type::const_iterator it = sv.begin();
99  DDValue v(name);
100  for (; it != sv.end(); ++it) {
101  if (DDfetch(*it, v)) {
102  result += v.size();
103  }
104  }
105  }
106  return result;
107 }
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
std::map< KeyType, ValueType > keyToValue_
Definition: DDMapper.h:69
key
prepare the HTCondor submission files and eventually submit them

◆ toDouble() [1/2]

template<class K, class V >
unsigned int DDMapper< K, V >::toDouble ( const std::string &  name,
const K &  key,
double &  value,
unsigned int  pos = 0 
) const

returns the number specific parameters named 'name' and the corrsponding double

of the DDLogicalPart which corresponds to the given KeyType key. The returned value is assigned to the 'value'-reference

  • if no parameters exist, 0 is returned and value is left unchanged
  • if more than one parameter with the given name exists, the first is returned by default, alternatively 'pos' can be used to address another value (note: pos=0 -> first value)

Definition at line 111 of file DDMapper.h.

Referenced by DDG4ProductionCuts::setProdCuts().

111  {
112  typedef std::vector<const DDsvalues_type *> sv_type;
113  unsigned int result = 0;
114  typename std::map<K, V>::const_iterator it = keyToValue_.find(key);
115  if (it != keyToValue_.end()) {
116  sv_type sv = it->second.specifics();
117  sv_type::const_iterator svIt = sv.begin();
118  sv_type::const_iterator svEd = sv.end();
119  DDValue v(name);
120  for (; svIt != svEd; ++svIt) {
121  if (DDfetch(*svIt, v)) {
122  result = v.size();
123  value = v.doubles()[pos];
124  break;
125  }
126  }
127  }
128  return result;
129 }
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
std::map< KeyType, ValueType > keyToValue_
Definition: DDMapper.h:69
key
prepare the HTCondor submission files and eventually submit them
Definition: value.py:1

◆ toDouble() [2/2]

template<class K , class V>
unsigned int DDMapper< K, V >::toDouble ( const std::string &  name,
const V &  key,
double &  value,
unsigned int  pos = 0 
) const

Definition at line 132 of file DDMapper.h.

132  {
133  typedef std::vector<const DDsvalues_type *> sv_type;
134  unsigned int result = 0;
135  sv_type sv = val.specifics();
136  sv_type::const_iterator svIt = sv.begin();
137  sv_type::const_iterator svEd = sv.end();
138  DDValue v(name);
139  for (; svIt != svEd; ++svIt) {
140  if (DDfetch(*svIt, v)) {
141  result = v.size();
142  value = v.doubles()[pos];
143  break;
144  }
145  }
146  return result;
147 }
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
Definition: value.py:1

◆ toString() [1/2]

template<class K, class V >
unsigned int DDMapper< K, V >::toString ( const std::string &  name,
const K &  key,
std::string &  value,
unsigned int  pos = 0 
) const

same as toDouble but for std::string-valued values of named parameters

Definition at line 172 of file DDMapper.h.

Referenced by DDG4ProductionCuts::initialize().

175  {
176  typedef std::vector<const DDsvalues_type *> sv_type;
177  unsigned int result = 0;
178  typename std::map<K, V>::const_iterator it = keyToValue_.find(key);
179  if (it != keyToValue_.end()) {
180  sv_type sv = it->second.specifics();
181  sv_type::const_iterator svIt = sv.begin();
182  sv_type::const_iterator svEd = sv.end();
183  DDValue v(name);
184  //std::cout << "DDValue=" << name << std::endl;
185  for (; svIt != svEd; ++svIt) {
186  //std::cout << "looping..." << **svIt << std::endl;
187  if (DDfetch(*svIt, v)) {
188  result = v.size();
189  //std::cout << "found!" << std::endl;
190  value = v.strings()[pos];
191  break;
192  }
193  }
194  }
195  return result;
196 }
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
std::map< KeyType, ValueType > keyToValue_
Definition: DDMapper.h:69
key
prepare the HTCondor submission files and eventually submit them
Definition: value.py:1

◆ toString() [2/2]

template<class K, class V>
unsigned int DDMapper< K, V >::toString ( const std::string &  name,
const V &  key,
std::string &  value,
unsigned int  pos = 0 
) const

same as toDouble but for std::string-valued values of named parameters

Definition at line 150 of file DDMapper.h.

153  {
154  typedef std::vector<const DDsvalues_type *> sv_type;
155  unsigned int result = 0;
156  sv_type sv = val.specifics();
157  sv_type::const_iterator svIt = sv.begin();
158  sv_type::const_iterator svEd = sv.end();
159  DDValue v(name);
160  for (; svIt != svEd; ++svIt) {
161  if (DDfetch(*svIt, v)) {
162  result = v.size();
163  value = v.strings()[pos];
164  break;
165  }
166  }
167  return result;
168 }
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
Definition: value.py:1

◆ value()

template<class K, class V>
bool DDMapper< K, V >::value ( const K &  key,
V &  result 
)

removes a key-value pair

non-existing keys are simply ignored removes a key-value pair non-existing values are simply ignored fetch a value given a key returns true, if sucessfull - value is assigned to result; else false

Definition at line 81 of file DDMapper.h.

Referenced by Types.int32::__nonzero__(), Types.uint32::__nonzero__(), Types.int64::__nonzero__(), Types.uint64::__nonzero__(), Types.double::__nonzero__(), Types.bool::__nonzero__(), Types.string::__nonzero__(), average.Average::average(), Types.string::configValue(), Types.FileInPath::configValue(), Mixins.UsingBlock::dumpPython(), Mixins.UsingBlock::insertInto(), Types.int32::insertInto(), Types.uint32::insertInto(), Types.int64::insertInto(), Types.uint64::insertInto(), Types.double::insertInto(), Types.bool::insertInto(), Types.string::insertInto(), Types.FileInPath::insertInto(), Types.vint32::insertInto(), Types.vuint32::insertInto(), Types.vint64::insertInto(), Types.vuint64::insertInto(), Types.vdouble::insertInto(), Types.vbool::insertInto(), and Types.vstring::insertInto().

81  {
82  bool result = false;
83  typename std::map<K, V>::const_iterator it = keyToValue_.find(key);
84  if (it != keyToValue_.end()) {
85  value = it->second;
86  result = true;
87  }
88  return result;
89 }
std::map< KeyType, ValueType > keyToValue_
Definition: DDMapper.h:69
key
prepare the HTCondor submission files and eventually submit them
Definition: value.py:1

Member Data Documentation

◆ keyToValue_

template<class KeyType, class ValueType>
std::map<KeyType, ValueType> DDMapper< KeyType, ValueType >::keyToValue_
private

Definition at line 69 of file DDMapper.h.

◆ valueToKey_

template<class KeyType, class ValueType>
std::multimap<ValueType, KeyType> DDMapper< KeyType, ValueType >::valueToKey_
private

Definition at line 70 of file DDMapper.h.