Logo ROOT   6.08/07
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 #ifndef ROOT_TGeoMatrix
16 #include "TGeoMatrix.h"
17 #endif
18 
19 #ifndef ROOT_TXMLEngine
20 #include "TXMLEngine.h"
21 #endif
22 
23 #ifndef ROOT_TGeoVolume
24 #include "TGeoVolume.h"
25 #endif
26 
27 #include "TFormula.h"
28 
29 #include <map>
30 #include <vector>
31 #include <iostream>
32 
33 /*************************************************************************
34  * TGDMLRefl - helper class for the import of GDML to ROOT. *
35  *************************************************************************/
36 
37 class TGDMLRefl : public TObject {
38 public:
39 
41 
42  fNameS = "";
43  fSolid = "";
44  fMatrix = 0;
45  }
46 
47  virtual ~TGDMLRefl() {}
48 
49  TGDMLRefl(const char* name, const char* solid, TGeoMatrix* matrix);
51 
52 private:
53 
54  const char* fNameS; //!reflected solid name
55  const char* fSolid; //!solid name being reflected
56  TGeoMatrix *fMatrix; //!matrix of reflected solid
57 
58  ClassDef(TGDMLRefl, 0) //helper class used for the storage of reflected solids
59 };
60 
61 /*************************************************************************
62  * TGDMLParse - base class for the import of GDML to ROOT. *
63  *************************************************************************/
64 
65 class TGDMLBaseTGDMMapHelper : public std::map<std::string, const void *> {
66 };
67 
68 //map's [] operator returns reference.
69 //to avoid ugly UB casts like static_cast<SomeType * &>(voidPtrLValue)
70 //I have this helper class.
71 template<typename T>
72 
74 private:
75  TGDMLBaseTGDMMapHelper::iterator fPosInMap;
76 
77 public:
78  TGDMAssignmentHelper(TGDMLBaseTGDMMapHelper &baseMap, const std::string &key) {
79  baseMap[key];//if we do not have this key-value pair before, insert it now (with zero for pointer).
80  //find iterator for this key now :)
81  fPosInMap = baseMap.find(key);
82  }
83 
84  operator T * ()const {
85  return (T*)fPosInMap->second;//const_cast<T*>(static_cast<const T *>(fPosInMap->second));
86  }
87 
89  fPosInMap->second = ptr;
90  return *this;
91  }
92 };
93 
94 template<class T>
96 public:
97  TGDMAssignmentHelper<T> operator [](const std::string &key) {
98  return TGDMAssignmentHelper<T>(*this, key);
99  }
100 };
101 
102 class TGDMLParse : public TObject {
103 public:
104 
106  TGeoVolume* fWorld; //top volume of geometry
107  int fVolID; //volume ID, incremented as assigned.
108  int fFILENO; //Holds which level of file the parser is at
109  TXMLEngine* fFileEngine[20]; //array of dom object pointers
110  const char* fStartFile; //name of originating file
111  const char* fCurrentFile; //current file name being parsed
112 
113  TGDMLParse() { //constructor
114  fWorldName = "";
115  fWorld = 0;
116  fVolID = 0;
117  fFILENO = 0;
118  for (Int_t i=0; i<20; i++) fFileEngine[i] = 0;
119  fStartFile = 0;
120  fCurrentFile = 0;
121  }
122 
123  virtual ~TGDMLParse() { //destructor
124  }
125 
126  static TGeoVolume* StartGDML(const char* filename) {
127  TGDMLParse* parser = new TGDMLParse;
128  TGeoVolume* world = parser->GDMLReadFile(filename);
129  return world;
130  }
131 
132  TGeoVolume* GDMLReadFile(const char* filename = "test.gdml");
133 
134 private:
135 
136  const char* ParseGDML(TXMLEngine* gdml, XMLNodePointer_t node) ;
137  TString GetScale(const char* unit);
138  double GetScaleVal(const char* unit);
139  double Evaluate(const char* evalline);
140  const char* NameShort(const char* name);
141  double Value(const char *svalue) const;
142 
143  //'define' section
144  XMLNodePointer_t ConProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
145  XMLNodePointer_t PosProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
146  XMLNodePointer_t RotProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
147  XMLNodePointer_t SclProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
148 
149  //'materials' section
150  XMLNodePointer_t IsoProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLNodePointer_t parentn);
151  XMLNodePointer_t EleProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLNodePointer_t parentn, Bool_t hasIsotopes, Bool_t hasIsotopesExtended);
152  //XMLNodePointer_t EleProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLNodePointer_t parentn);
153  XMLNodePointer_t MatProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr, int z);
154  //XMLNodePointer_t MatProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
155 
156  //'solids' section
157  XMLNodePointer_t BooSolid(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr, int num);
159  XMLNodePointer_t Paraboloid(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
167  XMLNodePointer_t Polycone(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
168  XMLNodePointer_t Polyhedra(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
173  XMLNodePointer_t TwistTrap(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
177  XMLNodePointer_t Reflection(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
178  XMLNodePointer_t Ellipsoid(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr); //not really implemented: just approximation to a TGeoBBox
179 
180  //'structure' section
181  XMLNodePointer_t VolProcess(TXMLEngine* gdml, XMLNodePointer_t node);
182  XMLNodePointer_t AssProcess(TXMLEngine* gdml, XMLNodePointer_t node);
183  XMLNodePointer_t UsrProcess(TXMLEngine* gdml, XMLNodePointer_t node);
184  Int_t SetAxis(const char* axisString); //Set Axis for Division
185 
186  //'setup' section
187  XMLNodePointer_t TopProcess(TXMLEngine* gdml, XMLNodePointer_t node);
188 
197 
202  typedef std::map<std::string, std::string> ReflectionsMap;
203  typedef std::map<std::string, std::string> ReflVolMap;
204  typedef std::map<std::string, double> FracMap;
205  typedef std::map<std::string, double> ConstMap;
206 
207  PosMap fposmap; //!Map containing position names and the TGeoTranslation for it
208  RotMap frotmap; //!Map containing rotation names and the TGeoRotation for it
209  SclMap fsclmap; //!Map containing scale names and the TGeoScale for it
210  IsoMap fisomap; //!Map containing isotope names and the TGeoIsotope for it
211  EleMap felemap; //!Map containing element names and the TGeoElement for it
212  MatMap fmatmap; //!Map containing material names and the TGeoMaterial for it
213  MedMap fmedmap; //!Map containing medium names and the TGeoMedium for it
214  MixMap fmixmap; //!Map containing mixture names and the TGeoMixture for it
215  SolMap fsolmap; //!Map containing solid names and the TGeoShape for it
216  VolMap fvolmap; //!Map containing volume names and the TGeoVolume for it
217  ReflectionsMap freflectmap; //!Map containing reflection names and the Solid name ir references to
218  ReflSolidMap freflsolidmap; //!Map containing reflection names and the TGDMLRefl for it - containing refl matrix
219  ReflVolMap freflvolmap; //!Map containing reflected volume names and the solid ref for it
220  FileMap ffilemap; //!Map containing files parsed during entire parsing, with their world volume name
221  ConstMap fconsts; //!Map containing values of constants declared in the file
222 
223  ClassDef(TGDMLParse, 0) //imports GDML using DOM and binds it to ROOT
224 };
225 
226 #endif
TGDMMapHelper< TGeoTranslation > PosMap
Definition: TGDMLParse.h:189
RotMap frotmap
Map containing position names and the TGeoTranslation for it.
Definition: TGDMLParse.h:208
TGDMMapHelper< TGeoMedium > MedMap
Definition: TGDMLParse.h:195
MatMap fmatmap
Map containing element names and the TGeoElement for it.
Definition: TGDMLParse.h:212
TGeoVolume * fWorld
Definition: TGDMLParse.h:106
std::map< std::string, double > ConstMap
Definition: TGDMLParse.h:205
TGDMAssignmentHelper(TGDMLBaseTGDMMapHelper &baseMap, const std::string &key)
Definition: TGDMLParse.h:78
Geometrical transformation package.
Definition: TGeoMatrix.h:40
double T(double x)
Definition: ChebyshevPol.h:34
TGDMMapHelper< TGeoIsotope > IsoMap
Definition: TGDMLParse.h:193
EleMap felemap
Map containing isotope names and the TGeoIsotope for it.
Definition: TGDMLParse.h:211
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition: TGeoVolume.h:61
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TGDMMapHelper< const char > FileMap
Definition: TGDMLParse.h:201
TGDMMapHelper< TGeoShape > SolMap
Definition: TGDMLParse.h:198
ReflectionsMap freflectmap
Map containing volume names and the TGeoVolume for it.
Definition: TGDMLParse.h:217
TGDMMapHelper< TGeoMaterial > MatMap
Definition: TGDMLParse.h:194
const char * fCurrentFile
Definition: TGDMLParse.h:111
TGDMMapHelper< TGeoVolume > VolMap
Definition: TGDMLParse.h:199
TGeoMatrix * fMatrix
solid name being reflected
Definition: TGDMLParse.h:56
#define ClassDef(name, id)
Definition: Rtypes.h:254
TGeoMatrix * GetMatrix()
this accessor method returns the matrix.
TGeoVolume * GDMLReadFile(const char *filename="test.gdml")
creates the new instance of the XMLEngine called &#39;gdml&#39;, using the filename >> then parses the file a...
Definition: TGDMLParse.cxx:127
TGDMMapHelper< TGeoElement > EleMap
Definition: TGDMLParse.h:192
virtual ~TGDMLParse()
Definition: TGDMLParse.h:123
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.cxx:103
FileMap ffilemap
Map containing reflected volume names and the solid ref for it.
Definition: TGDMLParse.h:220
ConstMap fconsts
Map containing files parsed during entire parsing, with their world volume name.
Definition: TGDMLParse.h:221
std::map< std::string, std::string > ReflectionsMap
Definition: TGDMLParse.h:202
std::map< std::string, double > FracMap
Definition: TGDMLParse.h:204
const char * fStartFile
Definition: TGDMLParse.h:110
const char * fSolid
reflected solid name
Definition: TGDMLParse.h:55
void * XMLNodePointer_t
Definition: TXMLEngine.h:19
IsoMap fisomap
Map containing scale names and the TGeoScale for it.
Definition: TGDMLParse.h:210
const char * fNameS
Definition: TGDMLParse.h:54
void * XMLAttrPointer_t
Definition: TXMLEngine.h:21
MixMap fmixmap
Map containing medium names and the TGeoMedium for it.
Definition: TGDMLParse.h:214
TGDMMapHelper< TGeoScale > SclMap
Definition: TGDMLParse.h:191
TGDMLBaseTGDMMapHelper::iterator fPosInMap
Definition: TGDMLParse.h:75
MedMap fmedmap
Map containing material names and the TGeoMaterial for it.
Definition: TGDMLParse.h:213
Mother of all ROOT objects.
Definition: TObject.h:37
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
TGDMMapHelper< TGeoRotation > RotMap
Definition: TGDMLParse.h:190
SclMap fsclmap
Map containing rotation names and the TGeoRotation for it.
Definition: TGDMLParse.h:209
TGDMMapHelper< TGeoMixture > MixMap
Definition: TGDMLParse.h:196
SolMap fsolmap
Map containing mixture names and the TGeoMixture for it.
Definition: TGDMLParse.h:215
ReflVolMap freflvolmap
Map containing reflection names and the TGDMLRefl for it - containing refl matrix.
Definition: TGDMLParse.h:219
VolMap fvolmap
Map containing solid names and the TGeoShape for it.
Definition: TGDMLParse.h:216
std::map< std::string, std::string > ReflVolMap
Definition: TGDMLParse.h:203
ReflSolidMap freflsolidmap
Map containing reflection names and the Solid name ir references to.
Definition: TGDMLParse.h:218
TGDMMapHelper< TGDMLRefl > ReflSolidMap
Definition: TGDMLParse.h:200
virtual ~TGDMLRefl()
Definition: TGDMLParse.h:47
TString fWorldName
Definition: TGDMLParse.h:105
char name[80]
Definition: TGX11.cxx:109
static TGeoVolume * StartGDML(const char *filename)
Definition: TGDMLParse.h:126
const char * Value
Definition: TXMLSetup.cxx:73
PosMap fposmap
Definition: TGDMLParse.h:207