Warning, file /include/root/TGDMLWrite.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TGDMLWRITE
0013 #define ROOT_TGDMLWRITE
0014
0015 #include "TGeoMatrix.h"
0016 #include "TGeoElement.h"
0017 #include "TXMLEngine.h"
0018 #include "TGeoVolume.h"
0019 #include "TGeoParaboloid.h"
0020 #include "TGeoSphere.h"
0021 #include "TGeoArb8.h"
0022 #include "TGeoCone.h"
0023 #include "TGeoPara.h"
0024 #include "TGeoTrd1.h"
0025 #include "TGeoTrd2.h"
0026 #include "TGeoTube.h"
0027 #include "TGeoPcon.h"
0028 #include "TGeoTorus.h"
0029 #include "TGeoPgon.h"
0030 #include "TGeoXtru.h"
0031 #include "TGeoEltu.h"
0032 #include "TGeoHype.h"
0033 #include "TGeoBoolNode.h"
0034 #include "TGeoCompositeShape.h"
0035 #include "TGeoScaledShape.h"
0036 #include "TGeoTessellated.h"
0037 #include "TGeoManager.h"
0038 #include "TGDMLMatrix.h"
0039
0040 #include <map>
0041 #include <set>
0042 #include <iostream>
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 class TGeoOpticalSurface;
0053 class TGeoSkinSurface;
0054 class TGeoBorderSurface;
0055
0056 class TGDMLWrite : public TObject {
0057 public:
0058 TGDMLWrite();
0059 ~TGDMLWrite() override;
0060
0061 static void StartGDMLWriting(TGeoManager *geomanager, const char *filename, TString option)
0062 {
0063
0064
0065
0066
0067
0068
0069
0070 TGDMLWrite *writer = new TGDMLWrite;
0071 writer->WriteGDMLfile(geomanager, filename, option);
0072 delete writer;
0073 }
0074
0075 void WriteGDMLfile(TGeoManager *geomanager, const char *filename = "test.gdml", TString option = "");
0076
0077 void
0078 WriteGDMLfile(TGeoManager *geomanager, TGeoNode *top_node, const char *filename = "test.gdml", TString option = "");
0079
0080 enum ENamingType { kelegantButSlow = 0, kwithoutSufixNotUniq = 1, kfastButUglySufix = 2 };
0081 void SetNamingSpeed(ENamingType naming);
0082
0083 void SetIgnoreDummyMaterial(bool value);
0084 void SetG4Compatibility(Bool_t G4Compatible) { fgG4Compatibility = G4Compatible; };
0085
0086 private:
0087 struct Xyz {
0088 Double_t x;
0089 Double_t y;
0090 Double_t z;
0091 };
0092
0093 typedef std::set<const TGeoOpticalSurface *> SurfaceList;
0094 typedef std::set<const TGeoVolume *> VolList;
0095 typedef std::set<const TGeoNode *> NodeList;
0096 typedef std::map<TString, Bool_t> NameList;
0097 typedef std::map<TString, TString> NameListS;
0098 typedef std::map<TString, Int_t> NameListI;
0099 typedef std::map<TString, Float_t> NameListF;
0100 struct StructLst {
0101 NameList fLst;
0102 };
0103 struct NameLst {
0104 NameListS fLst;
0105 NameListI fLstIter;
0106 };
0107
0108
0109 StructLst *fIsotopeList;
0110 StructLst *fElementList;
0111 StructLst *fAccPatt;
0112 StructLst *fRejShape;
0113 SurfaceList fSurfaceList;
0114 VolList fVolumeList;
0115 NodeList fNodeList;
0116
0117 NameLst *fNameList;
0118
0119
0120 static TGDMLWrite *fgGDMLWrite;
0121 Int_t fgNamingSpeed;
0122 Int_t fIgnoreDummyMaterial;
0123 Bool_t fgG4Compatibility;
0124 XMLDocPointer_t fGdmlFile;
0125 TString fDefault_lunit;
0126 TString fTopVolumeName;
0127 TGeoVolume *fTopVolume = nullptr;
0128 TXMLEngine *fGdmlE;
0129
0130 XMLNodePointer_t fDefineNode;
0131 XMLNodePointer_t fMaterialsNode;
0132 XMLNodePointer_t fSolidsNode;
0133 XMLNodePointer_t fStructureNode;
0134 Int_t fVolCnt;
0135 Int_t fPhysVolCnt;
0136 UInt_t fActNameErr;
0137 UInt_t fSolCnt;
0138 UInt_t fFltPrecision;
0139
0140 static const UInt_t fgkProcBit = BIT(14);
0141 static const UInt_t fgkProcBitVol = BIT(19);
0142 static const UInt_t fgkMaxNameErr = 5;
0143
0144
0145
0146 XMLNodePointer_t ExtractMaterials(TList *materialsLst);
0147 TString ExtractSolid(TGeoShape *volShape);
0148 void ExtractVolumes(TGeoNode *topNode);
0149 void ExtractMatrices(TObjArray *matrices);
0150 void ExtractConstants(TGeoManager *geom);
0151 void ExtractOpticalSurfaces(TObjArray *surfaces);
0152 void ExtractSkinSurfaces(TObjArray *surfaces);
0153 void ExtractBorderSurfaces(TObjArray *surfaces);
0154
0155
0156 void WriteGDMLfile(TGeoManager *geomanager, TGeoNode *top_node, TList *materialsLst, const char *filename,
0157 TString option);
0158
0159
0160 XMLNodePointer_t CreateAtomN(Double_t atom, const char *unit = "g/mole");
0161 XMLNodePointer_t CreateDN(Double_t density, const char *unit = "g/cm3");
0162 XMLNodePointer_t CreateFractionN(Double_t percentage, const char *refName);
0163 XMLNodePointer_t CreatePropertyN(TNamed const &property);
0164
0165 XMLNodePointer_t CreateIsotopN(TGeoIsotope *isotope, const char *name);
0166 XMLNodePointer_t CreateElementN(TGeoElement *element, XMLNodePointer_t materials, const char *name);
0167 XMLNodePointer_t CreateMixtureN(TGeoMixture *mixture, XMLNodePointer_t materials, TString mname);
0168 XMLNodePointer_t CreateMaterialN(TGeoMaterial *material, TString mname);
0169
0170
0171 XMLNodePointer_t ChooseObject(TGeoShape *geoShape);
0172 XMLNodePointer_t CreateZplaneN(Double_t z, Double_t rmin, Double_t rmax);
0173
0174 XMLNodePointer_t CreateBoxN(TGeoBBox *geoShape);
0175 XMLNodePointer_t CreateParaboloidN(TGeoParaboloid *geoShape);
0176 XMLNodePointer_t CreateSphereN(TGeoSphere *geoShape);
0177 XMLNodePointer_t CreateArb8N(TGeoArb8 *geoShape);
0178 XMLNodePointer_t CreateConeN(TGeoConeSeg *geoShape);
0179 XMLNodePointer_t CreateConeN(TGeoCone *geoShape);
0180 XMLNodePointer_t CreateParaN(TGeoPara *geoShape);
0181 XMLNodePointer_t CreateTrapN(TGeoTrap *geoShape);
0182 XMLNodePointer_t CreateTwistedTrapN(TGeoGtra *geoShape);
0183 XMLNodePointer_t CreateTrdN(TGeoTrd1 *geoShape);
0184 XMLNodePointer_t CreateTrdN(TGeoTrd2 *geoShape);
0185 XMLNodePointer_t CreateTubeN(TGeoTubeSeg *geoShape);
0186 XMLNodePointer_t CreateCutTubeN(TGeoCtub *geoShape);
0187 XMLNodePointer_t CreateTubeN(TGeoTube *geoShape);
0188 XMLNodePointer_t CreatePolyconeN(TGeoPcon *geoShape);
0189 XMLNodePointer_t CreateTorusN(TGeoTorus *geoShape);
0190 XMLNodePointer_t CreatePolyhedraN(TGeoPgon *geoShape);
0191 XMLNodePointer_t CreateEltubeN(TGeoEltu *geoShape);
0192 XMLNodePointer_t CreateHypeN(TGeoHype *geoShape);
0193 XMLNodePointer_t CreateXtrusionN(TGeoXtru *geoShape);
0194 XMLNodePointer_t CreateEllipsoidN(TGeoCompositeShape *geoShape, TString elName);
0195 XMLNodePointer_t CreateElConeN(TGeoScaledShape *geoShape);
0196 XMLNodePointer_t CreateScaledN(TGeoScaledShape *geoShape);
0197 XMLNodePointer_t CreateTessellatedN(TGeoTessellated *geoShape);
0198 XMLNodePointer_t CreateOpticalSurfaceN(TGeoOpticalSurface *geoSurf);
0199 XMLNodePointer_t CreateSkinSurfaceN(TGeoSkinSurface *geoSurf);
0200 XMLNodePointer_t CreateBorderSurfaceN(TGeoBorderSurface *geoSurf);
0201
0202 XMLNodePointer_t CreateCommonBoolN(TGeoCompositeShape *geoShape);
0203
0204
0205 XMLNodePointer_t CreatePhysVolN(const char *name, Int_t copyno, const char *volref, const char *posref,
0206 const char *rotref, XMLNodePointer_t scaleN);
0207 XMLNodePointer_t CreateDivisionN(Double_t offset, Double_t width, Int_t number, const char *axis, const char *unit,
0208 const char *volref);
0209
0210 XMLNodePointer_t CreateSetupN(const char *topVolName, const char *name = "default", const char *version = "1.0");
0211 XMLNodePointer_t StartVolumeN(const char *name, const char *solid, const char *material);
0212 XMLNodePointer_t StartAssemblyN(const char *name);
0213
0214
0215 Xyz GetXYZangles(const Double_t *rotationMatrix);
0216
0217 XMLNodePointer_t CreatePositionN(const char *name, Xyz position, const char *type, const char *unit);
0218 XMLNodePointer_t
0219 CreateRotationN(const char *name, Xyz rotation, const char *type = "rotation", const char *unit = "deg");
0220 XMLNodePointer_t CreateMatrixN(TGDMLMatrix const *matrix);
0221 XMLNodePointer_t CreateConstantN(const char *name, Double_t value);
0222 TGeoCompositeShape *CreateFakeCtub(TGeoCtub *geoShape);
0223
0224
0225 Bool_t IsInList(NameList list, TString name2check);
0226 TString GenName(TString oldname);
0227 TString GenName(TString oldname, TString objPointer);
0228 Bool_t CanProcess(TObject *pointer);
0229 TString GetPattAxis(Int_t divAxis, const char *pattName, TString &unit);
0230 Bool_t IsNullParam(Double_t parValue, TString parName, TString objName);
0231 void UnsetTemporaryBits(TGeoManager *geoMng);
0232 UInt_t GetFltPrecision() const { return fFltPrecision; }
0233 void SetFltPrecision(UInt_t prec) { fFltPrecision = prec; }
0234
0235
0236
0237
0238
0239
0240 public:
0241
0242 void
0243 WriteGDMLfile(TGeoManager *geomanager, TGeoVolume *top_vol, const char *filename = "test.gdml", TString option = "");
0244
0245 private:
0246
0247
0248 void WriteGDMLfile(TGeoManager *geomanager, TGeoVolume *top_vol, TList *materialsLst, const char *filename,
0249 TString option);
0250 void ExtractVolumes(TGeoVolume *topVolume);
0251
0252 ClassDefOverride(TGDMLWrite, 0)
0253 };
0254
0255 #endif