Commit cd064c66 authored by Jens Kroeger's avatar Jens Kroeger
Browse files

Merge branch 'cleanup_event' into 'master'

Properly Document Event Class

See merge request !188
parents b03bcb4e 8a141e76
Pipeline #1182856 passed with stages
in 36 minutes and 47 seconds
......@@ -2,6 +2,93 @@
using namespace corryvreckan;
double Event::start() const {
return timestamp();
}
double Event::end() const {
return end_;
}
double Event::duration() const {
return (end_ - timestamp());
}
void Event::addTrigger(uint32_t trigger_id, double trigger_ts) {
trigger_list_.emplace(trigger_id, trigger_ts);
}
bool Event::hasTriggerID(uint32_t trigger_id) const {
return (trigger_list_.find(trigger_id) != trigger_list_.end());
}
double Event::getTriggerTime(uint32_t trigger_id) const {
return trigger_list_.find(trigger_id)->second;
}
std::map<uint32_t, double> Event::triggerList() const {
return trigger_list_;
}
Event::Position Event::getTimestampPosition(double timestamp) const {
if(timestamp < start()) {
return Position::BEFORE;
} else if(end() < timestamp) {
return Position::AFTER;
} else {
return Position::DURING;
}
}
Event::Position Event::getFramePosition(double frame_start, double frame_end, bool inclusive) const {
// The frame is ill-defined, we have no idea what to do with this data:
if(frame_end < frame_start) {
return Position::UNKNOWN;
}
if(inclusive) {
// Return DURING if there is any overlap
if(frame_end < start()) {
return Position::BEFORE;
} else if(end() < frame_start) {
return Position::AFTER;
} else {
return Position::DURING;
}
} else {
// Return DURING only if fully covered
if(frame_start < start()) {
return Position::BEFORE;
} else if(end() < frame_end) {
return Position::AFTER;
} else {
return Position::DURING;
}
}
}
Event::Position Event::getTriggerPosition(uint32_t trigger_id) const {
// If we have no triggers we cannot make a statement:
if(trigger_list_.empty()) {
return Position::UNKNOWN;
}
if(hasTriggerID(trigger_id)) {
return Position::DURING;
} else if(trigger_list_.upper_bound(trigger_id) == trigger_list_.begin()) {
// Upper bound returns first element that is greater than the given key - in this case, the first map element
// is greater than the provided trigger number - which consequently is before the event.
return Position::BEFORE;
} else if(trigger_list_.lower_bound(trigger_id) == trigger_list_.end()) {
// Lower bound returns the first element that is *not less* than the given key - in this case, even the last
// map element is less than the trigger number - which consequently is after the event.
return Position::AFTER;
} else {
// We have not enough information to provide position information.
return Position::UNKNOWN;
}
}
void Event::print(std::ostream& out) const {
out << "Start: " << start() << std::endl;
out << "End: " << end();
......
......@@ -15,14 +15,37 @@ namespace corryvreckan {
AFTER, // StandardEvent is after current event
};
// Constructors and destructors
/**
* @brief Default constructor
*/
Event() = default;
/**
* @brief Constructor for event bojects
* @param start Start timestamp of the event
* @param end End timestamp of the event
* @param trigger_list Optional list of triggers assigned to this event, containing their ID and timestamps
*/
Event(double start, double end, std::map<uint32_t, double> trigger_list = std::map<uint32_t, double>())
: Object(start), end_(end), trigger_list_(std::move(trigger_list)){};
double start() const { return timestamp(); };
double end() const { return end_; };
double duration() const { return (end_ - timestamp()); };
/**
* @brief Get the timestamp of the start of the event
* @return Start timestamp of the event
*/
double start() const;
/**
* @brief Get the timestamp of the end of the event
* @return End timestamp of the event
*/
double end() const;
/**
* @brief Get the duration of the event
* @return Duration of the event
*/
double duration() const;
/**
* @brief Add a new trigger ID to this event
......@@ -30,23 +53,23 @@ namespace corryvreckan {
* @param trigger_ts Timestamp corresponding to the trigger
*
* Trigger IDs are only added if they do not exist yet. Adding the same trigger ID twice will not change the
*corresponding timestamp, the list remains unchanged.
* corresponding timestamp, the list remains unchanged.
**/
void addTrigger(uint32_t trigger_id, double trigger_ts) { trigger_list_.emplace(trigger_id, trigger_ts); }
void addTrigger(uint32_t trigger_id, double trigger_ts);
/**
* @brief Check if trigger ID exists in current event
* @param trigger_id ID of the trigger to be checked for
* @return Bool whether trigger ID was found
**/
bool hasTriggerID(uint32_t trigger_id) const { return (trigger_list_.find(trigger_id) != trigger_list_.end()); }
bool hasTriggerID(uint32_t trigger_id) const;
/**
* @brief Get trigger timestamp corresponding to a given trigger ID
* @param trigger_id ID of the trigger for which the timestamp shall be returned
* @return Timestamp corresponding to the trigger
**/
double getTriggerTime(uint32_t trigger_id) const { return trigger_list_.find(trigger_id)->second; }
double getTriggerTime(uint32_t trigger_id) const;
/**
* @brief Returns position of a timestamp relative to the current event
......@@ -55,15 +78,7 @@ namespace corryvreckan {
* @param frame_start Timestamp to get position for
* @return Position of the given timestamp with respect to the defined event.
*/
Position getTimestampPosition(double timestamp) {
if(timestamp < start()) {
return Position::BEFORE;
} else if(end() < timestamp) {
return Position::AFTER;
} else {
return Position::DURING;
}
}
Position getTimestampPosition(double timestamp) const;
/**
* @brief Returns position of a time frame defined by a start and end point relative to the current event
......@@ -79,32 +94,7 @@ namespace corryvreckan {
* @param inclusive Boolean to select inclusive or exclusive mode
* @return Position of the given time frame with respect to the defined event.
*/
Position getFramePosition(double frame_start, double frame_end, bool inclusive = true) {
// The frame is ill-defined, we have no idea what to do with this data:
if(frame_end < frame_start) {
return Position::UNKNOWN;
}
if(inclusive) {
// Return DURING if there is any overlap
if(frame_end < start()) {
return Position::BEFORE;
} else if(end() < frame_start) {
return Position::AFTER;
} else {
return Position::DURING;
}
} else {
// Return DURING only if fully covered
if(frame_start < start()) {
return Position::BEFORE;
} else if(end() < frame_end) {
return Position::AFTER;
} else {
return Position::DURING;
}
}
}
Position getFramePosition(double frame_start, double frame_end, bool inclusive = true) const;
/**
* @brief Returns position of a given trigger ID with respect to the currently defined event.
......@@ -116,29 +106,13 @@ namespace corryvreckan {
* @param trigger_id Given trigger ID to check
* @return Position of the given trigger ID with respect to the defined event.
*/
Position getTriggerPosition(uint32_t trigger_id) const {
// If we have no triggers we cannot make a statement:
if(trigger_list_.empty()) {
return Position::UNKNOWN;
}
if(hasTriggerID(trigger_id)) {
return Position::DURING;
} else if(trigger_list_.upper_bound(trigger_id) == trigger_list_.begin()) {
// Upper bound returns first element that is greater than the given key - in this case, the first map element
// is greater than the provided trigger number - which consequently is before the event.
return Position::BEFORE;
} else if(trigger_list_.lower_bound(trigger_id) == trigger_list_.end()) {
// Lower bound returns the first element that is *not less* than the given key - in this case, even the last
// map element is less than the trigger number - which consequently is after the event.
return Position::AFTER;
} else {
// We have not enough information to provide position information.
return Position::UNKNOWN;
}
}
std::map<uint32_t, double> triggerList() const { return trigger_list_; }
Position getTriggerPosition(uint32_t trigger_id) const;
/**
* @brief Retrieve list with all triggers know to the event
* @return Map of tirgger IDs with their corresponding timestamps
*/
std::map<uint32_t, double> triggerList() const;
/**
* @brief Print an ASCII representation of Pixel to the given stream
......@@ -147,11 +121,14 @@ namespace corryvreckan {
void print(std::ostream& out) const override;
protected:
// Timestamp of the end of the event
double end_;
// List with all triggers known to the event, containing the trigger ID and its timestamp
std::map<uint32_t, double> trigger_list_{};
// ROOT I/O class definition - update version number when you change this class!
ClassDefOverride(Event, 5)
ClassDefOverride(Event, 6)
};
} // namespace corryvreckan
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment