Skip to content

Commit 98399e0

Browse files
committed
Track message state as enum
1 parent d954802 commit 98399e0

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

Framework/Core/include/Framework/MessageContext.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ struct Output;
5353
class MessageContext
5454
{
5555
public:
56+
enum class DispatchState {
57+
NotDispatched,
58+
Dispatched,
59+
Discarded,
60+
};
61+
5662
constexpr static ServiceKind service_kind = ServiceKind::Stream;
5763

5864
// so far we are only using one instance per named channel
@@ -495,16 +501,17 @@ class MessageContext
495501
o2::header::DataHeader* findMessageHeader(const Output& spec);
496502
o2::header::Stack* findMessageHeaderStack(const Output& spec);
497503
[[nodiscard]] int countDeviceOutputs(bool excludeDPLOrigin = false) const;
498-
void fakeDispatch() { mDidDispatch = true; }
499-
bool didDispatch() { return mDidDispatch; }
504+
void fakeDispatch() { mDispatchState = DispatchState::Dispatched; }
505+
[[nodiscard]] bool didDispatch() const { return mDispatchState == DispatchState::Dispatched; }
506+
[[nodiscard]] DispatchState dispatchState() const { return mDispatchState; }
500507
o2::framework::DataProcessingHeader* findMessageDataProcessingHeader(const Output& spec);
501508
std::pair<o2::header::DataHeader*, o2::framework::DataProcessingHeader*> findMessageHeaders(const Output& spec);
502509

503510
private:
504511
FairMQDeviceProxy& mProxy;
505512
Messages mMessages;
506513
Messages mScheduledMessages;
507-
bool mDidDispatch = false;
514+
DispatchState mDispatchState = DispatchState::NotDispatched;
508515
DispatchControl mDispatchControl;
509516
/// Cached messages, in case we want to reuse them.
510517
std::unordered_map<int64_t, std::unique_ptr<fair::mq::Message>> mMessageCache;

Framework/Core/src/CommonServices.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ o2::framework::ServiceSpec CommonServices::streamContextSpec()
185185
auto& routes = processingContext.services().get<DeviceSpec const>().outputs;
186186
auto& timeslice = processingContext.services().get<TimingInfo>().timeslice;
187187
auto& messageContext = processingContext.services().get<MessageContext>();
188+
// Do not report discarded messages as missing outputs.
189+
if (messageContext.dispatchState() == MessageContext::DispatchState::Discarded) {
190+
return;
191+
}
188192
// Check if we never created any data for this timeslice
189193
// if we did not, but we still have didDispatched set to true
190194
// it means it was created out of band.

Framework/Core/src/MessageContext.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ int MessageContext::countDeviceOutputs(bool excludeDPLOrigin) const
8484
{
8585
// If we dispatched some messages before the end of the callback
8686
// we need to account for them as well.
87-
int noutputs = mDidDispatch ? 1 : 0;
87+
int noutputs = mDispatchState == DispatchState::Dispatched ? 1 : 0;
8888
constexpr o2::header::DataOrigin DataOriginDPL{"DPL"};
8989
for (auto it = mMessages.rbegin(); it != mMessages.rend(); ++it) {
9090
if (!excludeDPLOrigin || (*it)->header()->dataOrigin != DataOriginDPL) {
@@ -103,13 +103,13 @@ void MessageContext::clear()
103103
{
104104
// Verify that everything has been sent on clear.
105105
assert(std::all_of(mMessages.begin(), mMessages.end(), [](auto& m) { return m->empty(); }));
106-
mDidDispatch = false;
106+
mDispatchState = DispatchState::NotDispatched;
107107
mMessages.clear();
108108
}
109109

110110
void MessageContext::discard()
111111
{
112-
mDidDispatch = false;
112+
mDispatchState = DispatchState::Discarded;
113113
mScheduledMessages.clear();
114114
mMessages.clear();
115115
}
@@ -164,7 +164,7 @@ void MessageContext::schedule(Messages::value_type&& message)
164164
}
165165
mDispatchControl.dispatch(std::move(parts), ChannelIndex{ci}, DefaultChannelIndex);
166166
}
167-
mDidDispatch = mScheduledMessages.empty() == false;
167+
mDispatchState = DispatchState::Dispatched;
168168
mScheduledMessages.clear();
169169
}
170170
}

0 commit comments

Comments
 (0)