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

Allow global::OutputModule to use a StreamCache #34567

Merged
merged 1 commit into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions FWCore/Framework/interface/global/OutputModuleBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ namespace edm {
void doBeginJob();
void doEndJob();

void doBeginStream(StreamID id);
void doEndStream(StreamID id);
void doBeginStream(StreamID id) { doBeginStream_(id); }
void doEndStream(StreamID id) { doEndStream_(id); }

bool doEvent(EventTransitionInfo const&, ActivityRegistry*, ModuleCallingContext const*);
//For now this is a placeholder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,37 @@ namespace edm {
virtual void respondToCloseInputFile(FileBlock const&) = 0;
};

template <typename T, typename C>
class StreamCacheHolder : public virtual T {
public:
explicit StreamCacheHolder(edm::ParameterSet const& iPSet) : OutputModuleBase(iPSet) {}
StreamCacheHolder(StreamCacheHolder<T, C> const&) = delete;
StreamCacheHolder<T, C>& operator=(StreamCacheHolder<T, C> const&) = delete;
~StreamCacheHolder() override {
for (auto c : caches_) {
delete c;
}
}

protected:
C* streamCache(edm::StreamID iID) const { return caches_[iID.value()]; }

private:
void preallocStreams(unsigned int iNStreams) final { caches_.resize(iNStreams, static_cast<C*>(nullptr)); }
void doBeginStream_(StreamID id) final { caches_[id.value()] = beginStream(id).release(); }
void doEndStream_(StreamID id) final {
endStream(id);
delete caches_[id.value()];
caches_[id.value()] = nullptr;
}

virtual std::unique_ptr<C> beginStream(edm::StreamID) const = 0;
virtual void endStream(edm::StreamID) const {}

//When threaded we will have a container for N items whre N is # of streams
std::vector<C*> caches_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious (since the pattern is already elsewhere), why are we not using std::vector<std::unique_ptr<C>> here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good question.

};

template <typename T, typename C>
class RunCacheHolder : public virtual T {
public:
Expand Down Expand Up @@ -117,6 +148,11 @@ namespace edm {
typedef edm::global::outputmodule::LuminosityBlockCacheHolder<edm::global::OutputModuleBase, C> Type;
};

template <typename C>
struct AbilityToImplementor<edm::StreamCache<C>> {
typedef edm::global::outputmodule::StreamCacheHolder<edm::global::OutputModuleBase, C> Type;
};

} // namespace outputmodule
} // namespace global
} // namespace edm
Expand Down
20 changes: 18 additions & 2 deletions FWCore/Framework/src/WorkerT.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ namespace edm {
static bool constexpr value = true;
};

template <typename T>
struct has_only_stream_transition_functions {
static bool constexpr value = false;
};

template <>
struct has_only_stream_transition_functions<edm::global::OutputModuleBase> {
static bool constexpr value = true;
};

struct DoNothing {
template <typename... T>
inline void operator()(const T&...) {}
Expand Down Expand Up @@ -456,7 +466,10 @@ namespace edm {

template <typename T>
inline void WorkerT<T>::implBeginStream(StreamID id) {
std::conditional_t<workerimpl::has_stream_functions<T>::value, workerimpl::DoBeginStream<T>, workerimpl::DoNothing>
std::conditional_t<workerimpl::has_stream_functions<T>::value or
workerimpl::has_only_stream_transition_functions<T>::value,
workerimpl::DoBeginStream<T>,
workerimpl::DoNothing>
might_call;
might_call(this, id);
}
Expand All @@ -469,7 +482,10 @@ namespace edm {

template <typename T>
inline void WorkerT<T>::implEndStream(StreamID id) {
std::conditional_t<workerimpl::has_stream_functions<T>::value, workerimpl::DoEndStream<T>, workerimpl::DoNothing>
std::conditional_t<workerimpl::has_stream_functions<T>::value or
workerimpl::has_only_stream_transition_functions<T>::value,
workerimpl::DoEndStream<T>,
workerimpl::DoNothing>
might_call;
might_call(this, id);
}
Expand Down