|
| 1 | +/// |
| 2 | +/// \file TaskDataProcessor.h |
| 3 | +/// \author Piotr Konopka |
| 4 | +/// |
| 5 | + |
| 6 | +#ifndef TASKDATAPROCESSOR_H |
| 7 | +#define TASKDATAPROCESSOR_H |
| 8 | + |
| 9 | +#include <thread> |
| 10 | +#include <mutex> |
| 11 | +// boost (should be first but then it makes errors in fairmq) |
| 12 | +#include <boost/serialization/array_wrapper.hpp> |
| 13 | +#include <boost/accumulators/accumulators.hpp> |
| 14 | +#include <boost/accumulators/statistics.hpp> |
| 15 | +#include <boost/asio.hpp> |
| 16 | +// O2 |
| 17 | +#include "Common/Timer.h" |
| 18 | +#include "Configuration/ConfigurationInterface.h" |
| 19 | +#include "Framework/DataProcessorSpec.h" |
| 20 | +#include "Monitoring/MonitoringFactory.h" |
| 21 | +// QC |
| 22 | +#include "QualityControl/TaskInterfaceDPL.h" |
| 23 | +#include "QualityControl/TaskConfig.h" |
| 24 | + |
| 25 | +namespace ba = boost::accumulators; |
| 26 | + |
| 27 | +namespace o2 { |
| 28 | +namespace quality_control { |
| 29 | +namespace core { |
| 30 | + |
| 31 | +using namespace o2::framework; |
| 32 | +using namespace std::chrono; |
| 33 | + |
| 34 | +/// \brief A class driving the execution of a QC task inside DPL. |
| 35 | +/// |
| 36 | +/// TaskDataProcessor is a port of TaskDevice class, adapted for usage inside Data Processing Layer. |
| 37 | +/// It is responsible for retrieving details about the task via the Configuration system and the Task (indirectly). |
| 38 | +/// It then steers the execution of the task and provides it with O2 Data Model data, provided by framework. |
| 39 | +/// It finally publishes the MonitorObjects owned and filled by the QC task and managed by the ObjectsManager. |
| 40 | +/// Usage: |
| 41 | +/// \code{.cxx} |
| 42 | +/// auto qcTask = std::make_shared<TaskDataProcessor>(taskName, configurationSource); |
| 43 | +/// DataProcessorSpec newTask{ |
| 44 | +/// taskName, |
| 45 | +/// qcTask->getInputsSpecs(), |
| 46 | +/// Outputs{ qcTask->getOutputSpec() }, |
| 47 | +/// AlgorithmSpec{ |
| 48 | +/// (AlgorithmSpec::InitCallback) [qcTask = std::move(qcTask)](InitContext& initContext) { |
| 49 | +/// |
| 50 | +/// qcTask->initCallback(initContext); |
| 51 | +/// |
| 52 | +/// return (AlgorithmSpec::ProcessCallback) [qcTask = std::move(qcTask)] (ProcessingContext &processingContext) { |
| 53 | +/// qcTask->processCallback(processingContext); |
| 54 | +/// }; |
| 55 | +/// } |
| 56 | +/// } |
| 57 | +/// }; |
| 58 | +/// \endcode |
| 59 | +/// |
| 60 | +/// \author Piotr Konopka |
| 61 | +/// \author Barthelemy von Haller |
| 62 | +class TaskDataProcessor { |
| 63 | + public: |
| 64 | + TaskDataProcessor(std::string taskName, std::string configurationSource); |
| 65 | + ~TaskDataProcessor(); |
| 66 | + |
| 67 | + /// \brief To be invoked during initialization of Data Processor |
| 68 | + void initCallback(InitContext& iCtx); |
| 69 | + /// \brief To be invoked inside Data Processor's main ProcessCallback |
| 70 | + void processCallback(ProcessingContext& pCtx); |
| 71 | + /// \brief To be invoked inside Data Processor's TimerCallback |
| 72 | + void timerCallback(ProcessingContext& pCtx); |
| 73 | + |
| 74 | + const Inputs& getInputsSpecs() { return mInputSpecs; }; |
| 75 | + const OutputSpec getOutputSpec() { return mMonitorObjectsSpec; }; |
| 76 | + |
| 77 | + private: |
| 78 | + void populateConfig(std::string taskName); |
| 79 | + void startOfActivity(); |
| 80 | + void endOfActivity(); |
| 81 | + void finishCycle(DataAllocator& outputs); |
| 82 | + unsigned long publish(DataAllocator& outputs); |
| 83 | + static void CustomCleanupTMessage(void* data, void* object); |
| 84 | + |
| 85 | + private: |
| 86 | + std::string mTaskName; |
| 87 | + TaskConfig mTaskConfig; |
| 88 | + std::shared_ptr<o2::configuration::ConfigurationInterface> mConfigFile; // used in init only |
| 89 | + std::shared_ptr<o2::monitoring::Monitoring> mCollector; |
| 90 | + TaskInterfaceDPL* mTask; |
| 91 | + std::shared_ptr<ObjectsManager> mObjectsManager; |
| 92 | + std::recursive_mutex mTaskMutex; // \todo should be plain mutex, when timer callback is implemented in dpl |
| 93 | + |
| 94 | + // consider moving these two to TaskConfig |
| 95 | + Inputs mInputSpecs; |
| 96 | + OutputSpec mMonitorObjectsSpec; |
| 97 | + |
| 98 | + int mNumberBlocks; |
| 99 | + int mLastNumberObjects; |
| 100 | + bool mCycleOn; |
| 101 | + int mCycleNumber; |
| 102 | + |
| 103 | + // stats |
| 104 | + AliceO2::Common::Timer mStatsTimer; |
| 105 | + int mTotalNumberObjectsPublished; |
| 106 | + AliceO2::Common::Timer mTimerTotalDurationActivity; |
| 107 | + ba::accumulator_set<double, ba::features<ba::tag::mean, ba::tag::variance>> mPCpus; |
| 108 | + ba::accumulator_set<double, ba::features<ba::tag::mean, ba::tag::variance>> mPMems; |
| 109 | +}; |
| 110 | + |
| 111 | +} |
| 112 | +} |
| 113 | +} |
| 114 | + |
| 115 | +#endif // TASKDATAPROCESSOR_H |
0 commit comments