source: trunk/source/persistency/gdml/src/G4GDMLEvaluator.cc@ 820

Last change on this file since 820 was 818, checked in by garnier, 17 years ago

import all except CVS

File size: 3.6 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: G4GDMLEvaluator.cc,v 1.11 2007/11/28 10:27:18 ztorzsok Exp $
28// GEANT4 tag $ Name:$
29//
30// class G4GDMLEvaluator Implementation
31//
32// Original author: Zoltan Torzsok, November 2007
33//
34// --------------------------------------------------------------------
35
36#include "G4GDMLEvaluator.hh"
37
38G4GDMLEvaluator::G4GDMLEvaluator() {
39
40 eval.clear();
41 eval.setStdMath();
42 eval.setSystemOfUnits(1.e+3,1./1.60217733e-25,1.e+9,1./1.60217733e-10,1.0,1.0,1.0);
43}
44
45void G4GDMLEvaluator::defineConstant(const G4String& name,G4double value) {
46
47 if (eval.findVariable(name)) G4Exception("GDML: Constant or variable '"+name+"' is already defined!");
48
49 eval.setVariable(name.c_str(),value);
50}
51
52void G4GDMLEvaluator::defineVariable(const G4String& name,G4double value) {
53
54 if (eval.findVariable(name)) G4Exception("GDML: Constant or variable '"+name+"' is already defined!");
55
56 eval.setVariable(name.c_str(),value);
57 variableList.push_back(name);
58}
59
60void G4GDMLEvaluator::setVariable(const G4String& name,G4double value) {
61
62 checkVariable(name);
63
64 eval.setVariable(name.c_str(),value);
65}
66
67void G4GDMLEvaluator::checkVariable(const G4String& name) {
68
69 for (std::vector<G4String>::iterator iter = variableList.begin(); iter != variableList.end(); iter++) {
70
71 if (name == *iter) return;
72 }
73
74 G4Exception("GDML: Variable '"+name+"' is not defined!");
75}
76
77G4double G4GDMLEvaluator::Evaluate(const G4String& expression) {
78
79 G4double value = 0.0;
80
81 if (!expression.empty()) {
82
83 value = eval.evaluate(expression.c_str());
84
85 if (eval.status() != HepTool::Evaluator::OK) {
86
87 eval.print_error();
88 G4Exception("Error in evaluator!");
89 }
90 }
91
92 return value;
93}
94
95G4int G4GDMLEvaluator::EvaluateInteger(const G4String& expression) {
96
97 G4double value = Evaluate(expression);
98
99 G4int whole = (G4int)value;
100 G4double frac = value - (G4double)whole;
101
102 if (frac != 0.0) G4Exception("GDML: Expression '"+expression+"' is expected to have an integer value!");
103
104 return whole;
105}
Note: See TracBrowser for help on using the repository browser.