CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDValue.cc
Go to the documentation of this file.
3 
4 #include <cassert>
5 
6 void
8 {
9  unsigned int temp = indexer().size()+1;
10  typedef std::map<std::string,unsigned int>::iterator itT;
11  std::pair<itT,bool> result = indexer().insert( std::make_pair( name, temp ));
12 
13  if( result.second )
14  {
15  id_ = temp;
16  names().push_back( name );
17  }
18  else
19  {
20  id_ = result.first->second;
21  }
22 }
23 
25  : id_( 0 ),
26  vecPair_( 0 )
27 {
28  init( name );
29 }
30 
31 DDValue::DDValue( const char * name )
32  : id_( 0 ),
33  vecPair_( 0 )
34 {
35  init( name );
36 }
37 
38 DDValue::DDValue( const std::string & name, const std::vector<DDValuePair>& v )
39  : id_( 0 )
40 {
41  init( name );
42 
43  std::vector<DDValuePair>::const_iterator it = v.begin();
44  std::vector<std::string> svec;
45  std::vector<double> dvec;
46  vecPair_ = new vecpair_type( false, std::make_pair( svec, dvec ));
47  mem( vecPair_ );
48  for(; it != v.end(); ++it )
49  {
50  vecPair_->second.first.push_back( it->first );
51  vecPair_->second.second.push_back( it->second );
52  }
53 }
54 
55 
56 DDValue::DDValue( const std::string & name, double val )
57  : id_( 0 )
58 {
59  init( name );
60 
61  std::vector<std::string> svec( 1, "" );
62  std::vector<double> dvec( 1, val );
63 
64  vecPair_ = new vecpair_type( false, std::make_pair( svec, dvec ));
65  setEvalState( true );
66  mem( vecPair_ );
67 }
68 
69 DDValue::DDValue( const std::string & name, const std::string & sval, double dval )
70  : id_( 0 )
71 {
72  init( name );
73 
74  std::vector<std::string> svec( 1, sval );
75  std::vector<double> dvec( 1, dval );
76  vecPair_ = new vecpair_type( false, std::make_pair( svec, dvec ));
77  setEvalState( true );
78  mem( vecPair_ );
79 }
80 
81 DDValue::DDValue( const std::string & name, const std::string & sval )
82  : id_( 0 )
83 {
84  init( name );
85 
86  std::vector<std::string> svec( 1, sval );
87  std::vector<double> dvec( 1, 0 );
88  vecPair_ = new vecpair_type( false, std::make_pair( svec, dvec ));
89  setEvalState( false );
90  mem( vecPair_ );
91 }
92 
93 DDValue::DDValue( unsigned int i )
94  : id_( 0 ),
95  vecPair_( 0 )
96 {
97  if( names().size() - 1 <= i )
98  id_ = i;
99 }
100 
102 {}
103 
104 void
106 {
107  std::vector<boost::shared_ptr<vecpair_type> > & v = mem( 0 );
108  v.clear();
109 }
110 
111 std::map<std::string, unsigned int>&
113 {
114  static std::map<std::string,unsigned int> indexer_;
115  return indexer_;
116 }
117 
118 std::vector<std::string>&
120 {
121  static std::vector<std::string> names_( 1 );
122  return names_;
123 }
124 
125 std::vector<boost::shared_ptr<DDValue::vecpair_type> >&
127 {
128  static std::vector<boost::shared_ptr<vecpair_type> > memory_;
129  memory_.push_back( boost::shared_ptr<vecpair_type>( vp ));
130  return memory_;
131 }
132 
133 const std::vector<double> &
134 DDValue::doubles( void ) const
135 {
136  if( vecPair_->first )
137  {
138  return vecPair_->second.second;
139  }
140  else
141  {
142  std::string message = "DDValue " + names()[id_] + " is not numerically evaluated! Use DDValue::std::strings()!";
143  edm::LogError("DDValue") << message << std::endl;
144  throw cms::Exception("DDException") << message;
145  }
146 }
147 
148 std::ostream & operator<<( std::ostream & o, const DDValue & v )
149 {
150  o << v.name() << " = ";
151  unsigned int i = 0;
152  if( v.isEvaluated())
153  {
154  for(; i < v.size(); ++i )
155  {
156  o << '(' << v[i].first << ',' << v[i].second << ") ";
157  }
158  }
159  else
160  {
161  const std::vector<std::string> & s = v.strings();
162  for(; i < v.size(); ++i )
163  {
164  o << s[i] << ' ';
165  }
166  }
167  return o;
168 }
169 
170 //FIXME move it elsewhere; DO NOT put out the name for now... need to fix DDCoreToDDXMLOutput
171 std::ostream & operator<<( std::ostream & o, const DDValuePair & v )
172 {
173  return o << v.second;
174 }
175 
177 DDValue::operator[]( unsigned int i ) const
178 {
179  if( vecPair_->first )
180  {
181  return DDValuePair( vecPair_->second.first[i], vecPair_->second.second[i] );
182  }
183  else
184  {
185  std::string message = "DDValue " + names()[id_] + " is not numerically evaluated! Use DDValue::std::strings()!";
186  edm::LogError( "DDValue" ) << message;
187  throw cms::Exception("DDException") << message;
188  }
189 }
190 
191 void
192 DDValue::setEvalState( bool newState )
193 {
194  vecPair_->first = newState;
195 }
196 
197 bool
198 DDValue::isEvaluated( void ) const
199 {
200  return vecPair_->first;
201 }
202 
203 bool
204 DDValue::operator==( const DDValue & v ) const
205 {
206  bool result( false );
207  if( id() == v.id())
208  {
209  assert( vecPair_ );
210  assert( v.vecPair_ );
211  if( vecPair_->first ) { // numerical values
212  result = ( vecPair_->second.second == v.vecPair_->second.second );
213  }
214  else { // std::string values
215  result = ( vecPair_->second.first == v.vecPair_->second.first );
216  }
217  }
218  return result;
219 }
220 
221 bool
222 DDValue::operator<( const DDValue & v ) const
223 {
224  bool result( false );
225  if( id() < v.id())
226  {
227  result = true;
228  }
229  else
230  {
231  if( id() == v.id())
232  {
233  assert( vecPair_ );
234  assert( v.vecPair_ );
235  if( vecPair_->first && v.vecPair_->first ) { // numerical values
236  result = ( vecPair_->second.second < v.vecPair_->second.second );
237  }
238  else { // std::string values
239  result = ( vecPair_->second.first < v.vecPair_->second.first );
240  }
241  }
242  }
243  return result;
244 }
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:64
static std::vector< boost::shared_ptr< vecpair_type > > & mem(vecpair_type *)
Definition: DDValue.cc:126
static std::vector< std::string > & names()
Definition: DDValue.cc:119
int i
Definition: DBlmapReader.cc:9
DDValue(void)
create a unnamed emtpy value. One can assing a named DDValue to it.
Definition: DDValue.h:31
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:134
std::pair< bool, std::pair< std::vector< std::string >, std::vector< double > > > vecpair_type
Definition: DDValue.h:101
static std::map< std::string, unsigned int > & indexer()
Definition: DDValue.cc:112
void setEvalState(bool newState)
set to true, if the double-values (method DDValue::doubles()) make sense
Definition: DDValue.cc:192
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
unsigned int id(void) const
returns the ID of the DDValue
Definition: DDValue.h:58
~DDValue(void)
Definition: DDValue.cc:101
bool isEvaluated(void) const
true, if values are numerical evaluated; else false.
Definition: DDValue.cc:198
unsigned int id_
Definition: DDValue.h:106
tuple result
Definition: query.py:137
void init(const std::string &)
Definition: DDValue.cc:7
bool operator==(const DDValue &v) const
Two DDValues are equal only if their id() is equal AND their values are equal.
Definition: DDValue.cc:204
const std::vector< std::string > & strings() const
a reference to the std::string-valued values stored in the given instance of DDValue ...
Definition: DDValue.h:71
DDValuePair operator[](unsigned int i) const
Definition: DDValue.cc:177
static void clear(void)
Definition: DDValue.cc:105
bool operator<(const DDValue &) const
A DDValue a is smaller than a DDValue b if (a.id()&lt;b.id()) OR (a.id()==b.id() and value(a)&lt;value(b)) ...
Definition: DDValue.cc:222
unsigned int size() const
the size of the stored value-pairs (std::string,double)
Definition: DDValue.h:78
vecpair_type * vecPair_
Definition: DDValue.h:109