Logo ROOT   6.16/01
Reference Guide
TGDMLParse.h
Go to the documentation of this file.
1/* @(#)root/gdml:$Id$ */
2// Authors: Ben Lloyd 09/11/06
3
4/*************************************************************************
5 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TGDMLParse
13#define ROOT_TGDMLParse
14
15#include "TFormula.h"
16#include "TXMLEngine.h"
17#include "TGeoMatrix.h"
18#include "TGeoVolume.h"
19
20#include <map>
21#include <vector>
22#include <iostream>
23
24/*************************************************************************
25 * TGDMLRefl - helper class for the import of GDML to ROOT. *
26 *************************************************************************/
27
28class TGDMLRefl : public TObject {
29public:
30
32
33 fNameS = "";
34 fSolid = "";
35 fMatrix = 0;
36 }
37
38 virtual ~TGDMLRefl() {}
39
40 TGDMLRefl(const char* name, const char* solid, TGeoMatrix* matrix);
42
43private:
44
45 const char* fNameS; //!reflected solid name
46 const char* fSolid; //!solid name being reflected
47 TGeoMatrix *fMatrix; //!matrix of reflected solid
48
49 ClassDef(TGDMLRefl, 0) //helper class used for the storage of reflected solids
50};
51
52/*************************************************************************
53 * TGDMLParse - base class for the import of GDML to ROOT. *
54 *************************************************************************/
55
56class TGDMLBaseTGDMMapHelper : public std::map<std::string, const void *> {
57};
58
59//map's [] operator returns reference.
60//to avoid ugly UB casts like static_cast<SomeType * &>(voidPtrLValue)
61//I have this helper class.
62template<typename T>
63
65private:
66 TGDMLBaseTGDMMapHelper::iterator fPosInMap;
67
68public:
69 TGDMAssignmentHelper(TGDMLBaseTGDMMapHelper &baseMap, const std::string &key) {
70 baseMap[key];//if we do not have this key-value pair before, insert it now (with zero for pointer).
71 //find iterator for this key now :)
72 fPosInMap = baseMap.find(key);
73 }
74
75 operator T * ()const {
76 return (T*)fPosInMap->second;//const_cast<T*>(static_cast<const T *>(fPosInMap->second));
77 }
78
80 fPosInMap->second = ptr;
81 return *this;
82 }
83};
84
85template<class T>
87public:
88 TGDMAssignmentHelper<T> operator [](const std::string &key) {
89 return TGDMAssignmentHelper<T>(*this, key);
90 }
91};
92
93class TGDMLParse : public TObject {
94public:
95
97 TGeoVolume* fWorld; //top volume of geometry
98 int fVolID; //volume ID, incremented as assigned.
99 int fFILENO; //Holds which level of file the parser is at
100 TXMLEngine* fFileEngine[20]; //array of dom object pointers
101 const char* fStartFile; //name of originating file
102 const char* fCurrentFile; //current file name being parsed
103 std::string fDefault_lunit = "mm";
104 std::string fDefault_aunit = "rad";
105
106 TGDMLParse();
107 virtual ~TGDMLParse() {}
108
109 static TGeoVolume* StartGDML(const char* filename) {
110 TGDMLParse* parser = new TGDMLParse;
111 TGeoVolume* world = parser->GDMLReadFile(filename);
112 return world;
113 }
114
115 TGeoVolume* GDMLReadFile(const char* filename = "test.gdml");
116
117private:
118
119 const char* ParseGDML(TXMLEngine* gdml, XMLNodePointer_t node) ;
120 TString GetScale(const char* unit);
121 double GetScaleVal(const char* unit);
122 double Evaluate(const char* evalline);
123 const char* NameShort(const char* name);
124 double Value(const char *svalue) const;
125
126 //'define' section
132
133 //'materials' section
135 XMLNodePointer_t EleProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLNodePointer_t parentn, Bool_t hasIsotopes, Bool_t hasIsotopesExtended);
136 //XMLNodePointer_t EleProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLNodePointer_t parentn);
138 //XMLNodePointer_t MatProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
139
140 //'solids' section
162 XMLNodePointer_t Ellipsoid(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr); //not really implemented: just approximation to a TGeoBBox
163
164 //'structure' section
168 Int_t SetAxis(const char* axisString); //Set Axis for Division
169
170 //'setup' section
172
181
186 typedef std::map<std::string, std::string> ReflectionsMap;
187 typedef std::map<std::string, std::string> ReflVolMap;
188 typedef std::map<std::string, double> FracMap;
189 typedef std::map<std::string, double> ConstMap;
190
191 PosMap fposmap; //!Map containing position names and the TGeoTranslation for it
192 RotMap frotmap; //!Map containing rotation names and the TGeoRotation for it
193 SclMap fsclmap; //!Map containing scale names and the TGeoScale for it
194 IsoMap fisomap; //!Map containing isotope names and the TGeoIsotope for it
195 EleMap felemap; //!Map containing element names and the TGeoElement for it
196 MatMap fmatmap; //!Map containing material names and the TGeoMaterial for it
197 MedMap fmedmap; //!Map containing medium names and the TGeoMedium for it
198 MixMap fmixmap; //!Map containing mixture names and the TGeoMixture for it
199 SolMap fsolmap; //!Map containing solid names and the TGeoShape for it
200 VolMap fvolmap; //!Map containing volume names and the TGeoVolume for it
201 ReflectionsMap freflectmap; //!Map containing reflection names and the Solid name ir references to
202 ReflSolidMap freflsolidmap; //!Map containing reflection names and the TGDMLRefl for it - containing refl matrix
203 ReflVolMap freflvolmap; //!Map containing reflected volume names and the solid ref for it
204 FileMap ffilemap; //!Map containing files parsed during entire parsing, with their world volume name
205 ConstMap fconsts; //!Map containing values of constants declared in the file
206
207 ClassDef(TGDMLParse, 0) //imports GDML using DOM and binds it to ROOT
208};
209
210#endif
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
#define ClassDef(name, id)
Definition: Rtypes.h:324
void * XMLNodePointer_t
Definition: TXMLEngine.h:17
void * XMLAttrPointer_t
Definition: TXMLEngine.h:19
TGDMLBaseTGDMMapHelper::iterator fPosInMap
Definition: TGDMLParse.h:66
TGDMAssignmentHelper & operator=(const T *ptr)
Definition: TGDMLParse.h:79
TGDMAssignmentHelper(TGDMLBaseTGDMMapHelper &baseMap, const std::string &key)
Definition: TGDMLParse.h:69
This class contains the implementation of the GDML parser associated to all the supported GDML elemen...
Definition: TGDMLParse.h:93
XMLNodePointer_t Ellipsoid(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, an ellipsoid may be declared.
double Evaluate(const char *evalline)
Takes a string containing a mathematical expression and returns the value of the expression.
Definition: TGDMLParse.cxx:382
TGeoVolume * GDMLReadFile(const char *filename="test.gdml")
Creates the new instance of the XMLEngine called 'gdml', using the filename >> then parses the file a...
Definition: TGDMLParse.cxx:152
XMLNodePointer_t Reflection(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Reflected Solid may be declared when the ReflectedSolid key...
XMLNodePointer_t TopProcess(TXMLEngine *gdml, XMLNodePointer_t node)
In the setup section of the GDML file, the top volume need to be declared.
std::map< std::string, std::string > ReflVolMap
Definition: TGDMLParse.h:187
std::map< std::string, double > ConstMap
Definition: TGDMLParse.h:189
ReflSolidMap freflsolidmap
Map containing reflection names and the Solid name ir references to.
Definition: TGDMLParse.h:202
const char * ParseGDML(TXMLEngine *gdml, XMLNodePointer_t node)
This function recursively moves thru the DOM tree of the GDML file.
Definition: TGDMLParse.cxx:189
XMLNodePointer_t SclProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the define section of the GDML file, rotations can be declared.
Definition: TGDMLParse.cxx:772
TGDMMapHelper< const char > FileMap
Definition: TGDMLParse.h:185
TGDMLParse()
Constructor.
Definition: TGDMLParse.cxx:122
virtual ~TGDMLParse()
Definition: TGDMLParse.h:107
XMLNodePointer_t Trd(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Trd may be declared.
const char * fCurrentFile
Definition: TGDMLParse.h:102
std::map< std::string, std::string > ReflectionsMap
Definition: TGDMLParse.h:186
const char * NameShort(const char *name)
This function looks thru a string for the chars '0x' next to each other, when it finds this,...
Definition: TGDMLParse.cxx:417
XMLNodePointer_t Orb(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, an Orb may be declared.
FileMap ffilemap
Map containing reflected volume names and the solid ref for it.
Definition: TGDMLParse.h:204
XMLNodePointer_t Hype(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Hype may be declared.
TGDMMapHelper< TGeoMaterial > MatMap
Definition: TGDMLParse.h:178
TGDMMapHelper< TGeoVolume > VolMap
Definition: TGDMLParse.h:183
VolMap fvolmap
Map containing solid names and the TGeoShape for it.
Definition: TGDMLParse.h:200
double GetScaleVal(const char *unit)
Throughout the GDML file, a unit can de specified.
Definition: TGDMLParse.cxx:544
std::string fDefault_lunit
Definition: TGDMLParse.h:103
XMLNodePointer_t BooSolid(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr, int num)
In the solid section of the GDML file, boolean solids can be declared.
XMLNodePointer_t Para(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Para may be declared.
XMLNodePointer_t Arb8(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, an Arb8 may be declared.
RotMap frotmap
Map containing position names and the TGeoTranslation for it.
Definition: TGDMLParse.h:192
XMLNodePointer_t PosProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the define section of the GDML file, positions can be declared.
Definition: TGDMLParse.cxx:661
ReflVolMap freflvolmap
Map containing reflection names and the TGDMLRefl for it - containing refl matrix.
Definition: TGDMLParse.h:203
XMLNodePointer_t Sphere(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Sphere may be declared.
TString fWorldName
Definition: TGDMLParse.h:96
ReflectionsMap freflectmap
Map containing volume names and the TGeoVolume for it.
Definition: TGDMLParse.h:201
int fFILENO
Definition: TGDMLParse.h:99
XMLNodePointer_t Trap(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Trap may be declared.
TGeoVolume * fWorld
Definition: TGDMLParse.h:97
std::map< std::string, double > FracMap
Definition: TGDMLParse.h:188
XMLNodePointer_t EleProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLNodePointer_t parentn, Bool_t hasIsotopes, Bool_t hasIsotopesExtended)
When the element keyword is found, this function is called, and the name and values of the element ar...
Definition: TGDMLParse.cxx:888
XMLNodePointer_t Polyhedra(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Polyhedra may be declared.
XMLNodePointer_t Cone(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a cone may be declared.
XMLNodePointer_t ElCone(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, an elliptical cone may be declared.
TGDMMapHelper< TGeoElement > EleMap
Definition: TGDMLParse.h:176
MatMap fmatmap
Map containing element names and the TGeoElement for it.
Definition: TGDMLParse.h:196
TGDMMapHelper< TGeoMixture > MixMap
Definition: TGDMLParse.h:180
SclMap fsclmap
Map containing rotation names and the TGeoRotation for it.
Definition: TGDMLParse.h:193
IsoMap fisomap
Map containing scale names and the TGeoScale for it.
Definition: TGDMLParse.h:194
XMLNodePointer_t IsoProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLNodePointer_t parentn)
In the material section of the GDML file, an isotope may be declared.
Definition: TGDMLParse.cxx:816
double Value(const char *svalue) const
Convert number in string format to double value.
Definition: TGDMLParse.cxx:584
XMLNodePointer_t TwistTrap(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a TwistTrap may be declared.
MedMap fmedmap
Map containing material names and the TGeoMaterial for it.
Definition: TGDMLParse.h:197
static TGeoVolume * StartGDML(const char *filename)
Definition: TGDMLParse.h:109
TGDMMapHelper< TGeoShape > SolMap
Definition: TGDMLParse.h:182
XMLNodePointer_t Paraboloid(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Paraboloid may be declared.
Int_t SetAxis(const char *axisString)
When using the 'divide' process in the geometry this function sets the variable 'axis' depending on w...
Definition: TGDMLParse.cxx:392
const char * fStartFile
Definition: TGDMLParse.h:101
ConstMap fconsts
Map containing files parsed during entire parsing, with their world volume name.
Definition: TGDMLParse.h:205
std::string fDefault_aunit
Definition: TGDMLParse.h:104
XMLNodePointer_t QuantityProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the define section of the GDML file, quantities can be declared.
Definition: TGDMLParse.cxx:464
TGDMMapHelper< TGeoTranslation > PosMap
Definition: TGDMLParse.h:173
XMLNodePointer_t Polycone(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Polycone may be declared.
XMLNodePointer_t Box(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a box may be declared.
SolMap fsolmap
Map containing mixture names and the TGeoMixture for it.
Definition: TGDMLParse.h:199
EleMap felemap
Map containing isotope names and the TGeoIsotope for it.
Definition: TGDMLParse.h:195
XMLNodePointer_t Tube(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Tube may be declared.
TString GetScale(const char *unit)
Throughout the GDML file, a unit can de specified.
Definition: TGDMLParse.cxx:498
XMLNodePointer_t AssProcess(TXMLEngine *gdml, XMLNodePointer_t node)
In the structure section of the GDML file, assembly volumes can be declared.
PosMap fposmap
Definition: TGDMLParse.h:191
TXMLEngine * fFileEngine[20]
Definition: TGDMLParse.h:100
XMLNodePointer_t RotProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the define section of the GDML file, rotations can be declared.
Definition: TGDMLParse.cxx:714
TGDMMapHelper< TGeoMedium > MedMap
Definition: TGDMLParse.h:179
TGDMMapHelper< TGeoIsotope > IsoMap
Definition: TGDMLParse.h:177
XMLNodePointer_t Torus(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Torus may be declared.
TGDMMapHelper< TGeoScale > SclMap
Definition: TGDMLParse.h:175
XMLNodePointer_t ConProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the define section of the GDML file, constants can be declared.
Definition: TGDMLParse.cxx:432
XMLNodePointer_t VolProcess(TXMLEngine *gdml, XMLNodePointer_t node)
In the structure section of the GDML file, volumes can be declared.
XMLNodePointer_t ElTube(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a ElTube may be declared.
XMLNodePointer_t Xtru(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, an Xtru may be declared.
XMLNodePointer_t MatProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr, int z)
In the materials section of the GDML file, materials can be declared.
TGDMMapHelper< TGDMLRefl > ReflSolidMap
Definition: TGDMLParse.h:184
XMLNodePointer_t CutTube(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Cut Tube may be declared.
int fVolID
Definition: TGDMLParse.h:98
TGDMMapHelper< TGeoRotation > RotMap
Definition: TGDMLParse.h:174
MixMap fmixmap
Map containing medium names and the TGeoMedium for it.
Definition: TGDMLParse.h:198
XMLNodePointer_t UsrProcess(TXMLEngine *gdml, XMLNodePointer_t node)
User data to be processed.
This class is a helper class for TGDMLParse.
Definition: TGDMLParse.h:28
virtual ~TGDMLRefl()
Definition: TGDMLParse.h:38
const char * fNameS
Definition: TGDMLParse.h:45
TGeoMatrix * fMatrix
solid name being reflected
Definition: TGDMLParse.h:47
TGeoMatrix * GetMatrix()
This accessor method returns the matrix.
const char * fSolid
reflected solid name
Definition: TGDMLParse.h:46
TGDMAssignmentHelper< T > operator[](const std::string &key)
Definition: TGDMLParse.h:88
Geometrical transformation package.
Definition: TGeoMatrix.h:41
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition: TGeoVolume.h:53
Mother of all ROOT objects.
Definition: TObject.h:37
Basic string class.
Definition: TString.h:131
double T(double x)
Definition: ChebyshevPol.h:34