Wrong indexing for nested ProcessSequences?
There is something wrong with the indexing of SwitchProcessSequence
. Felix already gave a first analysis of this problem in #573 (closed), where the the issue have been quick-fixed by just switching the order of the processes in make_sequence
.
Working on the test-high-energy-showers
branch (commit c6f90c32), and simulating EM showers with the corsika.cpp
example produced very wrong showers. This can be fixed by replacing emContinuous
with emContinuousProposal
, where the former is constructed by using make_select
. Therefore, I believe that the make_select
(and therefore the SwitchProcessSequence
object) is the reason for this bug.
I have identified the following lines in the code as fishy:
template <typename TCondition, typename TSequence, typename USequence,
int IndexFirstProcess = 0,
int IndexOfProcess1 = count_processes<TSequence, IndexFirstProcess>::count,
int IndexOfProcess2 = count_processes<USequence, IndexOfProcess1>::count>
class SwitchProcessSequence
When determining the index of process 2, why do we start counting at IndexOfProcess1
? Shouldn't we also start counting with IndexFirstProcess
? I have tried this change (with the appropriate change of line 194), and my simulations were correct again. But I am not sure whether this is a general fix or I just got "lucky" for my use case
It would be very important to track down and fix this issue, because otherwise users (and developers) won't be able to trust the make_select
functionality anymore, and random bugs which are very hard to backtrace can start to apperar...