-
Notifications
You must be signed in to change notification settings - Fork 35
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
Implement event batching in the miniframework #143
base: master
Are you sure you want to change the base?
Changes from all commits
64f574c
277830d
5adaa3d
a8ce518
5fc49aa
424f889
8594f86
2b0de20
8070c2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||||||||||||
#ifndef EventBatch_h | ||||||||||||||
#define EventBatch_h | ||||||||||||||
|
||||||||||||||
#include <vector> | ||||||||||||||
|
||||||||||||||
#include "Framework/Event.h" | ||||||||||||||
#include "Framework/EventRange.h" | ||||||||||||||
|
||||||||||||||
namespace edm { | ||||||||||||||
|
||||||||||||||
class EventBatch { | ||||||||||||||
public: | ||||||||||||||
Event& emplace(int streamId, int eventId, ProductRegistry const& reg) { | ||||||||||||||
events_.emplace_back(streamId, eventId, reg); | ||||||||||||||
return events_.back(); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
void reserve(size_t capacity) { events_.reserve(capacity); } | ||||||||||||||
|
||||||||||||||
void clear() { events_.clear(); } | ||||||||||||||
|
||||||||||||||
size_t size() const { return events_.size(); } | ||||||||||||||
|
||||||||||||||
bool empty() const { return events_.empty(); } | ||||||||||||||
|
||||||||||||||
EventRange range() { return EventRange(&events_.front(), &events_.back() + 1); } | ||||||||||||||
|
||||||||||||||
ConstEventRange range() const { return ConstEventRange(&events_.front(), &events_.back() + 1); } | ||||||||||||||
Comment on lines
+26
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not very relevant for prototyping itself, but i think being able to use something along
Suggested change
would be clearer to read. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason I didn't do that was to avoid making An alternative could be to add a constructor like template <typename IT>
EventRange(IT begin, IT end) : begin_(std::addressof(*begin)), end_(std::addressof((*end)) { ... } but then one could be tempted to pass non-contiguous iterators. assert((end - begin) == (end_ - begin_)); or, once we move to C++20 with concepts, we could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the purposes of the prototype the current pointers are fine for me. With C++20 maybe even passing the range as |
||||||||||||||
|
||||||||||||||
private: | ||||||||||||||
std::vector<edm::Event> events_; | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
} // namespace edm | ||||||||||||||
|
||||||||||||||
#endif // EventBatch_h |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#ifndef EventRange_h | ||
#define EventRange_h | ||
|
||
#include <cassert> | ||
#include <sstream> | ||
#include <stdexcept> | ||
|
||
#include "Framework/Event.h" | ||
|
||
namespace edm { | ||
|
||
class EventRange { | ||
public: | ||
EventRange(Event* begin, Event* end) : begin_(begin), end_(end) { | ||
assert(begin_); | ||
assert(end_); | ||
assert(end_ >= begin_); | ||
} | ||
|
||
Event* begin() { return begin_; } | ||
|
||
Event const* begin() const { return begin_; } | ||
|
||
Event* end() { return end_; } | ||
|
||
Event const* end() const { return end_; } | ||
|
||
size_t size() const { return end_ - begin_; } | ||
|
||
bool empty() const { return end_ == begin_; } | ||
|
||
Event& at(size_t index) { | ||
if (index >= size()) { | ||
std::stringstream msg; | ||
msg << "EventRange::at() range check failed: index " << index << " is outside the range [0.." << size() << ")"; | ||
throw std::out_of_range(msg.str()); | ||
} | ||
return begin_[index]; | ||
} | ||
|
||
Event const& at(size_t index) const { | ||
if (index >= size()) { | ||
std::stringstream msg; | ||
msg << "EventRange::at() range check failed: index " << index << " is outside the range [0.." << size() << ")"; | ||
throw std::out_of_range(msg.str()); | ||
} | ||
return begin_[index]; | ||
} | ||
|
||
Event& operator[](size_t index) { return begin_[index]; } | ||
|
||
Event const& operator[](size_t index) const { return begin_[index]; } | ||
|
||
private: | ||
Event* begin_; | ||
Event* end_; | ||
}; | ||
|
||
class ConstEventRange { | ||
public: | ||
ConstEventRange(Event const* begin, Event const* end) : begin_(begin), end_(end) { | ||
assert(begin_); | ||
assert(end_); | ||
assert(end_ >= begin_); | ||
} | ||
|
||
ConstEventRange(EventRange range) : begin_(range.begin()), end_(range.end()) {} | ||
|
||
Event const* begin() const { return begin_; } | ||
|
||
Event const* end() const { return end_; } | ||
|
||
size_t size() const { return end_ - begin_; } | ||
|
||
bool empty() const { return end_ == begin_; } | ||
|
||
Event const& at(size_t index) { | ||
if (index >= size()) { | ||
std::stringstream msg; | ||
msg << "ConstEventRange::at() range check failed: index " << index << " is outside the range [0.." << size() | ||
<< ")"; | ||
throw std::out_of_range(msg.str()); | ||
} | ||
return begin_[index]; | ||
} | ||
|
||
Event const& operator[](size_t index) const { return begin_[index]; } | ||
|
||
private: | ||
Event const* begin_; | ||
Event const* end_; | ||
}; | ||
|
||
} // namespace edm | ||
|
||
#endif // EventRange_h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really minor, but is this a typo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've used both spellings while prototyping, so I don't mind either way: this should capture the "state" or "states" of multiple events:
state
is more consistent withAsyncState
states
is more consistent withevents
Re-thinking a bit more... maybe
state
is more correct, since it is one object, not e.g. avector<AsyncState>
.