diff --git a/Framework/ProcessSequence/BoundaryCrossingProcess.h b/Framework/ProcessSequence/BoundaryCrossingProcess.h index 24c2d93a8a5df5a8174e9e38cea5bca69a04f201..dca9243a57665efe6aa462da902c5b21eea5f81d 100644 --- a/Framework/ProcessSequence/BoundaryCrossingProcess.h +++ b/Framework/ProcessSequence/BoundaryCrossingProcess.h @@ -14,8 +14,10 @@ namespace corsika::process { template <typename TDerived> - struct BoundaryCrossingProcess : public BaseProcess<TDerived> { - + class BoundaryCrossingProcess : public BaseProcess<TDerived> { + private: + protected: + public: /** * This method is called when a particle crosses the boundary between the nodes * \p from and \p to. diff --git a/Framework/ProcessSequence/ContinuousProcess.h b/Framework/ProcessSequence/ContinuousProcess.h index 9171eeeebaf6cb0a700bd45b2e8c5775238f00d6..7a03d4d4a4504e95467c510131641e1693af761a 100644 --- a/Framework/ProcessSequence/ContinuousProcess.h +++ b/Framework/ProcessSequence/ContinuousProcess.h @@ -24,7 +24,10 @@ namespace corsika::process { */ template <typename TDerived> - struct ContinuousProcess : public BaseProcess<TDerived> { + class ContinuousProcess : public BaseProcess<TDerived>{ + private: + protected: + public: // here starts the interface part // -> enforce TDerived to implement DoContinuous... diff --git a/Framework/ProcessSequence/DecayProcess.h b/Framework/ProcessSequence/DecayProcess.h index 779abbc94940c4804872515556f4416cf263e190..d3f66f6d69ec60e1d738889f5d1214a8d737d0d9 100644 --- a/Framework/ProcessSequence/DecayProcess.h +++ b/Framework/ProcessSequence/DecayProcess.h @@ -25,7 +25,8 @@ namespace corsika::process { */ template <typename TDerived> - struct DecayProcess : BaseProcess<TDerived> { + class DecayProcess : BaseProcess<TDerived> { + public: using BaseProcess<TDerived>::GetRef; diff --git a/Framework/ProcessSequence/InteractionProcess.h b/Framework/ProcessSequence/InteractionProcess.h index 204d6db476f77a96841a9acb77622b1e3f74658b..880fbe2070c697a38b1d3704df83a860df57b06e 100644 --- a/Framework/ProcessSequence/InteractionProcess.h +++ b/Framework/ProcessSequence/InteractionProcess.h @@ -25,7 +25,7 @@ namespace corsika::process { */ template <typename TDerived> - struct InteractionProcess : public BaseProcess<TDerived> { + class InteractionProcess : public BaseProcess<TDerived> { using BaseProcess<TDerived>::GetRef; diff --git a/Framework/ProcessSequence/SecondariesProcess.h b/Framework/ProcessSequence/SecondariesProcess.h index 62133059fba81acb084da8dbb8bd7997121e0a6b..e3f1dfff8719807f08757b0762faf2f311640c9b 100644 --- a/Framework/ProcessSequence/SecondariesProcess.h +++ b/Framework/ProcessSequence/SecondariesProcess.h @@ -25,7 +25,7 @@ namespace corsika::process { */ template <typename TDerived> - struct SecondariesProcess : public BaseProcess<TDerived> { + class SecondariesProcess : public BaseProcess<TDerived> { /// here starts the interface-definition part // -> enforce TDerived to implement DoSecondaries... diff --git a/Processes/CMakeLists.txt b/Processes/CMakeLists.txt index 509bf305e20364d1151c9ad101504eec5245191a..2fb967787d87542ec709a6e792922b210a432892 100644 --- a/Processes/CMakeLists.txt +++ b/Processes/CMakeLists.txt @@ -30,6 +30,8 @@ add_subdirectory (OnShellCheck) add_subdirectory (InteractionCounter) add_subdirectory (SwitchProcess) +add_subdirectory (DevTools) + ########################################## # add_custom_target(CORSIKAprocesses) add_library (CORSIKAprocesses INTERFACE) diff --git a/Processes/DevTools/Analytics/CMakeLists.txt b/Processes/DevTools/Analytics/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..54acad48446f98f9bb31b0e80e4d75704193bee4 --- /dev/null +++ b/Processes/DevTools/Analytics/CMakeLists.txt @@ -0,0 +1,55 @@ +set ( + MODEL_SOURCES + ExecTime.cc + ) + +set ( + MODEL_HEADERS + ExecTime.h + ) + +set ( + MODEL_NAMESPACE + corsika/process/devtools + ) + +add_library (ProcessDevTools STATIC ${MODEL_SOURCES}) +CORSIKA_COPY_HEADERS_TO_NAMESPACE (ProcessDevTools ${MODEL_NAMESPACE} ${MODEL_HEADERS}) + +set_target_properties ( + ProcessDevTools + PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + ) + +# target dependencies on other libraries (also the header onlys) +target_link_libraries ( + ProcessDevTools + CORSIKAsetup + ) + +target_include_directories ( + ProcessDevTools + INTERFACE + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include> + $<INSTALL_INTERFACE:include/include> + ) + +install ( + TARGETS ProcessDevTools + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + PUBLIC_HEADER DESTINATION include/${MODEL_NAMESPACE} + ) + + +# -------------------- +# code unit testing +CORSIKA_ADD_TEST (testExecTime testExecTime.cc) +target_link_libraries ( + testExecTime ProcessDevTools + CORSIKAsetup + CORSIKAthirdparty # for catch2 + ) + diff --git a/Processes/DevTools/Analytics/ExecTime.cc b/Processes/DevTools/Analytics/ExecTime.cc new file mode 100644 index 0000000000000000000000000000000000000000..792e69ebcef61086fa864be8e4fe641883e3a9b7 --- /dev/null +++ b/Processes/DevTools/Analytics/ExecTime.cc @@ -0,0 +1,24 @@ +/* + * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu + * + * This software is distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3). See file LICENSE for a full version of + * the license. + */ + +#include <chrono> +#include <iostream> + +#include <corsika/process/devtools/ExecTime.h> + +namespace corsika::process { + namespace devtools { + + template <class T> + void ExecTime<T>::start() {} + + template <class T> + void ExecTime<T>::stop() {} + + } // namespace devtools +} // namespace corsika::process \ No newline at end of file diff --git a/Processes/DevTools/Analytics/ExecTime.h b/Processes/DevTools/Analytics/ExecTime.h new file mode 100644 index 0000000000000000000000000000000000000000..81da08022cc89e5e5a9c78b5108c2599f9f5c4b4 --- /dev/null +++ b/Processes/DevTools/Analytics/ExecTime.h @@ -0,0 +1,112 @@ +/* + * (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu + * + * This software is distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3). See file LICENSE for a full version of + * the license. + */ + +#pragma once + +#include <chrono> +#include <type_traits> + +#include <corsika/process/BoundaryCrossingProcess.h> +#include <corsika/process/ContinuousProcess.h> +#include <corsika/process/DecayProcess.h> +#include <corsika/process/InteractionProcess.h> +#include <corsika/process/SecondariesProcess.h> +#include <corsika/process/StackProcess.h> + +namespace corsika::process { + namespace devtools { + + template <class T> + class ExecTime : public T { + private: + void start(); + void stop(); + + protected: + public: + + float mean(); + float min(); + float max(); + float var(); + + /// Interface implementation + + // Boundary Crossing + template < + typename Particle, typename VTNType, + typename std::enable_if_t< + std::is_base_of<BoundaryCrossingProcess<typename T::TDerived>, T>::type, int> = 0 > + EProcessReturn DoBoundaryCrossing(Particle& p, VTNType const& from, + VTNType const& to) { + return T::DoBoundaryCrossing(p, from, to); + } + + // Continous + template <typename Particle, typename Track, + typename std::enable_if_t< + std::is_base_of<ContinuousProcess<typename T::TDerived>, T>::type, int> = 0> + EProcessReturn DoContinuous(Particle& p, Track const& t) const { + return T::DoContinous(p, t); + } + + template <typename Particle, typename Track, + typename std::enable_if_t< + std::is_base_of<ContinuousProcess<typename T::TDerived>, T>::type, int> = 0> + units::si::LengthType MaxStepLength(Particle const& p, Track const& track) const { + return T::MaxStepLength(p, track); + } + + // Decay + template <typename Particle, + typename std::enable_if_t< + std::is_base_of<DecayProcess<typename T::TDerived>, T>::type, int> = 0> + EProcessReturn DoDecay(Particle& p) { + return T::DoDecay(p); + } + + template <typename Particle, + typename std::enable_if_t< + std::is_base_of<DecayProcess<typename T::TDerived>, T>::type, int> = 0> + corsika::units::si::TimeType GetLifetime(Particle& p) { + return T::GetLifetime(p); + } + + // Interaction + template <typename Particle, + typename std::enable_if_t< + std::is_base_of<InteractionProcess<typename T::TDerived>, T>::type, int> = 0> + EProcessReturn DoInteraction(Particle& p) { + return T::DoInteraction(p); + } + + template <typename TParticle, + typename std::enable_if_t< + std::is_base_of<InteractionProcess<typename T::TDerived>, T>::type, int> = 0> + corsika::units::si::GrammageType GetInteractionLength(TParticle& p) { + return T::GetInteractionLength(p); + } + + // Secondaries + template <typename TSecondaries, + typename std::enable_if_t< + std::is_base_of<SecondariesProcess<typename T::TDerived>, T>::type, int> = 0> + inline EProcessReturn DoSecondaries(TSecondaries& sec) { + return T::DoSecondaries(sec); + } + + // Stack + template <typename TStack, + typename std::enable_if_t< + std::is_base_of<StackProcess<typename T::TDerived>, T>::type, int> = 0> + inline EProcessReturn DoStack(TStack& stack) { + return T::stack(stack); + } + }; + } // namespace devtools +} // namespace corsika::process \ No newline at end of file diff --git a/Processes/DevTools/Analytics/testExecTime.cc b/Processes/DevTools/Analytics/testExecTime.cc new file mode 100644 index 0000000000000000000000000000000000000000..559ad8694fb0034460e98161562f535d7f50d330 --- /dev/null +++ b/Processes/DevTools/Analytics/testExecTime.cc @@ -0,0 +1,23 @@ +/* + * (c) Copyright 2019 CORSIKA Project, corsika-project@lists.kit.edu + * + * This software is distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3). See file LICENSE for a full version of + * the license. + */ + +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one + // cpp file +#include <catch2/catch.hpp> + +#include <corsika/process/devtools/ExecTime.h> + + +using namespace corsika::process::devtools; + +TEST_CASE("ContinuousProcess interface", "[proccesses][DevTools ExecTime]") { + + + + +} diff --git a/Processes/DevTools/CMakeLists.txt b/Processes/DevTools/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..79493860887b72dd1b0c60146b07f481aa5e03c0 --- /dev/null +++ b/Processes/DevTools/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory (Analytics) +add_subdirectory (Dummy) \ No newline at end of file diff --git a/Processes/DevTools/Dummy/CMakeLists.txt b/Processes/DevTools/Dummy/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2b2a04293a70d373c706b6f908327e2754af85c4 --- /dev/null +++ b/Processes/DevTools/Dummy/CMakeLists.txt @@ -0,0 +1,48 @@ +add_library (DevTools_Dummy INTERFACE) + +set ( + DevTools_Dummy_HEADERS + DummyBoundaryCrossingProcess.h + DummyContinuousProcess.h + DummyDecayProcess.h + DummyInteractionProcess.h + DummySecondariesProcess.h + ) + +set ( + DevTools_Dummy_NAMESPACE + corsika/process/devtools + ) + +CORSIKA_COPY_HEADERS_TO_NAMESPACE (DevTools_Dummy ${DevTools_Dummy_NAMESPACE} ${DevTools_Dummy_HEADERS}) + + +target_include_directories ( + DevTools_Dummy + INTERFACE + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include> + $<INSTALL_INTERFACE:include/include> + ) + +install ( + FILES ${DevTools_Dummy_HEADERS} + DESTINATION include/${DevTools_Dummy_NAMESPACE} + ) + + +# -------------------- +# code unit testing +CORSIKA_ADD_TEST (TestDummy) + + +target_link_libraries ( + TestDummy + DevTools_Dummy + CORSIKAunits + CORSIKAstackinterface + CORSIKAprocesssequence + CORSIKAsetup + CORSIKAgeometry + CORSIKAenvironment + CORSIKAtesting + ) diff --git a/Processes/DevTools/Dummy/DummyBoundaryCrossingProcess.h b/Processes/DevTools/Dummy/DummyBoundaryCrossingProcess.h new file mode 100644 index 0000000000000000000000000000000000000000..b39e25bc6416b2f3d870e2a3f0e6e4671eedf790 --- /dev/null +++ b/Processes/DevTools/Dummy/DummyBoundaryCrossingProcess.h @@ -0,0 +1,32 @@ +/* + * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu + * + * This software is distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3). See file LICENSE for a full version of + * the license. + */ + +#pragma once + +#include <chrono> +#include <thread> + +#include <corsika/process/BoundaryCrossingProcess.h> + +namespace corsika::process { + namespace devtools { + + template <int ISleep> + class DummyBoundaryCrossingProcess : BoundaryCrossingProcess<DummyBoundaryCrossingProcess<ISleep>> { + private: + public: + template <typename Particle, typename VTNType> + EProcessReturn DoBoundaryCrossing(Particle&, VTNType const& from, + VTNType const& to) { + std::this_thread::sleep_for( std::chrono::milliseconds(ISleep) ); + return EProcessReturn::eOk; + } + }; + + } // namespace devtools +} // namespace corsika::process \ No newline at end of file diff --git a/Processes/DevTools/Dummy/DummyContinuousProcess.h b/Processes/DevTools/Dummy/DummyContinuousProcess.h new file mode 100644 index 0000000000000000000000000000000000000000..9fa9ae645f13a1ba8ec7229a4b0920ea36a3ee17 --- /dev/null +++ b/Processes/DevTools/Dummy/DummyContinuousProcess.h @@ -0,0 +1,41 @@ +/* + * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu + * + * This software is distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3). See file LICENSE for a full version of + * the license. + */ + +#pragma once + +#include <chrono> +#include <thread> + +#include <corsika/process/ContinuousProcess.h> + +namespace corsika::process { + namespace devtools { + + template <int ISleep> + class DummyContinuousProcess : ContinuousProcess<DummyContinuousProcess<ISleep>> { + private: + public: + template <typename Particle, typename Track> + EProcessReturn DoContinuous(Particle&, Track const&) const { + std::this_thread::sleep_for( + std::chrono::milliseconds(ISleep)); + return process::EProcessReturn::eOk; + } + + template <typename Particle, typename Track> + units::si::LengthType MaxStepLength(Particle const& p, Track const& track) const { + std::this_thread::sleep_for( + std::chrono::milliseconds(ISleep)); + return units::si::meter * std::numeric_limits<double>::infinity(); + } + + std::string name() { return "DummyContinuousProcess"; } + }; + + } // namespace devtools +} // namespace corsika::process \ No newline at end of file diff --git a/Processes/DevTools/Dummy/DummyDecayProcess.h b/Processes/DevTools/Dummy/DummyDecayProcess.h new file mode 100644 index 0000000000000000000000000000000000000000..3f18da6e1dfcaa9482e56db46798a47d6baa51a0 --- /dev/null +++ b/Processes/DevTools/Dummy/DummyDecayProcess.h @@ -0,0 +1,43 @@ +/* + * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu + * + * This software is distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3). See file LICENSE for a full version of + * the license. + */ + +#pragma once + +#include <chrono> +#include <thread> + +#include <corsika/process/DecayProcess.h> + +#include <corsika/units/PhysicalUnits.h> + +namespace corsika::process { + namespace devtools { + + template <int ISleep> + class DummyDecayProcess : DecayProcess<DummyDecayProcess<ISleep>> { + private: + public: + template <typename Particle> + EProcessReturn DoDecay(Particle&) { + std::this_thread::sleep_for( + std::chrono::milliseconds(ISleep)); + return process::EProcessReturn::eOk; + } + + template <typename Particle> + corsika::units::si::TimeType GetLifetime(Particle& p) { + using namespace corsika::units::si; + + std::this_thread::sleep_for( + std::chrono::milliseconds(ISleep)); + return std::numeric_limits<double>::infinity() * 1_s; + } + }; + + } // namespace devtools +} // namespace corsika::process \ No newline at end of file diff --git a/Processes/DevTools/Dummy/DummyInteractionProcess.h b/Processes/DevTools/Dummy/DummyInteractionProcess.h new file mode 100644 index 0000000000000000000000000000000000000000..6b2e64d0e19d3db48735eabfac2e525c3d7ad41a --- /dev/null +++ b/Processes/DevTools/Dummy/DummyInteractionProcess.h @@ -0,0 +1,42 @@ +/* + * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu + * + * This software is distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3). See file LICENSE for a full version of + * the license. + */ + +#pragma once + +#include <chrono> +#include <thread> + +#include <corsika/process/InteractionProcess.h> + +namespace corsika::process { + namespace devtools { + + template <int ISleep> + class DummyInteractionProcess : InteractionProcess< DummyInteractionProcess<ISleep> > { + private: + public: + template <typename Particle> + EProcessReturn DoInteraction(Particle&) + { + std::this_thread::sleep_for( + std::chrono::milliseconds(ISleep)); + return process::EProcessReturn::eOk; + } + + template <typename TParticle> + corsika::units::si::GrammageType GetInteractionLength(TParticle& p) { + using namespace corsika::units::si; + + std::this_thread::sleep_for( + std::chrono::milliseconds(ISleep)); + return std::numeric_limits<double>::infinity() * (1_g / 1_cm / 1_cm); + } + }; + + } // namespace devtools +} // namespace corsika::process \ No newline at end of file diff --git a/Processes/DevTools/Dummy/DummySecondariesProcess.h b/Processes/DevTools/Dummy/DummySecondariesProcess.h new file mode 100644 index 0000000000000000000000000000000000000000..55e05fbf9ead402cf4a37639b75662ef1a1c0b7e --- /dev/null +++ b/Processes/DevTools/Dummy/DummySecondariesProcess.h @@ -0,0 +1,33 @@ +/* + * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu + * + * This software is distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3). See file LICENSE for a full version of + * the license. + */ + +#pragma once + +#include <chrono> +#include <thread> + +#include <corsika/process/SecondariesProcess.h> + +namespace corsika::process { + namespace devtools { + + template <int ISleep> + class DummySecondariesProcess : SecondariesProcess<DummySecondariesProcess<ISleep>> { + private: + public: + template <typename TSecondaries> + inline EProcessReturn DoSecondaries(TSecondaries&) + { + std::this_thread::sleep_for( + std::chrono::milliseconds(ISleep)); + return process::EProcessReturn::eOk; + } + }; + + } // namespace devtools +} // namespace corsika::process \ No newline at end of file diff --git a/Processes/DevTools/Dummy/TestDummy.cc b/Processes/DevTools/Dummy/TestDummy.cc new file mode 100644 index 0000000000000000000000000000000000000000..41b58f425a37c43800c5c3855b69e069393001b9 --- /dev/null +++ b/Processes/DevTools/Dummy/TestDummy.cc @@ -0,0 +1,54 @@ +/* + * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu + * + * This software is distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3). See file LICENSE for a full version of + * the license. + */ + +#include <corsika/process/devtools/DummyBoundaryCrossingProcess.h> +#include <corsika/process/devtools/DummyContinuousProcess.h> +#include <corsika/process/devtools/DummyDecayProcess.h> +#include <corsika/process/devtools/DummyInteractionProcess.h> +#include <corsika/process/devtools/DummySecondariesProcess.h> + +#include <corsika/process/ProcessReturn.h> + +#include <catch2/catch.hpp> + +#include <chrono> + +using namespace corsika; +using namespace corsika::process; +using namespace corsika::process::devtools; + +TEST_CASE("Dummy Processes") { + DummyBoundaryCrossingProcess<1000> dbc; + DummyContinuousProcess<1000> dc; + DummyDecayProcess<1000> dd; + DummyInteractionProcess<1000> di; + DummySecondariesProcess<1000> dse; + + int tmp = 0; + SECTION("BoundaryCrossing") { + auto start = std::chrono::steady_clock::now(); + REQUIRE(dbc.DoBoundaryCrossing(tmp, 0, 0) == EProcessReturn::eOk); + auto end = std::chrono::steady_clock::now(); + REQUIRE(std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() == + Approx(1000).margin(1)); + } + + SECTION("Continuous") { + auto start = std::chrono::steady_clock::now(); + REQUIRE(dc.DoContinuous(tmp, nullptr) == EProcessReturn::eOk); + auto end = std::chrono::steady_clock::now(); + REQUIRE(std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() == + Approx(1000).margin(1)); + + start = std::chrono::steady_clock::now(); + REQUIRE(dc.MaxStepLength(nullptr, nullptr) == units::si::meter * std::numeric_limits<double>::infinity()); + end = std::chrono::steady_clock::now(); + REQUIRE(std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() == + Approx(1000).margin(1)); + } +} diff --git a/Processes/SwitchProcess/SwitchProcess.h b/Processes/SwitchProcess/SwitchProcess.h index fe9293cf05986536a3142fa9a303960da4cb0181..6da1b82d86c6075bf672d935bd4022e45f3b6800 100644 --- a/Processes/SwitchProcess/SwitchProcess.h +++ b/Processes/SwitchProcess/SwitchProcess.h @@ -17,7 +17,7 @@ namespace corsika::process::switch_process { /** * This process provides an energy-based switch between two interaction processes P1 and - * P1. For energies below the threshold, P1 is invoked, otherwise P2. Both can be either + * P2. For energies below the threshold, P1 is invoked, otherwise P2. Both can be either * single interaction processes or multiple ones combined in a ProcessSequence. A * SwitchProcess itself will always be regarded as a distinct case when assembled into a * (greater) ProcessSequence.