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