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

Please consider the following formatting changes to #13638 #307

Closed
wants to merge 2 commits into from
Closed
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
67 changes: 6 additions & 61 deletions Framework/Core/include/Framework/Task.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,66 +14,11 @@
#include "Framework/AlgorithmSpec.h"
#include "Framework/CallbackService.h"
#include "Framework/EndOfStreamContext.h"
#include <utility>
#include <memory>

namespace o2::framework
{

/// Check if the class task has EndOfStream
template <typename T>
class has_endOfStream
{
typedef char one;
struct two {
char x[2];
};

template <typename C>
static one test(decltype(&C::endOfStream));
template <typename C>
static two test(...);

public:
enum { value = sizeof(test<T>(nullptr)) == sizeof(char) };
};

/// Check if the class task has EndOfStream
template <typename T>
class has_finaliseCCDB
{
typedef char one;
struct two {
char x[2];
};

template <typename C>
static one test(decltype(&C::finaliseCCDB));
template <typename C>
static two test(...);

public:
enum { value = sizeof(test<T>(nullptr)) == sizeof(char) };
};

/// Check if the class task has Stop
template <typename T>
class has_stop
{
typedef char one;
struct two {
char x[2];
};

template <typename C>
static one test(decltype(&C::stop));
template <typename C>
static two test(...);

public:
enum { value = sizeof(test<T>(nullptr)) == sizeof(char) };
};

/// A more familiar task API for the DPL.
/// This allows you to define your own tasks as subclasses
/// of o2::framework::Task and to pass them in the specification
Expand Down Expand Up @@ -115,19 +60,19 @@ AlgorithmSpec adaptFromTask(Args&&... args)
{
return AlgorithmSpec::InitCallback{[=](InitContext& ic) {
auto task = std::make_shared<T>(args...);
if constexpr (has_endOfStream<T>::value) {
if constexpr (requires(T&) { &T::endOfStream; }) {
auto& callbacks = ic.services().get<CallbackService>();
callbacks.set<CallbackService::Id::EndOfStream>([task](EndOfStreamContext& eosContext) {
task->endOfStream(eosContext);
});
}
if constexpr (has_finaliseCCDB<T>::value) {
if constexpr (requires(T&) { &T::finaliseCCDB; }) {
auto& callbacks = ic.services().get<CallbackService>();
callbacks.set<CallbackService::Id::CCDBDeserialised>([task](ConcreteDataMatcher& matcher, void* obj) {
task->finaliseCCDB(matcher, obj);
});
}
if constexpr (has_stop<T>::value) {
if constexpr (requires(T&) { &T::stop; }) {
auto& callbacks = ic.services().get<CallbackService>();
callbacks.set<CallbackService::Id::Stop>([task]() {
task->stop();
Expand All @@ -144,19 +89,19 @@ template <typename T>
AlgorithmSpec adoptTask(std::shared_ptr<T> task)
{
return AlgorithmSpec::InitCallback{[task](InitContext& ic) {
if constexpr (has_endOfStream<T>::value) {
if constexpr (requires(T&) { &T::endOfStream; }) {
auto& callbacks = ic.services().get<CallbackService>();
callbacks.set<CallbackService::Id::EndOfStream>([task](EndOfStreamContext& eosContext) {
task->endOfStream(eosContext);
});
}
if constexpr (has_finaliseCCDB<T>::value) {
if constexpr (requires(T&) { &T::finaliseCCDB; }) {
auto& callbacks = ic.services().get<CallbackService>();
callbacks.set<CallbackService::Id::CCDBDeserialised>([task](ConcreteDataMatcher& matcher, void* obj) {
task->finaliseCCDB(matcher, obj);
});
}
if constexpr (has_stop<T>::value) {
if constexpr (requires(T&) { &T::stop; }) {
auto& callbacks = ic.services().get<CallbackService>();
callbacks.set<CallbackService::Id::Stop>([task]() {
task->stop();
Expand Down
Loading