Problem 2342

Summary: MultiUnion (and Assembly) write to GDML creates degenerate names breaking reloading
Product: Geant4 Reporter: Laurie Nevay <laurie.nevay>
Component: persistency/gdmlAssignee: Witold.Pokorski
Status: RESOLVED FIXED    
Severity: major    
Priority: P4    
Version: 10.7   
Hardware: All   
OS: All   
Attachments: Patch file from diff -Nru for fix

Description Laurie Nevay 2021-03-03 19:18:26 CET
Created attachment 679 [details]
Patch file from diff -Nru for fix

When writing out my world volume to GDML, I tried to visualise it again and realised bits were missing and it was wrong.  I also get an incredible amount of warnings from the GDML validation (note, this is just write out, read in again using G4GDMLParser).

Inspecting the GDML produced at one of the warning lines, there's an obvious flaw in it. Each node position is given the same name but are actually different positions.  I know from painful experience that degenerate names aren't allowed and you'll just get the previously defined object by that name.

```
 <multiUnion name="R33_zone2_munion_aae1c95afa17e4cd6ac3c042130359ba70x7fe3e07dd4c0">
      <multiUnionNode name="Node-1">
        <solid ref="UJ16PB_e0x7fe3e04ea4a0"/>
        <position name="R33_zone2_munion_aae1c95afa17e4cd6ac3c042130359ba70x7fe3e07dd4c0_pos" unit="mm" x="0" y="4499.99999989989" z="-360475.402579756"/>
      </multiUnionNode>
      <multiUnionNode name="Node-2">
        <solid ref="B46_e0x7fe3e04ef060"/>
        <position name="R33_zone2_munion_aae1c95afa17e4cd6ac3c042130359ba70x7fe3e07dd4c0_pos" unit="mm" x="-4100" y="50" z="48880.0000000008"/>
      </multiUnionNode>
```

Looking at source/persistency/gdml/src/G4GDMLWriteSolids.cc :: MultiUnionWrite around line 91 and 115, we see indeed the variable "name" is used for every node position. I think this should be a combination of that name (of the multiunion) + the node name so it's unique.

Also, the node objects themselves are not treated in the scope of that multiunion - I surmise by the warnings that they're not unique.

```
G4GDML: VALIDATION ERROR! ID value 'R2_zone0_munion_acb9882e2368846879dde37a21252c06c0x7fe3e0c1a4b0_pos' is not unique at line: 836
G4GDML: VALIDATION ERROR! ID value 'R2_zone0_munion_acb9882e2368846879dde37a21252c06c0x7fe3e0c1a4b0_pos' is not unique at line: 840
G4GDML: VALIDATION ERROR! ID value 'R2_zone0_munion_acb9882e2368846879dde37a21252c06c0x7fe3e0c1a4b0_pos' is not unique at line: 845
G4GDML: VALIDATION ERROR! ID value 'R2_zone0_munion_acb9882e2368846879dde37a21252c06c0x7fe3e0c1a4b0_rot' is not unique at line: 846
G4GDML: VALIDATION ERROR! ID value 'R2_zone0_munion_acb9882e2368846879dde37a21252c06c0x7fe3e0c1a4b0_pos' is not unique at line: 850
G4GDML: VALIDATION ERROR! ID value 'Node-1' is not unique at line: 883
G4GDML: VALIDATION ERROR! ID value 'Node-2' is not unique at line: 887
```

If the same nodes and positions are being used from previously defined multiunions, this would explain why half of my geometry is missing when I load it again.

I noticed this is also the same with the name of positions and rotations in Assemblies.

I'm attaching a patch file that fixes it by building the name of the position and rotations from the unique object name + node name etc.

I have GDMLS I can send, but not publicly.

Best,
Laurie
Comment 1 Witold.Pokorski 2021-03-16 15:36:45 CET
Thanks for spotting the problem and for providing the fix. I have applied your patch and everything seems to be working fine now.
Cheers,
Witek