Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:51:38

0001 #include "DetectorDescription/Core/interface/DDConstant.h"
0002 
0003 #include <string>
0004 #include <utility>
0005 #include <vector>
0006 
0007 #include "DetectorDescription/Core/interface/ClhepEvaluator.h"
0008 #include "FWCore/Utilities/interface/Exception.h"
0009 
0010 DDConstant::DDConstant() : DDBase<DDName, std::unique_ptr<double> >() {}
0011 
0012 DDConstant::DDConstant(const DDName& name) : DDBase<DDName, std::unique_ptr<double> >() { create(name); }
0013 
0014 DDConstant::DDConstant(const DDName& name, std::unique_ptr<double> vals) { create(name, std::move(vals)); }
0015 
0016 std::ostream& operator<<(std::ostream& os, const DDConstant& cons) {
0017   os << "DDConstant name=" << cons.name();
0018 
0019   if (cons.isDefined().second) {
0020     os << " val=" << cons.value();
0021   } else {
0022     os << " constant is not yet defined, only declared.";
0023   }
0024   return os;
0025 }
0026 
0027 void DDConstant::createConstantsFromEvaluator(ClhepEvaluator& eval) {
0028   const auto& vars = eval.variables();
0029   const auto& vals = eval.values();
0030   if (vars.size() != vals.size()) {
0031     throw cms::Exception("DDException")
0032         << "DDConstants::createConstansFromEvaluator(): different size of variable names & values!";
0033   }
0034   for (const auto& it : vars) {
0035     auto found = it.find("___");
0036     DDName name(std::string(it, found + 3, it.size() - 1), std::string(it, 0, found));
0037     DDConstant cst(name, std::make_unique<double>(eval.eval(it.c_str())));
0038   }
0039 }