Project
Loading...
Searching...
No Matches
Task.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11#ifndef O2_FRAMEWORK_TASK_H_
12#define O2_FRAMEWORK_TASK_H_
13
17#include <memory>
18
19namespace o2::framework
20{
21
31class Task
32{
33 public:
34 virtual ~Task();
37 virtual void init(InitContext& context) {}
40 virtual void run(ProcessingContext& context) = 0;
41
43 virtual void endOfStream(EndOfStreamContext& context) {}
44
47 virtual void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj)
48 {
49 LOGP(debug, "CCDB deserialization invoked");
50 }
51
53 virtual void stop() {}
54};
55
58template <typename T, typename... Args>
60{
62 auto task = std::make_shared<T>(args...);
63 if constexpr (requires { &T::endOfStream; }) {
64 auto& callbacks = ic.services().get<CallbackService>();
65 callbacks.set<CallbackService::Id::EndOfStream>([task](EndOfStreamContext& eosContext) {
66 task->endOfStream(eosContext);
67 });
68 }
69 if constexpr (requires { &T::finaliseCCDB; }) {
70 auto& callbacks = ic.services().get<CallbackService>();
71 callbacks.set<CallbackService::Id::CCDBDeserialised>([task](ConcreteDataMatcher& matcher, void* obj) {
72 task->finaliseCCDB(matcher, obj);
73 });
74 }
75 if constexpr (requires { &T::stop; }) {
76 auto& callbacks = ic.services().get<CallbackService>();
77 callbacks.set<CallbackService::Id::Stop>([task]() {
78 task->stop();
79 });
80 }
81 task->init(ic);
82 return [task](ProcessingContext& pc) {
83 task->run(pc);
84 };
85 }};
86}
87
88template <typename T>
89AlgorithmSpec adoptTask(std::shared_ptr<T> task)
90{
91 return AlgorithmSpec::InitCallback{[task](InitContext& ic) {
92 if constexpr (requires { &T::endOfStream; }) {
93 auto& callbacks = ic.services().get<CallbackService>();
94 callbacks.set<CallbackService::Id::EndOfStream>([task](EndOfStreamContext& eosContext) {
95 task->endOfStream(eosContext);
96 });
97 }
98 if constexpr (requires { &T::finaliseCCDB; }) {
99 auto& callbacks = ic.services().get<CallbackService>();
100 callbacks.set<CallbackService::Id::CCDBDeserialised>([task](ConcreteDataMatcher& matcher, void* obj) {
101 task->finaliseCCDB(matcher, obj);
102 });
103 }
104 if constexpr (requires { &T::stop; }) {
105 auto& callbacks = ic.services().get<CallbackService>();
106 callbacks.set<CallbackService::Id::Stop>([task]() {
107 task->stop();
108 });
109 }
110 task->init(ic);
111 return [&task](ProcessingContext& pc) {
112 task->run(pc);
113 };
114 }};
115}
116} // namespace o2::framework
117#endif // O2_FRAMEWORK_TASK_H_
std::ostringstream debug
virtual void finaliseCCDB(ConcreteDataMatcher &matcher, void *obj)
Definition Task.h:47
virtual void stop()
This is invoked on stop.
Definition Task.h:53
virtual void endOfStream(EndOfStreamContext &context)
This is invoked whenever we have an EndOfStream event.
Definition Task.h:43
virtual void init(InitContext &context)
Definition Task.h:37
virtual void run(ProcessingContext &context)=0
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
AlgorithmSpec adoptTask(std::shared_ptr< T > task)
Definition Task.h:89
AlgorithmSpec adaptFromTask(Args &&... args)
Definition Task.h:59
std::function< ProcessCallback(InitContext &)> InitCallback