From 5fe8754bac1434f58f8439929fa859241669572f Mon Sep 17 00:00:00 2001 From: Remy Prechelt <prechelt@hawaii.edu> Date: Fri, 10 Jul 2020 08:38:15 -1000 Subject: [PATCH] Remove Init() from Framework. --- Documentation/Examples/boundary_example.cc | 4 +- Documentation/Examples/cascade_example.cc | 2 +- .../Examples/cascade_proton_example.cc | 2 +- Documentation/Examples/vertical_EAS.cc | 1 - Framework/Cascade/Cascade.h | 9 --- Framework/Cascade/testCascade.cc | 9 --- Framework/ProcessSequence/ProcessSequence.h | 5 -- .../ProcessSequence/testProcessSequence.cc | 79 +++++++++---------- Framework/StackInterface/CombinedStack.h | 5 -- Framework/StackInterface/Stack.h | 7 +- Framework/StackInterface/testCombinedStack.cc | 3 - Framework/StackInterface/testTestStack.h | 1 - 12 files changed, 42 insertions(+), 85 deletions(-) diff --git a/Documentation/Examples/boundary_example.cc b/Documentation/Examples/boundary_example.cc index 549022b44..a2f0d1001 100644 --- a/Documentation/Examples/boundary_example.cc +++ b/Documentation/Examples/boundary_example.cc @@ -73,8 +73,6 @@ struct MyBoundaryCrossingProcess return EProcessReturn::eOk; } - void Init() {} - private: std::ofstream fFile; }; @@ -166,7 +164,7 @@ int main() { // define air shower object, run simulation cascade::Cascade EAS(env, tracking, sequence, stack); - EAS.Init(); + EAS.Run(); cout << "Result: E0=" << E0 / 1_GeV << endl; diff --git a/Documentation/Examples/cascade_example.cc b/Documentation/Examples/cascade_example.cc index 82c108e5c..fb94eaa5b 100644 --- a/Documentation/Examples/cascade_example.cc +++ b/Documentation/Examples/cascade_example.cc @@ -150,7 +150,7 @@ int main() { // define air shower object, run simulation cascade::Cascade EAS(env, tracking, sequence, stack); - EAS.Init(); + EAS.Run(); eLoss.PrintProfile(); // print longitudinal profile diff --git a/Documentation/Examples/cascade_proton_example.cc b/Documentation/Examples/cascade_proton_example.cc index 434652440..5125902df 100644 --- a/Documentation/Examples/cascade_proton_example.cc +++ b/Documentation/Examples/cascade_proton_example.cc @@ -140,7 +140,7 @@ int main() { // define air shower object, run simulation cascade::Cascade EAS(env, tracking, sequence, stack); - EAS.Init(); + EAS.Run(); cout << "Result: E0=" << E0 / 1_GeV << endl; diff --git a/Documentation/Examples/vertical_EAS.cc b/Documentation/Examples/vertical_EAS.cc index a691e1408..5d4731ad8 100644 --- a/Documentation/Examples/vertical_EAS.cc +++ b/Documentation/Examples/vertical_EAS.cc @@ -215,7 +215,6 @@ int main(int argc, char** argv) { // define air shower object, run simulation tracking_line::TrackingLine tracking; cascade::Cascade EAS(env, tracking, sequence, stack); - EAS.Init(); // to fix the point of first interaction, uncomment the following two lines: // EAS.SetNodes(); diff --git a/Framework/Cascade/Cascade.h b/Framework/Cascade/Cascade.h index 5130bebca..389ec0557 100644 --- a/Framework/Cascade/Cascade.h +++ b/Framework/Cascade/Cascade.h @@ -85,15 +85,6 @@ namespace corsika::cascade { , fProcessSequence(pl) , fStack(stack) {} - /** - * The Init function is called before the actual cascade simulations. - * All components of the Cascade simulation must be configured here. - */ - void Init() { - fProcessSequence.Init(); - fStack.Init(); - } - /** * set the nodes for all particles on the stack according to their numerical * position diff --git a/Framework/Cascade/testCascade.cc b/Framework/Cascade/testCascade.cc index 9c132c904..a22cfbcb4 100644 --- a/Framework/Cascade/testCascade.cc +++ b/Framework/Cascade/testCascade.cc @@ -84,8 +84,6 @@ public: return EProcessReturn::eInteracted; } - void Init() { fCalls = 0; } - int GetCalls() const { return fCalls; } }; @@ -117,11 +115,6 @@ public: return EProcessReturn::eOk; } - void Init() { - fCalls = 0; - fCount = 0; - } - int GetCount() const { return fCount; } int GetCalls() const { return fCalls; } }; @@ -158,8 +151,6 @@ TEST_CASE("Cascade", "[Cascade]") { TestCascadeStackView> EAS(env, tracking, sequence, stack); - EAS.Init(); - SECTION("full cascade") { EAS.Run(); diff --git a/Framework/ProcessSequence/ProcessSequence.h b/Framework/ProcessSequence/ProcessSequence.h index 69a4da36b..c54ea09f5 100644 --- a/Framework/ProcessSequence/ProcessSequence.h +++ b/Framework/ProcessSequence/ProcessSequence.h @@ -315,11 +315,6 @@ namespace corsika::process { } // end branch B return EProcessReturn::eOk; } - - void Init() { - A.Init(); - B.Init(); - } }; /// the << operator assembles many BaseProcess, ContinuousProcess, and diff --git a/Framework/ProcessSequence/testProcessSequence.cc b/Framework/ProcessSequence/testProcessSequence.cc index 1b46c9662..64f1266c7 100644 --- a/Framework/ProcessSequence/testProcessSequence.cc +++ b/Framework/ProcessSequence/testProcessSequence.cc @@ -25,16 +25,17 @@ static const int nData = 10; int globalCount = 0; class ContinuousProcess1 : public ContinuousProcess<ContinuousProcess1> { +public: int fV = 0; -public: ContinuousProcess1(const int v) - : fV(v) {} - void Init() { - cout << "ContinuousProcess1::Init" << endl; + : fV(v) { + + cout << "globalCount: " << globalCount << ", fV: " << fV << std::endl; assert(globalCount == fV); globalCount++; } + template <typename D, typename T> inline EProcessReturn DoContinuous(D& d, T&) const { cout << "ContinuousProcess1::DoContinuous" << endl; @@ -44,16 +45,16 @@ public: }; class ContinuousProcess2 : public ContinuousProcess<ContinuousProcess2> { +public: int fV = 0; -public: ContinuousProcess2(const int v) - : fV(v) {} - void Init() { - cout << "ContinuousProcess2::Init" << endl; + : fV(v) { + cout << "globalCount: " << globalCount << ", fV: " << fV << std::endl; assert(globalCount == fV); globalCount++; } + template <typename D, typename T> inline EProcessReturn DoContinuous(D& d, T&) const { cout << "ContinuousProcess2::DoContinuous" << endl; @@ -65,12 +66,12 @@ public: class Process1 : public InteractionProcess<Process1> { public: Process1(const int v) - : fV(v) {} - void Init() { - cout << "Process1::Init" << endl; + : fV(v) { + cout << "globalCount: " << globalCount << ", fV: " << fV << std::endl; assert(globalCount == fV); globalCount++; } + template <typename D, typename S> inline EProcessReturn DoInteraction(D& d, S&) const { for (int i = 0; i < nData; ++i) d.p[i] += 1 + i; @@ -85,12 +86,12 @@ class Process2 : public InteractionProcess<Process2> { public: Process2(const int v) - : fV(v) {} - void Init() { - cout << "Process2::Init" << endl; + : fV(v) { + cout << "globalCount: " << globalCount << ", fV: " << fV << std::endl; assert(globalCount == fV); globalCount++; } + template <typename Particle> inline EProcessReturn DoInteraction(Particle&) const { cout << "Process2::DoInteraction" << endl; @@ -108,12 +109,12 @@ class Process3 : public InteractionProcess<Process3> { public: Process3(const int v) - : fV(v) {} - void Init() { - cout << "Process3::Init" << endl; + : fV(v) { + cout << "globalCount: " << globalCount << ", fV: " << fV << std::endl; assert(globalCount == fV); globalCount++; } + template <typename Particle> inline EProcessReturn DoInteraction(Particle&) const { cout << "Process3::DoInteraction" << endl; @@ -131,12 +132,12 @@ class Process4 : public BaseProcess<Process4> { public: Process4(const int v) - : fV(v) {} - void Init() { - cout << "Process4::Init" << endl; + : fV(v) { + cout << "globalCount: " << globalCount << ", fV: " << fV << std::endl; assert(globalCount == fV); globalCount++; } + template <typename D, typename T> inline EProcessReturn DoContinuous(D& d, T&) const { for (int i = 0; i < nData; ++i) { d.p[i] /= 1.2; } @@ -154,12 +155,12 @@ class Decay1 : public DecayProcess<Decay1> { public: Decay1(const int v) - : fV(v) {} - void Init() { - cout << "Decay1::Init" << endl; + : fV(v) { + cout << "Decay1()" << endl; assert(globalCount == fV); globalCount++; } + template <typename Particle> TimeType GetLifetime(Particle&) const { return 1_s; @@ -193,6 +194,7 @@ struct DummyTrajectory {}; TEST_CASE("Process Sequence", "[Process Sequence]") { SECTION("Check init order") { + globalCount = 0; Process1 m1(0); Process2 m2(1); Process3 m3(2); @@ -201,16 +203,10 @@ TEST_CASE("Process Sequence", "[Process Sequence]") { auto sequence = m1 << m2 << m3 << m4; globalCount = 0; - sequence.Init(); - // REQUIRE_NOTHROW( (sequence.Init()) ); - - // const auto sequence_wrong = m3 + m2 + m1 + m4; - // globalCount = 0; - // sequence_wrong.Init(); - // REQUIRE_THROWS(sequence_wrong.Init()); } SECTION("interaction length") { + globalCount = 0; ContinuousProcess1 cp1(0); Process2 m2(1); Process3 m3(2); @@ -222,13 +218,15 @@ TEST_CASE("Process Sequence", "[Process Sequence]") { InverseGrammageType const tot_inv = sequence2.GetTotalInverseInteractionLength(particle); cout << "lambda_tot=" << tot << "; lambda_tot_inv=" << tot_inv << endl; + globalCount = 0; } SECTION("lifetime") { + globalCount = 0; ContinuousProcess1 cp1(0); Process2 m2(1); Process3 m3(2); - Decay1 d3(2); + Decay1 d3(3); DummyData particle; @@ -236,14 +234,16 @@ TEST_CASE("Process Sequence", "[Process Sequence]") { TimeType const tot = sequence2.GetTotalLifetime(particle); InverseTimeType const tot_inv = sequence2.GetTotalInverseLifetime(particle); cout << "lambda_tot=" << tot << "; lambda_tot_inv=" << tot_inv << endl; + + globalCount = 0; } SECTION("sectionTwo") { - + globalCount = 0; ContinuousProcess1 cp1(0); - ContinuousProcess2 cp2(3); - Process2 m2(1); - Process3 m3(2); + ContinuousProcess2 cp2(1); + Process2 m2(2); + Process3 m3(3); auto sequence2 = cp1 << m2 << m3 << cp2; @@ -252,7 +252,6 @@ TEST_CASE("Process Sequence", "[Process Sequence]") { cout << "-->init sequence2" << endl; globalCount = 0; - sequence2.Init(); cout << "-->docont" << endl; sequence2.DoContinuous(particle, track); @@ -270,10 +269,7 @@ TEST_CASE("Process Sequence", "[Process Sequence]") { SECTION("StackProcess") { - ContinuousProcess1 cp1(0); - ContinuousProcess2 cp2(3); - Process2 m2(1); - Process3 m3(2); + globalCount = 0; Stack1 s1(1); Stack1 s2(2); @@ -294,8 +290,9 @@ TEST_CASE("Process Sequence", "[Process Sequence]") { in Processes/SwitchProcess/testSwtichProcess */ TEST_CASE("SwitchProcess") { + globalCount = 0; Process1 p1(0); - Process2 p2(0); + Process2 p2(1); switch_process::SwitchProcess s(p1, p2, 10_GeV); REQUIRE(is_switch_process_v<decltype(s)>); } diff --git a/Framework/StackInterface/CombinedStack.h b/Framework/StackInterface/CombinedStack.h index f971b64a7..2534ced4e 100644 --- a/Framework/StackInterface/CombinedStack.h +++ b/Framework/StackInterface/CombinedStack.h @@ -106,11 +106,6 @@ namespace corsika::stack { class CombinedStackImpl : public Stack1Impl, public Stack2Impl { public: - void Init() { - Stack1Impl::Init(); - Stack2Impl::Init(); - } - void Clear() { Stack1Impl::Clear(); Stack2Impl::Clear(); diff --git a/Framework/StackInterface/Stack.h b/Framework/StackInterface/Stack.h index 7ddee326c..c4ce61945 100644 --- a/Framework/StackInterface/Stack.h +++ b/Framework/StackInterface/Stack.h @@ -63,8 +63,6 @@ namespace corsika::stack { delete; ///< since Stack can be very big, we don't want to copy it public: - // Stack() { Init(); } - /** * if StackDataType is a reference member we *HAVE* to initialize * it in the constructor, this is typically needed for SecondaryView @@ -128,10 +126,7 @@ namespace corsika::stack { */ unsigned int GetCapacity() const { return fData.GetCapacity(); } unsigned int GetSize() const { return fData.GetSize(); } - template <typename... Args> - auto Init(Args... args) { - return fData.Init(args...); - } + template <typename... Args> auto Clear(Args... args) { return fData.Clear(args...); diff --git a/Framework/StackInterface/testCombinedStack.cc b/Framework/StackInterface/testCombinedStack.cc index d728abeb4..6f4a9c17f 100644 --- a/Framework/StackInterface/testCombinedStack.cc +++ b/Framework/StackInterface/testCombinedStack.cc @@ -32,7 +32,6 @@ class TestStackData2 { public: // these functions are needed for the Stack interface - void Init() {} void Clear() { fData2.clear(); } unsigned int GetSize() const { return fData2.size(); } unsigned int GetCapacity() const { return fData2.size(); } @@ -104,7 +103,6 @@ TEST_CASE("Combined Stack", "[stack]") { // construct a valid Stack object StackTest s; - s.Init(); s.Clear(); s.AddParticle(std::tuple{0.}); s.Copy(s.cbegin(), s.begin()); @@ -200,7 +198,6 @@ class TestStackData3 { public: // these functions are needed for the Stack interface - void Init() {} void Clear() { fData3.clear(); } unsigned int GetSize() const { return fData3.size(); } unsigned int GetCapacity() const { return fData3.size(); } diff --git a/Framework/StackInterface/testTestStack.h b/Framework/StackInterface/testTestStack.h index 89897b96a..88e5fa1c6 100644 --- a/Framework/StackInterface/testTestStack.h +++ b/Framework/StackInterface/testTestStack.h @@ -22,7 +22,6 @@ class TestStackData { public: // these functions are needed for the Stack interface - void Init() {} void Clear() { fData.clear(); } unsigned int GetSize() const { return fData.size(); } unsigned int GetCapacity() const { return fData.size(); } -- GitLab