From 19be5ff5abbc1ee75df6229ee0556e40bcc2f740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?JulienD=C3=B6rner?= Date: Wed, 7 Aug 2024 18:00:36 +0200 Subject: [PATCH 1/7] add trajectory length observer feature --- include/crpropa/module/Observer.h | 11 +++++++++++ src/module/Observer.cpp | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/crpropa/module/Observer.h b/include/crpropa/module/Observer.h index adf7c8fc4..42234998e 100644 --- a/include/crpropa/module/Observer.h +++ b/include/crpropa/module/Observer.h @@ -281,6 +281,17 @@ class ObserverTimeEvolution: public ObserverFeature { DetectionState checkDetection(Candidate *candidate) const; std::string getDescription() const; }; + +class ObserverTrajectoryLength: public ObserverFeature { +private: + double maxLength; +public: + ObserverTrajectoryLength(double l); + + DetectionState checkDetection(Candidate *candidate) const; +}; + + /** @} */ } diff --git a/src/module/Observer.cpp b/src/module/Observer.cpp index c600dce50..3b464ed15 100644 --- a/src/module/Observer.cpp +++ b/src/module/Observer.cpp @@ -365,4 +365,17 @@ std::string ObserverSurface::getDescription() const { return ss.str(); } +// ObserverTrajectoryLength --------------------------------------------------- + +ObserverTrajectoryLength::ObserverTrajectoryLength(double l) : maxLength(l) { } + +DetectionState ObserverTrajectoryLength::checkDetection(Candidate *cand) const { + double currentLength = cand -> getTrajectoryLength(); + + if (currentLength > maxLength) + return DETECTED; + + cand -> limitNextStep(maxLength - currentLength); + return NOTHING; +} } // namespace crpropa From d48ba065e33c9bff76d25058ae97a935bbb208cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?JulienD=C3=B6rner?= Date: Wed, 28 Aug 2024 16:54:51 +0200 Subject: [PATCH 2/7] update Abstract condition with debug information about flags and default rejectionFlag --- include/crpropa/Module.h | 10 ++++++++++ src/Module.cpp | 12 ++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/crpropa/Module.h b/include/crpropa/Module.h index e1fd41aaa..eaa6e20b4 100644 --- a/include/crpropa/Module.h +++ b/include/crpropa/Module.h @@ -59,7 +59,17 @@ class AbstractCondition: public Module { void setMakeAcceptedInactive(bool makeInactive); void setRejectFlag(std::string key, std::string value); void setAcceptFlag(std::string key, std::string value); + + void printRejectFlag(); + void printAcceptFlag(); +}; + +class DeactivateModule: public AbstractCondition { + public: + void process(Candidate *cand) const { reject(cand); } }; + + } // namespace crpropa #endif /* CRPROPA_MODULE_H */ diff --git a/src/Module.cpp b/src/Module.cpp index aa32c4a8c..aabbfd694 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -19,8 +19,7 @@ void Module::setDescription(const std::string &d) { AbstractCondition::AbstractCondition() : makeRejectedInactive(true), makeAcceptedInactive(false), rejectFlagKey( - "Rejected") { - + "Rejected"), rejectFlagValue( typeid(*this).name() ) { } void AbstractCondition::reject(Candidate *candidate) const { @@ -77,4 +76,13 @@ void AbstractCondition::setAcceptFlag(std::string key, std::string value) { acceptFlagValue = value; } +void AbstractCondition::printRejectFlag() { + std::cout << "rejectKey: " << rejectFlagKey << " with flag: " << rejectFlagValue << "\n"; +} + +void AbstractCondition::printAcceptFlag() { + std::cout << "acceptKey: " << acceptFlagKey << " with flag: " << acceptFlagValue << "\n"; +} + + } // namespace crpropa From 0f4ecdb1b46f9e100738f5d723a6dc787b34e6f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?JulienD=C3=B6rner?= Date: Wed, 28 Aug 2024 16:55:37 +0200 Subject: [PATCH 3/7] add type to destructor in Variant. --- src/Variant.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Variant.cpp b/src/Variant.cpp index f2f2bbfcb..822c3e30c 100644 --- a/src/Variant.cpp +++ b/src/Variant.cpp @@ -27,7 +27,7 @@ Variant::Variant(const char* s) { } Variant::~Variant() { - clear(); + clear(type); } const char* Variant::getTypeName() const { From c5304807d2169f3b4ad59e0609e02791cefc1215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?JulienD=C3=B6rner?= Date: Mon, 2 Sep 2024 08:50:13 +0200 Subject: [PATCH 4/7] rename Deactivation module, add comment --- include/crpropa/Module.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/crpropa/Module.h b/include/crpropa/Module.h index eaa6e20b4..e21c6b555 100644 --- a/include/crpropa/Module.h +++ b/include/crpropa/Module.h @@ -64,7 +64,11 @@ class AbstractCondition: public Module { void printAcceptFlag(); }; -class DeactivateModule: public AbstractCondition { +/** + @class Deactivation + @brief Direct deactivation of the candidate. Can be used for debuging. +*/ +class Deactivation: public AbstractCondition { public: void process(Candidate *cand) const { reject(cand); } }; From 63a1a3193249468cbac5ebb7353140903e3fef00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?JulienD=C3=B6rner?= Date: Tue, 3 Sep 2024 09:57:40 +0200 Subject: [PATCH 5/7] change printing flag to get functions --- include/crpropa/Module.h | 7 +++++-- src/Module.cpp | 10 ++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/crpropa/Module.h b/include/crpropa/Module.h index e21c6b555..e62f5b14e 100644 --- a/include/crpropa/Module.h +++ b/include/crpropa/Module.h @@ -60,8 +60,11 @@ class AbstractCondition: public Module { void setRejectFlag(std::string key, std::string value); void setAcceptFlag(std::string key, std::string value); - void printRejectFlag(); - void printAcceptFlag(); + // return the reject flag (key & value), delimiter is the "&". + std::string getRejectFlag(); + + // return the accept flag (key & value), delimiter is the "&" + std::string getAcceptFlag(); }; /** diff --git a/src/Module.cpp b/src/Module.cpp index aabbfd694..3af768bf9 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -76,12 +76,14 @@ void AbstractCondition::setAcceptFlag(std::string key, std::string value) { acceptFlagValue = value; } -void AbstractCondition::printRejectFlag() { - std::cout << "rejectKey: " << rejectFlagKey << " with flag: " << rejectFlagValue << "\n"; +std::string AbstractCondition::getRejectFlag() { + std::string out = rejectFlagKey + "&" + rejectFlagValue; + return out; } -void AbstractCondition::printAcceptFlag() { - std::cout << "acceptKey: " << acceptFlagKey << " with flag: " << acceptFlagValue << "\n"; +std::string AbstractCondition::getAcceptFlag() { + std::string out = acceptFlagKey + "&" + acceptFlagValue; + return out; } From e8f373ffeb0c4ab50874d4517b56127d079ed46f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?JulienD=C3=B6rner?= Date: Tue, 3 Sep 2024 09:59:06 +0200 Subject: [PATCH 6/7] remove ObserverTrajectoryLength, same can be done with a ObserverTimeEvolution with one timestep. --- include/crpropa/module/Observer.h | 10 ---------- src/module/Observer.cpp | 12 ------------ 2 files changed, 22 deletions(-) diff --git a/include/crpropa/module/Observer.h b/include/crpropa/module/Observer.h index 42234998e..529aa62ee 100644 --- a/include/crpropa/module/Observer.h +++ b/include/crpropa/module/Observer.h @@ -282,16 +282,6 @@ class ObserverTimeEvolution: public ObserverFeature { std::string getDescription() const; }; -class ObserverTrajectoryLength: public ObserverFeature { -private: - double maxLength; -public: - ObserverTrajectoryLength(double l); - - DetectionState checkDetection(Candidate *candidate) const; -}; - - /** @} */ } diff --git a/src/module/Observer.cpp b/src/module/Observer.cpp index 3b464ed15..5f1b3a2d5 100644 --- a/src/module/Observer.cpp +++ b/src/module/Observer.cpp @@ -365,17 +365,5 @@ std::string ObserverSurface::getDescription() const { return ss.str(); } -// ObserverTrajectoryLength --------------------------------------------------- -ObserverTrajectoryLength::ObserverTrajectoryLength(double l) : maxLength(l) { } - -DetectionState ObserverTrajectoryLength::checkDetection(Candidate *cand) const { - double currentLength = cand -> getTrajectoryLength(); - - if (currentLength > maxLength) - return DETECTED; - - cand -> limitNextStep(maxLength - currentLength); - return NOTHING; -} } // namespace crpropa From 84581ddd11705effc8ad014eb4cc19d3a264cd41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?JulienD=C3=B6rner?= Date: Thu, 5 Sep 2024 17:49:02 +0200 Subject: [PATCH 7/7] add explicit deleting of variant string --- src/Variant.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Variant.cpp b/src/Variant.cpp index 822c3e30c..dfd6b8c9e 100644 --- a/src/Variant.cpp +++ b/src/Variant.cpp @@ -28,6 +28,7 @@ Variant::Variant(const char* s) { Variant::~Variant() { clear(type); + delete data._t_string; } const char* Variant::getTypeName() const { @@ -676,7 +677,7 @@ Variant Variant::fromString(const std::string& s, Type t) { } void Variant::clear(Type t) { - if (t == TYPE_STRING) + if (t == TYPE_STRING) safeDelete(data._t_string); else if (t == TYPE_VECTOR3F) safeDelete(data._t_vector3f);