14
14
#include " Framework/AlgorithmSpec.h"
15
15
#include " Framework/CallbackService.h"
16
16
#include " Framework/EndOfStreamContext.h"
17
- #include < utility>
18
17
#include < memory>
19
18
20
19
namespace o2 ::framework
21
20
{
22
21
23
- // / Check if the class task has EndOfStream
24
- template <typename T>
25
- class has_endOfStream
26
- {
27
- typedef char one;
28
- struct two {
29
- char x[2 ];
30
- };
31
-
32
- template <typename C>
33
- static one test (decltype(&C::endOfStream));
34
- template <typename C>
35
- static two test (...);
36
-
37
- public:
38
- enum { value = sizeof (test<T>(nullptr )) == sizeof (char ) };
39
- };
40
-
41
- // / Check if the class task has EndOfStream
42
- template <typename T>
43
- class has_finaliseCCDB
44
- {
45
- typedef char one;
46
- struct two {
47
- char x[2 ];
48
- };
49
-
50
- template <typename C>
51
- static one test (decltype(&C::finaliseCCDB));
52
- template <typename C>
53
- static two test (...);
54
-
55
- public:
56
- enum { value = sizeof (test<T>(nullptr )) == sizeof (char ) };
57
- };
58
-
59
- // / Check if the class task has Stop
60
- template <typename T>
61
- class has_stop
62
- {
63
- typedef char one;
64
- struct two {
65
- char x[2 ];
66
- };
67
-
68
- template <typename C>
69
- static one test (decltype(&C::stop));
70
- template <typename C>
71
- static two test (...);
72
-
73
- public:
74
- enum { value = sizeof (test<T>(nullptr )) == sizeof (char ) };
75
- };
76
-
77
22
// / A more familiar task API for the DPL.
78
23
// / This allows you to define your own tasks as subclasses
79
24
// / of o2::framework::Task and to pass them in the specification
@@ -115,19 +60,19 @@ AlgorithmSpec adaptFromTask(Args&&... args)
115
60
{
116
61
return AlgorithmSpec::InitCallback{[=](InitContext& ic) {
117
62
auto task = std::make_shared<T>(args...);
118
- if constexpr (has_endOfStream<T>::value ) {
63
+ if constexpr (requires { &T::endOfStream; } ) {
119
64
auto & callbacks = ic.services ().get <CallbackService>();
120
65
callbacks.set <CallbackService::Id::EndOfStream>([task](EndOfStreamContext& eosContext) {
121
66
task->endOfStream (eosContext);
122
67
});
123
68
}
124
- if constexpr (has_finaliseCCDB<T>::value ) {
69
+ if constexpr (requires { &T::finaliseCCDB; } ) {
125
70
auto & callbacks = ic.services ().get <CallbackService>();
126
71
callbacks.set <CallbackService::Id::CCDBDeserialised>([task](ConcreteDataMatcher& matcher, void * obj) {
127
72
task->finaliseCCDB (matcher, obj);
128
73
});
129
74
}
130
- if constexpr (has_stop<T>::value ) {
75
+ if constexpr (requires { &T::stop; } ) {
131
76
auto & callbacks = ic.services ().get <CallbackService>();
132
77
callbacks.set <CallbackService::Id::Stop>([task]() {
133
78
task->stop ();
@@ -144,19 +89,19 @@ template <typename T>
144
89
AlgorithmSpec adoptTask (std::shared_ptr<T> task)
145
90
{
146
91
return AlgorithmSpec::InitCallback{[task](InitContext& ic) {
147
- if constexpr (has_endOfStream<T>::value ) {
92
+ if constexpr (requires { &T::endOfStream; } ) {
148
93
auto & callbacks = ic.services ().get <CallbackService>();
149
94
callbacks.set <CallbackService::Id::EndOfStream>([task](EndOfStreamContext& eosContext) {
150
95
task->endOfStream (eosContext);
151
96
});
152
97
}
153
- if constexpr (has_finaliseCCDB<T>::value ) {
98
+ if constexpr (requires { &T::finaliseCCDB; } ) {
154
99
auto & callbacks = ic.services ().get <CallbackService>();
155
100
callbacks.set <CallbackService::Id::CCDBDeserialised>([task](ConcreteDataMatcher& matcher, void * obj) {
156
101
task->finaliseCCDB (matcher, obj);
157
102
});
158
103
}
159
- if constexpr (has_stop<T>::value ) {
104
+ if constexpr (requires { &T::stop; } ) {
160
105
auto & callbacks = ic.services ().get <CallbackService>();
161
106
callbacks.set <CallbackService::Id::Stop>([task]() {
162
107
task->stop ();
0 commit comments