Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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#include "TGeoElement.h"
20
21#include <map>
22#include <iostream>
23
24class TGDMLMatrix;
25
26/*************************************************************************
27 * TGDMLRefl - helper class for the import of GDML to ROOT. *
28 *************************************************************************/
29
30class TGDMLRefl : public TObject {
31public:
33 {
34
35 fNameS = "";
36 fSolid = "";
37 fMatrix = nullptr;
38 }
39
40 ~TGDMLRefl() override {}
41
42 TGDMLRefl(const char *name, const char *solid, TGeoMatrix *matrix);
44
45private:
46 const char *fNameS; //! reflected solid name
47 const char *fSolid; //! solid name being reflected
48 TGeoMatrix *fMatrix; //! matrix of reflected solid
49
50 ClassDefOverride(TGDMLRefl, 0) // helper class used for the storage of reflected solids
51};
52
53/*************************************************************************
54 * TGDMLParse - base class for the import of GDML to ROOT. *
55 *************************************************************************/
56
57class TGDMLBaseTGDMMapHelper : public std::map<std::string, const void *> {
58};
59
60// map's [] operator returns reference.
61// to avoid ugly UB casts like static_cast<SomeType * &>(voidPtrLValue)
62// I have this helper class.
63template <typename T>
64
66private:
67 TGDMLBaseTGDMMapHelper::iterator fPosInMap;
68
69public:
70 TGDMAssignmentHelper(TGDMLBaseTGDMMapHelper &baseMap, const std::string &key)
71 {
72 baseMap[key]; // if we do not have this key-value pair before, insert it now (with zero for pointer).
73 // find iterator for this key now :)
74 fPosInMap = baseMap.find(key);
75 }
76
77 operator T *() const
78 {
79 return (T *)fPosInMap->second; // const_cast<T*>(static_cast<const T *>(fPosInMap->second));
80 }
81
83 {
84 fPosInMap->second = ptr;
85 return *this;
86 }
87};
88
89template <class T>
91public:
92 TGDMAssignmentHelper<T> operator[](const std::string &key) { return TGDMAssignmentHelper<T>(*this, key); }
93};
94
95class TGDMLParse : public TObject {
96public:
98 TGeoVolume *fWorld; // top volume of geometry
99 int fVolID; // volume ID, incremented as assigned.
100 int fFILENO; // Holds which level of file the parser is at
101 int fNunitless{0}; // Number of entities defined unitless
102 TXMLEngine *fFileEngine[20]; // array of dom object pointers
103 const char *fStartFile; // name of originating file
104 const char *fCurrentFile; // current file name being parsed
105 std::string fDefault_lunit = "mm";
106 std::string fDefault_aunit = "rad";
107
108 TGDMLParse();
109 ~TGDMLParse() override {}
110
111 static TGeoVolume *StartGDML(const char *filename)
112 {
113 TGDMLParse *parser = new TGDMLParse;
114 TGeoVolume *world = parser->GDMLReadFile(filename);
115 return world;
116 }
117
118 TGeoVolume *GDMLReadFile(const char *filename = "test.gdml");
119
120private:
121 const char *ParseGDML(TXMLEngine *gdml, XMLNodePointer_t node);
122 TString GetScale(const char *unit);
123 double GetScaleVal(const char *unit);
124 double Evaluate(const char *evalline);
125 const char *NameShort(const char *name);
126 double Value(const char *svalue) const;
127 void DefineConstants();
128
129 //'define' section
136
137 //'materials' section
140 Bool_t hasIsotopesExtended);
142
143 //'solids' section
169
170 //'structure' section
176 Int_t SetAxis(const char *axisString); // Set Axis for Division
177
178 //'setup' section
180
181 // Find defined objects by name
182 TGeoTranslation *GetPosition(const char *name);
183 TGeoRotation *GetRotation(const char *name);
184 TGeoScale *GetScaleObj(const char *name);
185 TGeoShape *GetSolid(const char *name);
186 TGeoVolume *GetVolume(const char *name);
187
196
203 typedef std::map<std::string, std::string> ReflectionsMap;
204 typedef std::map<std::string, std::string> ReflVolMap;
205 typedef std::map<std::string, double> FracMap;
206 typedef std::map<std::string, double> ConstMap;
207
208 PosMap fposmap; //! Map containing position names and the TGeoTranslation for it
209 RotMap frotmap; //! Map containing rotation names and the TGeoRotation for it
210 SclMap fsclmap; //! Map containing scale names and the TGeoScale for it
211 IsoMap fisomap; //! Map containing isotope names and the TGeoIsotope for it
212 EleMap felemap; //! Map containing element names and the TGeoElement for it
213 MatMap fmatmap; //! Map containing material names and the TGeoMaterial for it
214 MedMap fmedmap; //! Map containing medium names and the TGeoMedium for it
215 MixMap fmixmap; //! Map containing mixture names and the TGeoMixture for it
216 SolMap fsolmap; //! Map containing solid names and the TGeoShape for it
217 VolMap fvolmap; //! Map containing volume names and the TGeoVolume for it
218 PvolMap fpvolmap; //! Map containing placed volume names and the TGeoNode for it
219 ReflectionsMap freflectmap; //! Map containing reflection names and the Solid name ir references to
220 ReflSolidMap freflsolidmap; //! Map containing reflection names and the TGDMLRefl for it - containing refl matrix
221 ReflVolMap freflvolmap; //! Map containing reflected volume names and the solid ref for it
222 FileMap ffilemap; //! Map containing files parsed during entire parsing, with their world volume name
223 ConstMap fconsts; //! Map containing values of constants declared in the file
224 MatrixMap fmatrices; //! Map containing matrices defined in the GDML file
225
226 ClassDefOverride(TGDMLParse, 0) // imports GDML using DOM and binds it to ROOT
227};
228
229#endif
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
char name[80]
Definition TGX11.cxx:110
void * XMLNodePointer_t
Definition TXMLEngine.h:17
void * XMLAttrPointer_t
Definition TXMLEngine.h:19
TGDMLBaseTGDMMapHelper::iterator fPosInMap
Definition TGDMLParse.h:67
TGDMAssignmentHelper & operator=(const T *ptr)
Definition TGDMLParse.h:82
TGDMAssignmentHelper(TGDMLBaseTGDMMapHelper &baseMap, const std::string &key)
Definition TGDMLParse.h:70
This class is used in the process of reading and writing the GDML "matrix" tag.
Definition TGDMLMatrix.h:33
This class contains the implementation of the GDML parser associated to all the supported GDML elemen...
Definition TGDMLParse.h:95
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.
TGeoVolume * GDMLReadFile(const char *filename="test.gdml")
Creates the new instance of the XMLEngine called 'gdml', using the filename >> then parses the file a...
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.
TGeoVolume * GetVolume(const char *name)
TGeoScale * GetScaleObj(const char *name)
std::map< std::string, std::string > ReflVolMap
Definition TGDMLParse.h:204
std::map< std::string, double > ConstMap
Definition TGDMLParse.h:206
ReflSolidMap freflsolidmap
Map containing reflection names and the Solid name ir references to.
Definition TGDMLParse.h:220
const char * ParseGDML(TXMLEngine *gdml, XMLNodePointer_t node)
This function recursively moves thru the DOM tree of the GDML file.
XMLNodePointer_t SclProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the define section of the GDML file, rotations can be declared.
TGDMMapHelper< const char > FileMap
Definition TGDMLParse.h:202
TGDMLParse()
Constructor.
XMLNodePointer_t BorderSurfaceProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the structure section of the GDML file, border surfaces can be declared.
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:104
TGeoRotation * GetRotation(const char *name)
void DefineConstants()
Define constant expressions used.
std::map< std::string, std::string > ReflectionsMap
Definition TGDMLParse.h:203
const char * NameShort(const char *name)
This function looks thru a string for the chars '0x' next to each other, when it finds this,...
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:222
TGDMMapHelper< TGDMLMatrix > MatrixMap
Definition TGDMLParse.h:200
MatrixMap fmatrices
Map containing values of constants declared in the file.
Definition TGDMLParse.h:224
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:193
TGDMMapHelper< TGeoVolume > VolMap
Definition TGDMLParse.h:198
VolMap fvolmap
Map containing solid names and the TGeoShape for it.
Definition TGDMLParse.h:217
double GetScaleVal(const char *unit)
Throughout the GDML file, a unit can de specified.
std::string fDefault_lunit
Definition TGDMLParse.h:105
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:209
XMLNodePointer_t PosProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the define section of the GDML file, positions can be declared.
ReflVolMap freflvolmap
Map containing reflection names and the TGDMLRefl for it - containing refl matrix.
Definition TGDMLParse.h:221
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:97
ReflectionsMap freflectmap
Map containing placed volume names and the TGeoNode for it.
Definition TGDMLParse.h:219
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:98
std::map< std::string, double > FracMap
Definition TGDMLParse.h:205
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...
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:191
TGDMMapHelper< TGeoNode > PvolMap
Definition TGDMLParse.h:199
MatMap fmatmap
Map containing element names and the TGeoElement for it.
Definition TGDMLParse.h:213
TGDMMapHelper< TGeoMixture > MixMap
Definition TGDMLParse.h:195
SclMap fsclmap
Map containing rotation names and the TGeoRotation for it.
Definition TGDMLParse.h:210
XMLNodePointer_t MatrixProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the define section of the GDML file, matrices These are referenced by other GDML tags,...
IsoMap fisomap
Map containing scale names and the TGeoScale for it.
Definition TGDMLParse.h:211
XMLNodePointer_t IsoProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLNodePointer_t parentn)
In the material section of the GDML file, an isotope may be declared.
PvolMap fpvolmap
Map containing volume names and the TGeoVolume for it.
Definition TGDMLParse.h:218
TGeoTranslation * GetPosition(const char *name)
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:214
static TGeoVolume * StartGDML(const char *filename)
Definition TGDMLParse.h:111
TGDMMapHelper< TGeoShape > SolMap
Definition TGDMLParse.h:197
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...
const char * fStartFile
Definition TGDMLParse.h:103
ConstMap fconsts
Map containing files parsed during entire parsing, with their world volume name.
Definition TGDMLParse.h:223
std::string fDefault_aunit
Definition TGDMLParse.h:106
XMLNodePointer_t QuantityProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the define section of the GDML file, quantities can be declared.
TGDMMapHelper< TGeoTranslation > PosMap
Definition TGDMLParse.h:188
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:216
EleMap felemap
Map containing isotope names and the TGeoIsotope for it.
Definition TGDMLParse.h:212
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.
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:208
TGeoShape * GetSolid(const char *name)
TXMLEngine * fFileEngine[20]
Definition TGDMLParse.h:102
XMLNodePointer_t RotProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the define section of the GDML file, rotations can be declared.
TGDMMapHelper< TGeoMedium > MedMap
Definition TGDMLParse.h:194
TGDMMapHelper< TGeoIsotope > IsoMap
Definition TGDMLParse.h:192
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:190
XMLNodePointer_t ConProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the define section of the GDML file, constants can be declared.
XMLNodePointer_t VolProcess(TXMLEngine *gdml, XMLNodePointer_t node)
In the structure section of the GDML file, volumes can be declared.
XMLNodePointer_t OpticalSurfaceProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, optical surfaces can be defined.
XMLNodePointer_t SkinSurfaceProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the structure section of the GDML file, skin surfaces 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:201
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.
XMLNodePointer_t ScaledSolid(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Scaled Solid may be declared when the scaledSolid keyword i...
TGDMMapHelper< TGeoRotation > RotMap
Definition TGDMLParse.h:189
~TGDMLParse() override
Definition TGDMLParse.h:109
MixMap fmixmap
Map containing medium names and the TGeoMedium for it.
Definition TGDMLParse.h:215
XMLNodePointer_t UsrProcess(TXMLEngine *gdml, XMLNodePointer_t node)
User data to be processed.
This class is a helper class for TGDMLParse.
Definition TGDMLParse.h:30
const char * fNameS
Definition TGDMLParse.h:46
~TGDMLRefl() override
Definition TGDMLParse.h:40
TGeoMatrix * fMatrix
solid name being reflected
Definition TGDMLParse.h:48
TGeoMatrix * GetMatrix()
This accessor method returns the matrix.
const char * fSolid
reflected solid name
Definition TGDMLParse.h:47
TGDMAssignmentHelper< T > operator[](const std::string &key)
Definition TGDMLParse.h:92
Geometrical transformation package.
Definition TGeoMatrix.h:38
Class describing rotations.
Definition TGeoMatrix.h:168
Class describing scale transformations.
Definition TGeoMatrix.h:253
Base abstract class for all shapes.
Definition TGeoShape.h:25
Class describing translations.
Definition TGeoMatrix.h:116
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:139
Typedefs used by the geometry group.