Ignore:
Timestamp:
Sep 10, 2008, 5:40:37 PM (17 years ago)
Author:
garnier
Message:

geant4.8.2 beta

Location:
trunk/source/persistency/gdml
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/persistency/gdml/GNUmakefile

    r818 r850  
    1 # $Id: GNUmakefile,v 1.6 2007/12/11 15:00:49 gcosmo Exp $
     1# $Id: GNUmakefile,v 1.10 2008/07/02 14:15:16 gcosmo Exp $
    22# -----------------------------------------------------------------------
    33# GNUmakefile for persistency library.  Gabriele Cosmo, 16/11/96.
     
    1414CPPFLAGS += -I$(G4INSTALL)/source/global/management/include \
    1515            -I$(G4INSTALL)/source/global/HEPGeometry/include \
     16            -I$(G4INSTALL)/source/global/HEPNumerics/include \
    1617            -I$(G4INSTALL)/source/digits_hits/hits/include \
    1718            -I$(G4INSTALL)/source/digits_hits/digits/include \
     
    2425            -I$(G4INSTALL)/source/geometry/management/include \
    2526            -I$(G4INSTALL)/source/geometry/volumes/include \
    26             -I$(G4INSTALL)/source/geometry/management/include \
     27            -I$(G4INSTALL)/source/geometry/navigation/include \
    2728            -I$(G4INSTALL)/source/geometry/solids/CSG/include \
    2829            -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 ztorzsok Exp $
     1$Id: History,v 1.89 2008/08/22 16:01:02 gcosmo Exp $
    22-------------------------------------------------------------------
    33
     
    1818     ----------------------------------------------------------
    1919
    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.
     2022 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
     2720 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
     3618 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
     4129 July 2008 Tatiana Nikitina
     42- Fixes to parameterisation read and write to match the schema.
     43
     4424 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
     4824 July 2008 Tatiana Nikitina
     49- Fixes in reading/writing G4TwistedTrap shapes.
     50 
     5122 July 2008 Tatiana Nikitina
     52- Added G4Paraboloid to list of supported solids for reader and writer.
     53
     5416 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
     5815 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
     663 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
     7225 June 2008 Zoltan Torzsok (gdml-V09-01-08)
     73- Units are set according to CLHEP units in G4GDMLEvaluator.
     74
     7523 June 2008 Zoltan Torzsok
     76- Optimised string handling. Schema location can be set in the writer.
     77
     7820 June 2008 Zoltan Torzsok (gdml-V09-01-07)
     79- Set correct URL for schema for 'noNamespaceSchemaLocation' parameter.
     80
     8117 June 2008 Zoltan Torzsok
     82- Added schema validation.
     83- Added schema definition files.
     84
     8510 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
     899 June 2008 Zoltan Torzsok
     90- Naming convention can be configured in the writer.
     91
     925 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
     962 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
     10029 May 2008 Zoltan Torzsok
     101- Added support for writing modular files.
     102
     10328 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
     10827 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
     11223 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
     1176 May 2008 Zoltan Torzsok (gdml-V09-01-04)
     118- Added a constant limiting the maximum number of reflections/displacements of a single solid
     119
     12021 April 2008 Zoltan Torzsok
     121- Divisionvol, replicavol and paramvol are resolved now.
     122
     12311 April 2008 Zoltan Torzsok (gdml-V09-01-03)
     124- Referenced solid in volume is resolved in case of displacements/reflections.
     125
     12610 April 2008 Zoltan Torzsok
     127- Added text output to console to inform of progress during processing.
     128
     1299 April 2008 Zoltan Torzsok
     130- Worked out an algorithm for sorting logical volumes in the writer.
     131
     1324 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
     1361 April 2008 Z.Torzsok
     137- Corrected function names to have all starting with capital letter.
     138
     13911 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
     1447 March 2008 Z.Torzsok (gdml-V09-01-01)
     145- Material properties added to reader
     146
     14720 February 2008 Z.Torzsok
     148- Completed support for parameterised volumes in writer.
     149- Name is added to physvol in reader.
     150
     15119 February 2008 Z.Torzsok
     152- Replicavol is simplified and no longer restricted to replication along axes.
     153
     15418 February 2008 Z.Torzsok
     155- Added G4GDMLWriteParamvol class implementing the parameterised volumes
     156  in the writer. Added box parameterisation and succesfully tested.
     157
     15815 February 2008 Z.Torzsok
     159- Division volumes added to writer and succesfully tested.
     160
     16114 February 2008 Z.Torzsok
     162- Replica volumes added to writer and succesfully tested.
     163
     16413 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
     17111 February 2008 Z.Torzsok
     172- Added matrices to writer.
     173- Exception handling is added to loops (identify infinite loops).
     174
     1758 Febryary 2008 Z.Torzsok
     176- Naming of physvol changed to 'ReferencedVolumeName_in_MotherVolumeName'.
     177
     1787 February 2008 Z.Torzsok
     179- Added twistedtrap and twistedtubs to writer.
     180
     1816 february 2008 Z.Torzsok
     182- Tet, Twistedbox and Twistedtrd added to writer and succesfully tested.
     183
     1845 February 2008 Z.Torzsok
     185- Hype, orb and para added to writer.
     186  Succesfully tested, except the para.
     187
     1881 February 2008 Z.Torzsok
     189- Ellipsoid and elliptical-tube added to writer.
     190
     19131 January 2008 Z.Torzsok
     192- Quantities now can be referenced
     193- Naming of physical volumes changed: MotherLogicalName_daughter(index)
     194
     19530 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
     20128 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
     20625 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
     21423 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
     21922 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
     22921 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 
     24318 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
     25016 January 2008 Z.Torzsok
     251- Starting the materials section.
     252
     25315 January 2008 Z.Torzsok
     254- Writer implements the setup section too.
     255
     25611 January 2008 Z.Torzsok (gdml-V09-01-00)
     257- Reader is now capable of resolving entities.
     258
     25908 January 2008 Z.Torzsok
     260- Vertex referencing is fixed in tessellated solid
     261  (using the identifier "vertex" according to the schema).
     262
     26307 January 2008 Z.Torzsok
     264- Starting to implement the writer.
    24265
    2526630 November, 07  Z.Torzsok (gdml-V09-00-04)
  • trunk/source/persistency/gdml/include/G4GDMLEvaluator.hh

    r818 r850  
    2525//
    2626//
    27 // $Id: G4GDMLEvaluator.hh,v 1.10 2007/11/28 10:27:18 ztorzsok Exp $
    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 $
    2929//
    3030//
     
    4343
    4444#include <CLHEP/Evaluator/Evaluator.h>
     45#include <vector>
    4546
    46 #include "G4Types.hh"
    47 #include "G4String.hh"
    48 #include "G4Box.hh"
     47#include "globals.hh"
    4948
    50 class G4GDMLEvaluator {
     49class 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
    5169   HepTool::Evaluator eval;
    5270   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&);
    6371};
    6472
  • trunk/source/persistency/gdml/include/G4GDMLParser.hh

    r818 r850  
    2525//
    2626//
    27 // $Id: G4GDMLParser.hh,v 1.10 2007/11/30 11:58:46 ztorzsok Exp $
    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 $
    2929//
    3030//
     
    3333// Class description:
    3434//
     35// GDML main parser.
     36
    3537// History:
    3638// - Created.                                  Zoltan Torzsok, November 2007
    3739// -------------------------------------------------------------------------
    38 
     40 
    3941#ifndef _G4GDMLPARSER_INCLUDED_
    4042#define _G4GDMLPARSER_INCLUDED_
    4143
    42 #include "G4GDMLStructure.hh"
     44#include "G4GDMLReadStructure.hh"
     45#include "G4GDMLWriteStructure.hh"
     46#include "G4STRead.hh"
    4347
    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
     50class 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
    49113};
    50114
     115#include "G4GDMLParser.icc"
     116
    51117#endif
  • trunk/source/persistency/gdml/src/G4GDMLEvaluator.cc

    r818 r850  
    2525//
    2626//
    27 // $Id: G4GDMLEvaluator.cc,v 1.11 2007/11/28 10:27:18 ztorzsok Exp $
     27// $Id: G4GDMLEvaluator.cc,v 1.20 2008/07/16 15:46:34 gcosmo Exp $
    2828// GEANT4 tag $ Name:$
    2929//
     
    3434// --------------------------------------------------------------------
    3535
     36#include <sstream>
    3637#include "G4GDMLEvaluator.hh"
    3738
    38 G4GDMLEvaluator::G4GDMLEvaluator() {
    39 
     39G4GDMLEvaluator::G4GDMLEvaluator()
     40{
    4041   eval.clear();
    4142   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
     46void 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   }
    4954   eval.setVariable(name.c_str(),value);
    5055}
    5156
    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 
     57void 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   }
    5665   eval.setVariable(name.c_str(),value);
    5766   variableList.push_back(name);
    5867}
    5968
    60 void G4GDMLEvaluator::setVariable(const G4String& name,G4double value) {
    61 
    62    checkVariable(name);
    63 
     69void 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
     121void 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   }
    64129   eval.setVariable(name.c_str(),value);
    65130}
    66131
    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) {
     132G4bool 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
     144G4String 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
     181G4double G4GDMLEvaluator::Evaluate(const G4String& in)
     182{
     183   G4String expression = SolveBrackets(in);
    78184
    79185   G4double value = 0.0;
    80186
    81    if (!expression.empty()) {
    82    
     187   if (!expression.empty())
     188   {
    83189      value = eval.evaluate(expression.c_str());
    84190
    85       if (eval.status() != HepTool::Evaluator::OK) {
    86 
     191      if (eval.status() != HepTool::Evaluator::OK)
     192      {
    87193         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);
    89197      }
    90198   }
    91    
    92199   return value;
    93200}
    94201
    95 G4int G4GDMLEvaluator::EvaluateInteger(const G4String& expression) {
     202G4int 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
    96208
    97209   G4double value = Evaluate(expression);
     
    100212   G4double frac = value - (G4double)whole;
    101213
    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   }
    104221   return whole;
    105222}
     223
     224G4double 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
     242G4double 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.