Skip to content
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
38 changes: 29 additions & 9 deletions Framework/Core/include/Framework/CallbackService.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "CallbackRegistry.h"
#include <tuple>

class FairMQRegionInfo;

namespace o2
{
namespace framework
Expand All @@ -35,7 +37,23 @@ class CallbackService
/// Invoked when we are notified that no further data will arrive.
/// Notice that one could have more "EndOfData" notifications. Because
/// we could be signaled by control that the data flow restarted.
EndOfStream
EndOfStream,

/// Invoked whenever FairMQ notifies us of a new region
///
/// return AlgorithmSpec::InitCallback{[=](InitContext& ic) {
/// auto& callbacks = ic.services().get<CallbackService>();
/// callbacks.set(CallbackService::Id::RegionInfoCallback, [](FairMQRegionInfo const& info) {
/// ... do GPU init ...
/// });
/// }
/// ...
/// return [task](ProcessingContext& pc) {
/// // your processing loop. Guaranteed to be called synchronously
/// // with the callback
/// };
/// }};
RegionInfoCallback
};

template <typename T, T... v>
Expand All @@ -51,15 +69,17 @@ class CallbackService
using IdleCallback = std::function<void()>;
using ClockTickCallback = std::function<void()>;
using EndOfStreamCallback = std::function<void(EndOfStreamContext&)>;
using RegionInfoCallback = std::function<void(FairMQRegionInfo const&)>;

using Callbacks = CallbackRegistry<Id, //
RegistryPair<Id, Id::Start, StartCallback>, //
RegistryPair<Id, Id::Stop, StopCallback>, //
RegistryPair<Id, Id::Reset, ResetCallback>, //
RegistryPair<Id, Id::Idle, IdleCallback>, //
RegistryPair<Id, Id::ClockTick, ClockTickCallback>, //
RegistryPair<Id, Id::EndOfStream, EndOfStreamCallback> //
>; //
using Callbacks = CallbackRegistry<Id, //
RegistryPair<Id, Id::Start, StartCallback>, //
RegistryPair<Id, Id::Stop, StopCallback>, //
RegistryPair<Id, Id::Reset, ResetCallback>, //
RegistryPair<Id, Id::Idle, IdleCallback>, //
RegistryPair<Id, Id::ClockTick, ClockTickCallback>, //
RegistryPair<Id, Id::EndOfStream, EndOfStreamCallback>, //
RegistryPair<Id, Id::RegionInfoCallback, RegionInfoCallback> //
>; //

// set callback for specified processing step
template <typename U>
Expand Down
2 changes: 2 additions & 0 deletions Framework/Core/include/Framework/DataProcessingDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class DataProcessingDevice : public FairMQDevice
public:
DataProcessingDevice(DeviceSpec const& spec, ServiceRegistry&, DeviceState& state);
void Init() final;
void InitTask() final;
void PreRun() final;
void PostRun() final;
void Reset() final;
Expand Down Expand Up @@ -84,6 +85,7 @@ class DataProcessingDevice : public FairMQDevice
uint64_t mBeginIterationTimestamp = 0; /// The timestamp of when the current ConditionalRun was started
DataProcessingStats mStats; /// Stats about the actual data processing.
int mCurrentBackoff = 0; /// The current exponential backoff value.
std::vector<FairMQRegionInfo> mPendingRegionInfos; /// A list of the region infos not yet notified.
};

} // namespace o2::framework
Expand Down
21 changes: 21 additions & 0 deletions Framework/Core/src/DataProcessingDevice.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@ void DataProcessingDevice::Init()
}
}

void DataProcessingDevice::InitTask()
{
for (auto& channel : fChannels) {
channel.second.at(0).Transport()->SubscribeToRegionEvents([& pendingRegionInfos = mPendingRegionInfos](FairMQRegionInfo info) {
LOG(debug) << ">>> Region info event" << info.event;
LOG(debug) << "id: " << info.id;
LOG(debug) << "ptr: " << info.ptr;
LOG(debug) << "size: " << info.size;
LOG(debug) << "flags: " << info.flags;
pendingRegionInfos.push_back(info);
});
}
}

void DataProcessingDevice::PreRun() { mServiceRegistry.get<CallbackService>()(CallbackService::Id::Start); }

void DataProcessingDevice::PostRun() { mServiceRegistry.get<CallbackService>()(CallbackService::Id::Stop); }
Expand Down Expand Up @@ -250,6 +264,13 @@ bool DataProcessingDevice::ConditionalRun()
auto now = std::chrono::high_resolution_clock::now();
mBeginIterationTimestamp = (uint64_t)std::chrono::duration<double, std::milli>(now.time_since_epoch()).count();

if (mPendingRegionInfos.empty() == false) {
std::vector<FairMQRegionInfo> toBeNotified;
toBeNotified.swap(mPendingRegionInfos); // avoid any MT issue.
for (auto& info : toBeNotified) {
mServiceRegistry.get<CallbackService>()(CallbackService::Id::RegionInfoCallback, info);
}
}
mServiceRegistry.get<CallbackService>()(CallbackService::Id::ClockTick);
// Whether or not we had something to do.
bool active = false;
Expand Down