00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TGDMLParse
00013 #define ROOT_TGDMLParse
00014
00015 #ifndef ROOT_TGeoMatrix
00016 #include "TGeoMatrix.h"
00017 #endif
00018
00019 #ifndef ROOT_TXMLEngine
00020 #include "TXMLEngine.h"
00021 #endif
00022
00023 #ifndef ROOT_TGeoVolume
00024 #include "TGeoVolume.h"
00025 #endif
00026
00027 #include "TFormula.h"
00028
00029 #include <map>
00030 #include <vector>
00031 #include <iostream>
00032
00033
00034
00035
00036
00037 class TGDMLRefl : public TObject {
00038 public:
00039
00040 TGDMLRefl() {
00041
00042 fNameS = "";
00043 fSolid = "";
00044 fMatrix = 0;
00045 }
00046
00047 virtual ~TGDMLRefl() {}
00048
00049 TGDMLRefl(const char* name, const char* solid, TGeoMatrix* matrix);
00050 TGeoMatrix* GetMatrix();
00051
00052 private:
00053
00054 const char* fNameS;
00055 const char* fSolid;
00056 TGeoMatrix *fMatrix;
00057
00058 ClassDef(TGDMLRefl, 0)
00059 };
00060
00061
00062
00063
00064
00065 class TGDMLBaseTGDMMapHelper : public std::map<std::string, const void *>{
00066 };
00067
00068
00069
00070
00071 template<typename T>
00072
00073 class TGDMAssignmentHelper{
00074 private:
00075 TGDMLBaseTGDMMapHelper::iterator fPosInMap;
00076
00077 public:
00078 TGDMAssignmentHelper(TGDMLBaseTGDMMapHelper &baseMap, const std::string &key) {
00079 baseMap[key];
00080
00081 fPosInMap = baseMap.find(key);
00082 }
00083
00084 operator T * ()const {
00085 return (T*)fPosInMap->second;
00086 }
00087
00088 TGDMAssignmentHelper & operator = (const T * ptr) {
00089 fPosInMap->second = ptr;
00090 return *this;
00091 }
00092 };
00093
00094 template<class T>
00095 class TGDMMapHelper : public TGDMLBaseTGDMMapHelper{
00096 public:
00097 TGDMAssignmentHelper<T> operator [] (const std::string &key)
00098 {
00099 return TGDMAssignmentHelper<T>(*this, key);
00100 }
00101 };
00102
00103 class TGDMLParse : public TObject {
00104 public:
00105
00106 const char* fWorldName;
00107 TGeoVolume* fWorld;
00108 int fVolID;
00109 int fFILENO;
00110 TXMLEngine* fFileEngine[20];
00111 const char* fStartFile;
00112 const char* fCurrentFile;
00113
00114 TGDMLParse() {
00115
00116 fVolID = 0;
00117 fFILENO = 0;
00118 }
00119
00120 virtual ~TGDMLParse() {
00121
00122 for (size_t i=0;i<fformvec.size();i++)
00123 if (fformvec[i] != NULL) delete fformvec[i];
00124 }
00125
00126 static TGeoVolume* StartGDML(const char* filename){
00127 TGDMLParse* parser = new TGDMLParse;
00128 TGeoVolume* world = parser->GDMLReadFile(filename);
00129 return world;
00130 }
00131
00132 TGeoVolume* GDMLReadFile(const char* filename = "test.gdml");
00133
00134 private:
00135
00136 const char* ParseGDML(TXMLEngine* gdml, XMLNodePointer_t node) ;
00137 const char* GetScale(const char* unit);
00138 double Evaluate(const char* evalline);
00139 const char* NameShort(const char* name);
00140
00141
00142 XMLNodePointer_t ConProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00143 XMLNodePointer_t PosProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00144 XMLNodePointer_t RotProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00145 XMLNodePointer_t SclProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00146
00147
00148 XMLNodePointer_t IsoProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLNodePointer_t parentn);
00149 XMLNodePointer_t EleProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLNodePointer_t parentn, Bool_t hasIsotopes);
00150 XMLNodePointer_t MatProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr, int z);
00151
00152
00153 XMLNodePointer_t BooSolid(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr, int num);
00154 XMLNodePointer_t Box(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00155 XMLNodePointer_t Paraboloid(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00156 XMLNodePointer_t Arb8(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00157 XMLNodePointer_t Tube(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00158 XMLNodePointer_t CutTube(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00159 XMLNodePointer_t Cone(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00160 XMLNodePointer_t Trap(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00161 XMLNodePointer_t Trd(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00162 XMLNodePointer_t Polycone(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00163 XMLNodePointer_t Polyhedra(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00164 XMLNodePointer_t Sphere(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00165 XMLNodePointer_t Torus(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00166 XMLNodePointer_t Hype(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00167 XMLNodePointer_t Para(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00168 XMLNodePointer_t TwistTrap(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00169 XMLNodePointer_t ElTube(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00170 XMLNodePointer_t Orb(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00171 XMLNodePointer_t Xtru(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00172 XMLNodePointer_t Reflection(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00173 XMLNodePointer_t Ellipsoid(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
00174
00175
00176 XMLNodePointer_t VolProcess(TXMLEngine* gdml, XMLNodePointer_t node);
00177 XMLNodePointer_t AssProcess(TXMLEngine* gdml, XMLNodePointer_t node);
00178 Int_t SetAxis(const char* axisString);
00179
00180
00181 XMLNodePointer_t TopProcess(TXMLEngine* gdml, XMLNodePointer_t node);
00182
00183 typedef TGDMMapHelper<TGeoTranslation> PosMap;
00184 typedef TGDMMapHelper<TGeoRotation> RotMap;
00185 typedef TGDMMapHelper<TGeoScale> SclMap;
00186 typedef TGDMMapHelper<TGeoElement> EleMap;
00187 typedef TGDMMapHelper<TGeoIsotope> IsoMap;
00188 typedef TGDMMapHelper<TGeoMaterial> MatMap;
00189 typedef TGDMMapHelper<TGeoMedium> MedMap;
00190 typedef TGDMMapHelper<TGeoMixture> MixMap;
00191
00192 typedef TGDMMapHelper<TGeoShape> SolMap;
00193 typedef TGDMMapHelper<TGeoVolume> VolMap;
00194 typedef TGDMMapHelper<TGDMLRefl> ReflSolidMap;
00195 typedef TGDMMapHelper<const char> FileMap;
00196 typedef std::map<std::string, std::string> ReflectionsMap;
00197 typedef std::map<std::string, std::string> ReflVolMap;
00198 typedef std::map<std::string, double> FracMap;
00199 typedef std::vector<TFormula*> FormVec;
00200
00201 PosMap fposmap;
00202 RotMap frotmap;
00203 SclMap fsclmap;
00204 IsoMap fisomap;
00205 EleMap felemap;
00206 MatMap fmatmap;
00207 MedMap fmedmap;
00208 MixMap fmixmap;
00209 SolMap fsolmap;
00210 VolMap fvolmap;
00211 ReflectionsMap freflectmap;
00212 ReflSolidMap freflsolidmap;
00213 ReflVolMap freflvolmap;
00214 FileMap ffilemap;
00215 FormVec fformvec;
00216
00217 ClassDef(TGDMLParse, 0)
00218 };
00219
00220 #endif