Problem 2273

Summary: GDML loop when to == from fails to run even once
Product: Geant4 Reporter: Wouter Deconinck <wdconinc>
Component: persistency/gdmlAssignee: Witold.Pokorski
Status: RESOLVED FIXED    
Severity: minor    
Priority: P4    
Version: 10.6   
Hardware: All   
OS: All   

Description Wouter Deconinck 2020-09-11 21:20:40 CEST
Currently the following (admittedly trivial) loop in geant4 is not accepted:
   <constant name="num" value="1"/>
   <loop for="i" from="1" to="num" step="1">
     <!-- stuff -->
   </loop>
due to the following code in G4GDMLRead
   if (_from == _to)
   {
     G4Exception("G4GDMLRead::loopRead()", "InvalidRead",
                 FatalException, "Empty loop!");
   }

This suggest that the loop is to be thought as the following C++ construct:
   for (int i = _from; i < _to; i += _step) { /* stuff */ }

This conflicts with the actual interpretation:
   while (_var <= _to)
   {
      eval.SetVariable(var,_var);
      (this->*func)(element);
      _var += _step;
      loopCount++;
   }
which indicates:
   for (int i = _from; i <= _to; i += _step) { /* stuff */ }

This results in the following confusing behavior in examples/extended/persistency/gdml/G01, in particular loop.gdml:
- With the default parameters (num = 4) you get 5 volumes.
- Therefore, changing the parameter num = 0 you would expect 1 volume, but that fails due to the "Empty loop!" error.

Suggestion: remove the Empty Loop error since any actual empty loop (from > to) would be caught by the subsequent Infinit Loop errors, e.g.
   if ((_from > _to) && (_step >= 0))
   {
     G4Exception("G4GDMLRead::loopRead()", "InvalidRead",
                 FatalException, "Infinite loop!");
   }
Comment 1 Witold.Pokorski 2020-10-19 14:40:03 CEST
Thanks for spotting that problem. The fix will be in the next release.