Links

Content Skeleton

This Page

Previous topic

GDML

Next topic

GDML Examination

Export GDML

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 ""

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

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

Perform Export creating 3.2M file

# --- GDML geometry export ---------------------------------
#
from GaussTools.GaussToolsConf import GiGaRunActionGDML
grag = GiGaRunActionGDML("GiGa.GiGaRunActionGDML")
giga = GiGa()
giga.RunAction = grag
#!/bin/sh
cd $ENV_HOME/geant4/geometry/gdml
nuwa.py -G $XMLDETDESCROOT/DDDB/dayabay.xml -n1 -m export



#!/usr/bin/env python
"""
Usage::

   cd ~/e/geant4/geometry/export
   nuwa.py -G $XMLDETDESCROOT/DDDB/dayabay.xml -n1 -m export 

   OR

   ~/e/geant4/geometry/export/export.sh


Based on opw/fmcpmuon.py from David Jaffe, 

* :dybsvn:`source:dybgaudi/trunk/Detector/XmlDetDesc/python/XmlDetDesc/dump_geo.py`


"""
import os
def configure(argv=None):
    
    #if argv:
    #    path = argv[0] 
    #else:   
    #    path = '/dd/Geometry'
    #
    #from XmlDetDescChecks.XmlDetDescChecksConf import XddDumpAlg
    #da = XddDumpAlg()
    #da.Paths = [path]

    sitevol = dict(DayaBay="/dd/Structure/Pool/db-ows", Lingao="/dd/Structure/Pool/la-ows", Far="/dd/Structure/Pool/far-ows",)
    site = 'DayaBay'
    volume = sitevol[site]

    import GaudiKernel.SystemOfUnits as units

    from GenTools.Helpers import HepEVT
    source =  os.path.join(os.path.dirname(os.path.abspath(__file__)), 'onemuon')
    hepevt = HepEVT(source)
    hepevt.positioner.Volume = volume
    hepevt.positioner.Mode = "Relative"
    hepevt.positioner.Position = [0,0,0]
    hepevt.timerator.LifeTime = 1*units.second
    hepevt.transformer.Volume = volume
    hepevt.transformer.Offset = [0., 0., (0.042)*units.meter]

    import GenTools
    wallTime = 0
    gt = GenTools.Configure(helper=hepevt)
    gt.generator.TimeStamp = int(wallTime)
    gt.generator.GenName = "Muon"


    # --- skip dumping particle properties ---------------------
    #
    from GiGa.GiGaConf import GiGa, GiGaRunManager
    giga = GiGa("GiGa")
    gigarm = GiGaRunManager("GiGa.GiGaMgr")
    gigarm.Verbosity = 2

    # --- geometry export ---------------------------------
    #
    from GaussTools.GaussToolsConf import GiGaRunActionGDML
    grag = GiGaRunActionGDML("GiGa.GiGaRunActionGDML")
    giga = GiGa()
    giga.RunAction = grag    
    #giga.VisManager = "GiGaVisManager/GiGaVis"
    # ---------------------------------------------------------
     
    import DetSim 
    DetSim.Configure(physlist=DetSim.physics_list_basic,site=site)

    #from Gaudi.Configuration import ApplicationMgr
    #app = ApplicationMgr()
    #app.TopAlg.append(da)


def run(app):
    pass
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
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gdml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd">

  <define/>

  <materials>
    <element Z="6" name="/dd/Materials/Carbon0xbe238a8">
      <atom unit="g/mole" value="12.0109936803044"/>
    </element>
    <element Z="1" name="/dd/Materials/Hydrogen0xbe22480">
      <atom unit="g/mole" value="1.00793946966331"/>
    </element>
    <material name="/dd/Materials/PPE0xbb80090" state="solid">
      <P unit="pascal" value="101324.946686941"/>
      <D unit="g/cm3" value="0.919999515933733"/>

[blyth@belle7 gdml]$ tail  -15 g4_00.gdml
      <materialref ref="/dd/Materials/Vacuum0xbe4e7d8"/>
      <solidref ref="WorldBox0xc9818a0"/>
      <physvol name="/dd/Structure/Sites/db-rock0xc982aa8">
        <volumeref ref="/dd/Geometry/Sites/lvNearSiteRock0xbb7d528"/>
        <position name="/dd/Structure/Sites/db-rock0xc982aa8_pos" unit="mm" x="-16519.9999999999" y="-802110" z="-2110"/>
        <rotation name="/dd/Structure/Sites/db-rock0xc982aa8_rot" unit="deg" x="0" y="0" z="-122.9"/>
      </physvol>
    </volume>
  </structure>

  <setup name="Default" version="1.0">
    <world ref="World0xc982758"/>
  </setup>

</gdml>

Obnoxious uniqing

3877     <volume name="/dd/Geometry/AD/lvLSO0xbe14900">
3878       <materialref ref="/dd/Materials/LiquidScintillator0xbf257f8"/>
3879       <solidref ref="lso0xbba9ff8"/>
3880       <physvol name="/dd/Geometry/AD/lvLSO#pvIAV0xbb2e4a8">
3881         <volumeref ref="/dd/Geometry/AD/lvIAV0xbe18188"/>
3882         <position name="/dd/Geometry/AD/lvLSO#pvIAV0xbb2e4a8_pos" unit="mm" x="0" y="0" z="2.5"/>
3883       </physvol>

$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

  1. physvol names are trucated to 99 chars
  2. names are sometimes but not always uniqued by appending pointer address
30017       <physvol name="/dd/Geometry/Pool/lvNearPoolOWS#pvNearUnistruts#pvNearHalfUnistruts:2#pvNearQuadCornerUnistrus:1#pv">
30018         <volumeref ref="/dd/Geometry/PoolDetails/lvCornerParRib20xbc9ee78"/>
30019         <position name="/dd/Geometry/Pool/lvNearPoolOWS#pvNearUnistruts#pvNearHalfUnistruts:2#pvNearQuadCornerUnistrus:1#pv" unit="mm" x="-5743.97485196094" y="-2743.97485196094" z="1944"/>
30020         <rotation name="/dd/Geometry/Pool/lvNearPoolOWS#pvNearUnistruts#pvNearHalfUnistruts:2#pvNearQuadCornerUnistrus:1#pv" unit="deg" x="0" y="0" z="-135"/>
30021       </physvol>

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:

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/