ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  for (size_t i = 0; i < fformvec.size(); i++)
126  if (fformvec[i] != NULL) delete fformvec[i];
127  }
128 
129  static TGeoVolume* StartGDML(const char* filename) {
130  TGDMLParse* parser = new TGDMLParse;
131  TGeoVolume* world = parser->GDMLReadFile(filename);
132  return world;
133  }
134 
135  TGeoVolume* GDMLReadFile(const char* filename = "test.gdml");
136 
137 private:
138 
139  const char* ParseGDML(TXMLEngine* gdml, XMLNodePointer_t node) ;
140  TString GetScale(const char* unit);
141  double GetScaleVal(const char* unit);
142  double Evaluate(const char* evalline);
143  const char* NameShort(const char* name);
144  double Value(const char *svalue) const;
145 
146  //'define' section
151 
152  //'materials' section
154  XMLNodePointer_t EleProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLNodePointer_t parentn, Bool_t hasIsotopes, Bool_t hasIsotopesExtended);
155  //XMLNodePointer_t EleProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLNodePointer_t parentn);
157  //XMLNodePointer_t MatProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
158 
159  //'solids' section
181  XMLNodePointer_t Ellipsoid(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr); //not really implemented: just approximation to a TGeoBBox
182 
183  //'structure' section
187  Int_t SetAxis(const char* axisString); //Set Axis for Division
188 
189  //'setup' section
191 
200 
205  typedef std::map<std::string, std::string> ReflectionsMap;
206  typedef std::map<std::string, std::string> ReflVolMap;
207  typedef std::map<std::string, double> FracMap;
208  typedef std::vector<TFormula*> FormVec;
209 
210  PosMap fposmap; //!Map containing position names and the TGeoTranslation for it
211  RotMap frotmap; //!Map containing rotation names and the TGeoRotation for it
212  SclMap fsclmap; //!Map containing scale names and the TGeoScale for it
213  IsoMap fisomap; //!Map containing isotope names and the TGeoIsotope for it
214  EleMap felemap; //!Map containing element names and the TGeoElement for it
215  MatMap fmatmap; //!Map containing material names and the TGeoMaterial for it
216  MedMap fmedmap; //!Map containing medium names and the TGeoMedium for it
217  MixMap fmixmap; //!Map containing mixture names and the TGeoMixture for it
218  SolMap fsolmap; //!Map containing solid names and the TGeoShape for it
219  VolMap fvolmap; //!Map containing volume names and the TGeoVolume for it
220  ReflectionsMap freflectmap; //!Map containing reflection names and the Solid name ir references to
221  ReflSolidMap freflsolidmap; //!Map containing reflection names and the TGDMLRefl for it - containing refl matrix
222  ReflVolMap freflvolmap; //!Map containing reflected volume names and the solid ref for it
223  FileMap ffilemap; //!Map containing files parsed during entire parsing, with their world volume name
224  FormVec fformvec; //!Vector containing constant functions for GDML constant definitions
225 
226  ClassDef(TGDMLParse, 0) //imports GDML using DOM and binds it to ROOT
227 };
228 
229 #endif
XMLNodePointer_t UsrProcess(TXMLEngine *gdml, XMLNodePointer_t node)
User data to be processed.
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:403
TGDMAssignmentHelper< T > operator[](const std::string &key)
Definition: TGDMLParse.h:97
TGDMMapHelper< TGeoTranslation > PosMap
Definition: TGDMLParse.h:192
XMLNodePointer_t TwistTrap(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a TwistTrap may be declared.
TGeoVolume * GDMLReadFile(const char *filename="test.gdml")
RotMap frotmap
Map containing position names and the TGeoTranslation for it.
Definition: TGDMLParse.h:211
TGDMMapHelper< TGeoMedium > MedMap
Definition: TGDMLParse.h:198
XMLNodePointer_t Trd(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Trd may be declared.
MatMap fmatmap
Map containing element names and the TGeoElement for it.
Definition: TGDMLParse.h:215
TGeoVolume * fWorld
Definition: TGDMLParse.h:106
TGDMAssignmentHelper(TGDMLBaseTGDMMapHelper &baseMap, const std::string &key)
Definition: TGDMLParse.h:78
XMLNodePointer_t Paraboloid(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Paraboloid 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.
TGDMMapHelper< TGeoIsotope > IsoMap
Definition: TGDMLParse.h:196
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...
EleMap felemap
Map containing isotope names and the TGeoIsotope for it.
Definition: TGDMLParse.h:214
XMLNodePointer_t Cone(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a cone may be declared.
static const char * filename()
TString GetScale(const char *unit)
Throughout the GDML file, a unit can de specified.
Definition: TGDMLParse.cxx:436
Basic string class.
Definition: TString.h:137
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:691
XMLNodePointer_t Polycone(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Polycone may be declared.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TGDMMapHelper< const char > FileMap
Definition: TGDMLParse.h:204
double GetScaleVal(const char *unit)
Throughout the GDML file, a unit can de specified.
Definition: TGDMLParse.cxx:482
TGDMMapHelper< TGeoShape > SolMap
Definition: TGDMLParse.h:201
ReflectionsMap freflectmap
Map containing volume names and the TGeoVolume for it.
Definition: TGDMLParse.h:220
TGDMMapHelper< TGeoMaterial > MatMap
Definition: TGDMLParse.h:197
TTree * T
const char * fCurrentFile
Definition: TGDMLParse.h:111
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:647
TGDMMapHelper< TGeoVolume > VolMap
Definition: TGDMLParse.h:202
TGeoMatrix * fMatrix
solid name being reflected
Definition: TGDMLParse.h:56
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.
double Evaluate(const char *evalline)
Definition: TGDMLParse.cxx:352
#define ClassDef(name, id)
Definition: Rtypes.h:254
FormVec fformvec
Map containing files parsed during entire parsing, with their world volume name.
Definition: TGDMLParse.h:224
TGeoMatrix * GetMatrix()
this accessor method returns the matrix.
TGDMMapHelper< TGeoElement > EleMap
Definition: TGDMLParse.h:195
double Value(const char *svalue) const
Convert number in string format to double value.
Definition: TGDMLParse.cxx:522
virtual ~TGDMLParse()
Definition: TGDMLParse.h:123
XMLNodePointer_t Arb8(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, an Arb8 may be declared.
std::vector< TFormula * > FormVec
Definition: TGDMLParse.h:208
FileMap ffilemap
Map containing reflected volume names and the solid ref for it.
Definition: TGDMLParse.h:223
Float_t z[5]
Definition: Ifit.C:16
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 Sphere(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Sphere may be declared.
XMLNodePointer_t Orb(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, an Orb may be declared.
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:536
XMLNodePointer_t Torus(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Torus may be declared.
std::map< std::string, std::string > ReflectionsMap
Definition: TGDMLParse.h:205
XMLNodePointer_t Box(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a box may be declared.
XMLNodePointer_t Ellipsoid(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, an ellipsoid may be declared.
std::map< std::string, double > FracMap
Definition: TGDMLParse.h:207
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 Trap(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Trap may be declared.
const char * fStartFile
Definition: TGDMLParse.h:110
const char * fSolid
reflected solid name
Definition: TGDMLParse.h:55
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:589
TXMLEngine * fFileEngine[20]
Definition: TGDMLParse.h:109
XMLNodePointer_t Hype(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Hype may be declared.
void * XMLNodePointer_t
Definition: TXMLEngine.h:19
IsoMap fisomap
Map containing scale names and the TGeoScale for it.
Definition: TGDMLParse.h:213
XMLNodePointer_t TopProcess(TXMLEngine *gdml, XMLNodePointer_t node)
In the setup section of the GDML file, the top volume need to be declared.
const char * fNameS
Definition: TGDMLParse.h:54
void * XMLAttrPointer_t
Definition: TXMLEngine.h:21
XMLNodePointer_t Polyhedra(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Polyhedra may be declared.
MixMap fmixmap
Map containing medium names and the TGeoMedium for it.
Definition: TGDMLParse.h:217
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:363
TGDMMapHelper< TGeoScale > SclMap
Definition: TGDMLParse.h:194
TGDMLBaseTGDMMapHelper::iterator fPosInMap
Definition: TGDMLParse.h:75
TGDMAssignmentHelper & operator=(const T *ptr)
Definition: TGDMLParse.h:88
#define name(a, b)
Definition: linkTestLib0.cpp:5
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:388
MedMap fmedmap
Map containing material names and the TGeoMaterial for it.
Definition: TGDMLParse.h:216
Mother of all ROOT objects.
Definition: TObject.h:58
TGDMMapHelper< TGeoRotation > RotMap
Definition: TGDMLParse.h:193
SclMap fsclmap
Map containing rotation names and the TGeoRotation for it.
Definition: TGDMLParse.h:212
TGDMMapHelper< TGeoMixture > MixMap
Definition: TGDMLParse.h:199
SolMap fsolmap
Map containing mixture names and the TGeoMixture for it.
Definition: TGDMLParse.h:218
const char * ParseGDML(TXMLEngine *gdml, XMLNodePointer_t node)
this function recursively moves thru the DOM tree of the GDML file.
Definition: TGDMLParse.cxx:164
ReflVolMap freflvolmap
Map containing reflection names and the TGDMLRefl for it - containing refl matrix.
Definition: TGDMLParse.h:222
VolMap fvolmap
Map containing solid names and the TGeoShape for it.
Definition: TGDMLParse.h:219
XMLNodePointer_t ElTube(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a ElTube may be declared.
std::map< std::string, std::string > ReflVolMap
Definition: TGDMLParse.h:206
#define NULL
Definition: Rtypes.h:82
ReflSolidMap freflsolidmap
Map containing reflection names and the Solid name ir references to.
Definition: TGDMLParse.h:221
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.
Definition: TGDMLParse.cxx:946
XMLNodePointer_t EleProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLNodePointer_t parentn, Bool_t hasIsotopes, Bool_t hasIsotopesExtended)
Definition: TGDMLParse.cxx:751
TGDMMapHelper< TGDMLRefl > ReflSolidMap
Definition: TGDMLParse.h:203
XMLNodePointer_t Tube(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr)
In the solids section of the GDML file, a Tube may be declared.
XMLNodePointer_t AssProcess(TXMLEngine *gdml, XMLNodePointer_t node)
In the structure section of the GDML file, assembly volumes can be declared.
XMLNodePointer_t VolProcess(TXMLEngine *gdml, XMLNodePointer_t node)
In the structure section of the GDML file, volumes can be declared.
virtual ~TGDMLRefl()
Definition: TGDMLParse.h:47
TString fWorldName
Definition: TGDMLParse.h:105
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.
static TGeoVolume * StartGDML(const char *filename)
Definition: TGDMLParse.h:129
PosMap fposmap
Definition: TGDMLParse.h:210