Logo ROOT   6.14/05
Reference Guide
Go to the documentation of this file.
1 // @(#)root/gdml:$Id$
2 // Author: Anton Pytel 15/9/2011
4 /*************************************************************************
5  * Copyright (C) 1995-2011, 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  *************************************************************************/
15 #include "TGeoMatrix.h"
16 #include "TXMLEngine.h"
17 #include "TGeoVolume.h"
18 #include "TGeoParaboloid.h"
19 #include "TGeoSphere.h"
20 #include "TGeoArb8.h"
21 #include "TGeoCone.h"
22 #include "TGeoPara.h"
23 #include "TGeoTrd1.h"
24 #include "TGeoTrd2.h"
25 #include "TGeoTube.h"
26 #include "TGeoPcon.h"
27 #include "TGeoTorus.h"
28 #include "TGeoPgon.h"
29 #include "TGeoXtru.h"
30 #include "TGeoPgon.h"
31 #include "TGeoEltu.h"
32 #include "TGeoHype.h"
33 #include "TGeoBoolNode.h"
34 #include "TGeoCompositeShape.h"
35 #include "TGeoScaledShape.h"
36 #include "TGeoManager.h"
38 #include <map>
39 #include <vector>
40 #include <iostream>
42 ////////////////////////////////////////////////////////////////////////////
43 // //
44 // TGDMLWrite - Class for exporting geometries From ROOT's gGeoManager //
45 // (instance of TGeoManager class) To GDML file. More about GDML //
46 // see http://gdml.web.cern.ch. //
47 // //
48 ////////////////////////////////////////////////////////////////////////////
50 class TGDMLWrite : public TObject {
51 public:
52  TGDMLWrite();
53  virtual ~TGDMLWrite();
55  static void StartGDMLWriting(TGeoManager * geomanager, const char* filename, TString option) {
56  //static function -
57  //options:
58  // g - set by default - geant4 compatibility
59  // f,n - if none of this two is set then naming convention is
60  // with incremental suffix, if "f" then suffix is pointer
61  // if "n" then there is no suffix, but uniqness of names
62  // is not secured.
65  writer->WriteGDMLfile(geomanager, filename, option);
66  delete writer;
67  }
68  //wrapper of all main methods for extraction
69  void WriteGDMLfile(TGeoManager * geomanager, const char* filename = "test.gdml", TString option = "");
70  // Wrapper to only selectively write one branch of the volume hierarchy to file
71  void WriteGDMLfile(TGeoManager * geomanager, TGeoVolume* volume, const char* filename = "test.gdml", TString option = "");
73  enum ENamingType {
77  };
78  void SetNamingSpeed(ENamingType naming);
79  void SetG4Compatibility(Bool_t G4Compatible) {
80  fgG4Compatibility = G4Compatible;
81  };
83 private:
84  struct Xyz {
88  };
90  typedef std::map<TString, Bool_t> NameList;
91  typedef std::map<TString, TString> NameListS;
92  typedef std::map<TString, Int_t> NameListI;
93  typedef std::map<TString, Float_t> NameListF;
94  struct StructLst {
95  NameList fLst;
96  }; //to store pointers
97  struct NameLst {
98  NameListS fLst; //to map pointers with names
99  NameListI fLstIter; //to store all the iterators for repeating names
100  };
102  //General lists
103  StructLst *fIsotopeList; //list of isotopes
104  StructLst *fElementList; //list of elements
105  StructLst *fAccPatt; //list of accepted patterns for division
106  StructLst *fRejShape; //list of rejected shapes
108  NameLst *fNameList; //list of names (pointer mapped)
110  //Data members
111  static TGDMLWrite *fgGDMLWrite; //pointer to gdml writer
112  Int_t fgNamingSpeed; //input option for volume and solid naming
113  Bool_t fgG4Compatibility; //input option for Geant4 compatibility
114  XMLDocPointer_t fGdmlFile; //pointer storing xml file
115  TString fTopVolumeName; //name of top volume
116  TXMLEngine *fGdmlE; //xml engine pointer
118  XMLNodePointer_t fDefineNode; //main <define> node...
119  XMLNodePointer_t fMaterialsNode; //main <materials> node...
120  XMLNodePointer_t fSolidsNode; //main <solids> node...
121  XMLNodePointer_t fStructureNode; //main <structure> node...
122  Int_t fVolCnt; //count of volumes
123  Int_t fPhysVolCnt; //count of physical volumes
124  UInt_t fActNameErr; //count of name errors
125  UInt_t fSolCnt; //count of name solids
126  UInt_t fFltPrecision; //! floating point precision when writing
128  static const UInt_t fgkProcBit = BIT(14); //14th bit is set when solid is processed
129  static const UInt_t fgkProcBitVol = BIT(19); //19th bit is set when volume is processed
130  static const UInt_t fgkMaxNameErr = 5; //maximum number of errors for naming
132  //I. Methods processing the gGeoManager geometry object structure
133  //1. Main methods to extract everything from ROOT gGeoManager
134  XMLNodePointer_t ExtractMaterials(TList* materialsLst); //result <materials>...
135  TString ExtractSolid(TGeoShape* volShape); //adds <shape> to <solids>
136  void ExtractVolumes(TGeoVolume* volume); //result <volume> node... + corresp. shape
138  // Combined implementation to extract GDML information from the geometry tree
139  void WriteGDMLfile(TGeoManager * geomanager, TGeoVolume* volume, TList* materialsLst, const char* filename, TString option);
141  //1.1 Materials sub methods - creating Nodes
142  XMLNodePointer_t CreateAtomN(Double_t atom, const char * unit = "g/mole");
143  XMLNodePointer_t CreateDN(Double_t density, const char * unit = "g/cm3");
144  XMLNodePointer_t CreateFractionN(Double_t percentage, const char * refName);
146  XMLNodePointer_t CreateIsotopN(TGeoIsotope * isotope, const char * name);
147  XMLNodePointer_t CreateElementN(TGeoElement * element, XMLNodePointer_t materials, const char * name);
152  //1.2 Solids sub methods
181  //1.3 Volume sub methods
182  XMLNodePointer_t CreatePhysVolN(const char * name, Int_t copyno, const char * volref, const char * posref, const char * rotref, XMLNodePointer_t scaleN);
183  XMLNodePointer_t CreateDivisionN(Double_t offset, Double_t width, Int_t number, const char * axis, const char * unit, const char * volref);
185  XMLNodePointer_t CreateSetupN(const char * topVolName , const char * name = "default", const char * version = "1.0");
186  XMLNodePointer_t StartVolumeN(const char * name, const char * solid, const char * material);
187  XMLNodePointer_t StartAssemblyN(const char * name);
190  //II. Utility methods
191  Xyz GetXYZangles(const Double_t * rotationMatrix);
192  //nodes to create position, rotation and similar types first-position/rotation...
193  XMLNodePointer_t CreatePositionN(const char * name, Xyz position, const char * type = "position", const char * unit = "cm");
194  XMLNodePointer_t CreateRotationN(const char * name, Xyz rotation, const char * type = "rotation", const char * unit = "deg");
195  TGeoCompositeShape* CreateFakeCtub(TGeoCtub * geoShape); //create fake cut tube as intersection
197  //check name (2nd parameter) whether it is in the list (1st parameter)
198  Bool_t IsInList(NameList list, TString name2check);
199  TString GenName(TString oldname);
200  TString GenName(TString oldname, TString objPointer);
201  Bool_t CanProcess(TObject *pointer);
202  TString GetPattAxis(Int_t divAxis, const char * pattName, TString& unit);
203  Bool_t IsNullParam(Double_t parValue, TString parName, TString objName);
204  void UnsetTemporaryBits(TGeoManager * geoMng);
206  void SetFltPrecision(UInt_t prec) { fFltPrecision = prec; }
208  ClassDef(TGDMLWrite, 0) //imports GDML using DOM and binds it to ROOT
209 };
211 #endif /* ROOT_TGDMLWRITE */
XMLNodePointer_t CreateMixtureN(TGeoMixture *mixture, XMLNodePointer_t materials, TString mname)
Creates "material" node for GDML with references to other sub elements.
Definition: TGDMLWrite.cxx:712
Mixtures of elements.
Definition: TGeoMaterial.h:134
Spherical shell class.
Definition: TGeoSphere.h:17
Cylindrical tube class.
Definition: TGeoTube.h:17
XMLNodePointer_t CreateHypeN(TGeoHype *geoShape)
Creates "hype" node for GDML.
The manager class for any TGeo geometry.
Definition: TGeoManager.h:38
This class contains implementation of converting ROOT&#39;s gGeoManager geometry to GDML file...
Definition: TGDMLWrite.h:50
Box class.
Definition: TGeoBBox.h:17
XMLNodePointer_t CreateFractionN(Double_t percentage, const char *refName)
Creates "fraction" node for GDML.
Definition: TGDMLWrite.cxx:623
Double_t z
Definition: TGDMLWrite.h:87
XMLNodePointer_t CreateParaN(TGeoPara *geoShape)
Creates "para" node for GDML.
Definition: TGDMLWrite.cxx:951
XMLNodePointer_t fStructureNode
Definition: TGDMLWrite.h:121
static TGDMLWrite * fgGDMLWrite
Definition: TGDMLWrite.h:111
Gtra is a twisted trapezoid.
Definition: TGeoArb8.h:143
XMLNodePointer_t StartVolumeN(const char *name, const char *solid, const char *material)
Creates "volume" node for GDML.
StructLst * fRejShape
Definition: TGDMLWrite.h:106
image html pict1_TGaxis_012 png width
Define new text attributes for the label number "labNum".
Definition: TGaxis.cxx:2551
A polycone.
Definition: TGeoPcon.h:17
A polygone.
Definition: TGeoPgon.h:19
#define BIT(n)
Definition: Rtypes.h:78
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition: TGeoVolume.h:48
TString ExtractSolid(TGeoShape *volShape)
Method creating solid to xml file and returning its name.
Definition: TGDMLWrite.cxx:420
Torus segment class.
Definition: TGeoTorus.h:17
void UnsetTemporaryBits(TGeoManager *geoMng)
Unsetting bits that were changed in gGeoManager during export so that export can be run more times wi...
XMLNodePointer_t CreateMaterialN(TGeoMaterial *material, TString mname)
Creates "material" node for GDML.
Definition: TGDMLWrite.cxx:765
Bool_t CanProcess(TObject *pointer)
Method which tests whether solids can be processed.
Basic string class.
Definition: TString.h:131
Base class describing materials.
Definition: TGeoMaterial.h:29
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
XMLNodePointer_t CreatePositionN(const char *name, Xyz position, const char *type="position", const char *unit="cm")
Creates "position" kind of node for GDML.
void WriteGDMLfile(TGeoManager *geomanager, const char *filename="test.gdml", TString option="")
Definition: TGDMLWrite.cxx:233
std::map< TString, Float_t > NameListF
Definition: TGDMLWrite.h:93
NameListI fLstIter
Definition: TGDMLWrite.h:99
XMLNodePointer_t CreateXtrusionN(TGeoXtru *geoShape)
Creates "xtru" node for GDML.
A shape scaled by a TGeoScale transformation.
Definition: writer.py:1
XMLNodePointer_t CreateEllipsoidN(TGeoCompositeShape *geoShape, TString elName)
Creates "ellipsoid" node for GDML this is a special case, because ellipsoid is not defined in ROOT so...
XMLNodePointer_t StartAssemblyN(const char *name)
Creates "assembly" node for GDML.
A trapezoid with only x length varying with z.
Definition: TGeoTrd1.h:17
Paraboloid class.
XMLNodePointer_t CreateTwistedTrapN(TGeoGtra *geoShape)
Creates "twistedtrap" node for GDML.
XMLDocPointer_t fGdmlFile
Definition: TGDMLWrite.h:114
XMLNodePointer_t CreateElConeN(TGeoScaledShape *geoShape)
Creates "elcone" (elliptical cone) node for GDML this is a special case, because elliptical cone is n...
XMLNodePointer_t CreateArb8N(TGeoArb8 *geoShape)
Creates "arb8" node for GDML.
Definition: TGDMLWrite.cxx:864
XMLNodePointer_t CreateZplaneN(Double_t z, Double_t rmin, Double_t rmax)
Creates "zplane" node for GDML.
XMLNodePointer_t CreateConeN(TGeoConeSeg *geoShape)
Creates "cone" node for GDML from TGeoConeSeg object.
Definition: TGDMLWrite.cxx:899
#define ClassDef(name, id)
Definition: Rtypes.h:320
A phi segment of a conical tube.
Definition: TGeoCone.h:98
XMLNodePointer_t CreateTrapN(TGeoTrap *geoShape)
Creates "trap" node for GDML.
Definition: TGDMLWrite.cxx:972
Bool_t IsInList(NameList list, TString name2check)
Checks whether name2check is in (NameList) list.
XMLNodePointer_t CreateIsotopN(TGeoIsotope *isotope, const char *name)
Creates "isotope" node for GDML.
Definition: TGDMLWrite.cxx:635
void * XMLDocPointer_t
Definition: TXMLEngine.h:20
Int_t fPhysVolCnt
Definition: TGDMLWrite.h:123
XMLNodePointer_t ExtractMaterials(TList *materialsLst)
Method exporting materials.
Definition: TGDMLWrite.cxx:388
TXMLEngine * fGdmlE
Definition: TGDMLWrite.h:116
UInt_t fActNameErr
Definition: TGDMLWrite.h:124
virtual ~TGDMLWrite()
Definition: TGDMLWrite.cxx:212
Base class for chemical elements.
Definition: TGeoElement.h:36
Default constructor.
Definition: TGDMLWrite.cxx:183
Double_t y
Definition: TGDMLWrite.h:86
TRAP is a general trapezoid, i.e.
Definition: TGeoArb8.h:89
void SetG4Compatibility(Bool_t G4Compatible)
Definition: TGDMLWrite.h:79
XMLNodePointer_t CreateEltubeN(TGeoEltu *geoShape)
Creates "eltube" node for GDML.
static UInt_t GetExportPrecision()
Definition: TGeoManager.h:457
Bool_t IsNullParam(Double_t parValue, TString parName, TString objName)
Check for null parameter to skip the NULL objects.
A doubly linked list.
Definition: TList.h:44
XMLNodePointer_t fDefineNode
Definition: TGDMLWrite.h:118
XMLNodePointer_t fSolidsNode
Definition: TGDMLWrite.h:120
Class handling Boolean composition of shapes.
A trapezoid with both x and y lengths varying with z.
Definition: TGeoTrd2.h:17
Parallelepiped class.
Definition: TGeoPara.h:17
Xyz GetXYZangles(const Double_t *rotationMatrix)
Retrieves X Y Z angles from rotation matrix.
XMLNodePointer_t CreatePhysVolN(const char *name, Int_t copyno, const char *volref, const char *posref, const char *rotref, XMLNodePointer_t scaleN)
Creates "physvol" node for GDML.
Base abstract class for all shapes.
Definition: TGeoShape.h:25
void SetNamingSpeed(ENamingType naming)
Set convention of naming solids and volumes.
Definition: TGDMLWrite.cxx:226
XMLNodePointer_t CreateBoxN(TGeoBBox *geoShape)
Creates "box" node for GDML.
Definition: TGDMLWrite.cxx:796
std::map< TString, Bool_t > NameList
Definition: TGDMLWrite.h:90
XMLNodePointer_t CreatePolyconeN(TGeoPcon *geoShape)
Creates "polycone" node for GDML.
XMLNodePointer_t CreateParaboloidN(TGeoParaboloid *geoShape)
Creates "paraboloid" node for GDML.
Definition: TGDMLWrite.cxx:818
XMLNodePointer_t CreateTorusN(TGeoTorus *geoShape)
Creates "torus" node for GDML.
StructLst * fIsotopeList
Definition: TGDMLWrite.h:103
unsigned int UInt_t
Definition: RtypesCore.h:42
Hyperboloid class defined by 5 parameters.
Definition: TGeoHype.h:17
TGeoCompositeShape * CreateFakeCtub(TGeoCtub *geoShape)
Method creating cutTube as an intersection of tube and two boxes.
TString fTopVolumeName
Definition: TGDMLWrite.h:115
void * XMLNodePointer_t
Definition: TXMLEngine.h:17
void SetFltPrecision(UInt_t prec)
Definition: TGDMLWrite.h:206
Bool_t fgG4Compatibility
Definition: TGDMLWrite.h:113
TString GenName(TString oldname)
NCNAME basic restrictions Replace "$" character with empty character etc.
UInt_t fFltPrecision
Definition: TGDMLWrite.h:126
A tube segment cut with 2 planes.
Definition: TGeoTube.h:168
XMLNodePointer_t CreateDivisionN(Double_t offset, Double_t width, Int_t number, const char *axis, const char *unit, const char *volref)
Creates "divisionvol" node for GDML.
An extrusion with fixed outline shape in x-y and a sequence of z extents (segments).
Definition: TGeoXtru.h:21
double Double_t
Definition: RtypesCore.h:55
Int_t fVolCnt
Definition: TGDMLWrite.h:122
int type
Definition: TGX11.cxx:120
Conical tube class.
Definition: TGeoCone.h:17
An arbitrary trapezoid with less than 8 vertices standing on two parallel planes perpendicular to Z a...
Definition: TGeoArb8.h:17
XMLNodePointer_t CreateTrdN(TGeoTrd1 *geoShape)
Creates "trd" node for GDML from object TGeoTrd1.
static const UInt_t fgkProcBitVol
Definition: TGDMLWrite.h:129
XMLNodePointer_t CreatePolyhedraN(TGeoPgon *geoShape)
Creates "polyhedra" node for GDML.
XMLNodePointer_t CreateAtomN(Double_t atom, const char *unit="g/mole")
Creates "atom" node for GDML.
Definition: TGDMLWrite.cxx:599
Mother of all ROOT objects.
Definition: TObject.h:37
XMLNodePointer_t ChooseObject(TGeoShape *geoShape)
Chooses the object and method that should be used for processing object.
XMLNodePointer_t CreateSphereN(TGeoSphere *geoShape)
Creates "sphere" node for GDML.
Definition: TGDMLWrite.cxx:839
void ExtractVolumes(TGeoVolume *volume)
Method extracting geometry structure recursively.
Definition: TGDMLWrite.cxx:438
XMLNodePointer_t fMaterialsNode
Definition: TGDMLWrite.h:119
Elliptical tube class.
Definition: TGeoEltu.h:17
UInt_t GetFltPrecision() const
Definition: TGDMLWrite.h:205
NameLst * fNameList
Definition: TGDMLWrite.h:108
XMLNodePointer_t CreateTubeN(TGeoTubeSeg *geoShape)
Creates "tube" node for GDML from object TGeoTubeSeg.
Int_t fgNamingSpeed
Definition: TGDMLWrite.h:112
StructLst * fElementList
Definition: TGDMLWrite.h:104
XMLNodePointer_t CreateDN(Double_t density, const char *unit="g/cm3")
Creates "D" density node for GDML.
Definition: TGDMLWrite.cxx:611
static const UInt_t fgkMaxNameErr
Definition: TGDMLWrite.h:130
XMLNodePointer_t CreateElementN(TGeoElement *element, XMLNodePointer_t materials, const char *name)
Creates "element" node for GDML element node and attribute.
Definition: TGDMLWrite.cxx:649
std::map< TString, TString > NameListS
Definition: TGDMLWrite.h:91
XMLNodePointer_t CreateCommonBoolN(TGeoCompositeShape *geoShape)
Creates common part of union intersection and subtraction nodes.
UInt_t fSolCnt
Definition: TGDMLWrite.h:125
Double_t x
Definition: TGDMLWrite.h:85
std::map< TString, Int_t > NameListI
Definition: TGDMLWrite.h:92
XMLNodePointer_t CreateSetupN(const char *topVolName, const char *name="default", const char *version="1.0")
Creates "setup" node for GDML.
TString GetPattAxis(Int_t divAxis, const char *pattName, TString &unit)
Method that retrieves axis and unit along which object is divided.
char name[80]
Definition: TGX11.cxx:109
static void StartGDMLWriting(TGeoManager *geomanager, const char *filename, TString option)
Definition: TGDMLWrite.h:55
XMLNodePointer_t CreateRotationN(const char *name, Xyz rotation, const char *type="rotation", const char *unit="deg")
Creates "rotation" kind of node for GDML.
StructLst * fAccPatt
Definition: TGDMLWrite.h:105
static const UInt_t fgkProcBit
floating point precision when writing
Definition: TGDMLWrite.h:128
XMLNodePointer_t CreateCutTubeN(TGeoCtub *geoShape)
Creates "cutTube" node for GDML.
A phi segment of a tube.
Definition: TGeoTube.h:88