File indexing completed on 2025-01-18 10:11:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TGDMLParse
0013 #define ROOT_TGDMLParse
0014
0015 #include "TFormula.h"
0016 #include "TXMLEngine.h"
0017 #include "TGeoMatrix.h"
0018 #include "TGeoVolume.h"
0019 #include "TGeoElement.h"
0020
0021 #include <map>
0022 #include <iostream>
0023
0024 class TGDMLMatrix;
0025
0026
0027
0028
0029
0030 class TGDMLRefl : public TObject {
0031 public:
0032 TGDMLRefl()
0033 {
0034
0035 fNameS = "";
0036 fSolid = "";
0037 fMatrix = nullptr;
0038 }
0039
0040 ~TGDMLRefl() override {}
0041
0042 TGDMLRefl(const char *name, const char *solid, TGeoMatrix *matrix);
0043 TGeoMatrix *GetMatrix();
0044
0045 private:
0046 const char *fNameS;
0047 const char *fSolid;
0048 TGeoMatrix *fMatrix;
0049
0050 ClassDefOverride(TGDMLRefl, 0)
0051 };
0052
0053
0054
0055
0056
0057 class TGDMLBaseTGDMMapHelper : public std::map<std::string, const void *> {
0058 };
0059
0060
0061
0062
0063 template <typename T>
0064
0065 class TGDMAssignmentHelper {
0066 private:
0067 TGDMLBaseTGDMMapHelper::iterator fPosInMap;
0068
0069 public:
0070 TGDMAssignmentHelper(TGDMLBaseTGDMMapHelper &baseMap, const std::string &key)
0071 {
0072 baseMap[key];
0073
0074 fPosInMap = baseMap.find(key);
0075 }
0076
0077 operator T *() const
0078 {
0079 return (T *)fPosInMap->second;
0080 }
0081
0082 TGDMAssignmentHelper &operator=(const T *ptr)
0083 {
0084 fPosInMap->second = ptr;
0085 return *this;
0086 }
0087 };
0088
0089 template <class T>
0090 class TGDMMapHelper : public TGDMLBaseTGDMMapHelper {
0091 public:
0092 TGDMAssignmentHelper<T> operator[](const std::string &key) { return TGDMAssignmentHelper<T>(*this, key); }
0093 };
0094
0095 class TGDMLParse : public TObject {
0096 public:
0097 TString fWorldName;
0098 TGeoVolume *fWorld;
0099 int fVolID;
0100 int fFILENO;
0101 int fNunitless{0};
0102 TXMLEngine *fFileEngine[20];
0103 const char *fStartFile;
0104 const char *fCurrentFile;
0105 std::string fDefault_lunit = "mm";
0106 std::string fDefault_aunit = "rad";
0107
0108 TGDMLParse();
0109 ~TGDMLParse() override {}
0110
0111 static TGeoVolume *StartGDML(const char *filename)
0112 {
0113 TGDMLParse *parser = new TGDMLParse;
0114 TGeoVolume *world = parser->GDMLReadFile(filename);
0115 return world;
0116 }
0117
0118 TGeoVolume *GDMLReadFile(const char *filename = "test.gdml");
0119
0120 private:
0121 const char *ParseGDML(TXMLEngine *gdml, XMLNodePointer_t node);
0122 TString GetScale(const char *unit);
0123 double GetScaleVal(const char *unit);
0124 double Evaluate(const char *evalline);
0125 const char *NameShort(const char *name);
0126 double Value(const char *svalue) const;
0127 void DefineConstants();
0128
0129
0130 XMLNodePointer_t ConProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0131 XMLNodePointer_t PosProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0132 XMLNodePointer_t QuantityProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0133 XMLNodePointer_t RotProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0134 XMLNodePointer_t SclProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0135 XMLNodePointer_t MatrixProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0136
0137
0138 XMLNodePointer_t IsoProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLNodePointer_t parentn);
0139 XMLNodePointer_t EleProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLNodePointer_t parentn, Bool_t hasIsotopes,
0140 Bool_t hasIsotopesExtended);
0141 XMLNodePointer_t MatProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr, int z);
0142
0143
0144 XMLNodePointer_t OpticalSurfaceProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0145 XMLNodePointer_t BooSolid(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr, int num);
0146 XMLNodePointer_t Box(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0147 XMLNodePointer_t Paraboloid(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0148 XMLNodePointer_t Arb8(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0149 XMLNodePointer_t Tube(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0150 XMLNodePointer_t CutTube(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0151 XMLNodePointer_t Cone(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0152 XMLNodePointer_t ElCone(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0153 XMLNodePointer_t Trap(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0154 XMLNodePointer_t Trd(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0155 XMLNodePointer_t Polycone(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0156 XMLNodePointer_t Polyhedra(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0157 XMLNodePointer_t Sphere(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0158 XMLNodePointer_t Torus(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0159 XMLNodePointer_t Hype(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0160 XMLNodePointer_t Para(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0161 XMLNodePointer_t TwistTrap(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0162 XMLNodePointer_t ElTube(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0163 XMLNodePointer_t Orb(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0164 XMLNodePointer_t Xtru(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0165 XMLNodePointer_t Reflection(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0166 XMLNodePointer_t Ellipsoid(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0167 XMLNodePointer_t Tessellated(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0168 XMLNodePointer_t ScaledSolid(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0169
0170
0171 XMLNodePointer_t VolProcess(TXMLEngine *gdml, XMLNodePointer_t node);
0172 XMLNodePointer_t AssProcess(TXMLEngine *gdml, XMLNodePointer_t node);
0173 XMLNodePointer_t UsrProcess(TXMLEngine *gdml, XMLNodePointer_t node);
0174 XMLNodePointer_t SkinSurfaceProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0175 XMLNodePointer_t BorderSurfaceProcess(TXMLEngine *gdml, XMLNodePointer_t node, XMLAttrPointer_t attr);
0176 Int_t SetAxis(const char *axisString);
0177
0178
0179 XMLNodePointer_t TopProcess(TXMLEngine *gdml, XMLNodePointer_t node);
0180
0181
0182 TGeoTranslation *GetPosition(const char *name);
0183 TGeoRotation *GetRotation(const char *name);
0184 TGeoScale *GetScaleObj(const char *name);
0185 TGeoShape *GetSolid(const char *name);
0186 TGeoVolume *GetVolume(const char *name);
0187
0188 typedef TGDMMapHelper<TGeoTranslation> PosMap;
0189 typedef TGDMMapHelper<TGeoRotation> RotMap;
0190 typedef TGDMMapHelper<TGeoScale> SclMap;
0191 typedef TGDMMapHelper<TGeoElement> EleMap;
0192 typedef TGDMMapHelper<TGeoIsotope> IsoMap;
0193 typedef TGDMMapHelper<TGeoMaterial> MatMap;
0194 typedef TGDMMapHelper<TGeoMedium> MedMap;
0195 typedef TGDMMapHelper<TGeoMixture> MixMap;
0196
0197 typedef TGDMMapHelper<TGeoShape> SolMap;
0198 typedef TGDMMapHelper<TGeoVolume> VolMap;
0199 typedef TGDMMapHelper<TGeoNode> PvolMap;
0200 typedef TGDMMapHelper<TGDMLMatrix> MatrixMap;
0201 typedef TGDMMapHelper<TGDMLRefl> ReflSolidMap;
0202 typedef TGDMMapHelper<const char> FileMap;
0203 typedef std::map<std::string, std::string> ReflectionsMap;
0204 typedef std::map<std::string, std::string> ReflVolMap;
0205 typedef std::map<std::string, double> FracMap;
0206 typedef std::map<std::string, double> ConstMap;
0207
0208 PosMap fposmap;
0209 RotMap frotmap;
0210 SclMap fsclmap;
0211 IsoMap fisomap;
0212 EleMap felemap;
0213 MatMap fmatmap;
0214 MedMap fmedmap;
0215 MixMap fmixmap;
0216 SolMap fsolmap;
0217 VolMap fvolmap;
0218 PvolMap fpvolmap;
0219 ReflectionsMap freflectmap;
0220 ReflSolidMap freflsolidmap;
0221 ReflVolMap freflvolmap;
0222 FileMap ffilemap;
0223 ConstMap fconsts;
0224 MatrixMap fmatrices;
0225
0226 ClassDefOverride(TGDMLParse, 0)
0227 };
0228
0229 #endif