Changeset 850 for trunk/source/persistency
- Timestamp:
- Sep 10, 2008, 5:40:37 PM (17 years ago)
- Location:
- trunk/source/persistency/gdml
- Files:
-
- 5 edited
-
GNUmakefile (modified) (3 diffs)
-
History (modified) (2 diffs)
-
include/G4GDMLEvaluator.hh (modified) (2 diffs)
-
include/G4GDMLParser.hh (modified) (2 diffs)
-
src/G4GDMLEvaluator.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/persistency/gdml/GNUmakefile
r818 r850 1 # $Id: GNUmakefile,v 1. 6 2007/12/11 15:00:49gcosmo Exp $1 # $Id: GNUmakefile,v 1.10 2008/07/02 14:15:16 gcosmo Exp $ 2 2 # ----------------------------------------------------------------------- 3 3 # GNUmakefile for persistency library. Gabriele Cosmo, 16/11/96. … … 14 14 CPPFLAGS += -I$(G4INSTALL)/source/global/management/include \ 15 15 -I$(G4INSTALL)/source/global/HEPGeometry/include \ 16 -I$(G4INSTALL)/source/global/HEPNumerics/include \ 16 17 -I$(G4INSTALL)/source/digits_hits/hits/include \ 17 18 -I$(G4INSTALL)/source/digits_hits/digits/include \ … … 24 25 -I$(G4INSTALL)/source/geometry/management/include \ 25 26 -I$(G4INSTALL)/source/geometry/volumes/include \ 26 -I$(G4INSTALL)/source/geometry/ management/include \27 -I$(G4INSTALL)/source/geometry/navigation/include \ 27 28 -I$(G4INSTALL)/source/geometry/solids/CSG/include \ 28 29 -I$(G4INSTALL)/source/geometry/solids/Boolean/include \ -
trunk/source/persistency/gdml/History
r818 r850 1 $Id: History,v 1. 5.2.1 2008/01/16 09:47:42 ztorzsokExp $1 $Id: History,v 1.89 2008/08/22 16:01:02 gcosmo Exp $ 2 2 ------------------------------------------------------------------- 3 3 … … 18 18 ---------------------------------------------------------- 19 19 20 16 January, 08 Z.Torzsok (gdml-V09-01-00) 21 - Fixed vertex referencing for tessellated-solid in G4GDMLSolids. 22 - Fixed entity resolution in G4GDMLBase. 23 - Fixed naming of convention for external files in G4GDMLStructure. 20 22 August 2008 Tatiana Nikitina (gdml-V09-01-14) 21 - G4GDMLReadStructure: added methods ReplicaRead(), AxisRead(), QuantityRead() 22 and introduced corrections in order to read replica volumes conforming to the 23 GDML Schema. Added possibility to read/write replication for Rho and Phi axes. 24 - G4GDMLWriteStructure: introduced corrections in order to write replica 25 volumes conforming to the GDML Schema. 26 27 20 August 2008 Gabriele Cosmo (gdml-V09-01-13) 28 - G4GDMLParser: added argument to Write() for specify if appending or not 29 reference pointer to generated names. Default is TRUE. 30 - G4GDMLRead: implemented filtering of names to remove from entity names 31 appended reference pointer which may have been generated. Simplified 32 name generated for physical-volumes to only append "_PV" to its logical 33 volume name. 34 - Removed wherever applicable additional strings appended to names. 35 36 18 August 2008 Gabriele Cosmo (gdml-V09-01-12) 37 - G4GDMLWriteSolids: fixes in naming convention for solids; added specification 38 of units where missing. Introduced parsing of vertices for tessellated solids 39 to avoid duplication in writing. 40 41 29 July 2008 Tatiana Nikitina 42 - Fixes to parameterisation read and write to match the schema. 43 44 24 July 2008 Tatiana Nikitina 45 - Added to reader the possibility to have a reference to position and rotation 46 for Boolean solids, as it was possible in GDML_2_10_0. 47 48 24 July 2008 Tatiana Nikitina 49 - Fixes in reading/writing G4TwistedTrap shapes. 50 51 22 July 2008 Tatiana Nikitina 52 - Added G4Paraboloid to list of supported solids for reader and writer. 53 54 16 July 2008 Gabriele Cosmo (gdml-V09-01-11) 55 - Renamed internal methods wherever needed to match code policy and having 56 them starting with capital letter. 57 58 15 July 2008 Gabriele Cosmo (gdml-V09-01-10) 59 - Code review, formatting and adoption of canonical form for calls to 60 G4Exception. Usage of std:: namespace for calls to standard mathematical 61 functions. 62 - Added class G4STRead, copy of the original class implemented by Z.Torzsok. 63 - Corrected compilation error on Windows/VC++8 compiler for incorrect 64 signature of method in base class. 65 66 3 July 2008 Gabriele Cosmo (gdml-V09-01-09) 67 - Corrected bugs introduced in last commits for modularization of files; 68 Restored original use of maps. 69 - Corrected syntax for parser writer to (optionally) take a pointer to the 70 top physical-volume instead of the logical volume. 71 72 25 June 2008 Zoltan Torzsok (gdml-V09-01-08) 73 - Units are set according to CLHEP units in G4GDMLEvaluator. 74 75 23 June 2008 Zoltan Torzsok 76 - Optimised string handling. Schema location can be set in the writer. 77 78 20 June 2008 Zoltan Torzsok (gdml-V09-01-07) 79 - Set correct URL for schema for 'noNamespaceSchemaLocation' parameter. 80 81 17 June 2008 Zoltan Torzsok 82 - Added schema validation. 83 - Added schema definition files. 84 85 10 June 2008 Zoltan Torzsok (gdml-V09-01-06) 86 - Modularization can be done either by physvol/depth/mixed. 87 Volume auxiliary information is requested by pointer instead of by name. 88 89 9 June 2008 Zoltan Torzsok 90 - Naming convention can be configured in the writer. 91 92 5 June 2008 Zoltan Torzsok 93 - Module name is optional now. If no name is specified, 94 the logical volume name will be the filename. 95 96 2 June 2008 Zoltan Torzsok (gdml-V09-01-05) 97 - Writer checks if the file to be created does already exist. 98 - Added GetVolume() function. 99 100 29 May 2008 Zoltan Torzsok 101 - Added support for writing modular files. 102 103 28 May 2008 Zoltan Torzsok 104 - Only the referenced materials/elements/isotopes are written out, not the 105 whole material/element/isotope store. 106 - Assigned the name to world physical volume. 107 108 27 May 2008 Zoltan Torzsok 109 - Optimized/simplified writing of structure: no array required for sorting. 110 - Only the referenced solids are written out, not the whole solid store. 111 112 23 May 2008 Zoltan Torzsok 113 - Writer: precision is now considered in case of scale, rotation and position 114 of the physical-volume. DBL_EPSILON is used to filter precision for avoiding 115 unnecessary scaling, rotation or positioning. 116 117 6 May 2008 Zoltan Torzsok (gdml-V09-01-04) 118 - Added a constant limiting the maximum number of reflections/displacements of a single solid 119 120 21 April 2008 Zoltan Torzsok 121 - Divisionvol, replicavol and paramvol are resolved now. 122 123 11 April 2008 Zoltan Torzsok (gdml-V09-01-03) 124 - Referenced solid in volume is resolved in case of displacements/reflections. 125 126 10 April 2008 Zoltan Torzsok 127 - Added text output to console to inform of progress during processing. 128 129 9 April 2008 Zoltan Torzsok 130 - Worked out an algorithm for sorting logical volumes in the writer. 131 132 4 April 2008 Zoltan Torzsok 133 - Modified writing out of volumes to happen in recursive way. 134 Still needs optimization. Does not recompute touched branches! 135 136 1 April 2008 Z.Torzsok 137 - Corrected function names to have all starting with capital letter. 138 139 11 March 2008 Z.Torzsok (gdml-V09-01-02) 140 - Added border surface to reader. 141 - Added skin surface to reader. 142 - Fixed compilation problems on Intel/icc compiler. 143 144 7 March 2008 Z.Torzsok (gdml-V09-01-01) 145 - Material properties added to reader 146 147 20 February 2008 Z.Torzsok 148 - Completed support for parameterised volumes in writer. 149 - Name is added to physvol in reader. 150 151 19 February 2008 Z.Torzsok 152 - Replicavol is simplified and no longer restricted to replication along axes. 153 154 18 February 2008 Z.Torzsok 155 - Added G4GDMLWriteParamvol class implementing the parameterised volumes 156 in the writer. Added box parameterisation and succesfully tested. 157 158 15 February 2008 Z.Torzsok 159 - Division volumes added to writer and succesfully tested. 160 161 14 February 2008 Z.Torzsok 162 - Replica volumes added to writer and succesfully tested. 163 164 13 February 2008 Z.Torzsok 165 - Added getRotationMatrix() function to G4GDMLReadDefine: this function 166 converts rotation angles into a rotation matrix. This wad used in physvol, 167 reflectedSolid and boolean solid. Now this conversion is in one place 168 - Added 'firstrotation' and 'firstposition' to boolean solid. Now the first 169 solid can be transformed too (Boolean solid is succesfully tested). 170 171 11 February 2008 Z.Torzsok 172 - Added matrices to writer. 173 - Exception handling is added to loops (identify infinite loops). 174 175 8 Febryary 2008 Z.Torzsok 176 - Naming of physvol changed to 'ReferencedVolumeName_in_MotherVolumeName'. 177 178 7 February 2008 Z.Torzsok 179 - Added twistedtrap and twistedtubs to writer. 180 181 6 february 2008 Z.Torzsok 182 - Tet, Twistedbox and Twistedtrd added to writer and succesfully tested. 183 184 5 February 2008 Z.Torzsok 185 - Hype, orb and para added to writer. 186 Succesfully tested, except the para. 187 188 1 February 2008 Z.Torzsok 189 - Ellipsoid and elliptical-tube added to writer. 190 191 31 January 2008 Z.Torzsok 192 - Quantities now can be referenced 193 - Naming of physical volumes changed: MotherLogicalName_daughter(index) 194 195 30 January 2008 Z.Torzsok 196 - If there is only one setup defined, name does not matter, that setup 197 will be loaded. 198 - Temperature, pressure and state are now processed in the reader. 199 Added Nist support. 200 201 28 January 2008 Z.Torzsok 202 - Element added to writer. 203 - Polyhedra and torus added to writer. 204 - Now the package is able to read/write the CMS geometry. 205 206 25 January 2008 Z.Torzsok 207 - Bugs fixed in the writer in G4GMLWriteStructure::physvolWrite(): 208 the signs of the rotational angles were incorrect in certain cases 209 (180 degrees, 90 degrees,...). The reflection was incorrect in case 210 of reflecting a subtree. 211 - Now the package is capable of reading and writing back the LHCb 212 geometry correctly. 213 214 23 January 2008 Z.Torzsok 215 - Composite materials added to writer. 216 - Cone and tube added to writer. 217 - Boolean solid (intersection, subtraction, union) added to writer. 218 219 22 January 2008 Z.Torzsok 220 - Extruded solid is added to writer. 221 - Reflected solid is removed from the written GDML files. 222 Scale transformation is used instead. 223 - Optimization to tha case of reading multiple GDML files and writing out 224 into a single GDML file: 225 The mother volume is moved to the end of the list after its daugthers are 226 processed... only when necessary, when new logical volumes come from the 227 daughters! 228 229 21 January 2008 Z.Torzsok 230 - Reflected solid is added to the writer. 231 - Solved problem of reading multiple GDML files and writing out into a single 232 GDML file: 233 if a logical volume (let's say the mother volume) is instantiated, it will 234 be added to the end of list of volumes (G4LogicalVolumeStore). 235 Once this logical volume is instantiated we can add daughters. 236 If a daughter refers to an external file, additional logical volumes will 237 come. These logical volumes will be added to the list as well, AFTER the 238 mother volume. In the mother volume these logical volumes can be referenced 239 ...but these logical volumes are not instantiated yet when we instantiate 240 the mother! That's why we move the mother volume at the end of the list 241 after the daughters are processed. 242 243 18 January 2008 Z.Torzsok 244 - The class hierarchy of the GDML parser/writer is finished: 245 Write <- WriteDefine <- WriteMaterials <- WriteSolids 246 <- WriteSetup <- WriteStructure 247 Parser Read <- ReadDefine <- ReadMaterials <- ReadSolids 248 <- ReadSetup <- ReadParamvol <- ReadStructure. 249 250 16 January 2008 Z.Torzsok 251 - Starting the materials section. 252 253 15 January 2008 Z.Torzsok 254 - Writer implements the setup section too. 255 256 11 January 2008 Z.Torzsok (gdml-V09-01-00) 257 - Reader is now capable of resolving entities. 258 259 08 January 2008 Z.Torzsok 260 - Vertex referencing is fixed in tessellated solid 261 (using the identifier "vertex" according to the schema). 262 263 07 January 2008 Z.Torzsok 264 - Starting to implement the writer. 24 265 25 266 30 November, 07 Z.Torzsok (gdml-V09-00-04) -
trunk/source/persistency/gdml/include/G4GDMLEvaluator.hh
r818 r850 25 25 // 26 26 // 27 // $Id: G4GDMLEvaluator.hh,v 1.1 0 2007/11/28 10:27:18 ztorzsokExp $28 // GEANT4 tag $Name: geant4-09-01-patch-02$27 // $Id: G4GDMLEvaluator.hh,v 1.16 2008/07/16 15:46:33 gcosmo Exp $ 28 // GEANT4 tag $Name: HEAD $ 29 29 // 30 30 // … … 43 43 44 44 #include <CLHEP/Evaluator/Evaluator.h> 45 #include <vector> 45 46 46 #include "G4Types.hh" 47 #include "G4String.hh" 48 #include "G4Box.hh" 47 #include "globals.hh" 49 48 50 class G4GDMLEvaluator { 49 class G4GDMLEvaluator 50 { 51 52 public: 53 54 G4GDMLEvaluator(); 55 56 void DefineConstant(const G4String&, G4double); 57 void DefineVariable(const G4String&, G4double); 58 void DefineMatrix(const G4String&, G4int, std::vector<G4double>); 59 void SetVariable(const G4String&, G4double); 60 G4bool IsVariable(const G4String&) const; 61 G4String SolveBrackets(const G4String&); 62 G4double Evaluate(const G4String&); 63 G4int EvaluateInteger(const G4String&); 64 G4double GetConstant(const G4String&); 65 G4double GetVariable(const G4String&); 66 67 private: 68 51 69 HepTool::Evaluator eval; 52 70 std::vector<G4String> variableList; 53 public:54 G4GDMLEvaluator();55 56 void defineConstant(const G4String&,G4double);57 void defineVariable(const G4String&,G4double);58 void setVariable(const G4String&,G4double);59 void checkVariable(const G4String&);60 61 G4double Evaluate(const G4String&);62 G4int EvaluateInteger(const G4String&);63 71 }; 64 72 -
trunk/source/persistency/gdml/include/G4GDMLParser.hh
r818 r850 25 25 // 26 26 // 27 // $Id: G4GDMLParser.hh,v 1. 10 2007/11/30 11:58:46 ztorzsokExp $28 // GEANT4 tag $Name: geant4-09-01-patch-02$27 // $Id: G4GDMLParser.hh,v 1.53 2008/08/21 12:17:09 gcosmo Exp $ 28 // GEANT4 tag $Name: HEAD $ 29 29 // 30 30 // … … 33 33 // Class description: 34 34 // 35 // GDML main parser. 36 35 37 // History: 36 38 // - Created. Zoltan Torzsok, November 2007 37 39 // ------------------------------------------------------------------------- 38 40 39 41 #ifndef _G4GDMLPARSER_INCLUDED_ 40 42 #define _G4GDMLPARSER_INCLUDED_ 41 43 42 #include "G4GDMLStructure.hh" 44 #include "G4GDMLReadStructure.hh" 45 #include "G4GDMLWriteStructure.hh" 46 #include "G4STRead.hh" 43 47 44 class G4GDMLParser { 45 G4GDMLStructure structure; 46 public: 47 void Read(const G4String& fileName) { structure.Parse(fileName); } 48 G4VPhysicalVolume* GetWorldVolume(const G4String& setupName="Default") { return structure.getTopVolume(setupName); } 48 #define G4GDML_DEFAULT_SCHEMALOCATION G4String("http://service-spi.web.cern.ch/service-spi/app/releases/GDML/GDML_2_10_0/src/GDMLSchema/gdml.xsd") 49 50 class G4GDMLParser 51 { 52 public: // with description 53 54 G4GDMLParser() { xercesc::XMLPlatformUtils::Initialize(); } 55 ~G4GDMLParser() { xercesc::XMLPlatformUtils::Terminate(); } 56 // 57 // Parser constructor & destructor 58 59 inline void Read(const G4String& filename, G4bool Validate=true); 60 // 61 // Imports geometry with world-volume, specified by the GDML filename 62 // in input. Validation against schema is activated by default. 63 64 inline void ReadModule(const G4String& filename, G4bool Validate=true); 65 // 66 // Imports a single GDML module, specified by the GDML filename 67 // in input. Validation against schema is activated by default. 68 69 inline void Write(const G4String& filename, 70 const G4VPhysicalVolume* const pvol = 0, 71 G4bool storeReferences = true, 72 const G4String& SchemaLocation = G4GDML_DEFAULT_SCHEMALOCATION); 73 // 74 // Exports on a GDML file, specified by 'filename' a geometry tree 75 // starting from 'pvol' as top volume. Uniqueness of stored entities 76 // is guaranteed by storing pointer-references by default. 77 // Alternative path for the schema location can be specified; by default 78 // the URL to the GDML web site is used. 79 80 inline G4LogicalVolume* ParseST(const G4String& name, 81 G4Material* medium, 82 G4Material* solid); 83 // 84 // Imports a tessellated geometry stored as STEP-Tools files 85 // 'name.geom' and 'name.tree'. It returns a pointer of a generated 86 // mother volume with 'medium' material associated, including the 87 // imported tessellated geometry with 'solid' material associated. 88 89 // Methods for Reader 90 // 91 inline G4double GetConstant(const G4String& name); 92 inline G4double GetVariable(const G4String& name); 93 inline G4double GetQuantity(const G4String& name); 94 inline G4ThreeVector GetPosition(const G4String& name); 95 inline G4ThreeVector GetRotation(const G4String& name); 96 inline G4ThreeVector GetScale(const G4String& name); 97 inline G4GDMLMatrix GetMatrix(const G4String& name); 98 inline G4LogicalVolume* GetVolume(const G4String& name); 99 inline G4VPhysicalVolume* GetWorldVolume(const G4String& setupName="Default"); 100 inline G4GDMLAuxListType GetVolumeAuxiliaryInformation(const G4LogicalVolume* const logvol); 101 102 // Methods for Writer 103 // 104 inline void AddModule(const G4VPhysicalVolume* const physvol); 105 inline void AddModule(const G4int depth); 106 inline void SetAddPointerToName(G4bool set); 107 108 private: 109 110 G4GDMLReadStructure reader; 111 G4GDMLWriteStructure writer; 112 49 113 }; 50 114 115 #include "G4GDMLParser.icc" 116 51 117 #endif -
trunk/source/persistency/gdml/src/G4GDMLEvaluator.cc
r818 r850 25 25 // 26 26 // 27 // $Id: G4GDMLEvaluator.cc,v 1. 11 2007/11/28 10:27:18 ztorzsokExp $27 // $Id: G4GDMLEvaluator.cc,v 1.20 2008/07/16 15:46:34 gcosmo Exp $ 28 28 // GEANT4 tag $ Name:$ 29 29 // … … 34 34 // -------------------------------------------------------------------- 35 35 36 #include <sstream> 36 37 #include "G4GDMLEvaluator.hh" 37 38 38 G4GDMLEvaluator::G4GDMLEvaluator() {39 39 G4GDMLEvaluator::G4GDMLEvaluator() 40 { 40 41 eval.clear(); 41 42 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 45 void G4GDMLEvaluator::defineConstant(const G4String& name,G4double value) { 46 47 if (eval.findVariable(name)) G4Exception("GDML: Constant or variable '"+name+"' is already defined!"); 48 43 eval.setSystemOfUnits(meter,kilogram,second,ampere,kelvin,mole,candela); 44 } 45 46 void G4GDMLEvaluator::DefineConstant(const G4String& name, G4double value) 47 { 48 if (eval.findVariable(name)) 49 { 50 G4String error_msg = "Redefinition of constant or variable: "+name; 51 G4Exception("G4GDMLEvaluator::DefineConstant()", "InvalidExpression", 52 FatalException, error_msg); 53 } 49 54 eval.setVariable(name.c_str(),value); 50 55 } 51 56 52 void G4GDMLEvaluator::defineVariable(const G4String& name,G4double value) { 53 54 if (eval.findVariable(name)) G4Exception("GDML: Constant or variable '"+name+"' is already defined!"); 55 57 void G4GDMLEvaluator::DefineVariable(const G4String& name,G4double value) 58 { 59 if (eval.findVariable(name)) 60 { 61 G4String error_msg = "Redefinition of constant or variable: "+name; 62 G4Exception("G4GDMLEvaluator::DefineVariable()", "InvalidExpression", 63 FatalException, error_msg); 64 } 56 65 eval.setVariable(name.c_str(),value); 57 66 variableList.push_back(name); 58 67 } 59 68 60 void G4GDMLEvaluator::setVariable(const G4String& name,G4double value) { 61 62 checkVariable(name); 63 69 void G4GDMLEvaluator::DefineMatrix(const G4String& name, 70 G4int coldim, 71 std::vector<G4double> valueList) 72 { 73 const G4int size = valueList.size(); 74 75 if (size == 0) 76 { 77 G4String error_msg = "Matrix '"+name+"' is empty!"; 78 G4Exception("G4GDMLEvaluator::DefineMatrix()", "InvalidSize", 79 FatalException, error_msg); 80 } 81 if (size == 1) 82 { 83 G4String error_msg = "Matrix '" + name 84 + "' has only one element! " 85 + "Define a constant instead!!"; 86 G4Exception("G4GDMLEvaluator::DefineMatrix()", "InvalidSize", 87 FatalException, error_msg); 88 } 89 if (size % coldim != 0) 90 { 91 G4String error_msg = "Matrix '" + name + "' is not filled correctly!"; 92 G4Exception("G4GDMLEvaluator::DefineMatrix()", "InvalidSize", 93 FatalException, error_msg); 94 } 95 96 if ((size == coldim) || (coldim == 1)) // Row- or column matrix 97 { 98 for (G4int i=0;i<size;i++) 99 { 100 std::stringstream MatrixElementNameStream; 101 MatrixElementNameStream << name << "_" << i; 102 DefineConstant(MatrixElementNameStream.str(),valueList[i]); 103 } 104 } 105 else // Normal matrix 106 { 107 const G4int rowdim = size/coldim; 108 109 for (G4int i=0;i<rowdim;i++) 110 { 111 for (G4int j=0;j<coldim;j++) 112 { 113 std::stringstream MatrixElementNameStream; 114 MatrixElementNameStream << name << "_" << i << "_" << j; 115 DefineConstant(MatrixElementNameStream.str(),valueList[coldim*i+j]); 116 } 117 } 118 } 119 } 120 121 void G4GDMLEvaluator::SetVariable(const G4String& name, G4double value) 122 { 123 if (!IsVariable(name)) 124 { 125 G4String error_msg = "Variable '" + name + "' is not defined!"; 126 G4Exception("G4GDMLEvaluator::SetVariable()", "InvalidSetup", 127 FatalException, error_msg); 128 } 64 129 eval.setVariable(name.c_str(),value); 65 130 } 66 131 67 void 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 77 G4double G4GDMLEvaluator::Evaluate(const G4String& expression) { 132 G4bool G4GDMLEvaluator::IsVariable(const G4String& name) const 133 { 134 const size_t variableCount = variableList.size(); 135 136 for (size_t i=0;i<variableCount;i++) 137 { 138 if (variableList[i] == name) { return true; } 139 } 140 141 return false; 142 } 143 144 G4String G4GDMLEvaluator::SolveBrackets(const G4String& in) 145 { 146 const std::string::size_type open = in.find("[",0); 147 const std::string::size_type close = in.find("]",0); 148 149 if (open==close) { return in; } 150 151 if (open>close) 152 { 153 G4String error_msg = "Bracket mismatch: " + in; 154 G4Exception("G4GDMLEvaluator::SolveBrackets()", "InvalidExpression", 155 FatalException, error_msg); 156 } 157 158 std::string::size_type begin = open; 159 std::string::size_type end = 0; 160 161 std::string out; 162 out.append(in,0,open); 163 164 do 165 { 166 end = in.find(",",begin+1); 167 if (end==std::string::npos) { end = close; } 168 169 std::stringstream indexStream; 170 indexStream << "_" << EvaluateInteger(in.substr(begin+1,end-begin-1)); 171 172 out.append(indexStream.str()); 173 174 begin = end; 175 176 } while (end<close); 177 178 return out; 179 } 180 181 G4double G4GDMLEvaluator::Evaluate(const G4String& in) 182 { 183 G4String expression = SolveBrackets(in); 78 184 79 185 G4double value = 0.0; 80 186 81 if (!expression.empty()) {82 187 if (!expression.empty()) 188 { 83 189 value = eval.evaluate(expression.c_str()); 84 190 85 if (eval.status() != HepTool::Evaluator::OK) {86 191 if (eval.status() != HepTool::Evaluator::OK) 192 { 87 193 eval.print_error(); 88 G4Exception("Error in evaluator!"); 194 G4String error_msg = "Error in expression: " + expression; 195 G4Exception("G4GDMLEvaluator::Evaluate()", "InvalidExpression", 196 FatalException, error_msg); 89 197 } 90 198 } 91 92 199 return value; 93 200 } 94 201 95 G4int G4GDMLEvaluator::EvaluateInteger(const G4String& expression) { 202 G4int G4GDMLEvaluator::EvaluateInteger(const G4String& expression) 203 { 204 // This function is for evaluating integer expressions, 205 // like loop variables and matrix indices. 206 // Complains if the evaluated expression has a fractional 207 // part different from zero 96 208 97 209 G4double value = Evaluate(expression); … … 100 212 G4double frac = value - (G4double)whole; 101 213 102 if (frac != 0.0) G4Exception("GDML: Expression '"+expression+"' is expected to have an integer value!"); 103 214 if (frac != 0.0) 215 { 216 G4String error_msg = "Expression '" + expression 217 + "' is expected to have an integer value!"; 218 G4Exception("G4GDMLEvaluator::EvaluateInteger()", "InvalidExpression", 219 FatalException, error_msg); 220 } 104 221 return whole; 105 222 } 223 224 G4double G4GDMLEvaluator::GetConstant(const G4String& name) 225 { 226 if (IsVariable(name)) 227 { 228 G4String error_msg = "Constant '" + name 229 + "' is not defined! It is a variable!"; 230 G4Exception("G4GDMLEvaluator::GetConstant()", "InvalidSetup", 231 FatalException, error_msg); 232 } 233 if (!eval.findVariable(name)) 234 { 235 G4String error_msg = "Constant '" + name + "' is not defined!"; 236 G4Exception("G4GDMLEvaluator::GetConstant()", "InvalidSetup", 237 FatalException, error_msg); 238 } 239 return Evaluate(name); 240 } 241 242 G4double G4GDMLEvaluator::GetVariable(const G4String& name) 243 { 244 if (!IsVariable(name)) 245 { 246 G4String error_msg = "Variable '" + name + "' is not a defined!"; 247 G4Exception("G4GDMLEvaluator::GetVariable()", "InvalidSetup", 248 FatalException, error_msg); 249 } 250 return Evaluate(name); 251 }
Note:
See TracChangeset
for help on using the changeset viewer.
