From 3f97dc64168f6d5854cdc94087765e9d6c44b85a Mon Sep 17 00:00:00 2001 From: Dominik Baack <dominik.baack@tu-dortmund.de> Date: Mon, 5 Oct 2020 19:51:18 +0200 Subject: [PATCH] Moved Process to correct classes Implemented more general timing functions --- Framework/Analytics/CMakeLists.txt | 6 - Framework/Analytics/Timer.h | 67 ------------ Framework/Analytics/testAnalytics.cc | 61 ----------- Processes/CMakeLists.txt | 4 - Processes/DevTools/Analytics/CMakeLists.txt | 68 ------------ Processes/DevTools/Analytics/ExecTime.cc | 103 ------------------ Processes/DevTools/Analytics/ExecTime.h | 100 ----------------- Processes/DevTools/Analytics/ImplBoundary.h | 39 ------- Processes/DevTools/Analytics/ImplContinuous.h | 45 -------- Processes/DevTools/Analytics/ImplDecay.h | 45 -------- .../DevTools/Analytics/ImplInteraction.h | 45 -------- .../DevTools/Analytics/ImplSecondaries.h | 37 ------- Processes/DevTools/Analytics/testExecTime.cc | 80 -------------- Processes/DevTools/CMakeLists.txt | 2 - Processes/DevTools/Dummy/CMakeLists.txt | 48 -------- .../Dummy/DummyBoundaryCrossingProcess.h | 33 ------ .../DevTools/Dummy/DummyContinuousProcess.h | 39 ------- Processes/DevTools/Dummy/DummyDecayProcess.h | 40 ------- .../DevTools/Dummy/DummyInteractionProcess.h | 39 ------- .../DevTools/Dummy/DummySecondariesProcess.h | 31 ------ Processes/DevTools/Dummy/TestDummy.cc | 93 ---------------- 21 files changed, 1025 deletions(-) delete mode 100644 Framework/Analytics/Timer.h delete mode 100644 Framework/Analytics/testAnalytics.cc delete mode 100644 Processes/DevTools/Analytics/CMakeLists.txt delete mode 100644 Processes/DevTools/Analytics/ExecTime.cc delete mode 100644 Processes/DevTools/Analytics/ExecTime.h delete mode 100644 Processes/DevTools/Analytics/ImplBoundary.h delete mode 100644 Processes/DevTools/Analytics/ImplContinuous.h delete mode 100644 Processes/DevTools/Analytics/ImplDecay.h delete mode 100644 Processes/DevTools/Analytics/ImplInteraction.h delete mode 100644 Processes/DevTools/Analytics/ImplSecondaries.h delete mode 100644 Processes/DevTools/Analytics/testExecTime.cc delete mode 100644 Processes/DevTools/CMakeLists.txt delete mode 100644 Processes/DevTools/Dummy/CMakeLists.txt delete mode 100644 Processes/DevTools/Dummy/DummyBoundaryCrossingProcess.h delete mode 100644 Processes/DevTools/Dummy/DummyContinuousProcess.h delete mode 100644 Processes/DevTools/Dummy/DummyDecayProcess.h delete mode 100644 Processes/DevTools/Dummy/DummyInteractionProcess.h delete mode 100644 Processes/DevTools/Dummy/DummySecondariesProcess.h delete mode 100644 Processes/DevTools/Dummy/TestDummy.cc diff --git a/Framework/Analytics/CMakeLists.txt b/Framework/Analytics/CMakeLists.txt index a9d33ea09..935ddaba5 100644 --- a/Framework/Analytics/CMakeLists.txt +++ b/Framework/Analytics/CMakeLists.txt @@ -45,7 +45,6 @@ install ( # ---------------- # code unit testing -<<<<<<< HEAD CORSIKA_ADD_TEST (testFunctionTimer) target_link_libraries ( testFunctionTimer @@ -56,11 +55,6 @@ target_link_libraries ( CORSIKA_ADD_TEST (testClassTimer) target_link_libraries ( testClassTimer -======= -CORSIKA_ADD_TEST (testAnalytics) -target_link_libraries ( - testAnalytics ->>>>>>> New timer class added for cleaner structure CORSIKAanalytics CORSIKAtesting ) diff --git a/Framework/Analytics/Timer.h b/Framework/Analytics/Timer.h deleted file mode 100644 index 4d305be0e..000000000 --- a/Framework/Analytics/Timer.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * (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. - */ - -// Another possibility: -// https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Execute-Around_Pointer - -#pragma once - -#include <chrono> -#include <utility> - -namespace corsika::analytics { - - template <typename TFunc, typename TClock = std::chrono::high_resolution_clock, - typename TDuration = std::chrono::microseconds> - class timeFunction { - private: - typename TClock::time_point vStart; - TDuration vDiff; - - TFunc vFunction; - - public: - timeFunction(TFunc f) - : vFunction(f) {} - - template <typename... TArgs> - auto operator()(TArgs&&... args) -> std::invoke_result_t<TFunc, TArgs...> { - vStart = TClock::now(); - auto tmp = vFunction(std::forward<TArgs>(args)...); - vDiff = std::chrono::duration_cast<TDuration>(TClock::now() - vStart); - return tmp; - } - - inline TDuration getTime() const { return vDiff; } - }; - - template <typename TClass, typename TClock = std::chrono::high_resolution_clock, - typename TDuration = std::chrono::microseconds> - class timeProxy : public TClass { - private: - typename TClock::time_point vStart; - TDuration vDiff; - - TClass& vObj; - - /*template <typename F, typename... Args> - decltype(auto) call_func(F func, Args&&... args) { - return (vObj.*func)(std::forward<Args>(args)...); - }*/ - - public: - template<typename ... TArgs> - timeProxy(TArgs args) : TClass<TArgs...>(std::forward<TArgs>(args)...) - {} - - auto operator->() {return 2;} - - inline TDuration getTime() const { return vDiff; } - }; - -} // namespace corsika::analytics diff --git a/Framework/Analytics/testAnalytics.cc b/Framework/Analytics/testAnalytics.cc deleted file mode 100644 index 8b4edbebb..000000000 --- a/Framework/Analytics/testAnalytics.cc +++ /dev/null @@ -1,61 +0,0 @@ -/* - * (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. - */ - -#include <corsika/analytics/Timer.h> - -#include <catch2/catch.hpp> - -#include <chrono> -#include <iostream> -#include <thread> - -using namespace corsika; - -int testFunc() { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - return 31415; -} - -class testClass { -public: - int testFunc() { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - return 31415; - } - - int operator()() { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - return 31415; - } -}; - -TEST_CASE("Analytics", "[Timer]") { - SECTION("Measure runtime of a free function") { - - auto test = corsika::analytics::timeFunction(testFunc); - - std::cout << test() << std::endl; - std::cout << test.getTime().count() << std::endl; - } - - SECTION("Measure runtime of a class functor") { - testClass testC; - auto test = corsika::analytics::timeFunction(testC); - - std::cout << test() << std::endl; - std::cout << test.getTime().count() << std::endl; - } - - SECTION("Measure runtime of a class member function") { - testClass testC; - auto test = corsika::analytics::timeProxy<testClass>(); - - std::cout << test() << std::endl; - std::cout << test.getTime().count() << std::endl; - } -} diff --git a/Processes/CMakeLists.txt b/Processes/CMakeLists.txt index 31136de7a..5deaf153c 100644 --- a/Processes/CMakeLists.txt +++ b/Processes/CMakeLists.txt @@ -33,10 +33,6 @@ add_subdirectory (OnShellCheck) add_subdirectory (InteractionCounter) add_subdirectory (SwitchProcess) -<<<<<<< HEAD -======= -add_subdirectory (DevTools) ->>>>>>> Added first implementations of timeing analytics for processor ########################################## # add_custom_target(CORSIKAprocesses) diff --git a/Processes/DevTools/Analytics/CMakeLists.txt b/Processes/DevTools/Analytics/CMakeLists.txt deleted file mode 100644 index 294f0057e..000000000 --- a/Processes/DevTools/Analytics/CMakeLists.txt +++ /dev/null @@ -1,68 +0,0 @@ -set ( - MODEL_SOURCES - ExecTime.cc - ) - -set ( - MODEL_HEADERS - ExecTime.h - ImplBoundary.h - ImplContinuous.h - ImplDecay.h - ImplInteraction.h - ImplSecondaries.h - ) - -set ( - MODEL_NAMESPACE - corsika/process/devtools - ) - -add_library (DevTools_Analytic STATIC ${MODEL_SOURCES}) -CORSIKA_COPY_HEADERS_TO_NAMESPACE (DevTools_Analytic ${MODEL_NAMESPACE} ${MODEL_HEADERS}) - -set_target_properties ( - DevTools_Analytic - PROPERTIES - VERSION ${PROJECT_VERSION} - SOVERSION 1 - ) - -# target dependencies on other libraries (also the header onlys) -target_link_libraries ( - DevTools_Analytic - CORSIKAprocesssequence - CORSIKAunits - CORSIKAthirdparty - ) - -target_include_directories ( - DevTools_Analytic - INTERFACE - $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include> - $<INSTALL_INTERFACE:include/include> - ) - -install ( - TARGETS DevTools_Analytic - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib - ) - - -# -------------------- -# code unit testing -CORSIKA_ADD_TEST (testExecTime - SOURCES - testExecTime.cc - ${MODEL_HEADERS} -) - -target_link_libraries ( - testExecTime - DevTools_Analytic - DevTools_Dummy - CORSIKAtesting - CORSIKAthirdparty # for catch2 - ) - diff --git a/Processes/DevTools/Analytics/ExecTime.cc b/Processes/DevTools/Analytics/ExecTime.cc deleted file mode 100644 index 8b7199e68..000000000 --- a/Processes/DevTools/Analytics/ExecTime.cc +++ /dev/null @@ -1,103 +0,0 @@ -/* - * (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 { - - - - } // namespace devtools -} // namespace corsika::process - -/* - template <typename T, bool> - class ExecTime_BoundaryCrossing {}; - - template <typename T> - class ExecTime_BoundaryCrossing<T, true> : protected T { - public: - template < - typename Particle, typename VTNType, - typename std::enable_if_t< - std::is_base_of<BoundaryCrossingProcess<typename T::_TDerived>, T>::value, - int> = 0> - EProcessReturn DoBoundaryCrossing(Particle& p, VTNType const& from, - VTNType const& to) { - - return T::DoBoundaryCrossing(p, from, to); - } - }; - - template <typename T, bool> - class ExecTime_Continuous {}; - - template <typename T> - class ExecTime_Continuous<T, true> : protected T { - public: - template <typename Particle, typename Track> - EProcessReturn DoContinuous(Particle& p, Track const& t) const { - return T::DoContinous(p, t); - } - - template <typename Particle, typename Track> - units::si::LengthType MaxStepLength(Particle const& p, Track const& track) const { - return T::MaxStepLength(p, track); - } - }; - - template <typename T, bool> - class ExecTime_Decay {}; - - template <typename T> - class ExecTime_Decay<T, true> : protected T { - public: - template <typename Particle> - EProcessReturn DoDecay(Particle& p) { - return T::DoDecay(p); - } - - template <typename Particle> - corsika::units::si::TimeType GetLifetime(Particle& p) { - return T::GetLifetime(p); - } - }; - - template <typename T, bool> - class ExecTime_Interaction {}; - - template <typename T> - class ExecTime_Interaction<T, true> : protected T { - public: - template <typename Particle> - EProcessReturn DoInteraction(Particle& p) { - return T::DoInteraction(p); - } - - template <typename Particle> - corsika::units::si::GrammageType GetInteractionLength(Particle& p) { - return T::GetInteractionLength(p); - } - }; - - template <typename T, bool> - class ExecTime_Secondaries {}; - - template <typename T> - class ExecTime_Secondaries<T, true> : protected T { - public: - template <typename Secondaries> - inline EProcessReturn DoSecondaries(Secondaries& sec) { - return T::DoSecondaries(sec); - } - }; - */ \ No newline at end of file diff --git a/Processes/DevTools/Analytics/ExecTime.h b/Processes/DevTools/Analytics/ExecTime.h deleted file mode 100644 index 288e254e1..000000000 --- a/Processes/DevTools/Analytics/ExecTime.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * (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> - -#include <corsika/process/devtools/ImplBoundary.h> -#include <corsika/process/devtools/ImplContinuous.h> -#include <corsika/process/devtools/ImplDecay.h> -#include <corsika/process/devtools/ImplInteraction.h> -#include <corsika/process/devtools/ImplSecondaries.h> - -namespace corsika::process { - namespace devtools { - - template <typename T> - class _ExecTimeImpl : protected T { - private: - std::chrono::high_resolution_clock::time_point startTime_; - std::chrono::duration<double, std::micro> cumulatedTime_; - double mean_; - double mean2_; - double min_; - double max_; - long long n_; - - protected: - public: - _ExecTimeImpl() { - min_ = std::numeric_limits<long long>::max(); - max_ = 0; - mean_ = 0; - mean2_ = 0; - n_ = 0; - } - - void start() { startTime_ = std::chrono::high_resolution_clock::now(); } - void stop() { - auto end = std::chrono::high_resolution_clock::now(); - std::chrono::duration<double, std::micro> timeDiv = - std::chrono::duration_cast<std::chrono::duration<double, std::micro> >( - end - startTime_); - - cumulatedTime_ += timeDiv; - n_ = n_ + 1; - - if (max_ < timeDiv.count()) max_ = timeDiv.count(); - - if (timeDiv.count() < min_) min_ = timeDiv.count(); - - double delta = timeDiv.count() - mean_; - mean_ += delta / static_cast<double>(n_); - - double delta2 = timeDiv.count() - mean_; - - mean2_ += delta * delta2; - } - - double mean() const { return mean_; } - double min() const { return min_; } - double max() const { return max_; } - double var() const { return mean2_ / n_; } - double sumTime() const { return cumulatedTime_.count(); } - }; - - template <typename T> - class ExecTime - : public Boundary<T, std::is_base_of<corsika::process::BoundaryCrossingProcess< - typename T::_TDerived>, - T>::value>, - public Continuous< - T, - std::is_base_of<corsika::process::ContinuousProcess<typename T::_TDerived>, - T>::value>, - public Decay< - T, std::is_base_of<corsika::process::DecayProcess<typename T::_TDerived>, - T>::value>, - public Interaction< - T, - std::is_base_of<corsika::process::InteractionProcess<typename T::_TDerived>, - T>::value>, - public Secondaries< - T, std::is_base_of<corsika::process::SecondariesProcess<typename T::_TDerived>, - T>::value> {}; - } // namespace devtools -} // namespace corsika::process \ No newline at end of file diff --git a/Processes/DevTools/Analytics/ImplBoundary.h b/Processes/DevTools/Analytics/ImplBoundary.h deleted file mode 100644 index 7f2ffcb48..000000000 --- a/Processes/DevTools/Analytics/ImplBoundary.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * (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 <corsika/process/BoundaryCrossingProcess.h> - -#include <corsika/process/devtools/ExecTime.h> - -namespace corsika::process { - namespace devtools { - - template <typename T> - class _ExecTimeImpl; - - template <class T, bool TCheck> - class Boundary; - - template <class T> - class Boundary<T, false> {}; - - template <class T> - class Boundary<T, true> : public _ExecTimeImpl<T> { - private: - public: - template <typename Particle, typename VTNType> - EProcessReturn DoBoundaryCrossing(Particle& p, VTNType const& from, - VTNType const& to) { - this->start(); - auto r = T::DoBoundaryCrossing(p, from, to); - this->stop(); - return r; - } - }; - } // namespace devtools -} // namespace corsika::process \ No newline at end of file diff --git a/Processes/DevTools/Analytics/ImplContinuous.h b/Processes/DevTools/Analytics/ImplContinuous.h deleted file mode 100644 index acddf1380..000000000 --- a/Processes/DevTools/Analytics/ImplContinuous.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * (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 <corsika/process/ContinuousProcess.h> - -#include <corsika/process/devtools/ExecTime.h> - -namespace corsika::process { - namespace devtools { - template <typename T> - class _ExecTimeImpl; - - template <class T, bool TCheck> - class Continuous; - - template <class T> - class Continuous<T, false> {}; - - template <class T> - class Continuous<T, true> : public _ExecTimeImpl<T> { - private: - public: - template <typename Particle, typename Track> - EProcessReturn DoContinuous(Particle& p, Track const& t) const { - this->start(); - auto r = T::DoContinous(p, t); - this->stop(); - return r; - } - - template <typename Particle, typename Track> - units::si::LengthType MaxStepLength(Particle const& p, Track const& track) const { - this->start(); - auto r = T::MaxStepLength(p, track); - this->stop(); - return r; - } - }; - } // namespace devtools -} // namespace corsika::process \ No newline at end of file diff --git a/Processes/DevTools/Analytics/ImplDecay.h b/Processes/DevTools/Analytics/ImplDecay.h deleted file mode 100644 index 22961f94e..000000000 --- a/Processes/DevTools/Analytics/ImplDecay.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * (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 <corsika/process/DecayProcess.h> - -#include <corsika/process/devtools/ExecTime.h> - -namespace corsika::process { - namespace devtools { - template <typename T> - class _ExecTimeImpl; - - template <class T, bool TCheck> - class Decay; - - template <class T> - class Decay<T, false> {}; - - template <class T> - class Decay<T, true> : public _ExecTimeImpl<T> { - private: - public: - template <typename Particle> - EProcessReturn DoDecay(Particle& p) { - this->start(); - auto r = T::DoDecay(p); - this->stop(); - return r; - } - - template <typename Particle> - corsika::units::si::TimeType GetLifetime(Particle& p) { - this->start(); - auto r = T::GetLifetime(p); - this->stop(); - return r; - } - }; - } // namespace devtools -} // namespace corsika::process \ No newline at end of file diff --git a/Processes/DevTools/Analytics/ImplInteraction.h b/Processes/DevTools/Analytics/ImplInteraction.h deleted file mode 100644 index e6faf403b..000000000 --- a/Processes/DevTools/Analytics/ImplInteraction.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * (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 <corsika/process/InteractionProcess.h> - -#include <corsika/process/devtools/ExecTime.h> - -namespace corsika::process { - namespace devtools { - template <typename T> - class _ExecTimeImpl; - - template <class T, bool TCheck> - class Interaction; - - template <class T> - class Interaction<T, false> {}; - - template <class T> - class Interaction<T, true> : public _ExecTimeImpl<T> { - private: - public: - template <typename Particle> - EProcessReturn DoInteraction(Particle& p) { - this->start(); - auto r = T::DoInteraction(p); - this->stop(); - return r; - } - - template <typename Particle> - corsika::units::si::GrammageType GetInteractionLength(Particle& p) { - this->start(); - auto r = T::GetInteractionLength(p); - this->stop(); - return r; - } - }; - } // namespace devtools -} // namespace corsika::process \ No newline at end of file diff --git a/Processes/DevTools/Analytics/ImplSecondaries.h b/Processes/DevTools/Analytics/ImplSecondaries.h deleted file mode 100644 index c2b3cee80..000000000 --- a/Processes/DevTools/Analytics/ImplSecondaries.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * (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 <corsika/process/SecondariesProcess.h> - -#include <corsika/process/devtools/ExecTime.h> - -namespace corsika::process { - namespace devtools { - template <typename T> - class _ExecTimeImpl; - - template <class T, bool TCheck> - class Secondaries; - - template <class T> - class Secondaries<T, false> {}; - - template <class T> - class Secondaries<T, true> : public _ExecTimeImpl<T> { - private: - public: - template <typename Secondaries> - inline EProcessReturn DoSecondaries(Secondaries& sec) { - this->start(); - auto r = T::DoSecondaries(sec); - this->stop(); - return r; - } - }; - } // 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 deleted file mode 100644 index 4b5701ffb..000000000 --- a/Processes/DevTools/Analytics/testExecTime.cc +++ /dev/null @@ -1,80 +0,0 @@ -/* - * (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> - -#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 <random> - -using namespace corsika::process; -using namespace corsika::process::devtools; - -TEST_CASE("ContinuousProcess interface", "[proccesses][DevTools ExecTime]") { - - ExecTime<DummyBoundaryCrossingProcess<50>> execTime; - int tmp = 0; - - SECTION("BoundaryCrossing") { - auto start = std::chrono::steady_clock::now(); - REQUIRE(execTime.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(50).margin(5)); - - for (int i = 0; i < 100; i++) execTime.DoBoundaryCrossing(tmp, 0, 0); - - REQUIRE(execTime.mean() == Approx(50 * 1000).margin(2 * 1000)); - - REQUIRE(execTime.sumTime() == Approx(50 * 100 * 1000).margin(200 * 1000)); - - REQUIRE(execTime.var() == Approx(0).margin(20000)); - } - - SECTION("TestMeanAlgo") { - std::default_random_engine generator; - std::normal_distribution<double> distribution(10000.0, 200.0); - - double fStart; - double fElapsedSum; - double fMean; - double fMean2; - long long fMin; - long long fMax; - long long fN; - - for (int i = 0; i < 1000000; i++) { - auto timeDiv = distribution(generator); - - fElapsedSum += timeDiv; - fN = fN + 1; - - if (fMax < timeDiv) fMax = timeDiv; - - if (timeDiv < fMin) fMin = timeDiv; - - double delta = timeDiv - fMean; - fMean += delta / static_cast<double>(fN); - - double delta2 = timeDiv - fMean; - - fMean2 += delta * delta2; - } - - REQUIRE(fMean2 / fN == Approx(200*200).margin(200)); // Varianz - REQUIRE(fMean == Approx(10000).margin(10)); - } -} diff --git a/Processes/DevTools/CMakeLists.txt b/Processes/DevTools/CMakeLists.txt deleted file mode 100644 index 794938608..000000000 --- a/Processes/DevTools/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index 2b2a04293..000000000 --- a/Processes/DevTools/Dummy/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -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 deleted file mode 100644 index 475cece83..000000000 --- a/Processes/DevTools/Dummy/DummyBoundaryCrossingProcess.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * (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 <corsika/process/BoundaryCrossingProcess.h> - -#include <chrono> -#include <thread> - -namespace corsika::process { - namespace devtools { - - template <int ISleep> - class DummyBoundaryCrossingProcess - : public BoundaryCrossingProcess<DummyBoundaryCrossingProcess<ISleep>> { - private: - public: - template <typename Particle, typename VTNType> - EProcessReturn DoBoundaryCrossing(Particle&, VTNType const&, - VTNType const&) { - 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 deleted file mode 100644 index c58794bfb..000000000 --- a/Processes/DevTools/Dummy/DummyContinuousProcess.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * (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 <corsika/process/ContinuousProcess.h> - -#include <chrono> -#include <thread> - -namespace corsika::process { - namespace devtools { - - template <int ISleep> - class DummyContinuousProcess : public 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&, Track const& ) 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 deleted file mode 100644 index 1b6739307..000000000 --- a/Processes/DevTools/Dummy/DummyDecayProcess.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * (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 <corsika/process/DecayProcess.h> -#include <corsika/units/PhysicalUnits.h> - -#include <chrono> -#include <thread> - -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&) { - 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 deleted file mode 100644 index 3e882afb9..000000000 --- a/Processes/DevTools/Dummy/DummyInteractionProcess.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * (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 <corsika/process/InteractionProcess.h> - -#include <chrono> -#include <thread> - -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&) { - 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 deleted file mode 100644 index f06db70b5..000000000 --- a/Processes/DevTools/Dummy/DummySecondariesProcess.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * (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 <corsika/process/SecondariesProcess.h> - -#include <chrono> -#include <thread> - -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 deleted file mode 100644 index a2226c3dd..000000000 --- a/Processes/DevTools/Dummy/TestDummy.cc +++ /dev/null @@ -1,93 +0,0 @@ -/* - * (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; - -using namespace corsika::units::si; - -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)); - } - - SECTION("Decay") { - auto start = std::chrono::steady_clock::now(); - REQUIRE(dd.DoDecay(tmp) == 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(dd.GetLifetime(tmp) == units::si::second * 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)); - } - - SECTION("Interaction") { - auto start = std::chrono::steady_clock::now(); - REQUIRE(di.DoInteraction(tmp) == 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(di.GetInteractionLength(tmp) == (units::si::gram / 1_cm / 1_cm) * 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)); - } - - SECTION("Secondaries") { - auto start = std::chrono::steady_clock::now(); - REQUIRE(dse.DoSecondaries(tmp) == EProcessReturn::eOk); - auto end = std::chrono::steady_clock::now(); - REQUIRE(std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() == - Approx(1000).margin(1)); - - } -} -- GitLab