#ifndef ROOT_TGDMLParse
#define ROOT_TGDMLParse
#ifndef ROOT_TGeoMatrix
#include "TGeoMatrix.h"
#endif
#ifndef ROOT_TXMLEngine
#include "TXMLEngine.h"
#endif
#ifndef ROOT_TGeoVolume
#include "TGeoVolume.h"
#endif
#include "TFormula.h"
#include <map>
#include <vector>
#include <iostream>
class TGDMLRefl : public TObject {
public:
TGDMLRefl() {
fNameS = "";
fSolid = "";
fMatrix = 0;
}
virtual ~TGDMLRefl() {}
TGDMLRefl(const char* name, const char* solid, TGeoMatrix* matrix);
TGeoMatrix* GetMatrix();
private:
const char* fNameS;
const char* fSolid;
TGeoMatrix *fMatrix;
ClassDef(TGDMLRefl, 0)
};
class TGDMLBaseTGDMMapHelper : public std::map<std::string, const void *>{
};
template<typename T>
class TGDMAssignmentHelper{
private:
TGDMLBaseTGDMMapHelper::iterator fPosInMap;
public:
TGDMAssignmentHelper(TGDMLBaseTGDMMapHelper &baseMap, const std::string &key) {
baseMap[key];
fPosInMap = baseMap.find(key);
}
operator T * ()const {
return (T*)fPosInMap->second;
}
TGDMAssignmentHelper & operator = (const T * ptr) {
fPosInMap->second = ptr;
return *this;
}
};
template<class T>
class TGDMMapHelper : public TGDMLBaseTGDMMapHelper{
public:
TGDMAssignmentHelper<T> operator [] (const std::string &key)
{
return TGDMAssignmentHelper<T>(*this, key);
}
};
class TGDMLParse : public TObject {
public:
const char* fWorldName;
TGeoVolume* fWorld;
int fVolID;
int fFILENO;
TXMLEngine* fFileEngine[20];
const char* fStartFile;
const char* fCurrentFile;
TGDMLParse() {
fVolID = 0;
fFILENO = 0;
}
virtual ~TGDMLParse() {
for (size_t i=0;i<fformvec.size();i++)
if (fformvec[i] != NULL) delete fformvec[i];
}
static TGeoVolume* StartGDML(const char* filename){
TGDMLParse* parser = new TGDMLParse;
TGeoVolume* world = parser->GDMLReadFile(filename);
return world;
}
TGeoVolume* GDMLReadFile(const char* filename = "test.gdml");
private:
const char* ParseGDML(TXMLEngine* gdml, XMLNodePointer_t node) ;
const char* GetScale(const char* unit);
double Evaluate(const char* evalline);
const char* NameShort(const char* name);
XMLNodePointer_t ConProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t PosProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t RotProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t SclProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t IsoProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLNodePointer_t parentn);
XMLNodePointer_t EleProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLNodePointer_t parentn, Bool_t hasIsotopes);
XMLNodePointer_t MatProcess(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr, int z);
XMLNodePointer_t BooSolid(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr, int num);
XMLNodePointer_t Box(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t Paraboloid(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t Arb8(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t Tube(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t CutTube(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t Cone(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t Trap(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t Trd(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t Polycone(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t Polyhedra(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t Sphere(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t Torus(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t Hype(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t Para(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t TwistTrap(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t ElTube(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t Orb(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t Xtru(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t Reflection(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t Ellipsoid(TXMLEngine* gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
XMLNodePointer_t VolProcess(TXMLEngine* gdml, XMLNodePointer_t node);
XMLNodePointer_t AssProcess(TXMLEngine* gdml, XMLNodePointer_t node);
Int_t SetAxis(const char* axisString);
XMLNodePointer_t TopProcess(TXMLEngine* gdml, XMLNodePointer_t node);
typedef TGDMMapHelper<TGeoTranslation> PosMap;
typedef TGDMMapHelper<TGeoRotation> RotMap;
typedef TGDMMapHelper<TGeoScale> SclMap;
typedef TGDMMapHelper<TGeoElement> EleMap;
typedef TGDMMapHelper<TGeoIsotope> IsoMap;
typedef TGDMMapHelper<TGeoMaterial> MatMap;
typedef TGDMMapHelper<TGeoMedium> MedMap;
typedef TGDMMapHelper<TGeoMixture> MixMap;
typedef TGDMMapHelper<TGeoShape> SolMap;
typedef TGDMMapHelper<TGeoVolume> VolMap;
typedef TGDMMapHelper<TGDMLRefl> ReflSolidMap;
typedef TGDMMapHelper<const char> FileMap;
typedef std::map<std::string, std::string> ReflectionsMap;
typedef std::map<std::string, std::string> ReflVolMap;
typedef std::map<std::string, double> FracMap;
typedef std::vector<TFormula*> FormVec;
PosMap fposmap;
RotMap frotmap;
SclMap fsclmap;
IsoMap fisomap;
EleMap felemap;
MatMap fmatmap;
MedMap fmedmap;
MixMap fmixmap;
SolMap fsolmap;
VolMap fvolmap;
ReflectionsMap freflectmap;
ReflSolidMap freflsolidmap;
ReflVolMap freflvolmap;
FileMap ffilemap;
FormVec fformvec;
ClassDef(TGDMLParse, 0)
};
#endif