Export GDML
=============
.. contents:: :local:
GDML is switched off in NuWa
-------------------------------
libG4gdml.so is built with geant4 if the switch is ON NuWa-trunk/lcgcmt/LCG_Builders/geant4/cmt/requirements::
90 set G4LIB_BUILD_GDML "1" \
91 dayabay ""
92
93 set G4LIB_USE_GDML "1" \
94 dayabay ""
.. _gdml_build:
Geant4 level manual GDML build
---------------------------------
::
[blyth@belle7 dyb]$ cd $DYB/external/build/LCG/geant4.9.2.p01/source/persistency/gdml
[blyth@belle7 gdml]$ make CLHEP_BASE_DIR=$DYB/external/clhep/2.0.4.2/i686-slc5-gcc41-dbg G4SYSTEM=Linux-g++ G4LIB_BUILD_SHARED=1 G4LIB_BUILD_GDML=1 G4LIB_USE_GDML=1 XERCESCROOT=$DYB/external/XercesC/2.8.0/i686-slc5-gcc41-dbg
Making dependency for file src/G4GDMLWriteStructure.cc ...
Making dependency for file src/G4GDMLWriteSolids.cc ...
Making dependency for file src/G4GDMLWriteSetup.cc ...
...
Compiling G4GDMLWriteSetup.cc ...
Compiling G4GDMLWriteSolids.cc ...
Compiling G4GDMLWriteStructure.cc ...
Compiling G4STRead.cc ...
Creating shared library ../../../lib/Linux-g++/libG4gdml.so ...
Subsequent Geant4Py build misses libG4persistency
---------------------------------------------------
Need to invoke the global target to make that::
[blyth@belle7 ~]$ cd $DYB/external/build/LCG/geant4.9.2.p01/source/persistency/
[blyth@belle7 persistency]$ vi ../../config/globlib.gmk
[blyth@belle7 persistency]$ make CLHEP_BASE_DIR=$DYB/external/clhep/2.0.4.2/i686-slc5-gcc41-dbg G4SYSTEM=Linux-g++ G4LIB_BUILD_SHARED=1 G4LIB_BUILD_GDML=1 G4LIB_USE_GDML=1 XERCESCROOT=$DYB/external/XercesC/2.8.0/i686-slc5-gcc41-dbg global
Nothing to be done for libG4persistency in mctruth/.
Nothing to be done for libG4persistency in ascii/.
Nothing to be done for libG4persistency in gdml/.
Creating global shared library ../../lib/Linux-g++/libG4persistency.so ...
[blyth@belle7 persistency]$
Manual install::
.. _gdml_install:
GDML Manual Install lib and includes
-------------------------------------
::
[blyth@belle7 gdml]$ cp ../../../lib/Linux-g++/libG4gdml.so $DYB/NuWa-trunk/../external/geant4/4.9.2.p01/i686-slc5-gcc41-dbg/lib/libG4gdml.so
[blyth@belle7 gdml]$ l $DYB/external/geant4/4.9.2.p01/i686-slc5-gcc41-dbg/include/G4ST*
-rw-r--r-- 1 blyth blyth 2249 Mar 16 2009 /data1/env/local/dyb/external/geant4/4.9.2.p01/i686-slc5-gcc41-dbg/include/G4STEPEntity.hh
[blyth@belle7 gdml]$ l $DYB/external/geant4/4.9.2.p01/i686-slc5-gcc41-dbg/include/G4GDML*
ls: /data1/env/local/dyb/external/geant4/4.9.2.p01/i686-slc5-gcc41-dbg/include/G4GDML*: No such file or directory
[blyth@belle7 gdml]$ cp include/* $DYB/external/geant4/4.9.2.p01/i686-slc5-gcc41-dbg/include/
GDML via GiGa
--------------
* :google:`geant4 giga gdml`
* http://svn.cern.ch/guest/lhcb/Gauss/trunk/Sim/LbGDML/options/GDMLWriter.opts
* http://svn.cern.ch/guest/lhcb/packages/trunk/Sim/GDMLG4Writer/src/GDMLRunAction.cpp
Find something relevant. API has changed, but principal is the same. Mostly GiGa glue code.
::
[blyth@belle7 NuWa-trunk]$ find . -name '*.cpp' -exec grep -l RunAction {} \;
./lhcb/Sim/GaussTools/src/Components/GiGaRunActionCommand.cpp
./lhcb/Sim/GaussTools/src/Components/TrCutsRunAction.cpp
./lhcb/Sim/GaussTools/src/Components/GaussTools_load.cpp
./lhcb/Sim/GaussTools/src/Components/GiGaRunActionSequence.cpp
./lhcb/Sim/GiGa/src/Lib/GiGaInterfaces.cpp
./lhcb/Sim/GiGa/src/Lib/GiGaRunActionBase.cpp
./lhcb/Sim/GiGa/src/component/GiGa.cpp
./lhcb/Sim/GiGa/src/component/GiGaRunManagerInterface.cpp
./lhcb/Sim/GiGa/src/component/GiGaIGiGaSetUpSvc.cpp
./lhcb/Sim/GiGa/src/component/GiGaRunManager.cpp
[blyth@belle7 NuWa-trunk]$
Identify something similar `lhcb/Sim/GaussTools/src/Components/GiGaRunActionCommand.cpp`
to base `GiGaRunActionGDML` upon and piggyback the CMT controlled build, from::
[blyth@belle7 cmt]$ pwd
/data1/env/local/dyb/NuWa-trunk/lhcb/Sim/GaussTools/cmt
.. _gdml_export:
Perform Export creating 3.2M file
--------------------------------------
::
# --- GDML geometry export ---------------------------------
#
from GaussTools.GaussToolsConf import GiGaRunActionGDML
grag = GiGaRunActionGDML("GiGa.GiGaRunActionGDML")
giga = GiGa()
giga.RunAction = grag
.. literalinclude:: export.sh
.. literalinclude:: export.py
::
GiGaRunActionGDML::BeginOfRunAction writing to
G4GDML: Writing 'g4_00.gdml'...
G4GDML: Writing definitions...
G4GDML: Writing materials...
G4GDML: Writing solids...
G4GDML: Writing structure...
G4GDML: Writing setup...
G4GDML: Writing 'g4_00.gdml' done !
Start Run processing.
Perform the export::
[blyth@belle7 gdml]$ cd ~/e/geant4/geometry/gdml
[blyth@belle7 gdml]$ fenv
[blyth@belle7 gdml]$ ./export.sh
Cursory Look
-------------
::
[blyth@belle7 gdml]$ du -h g4_00.gdml
3.2M g4_00.gdml
[blyth@belle7 gdml]$ wc -l g4_00.gdml
30946 g4_00.gdml
[blyth@belle7 gdml]$ head -15 g4_00.gdml
[blyth@belle7 gdml]$ tail -15 g4_00.gdml
Obnoxious uniqing
~~~~~~~~~~~~~~~~~~~~
::
3877
3878
3879
3880
3881
3882
3883
$DYB/external/build/LCG/geant4.9.2.p01/examples/extended/persistency/gdml/G02/src/DetectorConstruction.cc::
156 // OPTION: SETTING ADDITION OF POINTER TO NAME TO FALSE
157 //
158 // By default, written names in GDML consist of the given name with
159 // appended the pointer reference to it, in order to make it unique.
160 // Naming policy can be changed by using the following method, or
161 // calling Write with additional Boolean argument to "false".
162 // NOTE: you have to be sure not to have duplication of names in your
163 // Geometry Setup.
164 //
165 // parser.SetAddPointerToName(false);
166 //
167 // or
168 //
169 // parser.Write(fWriteFile, fWorldPhysVol, false);
170
Annoying physvol name truncation + uniqing
---------------------------------------------
#. physvol names are trucated to 99 chars
#. names are sometimes but not always uniqued by appending pointer address
::
30017
30018
30019
30020
30021
Yep traversing the gdml and dumping physvol names, confirms the truncation::
71 /dd/Geometry/AdDetails/lvCtrLsoOflInOil#pvCtrGdsOflTfbInLsoOfl0xbe03178
68 /dd/Geometry/AdDetails/lvOcrGdsTfbInLsoOfl#pvOcrGdsInLsoOfl0xbadf408
66 /dd/Geometry/AdDetails/lvOcrGdsLsoOfl#pvOcrGdsTfbInLsoOfl0xbb77f40
82 /dd/Geometry/CalibrationSources/lvWallLedSourceAssy#pvWallLedDiffuserBall0xc065178
80 /dd/Geometry/CalibrationSources/lvWallLedSourceAssy#pvWallLedAcrylicRod0xbd92aa0
36 /dd/Geometry/AD/lvOIL#pvOAV0xbf66370
99 /dd/Geometry/AD/lvOIL#pvAdPmtArray#pvAdPmtArrayRotated#pvAdPmtRingInCyl:1#pvAdPmtInRing:1#pvAdPmtUn
99 /dd/Geometry/AD/lvOIL#pvAdPmtArray#pvAdPmtArrayRotated#pvAdPmtRingInCyl:1#pvAdPmtInRing:1#pvAdPmtUn
99 /dd/Geometry/AD/lvOIL#pvAdPmtArray#pvAdPmtArrayRotated#pvAdPmtRingInCyl:1#pvAdPmtInRing:2#pvAdPmtUn
99 /dd/Geometry/AD/lvOIL#pvAdPmtArray#pvAdPmtArrayRotated#pvAdPmtRingInCyl:1#pvAdPmtInRing:2#pvAdPmtUn
99 /dd/Geometry/AD/lvOIL#pvAdPmtArray#pvAdPmtArrayRotated#pvAdPmtRingInCyl:1#pvAdPmtInRing:3#pvAdPmtUn
99 /dd/Geometry/AD/lvOIL#pvAdPmtArray#pvAdPmtArrayRotated#pvAdPmtRingInCyl:1#pvAdPmtInRing:3#pvAdPmtUn
Compare against the shape shapes from the VRML2FILE export::
sqlite> select name,length(name) from shape where name like '/dd/Geometry/Pool/lvNearPoolOWS#pvNearUnistruts#pvNearHalfUnistruts:2#pvNearQuadCornerUnistrus:1#pv%' ;
name length(name)
--------------------------------------------------------------------------------------------- ------------
/dd/Geometry/Pool/lvNearPoolOWS#pvNearUnistruts#pvNearHalfUnistruts:2#pvNearQuadCornerUnistrus:1#pvCornerUnistrut1#pvBotCornerLinerParRib1.2 140
/dd/Geometry/Pool/lvNearPoolOWS#pvNearUnistruts#pvNearHalfUnistruts:2#pvNearQuadCornerUnistrus:1#pvCornerUnistrut1#pvBotCornerLinerParRib2.2 140
/dd/Geometry/Pool/lvNearPoolOWS#pvNearUnistruts#pvNearHalfUnistruts:2#pvNearQuadCornerUnistrus:1#pvCornerUnistrut1#pvBotCornerCurtainParRib1.2 142
/dd/Geometry/Pool/lvNearPoolOWS#pvNearUnistruts#pvNearHalfUnistruts:2#pvNearQuadCornerUnistrus:1#pvCornerUnistrut1#pvBotCornerCurtainParRib2.2 142
/dd/Geometry/Pool/lvNearPoolOWS#pvNearUnistruts#pvNearHalfUnistruts:2#pvNearQuadCornerUnistrus:1#pvCornerUnistrut1#pvBotCornerLinerVerRib1.2 140
/dd/Geometry/Pool/lvNearPoolOWS#pvNearUnistruts#pvNearHalfUnistruts:2#pvNearQuadCornerUnistrus:1#pvCornerUnistrut1#pvBotCornerLinerVerRib2.2 140
/dd/Geometry/Pool/lvNearPoolOWS#pvNearUnistruts#pvNearHalfUnistruts:2#pvNearQuadCornerUnistrus:1#pvCornerUnistrut1#pvBotCornerCurtainVerRib1#pvBotVertiRibUnit.2 160
/dd/Geometry/Pool/lvNearPoolOWS#pvNearUnistruts#pvNearHalfUnistruts:2#pvNearQuadCornerUnistrus:1#pvCornerUnistrut1#pvBotCornerCurtainVerRib2#pvBotVertiRibUnit.2 160
/dd/Geometry/Pool/lvNearPoolOWS#pvNearUnistruts#pvNearHalfUnistruts:2#pvNearQuadCornerUnistrus:1#pvCornerUnistrut1#pvBotCornerLinerVerRib0.2 140
Hunt the truncation::
[blyth@cms01 src]$ pwd
/data/env/local/dyb/trunk/external/build/LCG/geant4.9.2.p01/source/persistency/gdml/src
[blyth@cms01 src]$ grep 99 *.*
G4GDMLWrite.cc: xercesc::XMLString::transcode(name,tempStr,99);
G4GDMLWrite.cc: xercesc::XMLString::transcode(value,tempStr,99);
G4GDMLWrite.cc: xercesc::XMLString::transcode(name,tempStr,99);
G4GDMLWrite.cc: xercesc::XMLString::transcode(str,tempStr,99);
G4GDMLWrite.cc: xercesc::XMLString::transcode(name,tempStr,99);
G4GDMLWrite.cc: xercesc::XMLString::transcode("LS", tempStr, 99);
G4GDMLWrite.cc: xercesc::XMLString::transcode("Range", tempStr, 99);
G4GDMLWrite.cc: xercesc::XMLString::transcode("gdml", tempStr, 99);
[blyth@cms01 src]$
Rebuild GDML with simple fix
-----------------------------
::
[blyth@belle7 gdml]$ cd $DYB/external/build/LCG/geant4.9.2.p01/source/persistency/gdml/src
[blyth@belle7 src]$ vi ../include/G4GDMLWrite.hh
::
099 private:
100
101 static G4bool addPointerToName;
102 xercesc::DOMDocument* doc;
103 //XMLCh tempStr[100];
const static int tempStrSize = 256;
XMLCh tempStr[tempStrSize];
104
105 };
::
80 xercesc::XMLString::transcode(name,tempStr,99);
:.,$s,99,tempStrSize-1,gc
Repeat the above steps:
* :ref:`gdml_build`
* :ref:`gdml_install`
* :ref:`gdml_export`
Confirm the fix
------------------
::
[blyth@belle7 gdml]$ du -hs g4_00.gdml
4.0M g4_00.gdml
[blyth@belle7 gdml]$ mv g4_00.gdml $LOCAL_BASE/env/geant4/geometry/gdml/g4_01.gdml
Address uniqing causes too many diffs.
::
simon:gdml blyth$ scp N:/data1/env/local/env/geant4/geometry/gdml/g4_01.gdml $LOCAL_BASE/env/geant4/geometry/gdml/