Skip to content

Commit 788fb7e

Browse files
ktfshahor02
authored andcommitted
DPL: add Task::stop
1 parent 3b3a626 commit 788fb7e

File tree

1 file changed

+27
-0
lines changed
  • Framework/Core/include/Framework

1 file changed

+27
-0
lines changed

Framework/Core/include/Framework/Task.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ class has_endOfStream
3838
enum { value = sizeof(test<T>(nullptr)) == sizeof(char) };
3939
};
4040

41+
/// Check if the class task has Stop
42+
template <typename T>
43+
class has_stop
44+
{
45+
typedef char one;
46+
struct two {
47+
char x[2];
48+
};
49+
50+
template <typename C>
51+
static one test(decltype(&C::stop));
52+
template <typename C>
53+
static two test(...);
54+
55+
public:
56+
enum { value = sizeof(test<T>(nullptr)) == sizeof(char) };
57+
};
58+
4159
/// A more familiar task API for the DPL.
4260
/// This allows you to define your own tasks as subclasses
4361
/// of o2::framework::Task and to pass them in the specification
@@ -60,6 +78,9 @@ class Task
6078

6179
/// This is invoked whenever we have an EndOfStream event
6280
virtual void endOfStream(EndOfStreamContext& context) {}
81+
82+
/// This is invoked on stop
83+
virtual void stop() {}
6384
};
6485

6586
/// Adaptor to make an AlgorithmSpec from a o2::framework::Task
@@ -75,6 +96,12 @@ AlgorithmSpec adaptFromTask(Args&&... args)
7596
task->endOfStream(eosContext);
7697
});
7798
}
99+
if constexpr (has_stop<T>::value) {
100+
auto& callbacks = ic.services().get<CallbackService>();
101+
callbacks.set(CallbackService::Id::Stop, [task]() {
102+
task->stop();
103+
});
104+
}
78105
task->init(ic);
79106
return [task](ProcessingContext& pc) {
80107
task->run(pc);

0 commit comments

Comments
 (0)