ClhepEvaluator

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#ifndef ClhepEvaluator_h
#define ClhepEvaluator_h

#include <vector>
#include <string>
#include "CLHEP/Evaluator/Evaluator.h"

class ClhepEvaluator {
public:
  ClhepEvaluator();

  ~ClhepEvaluator();

  void set(const std::string& ns, const std::string& name, const std::string& exprValue);

  double eval(const std::string& ns, const std::string& expr);

  bool isDefined(const std::string& ns,   //< current namespace
                 const std::string& name  //< name of the variable inside current namespace
  );

  //! access to the clhep-implementation of the dictionary variables
  const std::vector<std::string>& variables() const { return variables_; }
  const std::vector<std::string>& values() const { return values_; }

  //! evaluations using directly the CLHEP-evaluator
  /** expression must be an expression compatible with the CLHEP-Evaluator syntax */
  double eval(const char* expression);

  //! filling the clhep-implementation of the dictionary
  void set(const std::string& name, const std::string& value);

  void clear();

private:
  void prepare(const std::string& ns,          // input
               const std::string& name,        // input
               const std::string& exprValue,   // input
               std::string& nameResult,        // output
               std::string& valResult) const;  // output

  void throwex(const std::string& ns,
               const std::string& name,
               const std::string& expr,
               const std::string& reason,
               int idx = 0) const;

  void checkname(const std::string& name) const;

  HepTool::Evaluator evaluator_;
  std::vector<std::string> variables_;
  std::vector<std::string> values_;
};

#endif