// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // // $Id: G4GDMLEvaluator.cc,v 1.26 2010/11/04 11:33:49 gcosmo Exp $ // GEANT4 tag $ Name:$ // // class G4GDMLEvaluator Implementation // // Original author: Zoltan Torzsok, November 2007 // // -------------------------------------------------------------------- #include #include "globals.hh" #include "G4GDMLEvaluator.hh" G4GDMLEvaluator::G4GDMLEvaluator() { eval.clear(); eval.setStdMath(); eval.setSystemOfUnits(meter,kilogram,second,ampere,kelvin,mole,candela); } void G4GDMLEvaluator::Clear() { eval.clear(); eval.setStdMath(); eval.setSystemOfUnits(meter,kilogram,second,ampere,kelvin,mole,candela); variableList.clear(); } void G4GDMLEvaluator::DefineConstant(const G4String& name, G4double value) { if (eval.findVariable(name)) { G4String error_msg = "Redefinition of constant or variable: "+name; G4Exception("G4GDMLEvaluator::DefineConstant()", "InvalidExpression", FatalException, error_msg); } eval.setVariable(name.c_str(),value); } void G4GDMLEvaluator::DefineVariable(const G4String& name,G4double value) { if (eval.findVariable(name)) { G4String error_msg = "Redefinition of constant or variable: "+name; G4Exception("G4GDMLEvaluator::DefineVariable()", "InvalidExpression", FatalException, error_msg); } eval.setVariable(name.c_str(),value); variableList.push_back(name); } void G4GDMLEvaluator::DefineMatrix(const G4String& name, G4int coldim, std::vector valueList) { const G4int size = valueList.size(); if (size == 0) { G4String error_msg = "Matrix '"+name+"' is empty!"; G4Exception("G4GDMLEvaluator::DefineMatrix()", "InvalidSize", FatalException, error_msg); } if (size == 1) { G4String error_msg = "Matrix '" + name + "' has only one element! " + "Define a constant instead!!"; G4Exception("G4GDMLEvaluator::DefineMatrix()", "InvalidSize", FatalException, error_msg); } if (size % coldim != 0) { G4String error_msg = "Matrix '" + name + "' is not filled correctly!"; G4Exception("G4GDMLEvaluator::DefineMatrix()", "InvalidSize", FatalException, error_msg); } if ((size == coldim) || (coldim == 1)) // Row- or column matrix { for (G4int i=0;iclose) || (open==std::string::npos) || (close==std::string::npos)) { G4String error_msg = "Bracket mismatch: " + in; G4Exception("G4GDMLEvaluator::SolveBrackets()", "InvalidExpression", FatalException, error_msg); return in; } std::string::size_type begin = open; std::string::size_type end = 0; std::string::size_type end1 = 0; std::string out; out.append(in,0,open); do // Loop for all possible matrix elements in 'in' { do // SolveBrackets for one matrix element { end = in.find(",",begin+1); end1= in.find("]",begin+1); if (end>end1) { end = end1; } if (end==std::string::npos) { end = close;} std::stringstream indexStream; indexStream << "_" << EvaluateInteger(in.substr(begin+1,end-begin-1))-1; out.append(indexStream.str()); begin = end; } while (end