ROOT  6.06/09
Reference Guide
TGDMLWrite.h
Go to the documentation of this file.
1 // @(#)root/gdml:$Id$
2 // Author: Anton Pytel 15/9/2011
3 
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  *************************************************************************/
11 
12 #ifndef ROOT_TGDMLWRITE
13 #define ROOT_TGDMLWRITE
14 
15 #ifndef ROOT_TGeoMatrix
16 #include "TGeoMatrix.h"
17 #endif
18 
19 #ifndef ROOT_TXMLEngine
20 #include "TXMLEngine.h"
21 #endif
22 
23 #ifndef ROOT_TGeoVolume
24 #include "TGeoVolume.h"
25 #endif
26 
27 #ifndef ROOT_TGeoParaboloid
28 #include "TGeoParaboloid.h"
29 #endif
30 
31 #ifndef ROOT_TGeoSphere
32 #include "TGeoSphere.h"
33 #endif
34 
35 #ifndef ROOT_TGeoArb8
36 #include "TGeoArb8.h"
37 #endif
38 
39 #ifndef ROOT_TGeoCone
40 #include "TGeoCone.h"
41 #endif
42 
43 #ifndef ROOT_TGeoPara
44 #include "TGeoPara.h"
45 #endif
46 
47 #ifndef ROOT_TGeoTrd1
48 #include "TGeoTrd1.h"
49 #endif
50 
51 #ifndef ROOT_TGeoTrd2
52 #include "TGeoTrd2.h"
53 #endif
54 
55 #ifndef ROOT_TGeoTube
56 #include "TGeoTube.h"
57 #endif
58 
59 #ifndef ROOT_TGeoPcon
60 #include "TGeoPcon.h"
61 #endif
62 
63 #ifndef ROOT_TGeoTorus
64 #include "TGeoTorus.h"
65 #endif
66 
67 #ifndef ROOT_TGeoPgon
68 #include "TGeoPgon.h"
69 #endif
70 
71 #ifndef ROOT_TGeoXtru
72 #include "TGeoXtru.h"
73 #endif
74 
75 #ifndef ROOT_TGeoPgon
76 #include "TGeoPgon.h"
77 #endif
78 
79 #ifndef ROOT_TGeoEltu
80 #include "TGeoEltu.h"
81 #endif
82 
83 #ifndef ROOT_TGeoHype
84 #include "TGeoHype.h"
85 #endif
86 
87 #ifndef ROOT_TGeoBoolNode
88 #include "TGeoBoolNode.h"
89 #endif
90 
91 #ifndef ROOT_TGeoCompositeShape
92 #include "TGeoCompositeShape.h"
93 #endif
94 
95 #ifndef ROOT_TGeoScaledShape
96 #include "TGeoScaledShape.h"
97 #endif
98 
99 #include <map>
100 #include <vector>
101 #include <iostream>
102 
103 ////////////////////////////////////////////////////////////////////////////
104 // //
105 // TGDMLWrite - Class for exporting geometries From ROOT's gGeoManager //
106 // (instance of TGeoManager class) To GDML file. More about GDML //
107 // see http://gdml.web.cern.ch. //
108 // //
109 ////////////////////////////////////////////////////////////////////////////
110 
111 class TGDMLWrite : public TObject {
112 public:
113  TGDMLWrite();
114  virtual ~TGDMLWrite();
115 
116  static void StartGDMLWriting(TGeoManager * geomanager, const char* filename, TString option) {
117  //static function -
118  //options:
119  // g - set by default - geant4 compatibility
120  // f,n - if none of this two is set then naming convention is
121  // with incremental suffix, if "f" then suffix is pointer
122  // if "n" then there is no suffix, but uniqness of names
123  // is not secured.
125  writer->WriteGDMLfile(geomanager, filename, option);
126  delete writer;
127  }
128  //wrapper of all main methods for extraction
129  void WriteGDMLfile(TGeoManager * geomanager, const char* filename = "test.gdml", TString option = "");
130  enum ENamingType {
134  };
135  void SetNamingSpeed(ENamingType naming);
136  void SetG4Compatibility(Bool_t G4Compatible) {
137  fgG4Compatibility = G4Compatible;
138  };
139 
140 private:
141  struct Xyz {
145  };
146 
147  typedef std::map<TString, Bool_t> NameList;
148  typedef std::map<TString, TString> NameListS;
149  typedef std::map<TString, Int_t> NameListI;
150  typedef std::map<TString, Float_t> NameListF;
151  struct StructLst {
152  NameList fLst;
153  }; //to store pointers
154  struct NameLst {
155  NameListS fLst; //to map pointers with names
156  NameListI fLstIter; //to store all the iterators for repeating names
157  };
158 
159  //General lists
160  StructLst *fIsotopeList; //list of isotopes
161  StructLst *fElementList; //list of elements
162  StructLst *fAccPatt; //list of accepted patterns for division
163  StructLst *fRejShape; //list of rejected shapes
164 
165  NameLst *fNameList; //list of names (pointer mapped)
166 
167  //Data members
168  static TGDMLWrite *fgGDMLWrite; //pointer to gdml writer
169  Int_t fgNamingSpeed; //input option for volume and solid naming
170  Bool_t fgG4Compatibility; //input option for Geant4 compatibility
171  XMLDocPointer_t fGdmlFile; //pointer storing xml file
172  TString fTopVolumeName; //name of top volume
173  TXMLEngine *fGdmlE; //xml engine pointer
174 
175  XMLNodePointer_t fDefineNode; //main <define> node...
176  XMLNodePointer_t fMaterialsNode; //main <materials> node...
177  XMLNodePointer_t fSolidsNode; //main <solids> node...
178  XMLNodePointer_t fStructureNode; //main <structure> node...
179  Int_t fVolCnt; //count of volumes
180  Int_t fPhysVolCnt; //count of physical volumes
181  UInt_t fActNameErr; //count of name errors
182  UInt_t fSolCnt; //count of name solids
183 
184  static const UInt_t fgkProcBit = BIT(14); //14th bit is set when solid is processed
185  static const UInt_t fgkProcBitVol = BIT(19); //19th bit is set when volume is processed
186  static const UInt_t fgkMaxNameErr = 5; //maximum number of errors for naming
187 
188  //I. Methods processing the gGeoManager geometry object structure
189  //1. Main methods to extract everything from ROOT gGeoManager
190  XMLNodePointer_t ExtractMaterials(TList* materialsLst); //result <materials>...
191  TString ExtractSolid(TGeoShape* volShape); //adds <shape> to <solids>
192  void ExtractVolumes(TGeoVolume* volume); //result <volume> node... + corresp. shape
193 
194 
195  //1.1 Materials sub methods - creating Nodes
196  XMLNodePointer_t CreateAtomN(Double_t atom, const char * unit = "g/mole");
197  XMLNodePointer_t CreateDN(Double_t density, const char * unit = "g/cm3");
198  XMLNodePointer_t CreateFractionN(Double_t percentage, const char * refName);
199 
200  XMLNodePointer_t CreateIsotopN(TGeoIsotope * isotope, const char * name);
201  XMLNodePointer_t CreateElementN(TGeoElement * element, XMLNodePointer_t materials, const char * name);
204 
205 
206  //1.2 Solids sub methods
209 
232 
234 
235  //1.3 Volume sub methods
236  XMLNodePointer_t CreatePhysVolN(const char * name, Int_t copyno, const char * volref, const char * posref, const char * rotref, XMLNodePointer_t scaleN);
237  XMLNodePointer_t CreateDivisionN(Double_t offset, Double_t width, Int_t number, const char * axis, const char * unit, const char * volref);
238 
239  XMLNodePointer_t CreateSetupN(const char * topVolName , const char * name = "default", const char * version = "1.0");
240  XMLNodePointer_t StartVolumeN(const char * name, const char * solid, const char * material);
241  XMLNodePointer_t StartAssemblyN(const char * name);
242 
243 
244  //II. Utility methods
245  Xyz GetXYZangles(const Double_t * rotationMatrix);
246  //nodes to create position, rotation and similar types first-position/rotation...
247  XMLNodePointer_t CreatePositionN(const char * name, Xyz position, const char * type = "position", const char * unit = "cm");
248  XMLNodePointer_t CreateRotationN(const char * name, Xyz rotation, const char * type = "rotation", const char * unit = "deg");
249  TGeoCompositeShape* CreateFakeCtub(TGeoCtub * geoShape); //create fake cut tube as intersection
250 
251  //check name (2nd parameter) whether it is in the list (1st parameter)
252  Bool_t IsInList(NameList list, TString name2check);
253  TString GenName(TString oldname);
254  TString GenName(TString oldname, TString objPointer);
255  Bool_t CanProcess(TObject *pointer);
256  TString GetPattAxis(Int_t divAxis, const char * pattName, TString& unit);
257  Bool_t IsNullParam(Double_t parValue, TString parName, TString objName);
258  void UnsetTemporaryBits(TGeoManager * geoMng);
259 
260  ClassDef(TGDMLWrite, 0) //imports GDML using DOM and binds it to ROOT
261 };
262 
263 #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:651
XMLNodePointer_t CreateHypeN(TGeoHype *geoShape)
Creates "hype" node for GDML.
XMLNodePointer_t CreateFractionN(Double_t percentage, const char *refName)
Creates "fraction" node for GDML.
Definition: TGDMLWrite.cxx:563
XMLNodePointer_t CreateParaN(TGeoPara *geoShape)
Creates "para" node for GDML.
Definition: TGDMLWrite.cxx:883
XMLNodePointer_t fStructureNode
Definition: TGDMLWrite.h:178
XMLNodePointer_t StartVolumeN(const char *name, const char *solid, const char *material)
Creates "volume" node for GDML.
StructLst * fRejShape
Definition: TGDMLWrite.h:163
#define BIT(n)
Definition: Rtypes.h:120
TString ExtractSolid(TGeoShape *volShape)
Method creating solid to xml file and returning its name.
Definition: TGDMLWrite.cxx:363
static const char * filename()
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:704
Bool_t CanProcess(TObject *pointer)
Method which tests whether solids can be processed.
Basic string class.
Definition: TString.h:137
static TGDMLWrite * fgGDMLWrite
Definition: TGDMLWrite.h:168
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="")
Wrapper of all exporting methods Creates blank GDML file and fills it with gGeoManager structure conv...
Definition: TGDMLWrite.cxx:209
std::map< TString, Float_t > NameListF
Definition: TGDMLWrite.h:150
NameListI fLstIter
Definition: TGDMLWrite.h:156
XMLNodePointer_t CreateXtrusionN(TGeoXtru *geoShape)
Creates "xtru" node for GDML.
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.
XMLNodePointer_t CreateTwistedTrapN(TGeoGtra *geoShape)
Creates "twistedtrap" node for GDML.
Definition: TGDMLWrite.cxx:948
XMLDocPointer_t fGdmlFile
Definition: TGDMLWrite.h:171
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:799
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:833
#define ClassDef(name, id)
Definition: Rtypes.h:254
XMLNodePointer_t CreateTrapN(TGeoTrap *geoShape)
Creates "trap" node for GDML.
Definition: TGDMLWrite.cxx:903
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:574
void * XMLDocPointer_t
Definition: TXMLEngine.h:22
Int_t fPhysVolCnt
Definition: TGDMLWrite.h:180
XMLNodePointer_t ExtractMaterials(TList *materialsLst)
Method exporting materials.
Definition: TGDMLWrite.cxx:331
TXMLEngine * fGdmlE
Definition: TGDMLWrite.h:173
UInt_t fActNameErr
Definition: TGDMLWrite.h:181
virtual ~TGDMLWrite()
Destructor.
Definition: TGDMLWrite.cxx:185
void SetG4Compatibility(Bool_t G4Compatible)
Definition: TGDMLWrite.h:136
XMLNodePointer_t CreateEltubeN(TGeoEltu *geoShape)
Creates "eltube" node for GDML.
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:47
XMLNodePointer_t fDefineNode
Definition: TGDMLWrite.h:175
XMLNodePointer_t fSolidsNode
Definition: TGDMLWrite.h:177
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.
void SetNamingSpeed(ENamingType naming)
Set convetion of naming solids and volumes.
Definition: TGDMLWrite.cxx:199
XMLNodePointer_t CreateBoxN(TGeoBBox *geoShape)
Creates "box" node for GDML.
Definition: TGDMLWrite.cxx:734
std::map< TString, Bool_t > NameList
Definition: TGDMLWrite.h:147
XMLNodePointer_t CreatePolyconeN(TGeoPcon *geoShape)
Creates "polycone" node for GDML.
XMLNodePointer_t CreateParaboloidN(TGeoParaboloid *geoShape)
Creates "paraboloid" node for GDML.
Definition: TGDMLWrite.cxx:755
XMLNodePointer_t CreateTorusN(TGeoTorus *geoShape)
Creates "torus" node for GDML.
StructLst * fIsotopeList
Definition: TGDMLWrite.h:160
unsigned int UInt_t
Definition: RtypesCore.h:42
TGeoCompositeShape * CreateFakeCtub(TGeoCtub *geoShape)
Method creating cutTube as an intersection of tube and two boxes.
TString fTopVolumeName
Definition: TGDMLWrite.h:172
void * XMLNodePointer_t
Definition: TXMLEngine.h:19
Bool_t fgG4Compatibility
Definition: TGDMLWrite.h:170
TString GenName(TString oldname)
NCNAME basic restrictions Replace "$" character with empty character etc.
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.
double Double_t
Definition: RtypesCore.h:55
Int_t fVolCnt
Definition: TGDMLWrite.h:179
int type
Definition: TGX11.cxx:120
XMLNodePointer_t CreateTrdN(TGeoTrd1 *geoShape)
Creates "trd" node for GDML from object TGeoTrd1.
static const UInt_t fgkProcBitVol
Definition: TGDMLWrite.h:185
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:541
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
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:775
void ExtractVolumes(TGeoVolume *volume)
Method extracting geometry structure recursively.
Definition: TGDMLWrite.cxx:381
XMLNodePointer_t fMaterialsNode
Definition: TGDMLWrite.h:176
NameLst * fNameList
Definition: TGDMLWrite.h:165
XMLNodePointer_t CreateTubeN(TGeoTubeSeg *geoShape)
Creates "tube" node for GDML from object TGeoTubeSeg.
Int_t fgNamingSpeed
Definition: TGDMLWrite.h:169
StructLst * fElementList
Definition: TGDMLWrite.h:161
XMLNodePointer_t CreateDN(Double_t density, const char *unit="g/cm3")
Creates "D" density node for GDML.
Definition: TGDMLWrite.cxx:552
static const UInt_t fgkMaxNameErr
Definition: TGDMLWrite.h:186
XMLNodePointer_t CreateElementN(TGeoElement *element, XMLNodePointer_t materials, const char *name)
Creates "element" node for GDML element node and attribute.
Definition: TGDMLWrite.cxx:588
std::map< TString, TString > NameListS
Definition: TGDMLWrite.h:148
XMLNodePointer_t CreateCommonBoolN(TGeoCompositeShape *geoShape)
Creates common part of union intersection and subtraction nodes.
UInt_t fSolCnt
Definition: TGDMLWrite.h:182
std::map< TString, Int_t > NameListI
Definition: TGDMLWrite.h:149
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.
static void StartGDMLWriting(TGeoManager *geomanager, const char *filename, TString option)
Definition: TGDMLWrite.h:116
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:162
static const UInt_t fgkProcBit
Definition: TGDMLWrite.h:184
XMLNodePointer_t CreateCutTubeN(TGeoCtub *geoShape)
Creates "cutTube" node for GDML.