CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDConstant.cc
Go to the documentation of this file.
1 
4 
5 // Evaluator
7 
9 
10 
12 {
13  prep_ = StoreT::instance().create(name);
14 }
15 
16 DDConstant::DDConstant(const DDName & name,double* vals)
17 {
18  prep_ = StoreT::instance().create(name,vals);
19 }
20 
21 
22 std::ostream & operator<<(std::ostream & os, const DDConstant & cons)
23 {
24  os << "DDConstant name=" << cons.name();
25 
26  if(cons.isDefined().second) {
27  os << " val=" << cons.value();
28  }
29  else {
30  os << " constant is not yet defined, only declared.";
31  }
32  return os;
33 }
34 
35 
37 {
39  ClhepEvaluator * eval = dynamic_cast<ClhepEvaluator*>(&ev);
40  if (eval){
41  const std::vector<std::string> & vars = eval->variables();
42  const std::vector<std::string> & vals = eval->values();
43  if (vars.size() != vals.size()) {
44  throw DDException("DDConstants::createConstansFromEvaluator(): different size of variable names & values!") ;
45  }
46  size_t i(0), s(vars.size());
47  for (; i<s; ++i) {
48  const std::string & sr = vars[i];
49  typedef std::string::size_type ST;
50  ST i1 = sr.find("___");
51  DDName name(std::string(sr,i1+3,sr.size()-1),std::string(sr,0,i1));
52  double* dv = new double;
53  *dv = eval->eval(sr.c_str());
54  DDConstant cst(name,dv);//(ddname);
55  }
56  }
57  else {
58  throw DDException("DDConstants::createConstansFromEvaluator(): expression-evaluator is not a ClhepEvaluator-implementation!");
59  }
60 }
61 
62 
Definition: DDBase.h:18
int i
Definition: DBlmapReader.cc:9
def_type isDefined() const
Definition: DDBase.h:121
const N & name() const
Definition: DDBase.h:88
An exception for DDD errors.
Definition: DDException.h:23
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:18
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
uint16_t size_type
static value_type & instance()
Interface of an Expression Evaluator.
const std::vector< std::string > & variables() const
access to the clhep-implementation of the dictionary variables
const std::vector< std::string > & values() const
double value() const
return the first stored value; does not check boundaries!
Definition: DDConstant.h:31
DDConstant()
an uninitialized constant; one can assign an initialized constant to make it valid ...
Definition: DDConstant.cc:8
static void createConstantsFromEvaluator()
creates all DDConstants from the variables of the ClhepEvaluator
Definition: DDConstant.cc:36
double eval(const std::string &ns, const std::string &expr)
evaluate an expression expr inside the local namespace
string s
Definition: asciidump.py:422
a named constant corresponding to the DDL-XML tag &lt;Constant&gt; and &lt;ConstantsVector&gt; ...
Definition: DDConstant.h:15