Allow multiple initialization of sibyll nuclear interaction
I had an error based on multiple initialization calls. See #226 (closed). Based on this experience I wrote a patch to handle multiple initialization of sibyll nuclear interaction based on the implementation for sibyll interaction for me. I'am willing to contribute this work to CORSIKA.
From 7dfeb869cf69acdc674e9f57a306ff5b4247d150 Mon Sep 17 00:00:00 2001
From: Martin Ness <martin.ness@cs.tu-dortmund.de>
Date: Wed, 31 Jul 2019 23:49:16 +0200
Subject: [PATCH] allow multiple init calls in nuclear interaction
From 7dfeb869cf69acdc674e9f57a306ff5b4247d150 Mon Sep 17 00:00:00 2001
From: Martin Ness <martin.ness@cs.tu-dortmund.de>
Date: Wed, 31 Jul 2019 23:49:16 +0200
Subject: [PATCH] allow multiple init calls in nuclear interaction
---
Processes/Sibyll/NuclearInteraction.cc | 6 ++++++
Processes/Sibyll/NuclearInteraction.h | 1 +
2 files changed, 7 insertions(+)
diff --git a/Processes/Sibyll/NuclearInteraction.cc b/Processes/Sibyll/NuclearInteraction.cc
index 384330c..737c04a 100644
--- a/Processes/Sibyll/NuclearInteraction.cc
+++ b/Processes/Sibyll/NuclearInteraction.cc
@@ -138,6 +138,12 @@ namespace corsika::process::sibyll {
template <>
void NuclearInteraction<SetupEnvironment>::Init() {
+ if (fInitialized) { // already initialized
+ return;
+ }
+
+ fInitialized = true;
+
// initialize hadronic interaction module
// TODO: safe to run multiple initializations?
if (!fHadronicInteraction.WasInitialized()) fHadronicInteraction.Init();
diff --git a/Processes/Sibyll/NuclearInteraction.h b/Processes/Sibyll/NuclearInteraction.h
index 4d12647..80fb20a 100644
--- a/Processes/Sibyll/NuclearInteraction.h
+++ b/Processes/Sibyll/NuclearInteraction.h
@@ -29,6 +29,7 @@ namespace corsika::process::sibyll {
int fCount = 0;
int fNucCount = 0;
+ bool fInitialized = false;
public:
NuclearInteraction(corsika::process::sibyll::Interaction&, TEnvironment const&);
--
2.20.1
Please check and commit to master (or some branch) it is based on master branch commit 3ce2f076.
And a small cleanup for the case sibyll interaction is used as hadronic interaction module.
From e454a5db33919e42035323ca8141287ec53144fb Mon Sep 17 00:00:00 2001
From: Martin Ness <martin.ness@cs.tu-dortmund.de>
Date: Thu, 1 Aug 2019 11:04:14 +0200
Subject: [PATCH] It is save to run multiple initializations for hadronic
interaction module when it is sibyll.
---
Processes/Sibyll/NuclearInteraction.cc | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/Processes/Sibyll/NuclearInteraction.cc b/Processes/Sibyll/NuclearInteraction.cc
index 737c04a..d9df934 100644
--- a/Processes/Sibyll/NuclearInteraction.cc
+++ b/Processes/Sibyll/NuclearInteraction.cc
@@ -145,8 +145,7 @@ namespace corsika::process::sibyll {
fInitialized = true;
// initialize hadronic interaction module
- // TODO: safe to run multiple initializations?
- if (!fHadronicInteraction.WasInitialized()) fHadronicInteraction.Init();
+ fHadronicInteraction.Init();
// check compatibility of energy ranges, someone could try to use low-energy model..
if (!fHadronicInteraction.IsValidCoMEnergy(GetMinEnergyPerNucleonCoM()) ||
--
2.20.1