Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory management in Variants #502

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/crpropa/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
JulienDoerner marked this conversation as resolved.
Show resolved Hide resolved
void printAcceptFlag();
};

class DeactivateModule: public AbstractCondition {
JulienDoerner marked this conversation as resolved.
Show resolved Hide resolved
public:
void process(Candidate *cand) const { reject(cand); }
};


} // namespace crpropa

#endif /* CRPROPA_MODULE_H */
11 changes: 11 additions & 0 deletions include/crpropa/module/Observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,17 @@ class ObserverTimeEvolution: public ObserverFeature {
DetectionState checkDetection(Candidate *candidate) const;
std::string getDescription() const;
};

JulienDoerner marked this conversation as resolved.
Show resolved Hide resolved
class ObserverTrajectoryLength: public ObserverFeature {
private:
double maxLength;
public:
ObserverTrajectoryLength(double l);

DetectionState checkDetection(Candidate *candidate) const;
};


/** @} */

}
Expand Down
12 changes: 10 additions & 2 deletions src/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ void Module::setDescription(const std::string &d) {

AbstractCondition::AbstractCondition() :
makeRejectedInactive(true), makeAcceptedInactive(false), rejectFlagKey(
"Rejected") {

"Rejected"), rejectFlagValue( typeid(*this).name() ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would allow to check which module deactivated the candidate, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is the idea. This function was already implemented earlier but the value was not set correctly. I think the module name as default is a good starting option, without going through all modules and set it by hand.

}

void AbstractCondition::reject(Candidate *candidate) const {
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/Variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Variant::Variant(const char* s) {
}

Variant::~Variant() {
clear();
clear(type);
}

const char* Variant::getTypeName() const {
Expand Down
13 changes: 13 additions & 0 deletions src/module/Observer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading