Skip to content
Snippets Groups Projects
Commit 57b89c82 authored by Sergei Zharko's avatar Sergei Zharko Committed by Pierre-Alain Loizeau
Browse files

online: processing of multiple tasks in a single qa::Data instance

parent feca4502
No related branches found
No related tags found
1 merge request!2021Online qa manager
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
using cbm::algo::qa::Data; using cbm::algo::qa::Data;
// --------------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------------
// //
void Data::Init(std::shared_ptr<HistogramSender> histSender) void Data::Init(std::shared_ptr<HistogramSender> histSender)
...@@ -28,20 +29,22 @@ try { ...@@ -28,20 +29,22 @@ try {
nHistograms += std::distance(fHistograms.fvP2.begin(), fHistograms.fvP2.end()); nHistograms += std::distance(fHistograms.fvP2.begin(), fHistograms.fvP2.end());
vHistCfgs.reserve(nHistograms); vHistCfgs.reserve(nHistograms);
auto RegHist = [&](const auto& h) { for (const auto& task: fvTaskProperties) {
if (!h.GetMetadata().CheckFlags()) { auto RegHist = [&](const auto& h) {
std::stringstream msg; if (!h.GetMetadata().CheckFlags()) {
msg << "attempt to pass a histogram " << h.GetName() std::stringstream msg;
<< " with inconsistent flags (see HistogramMetadata::CheckFlags for detailes)"; msg << "attempt to pass a histogram " << h.GetName()
throw std::runtime_error(msg.str()); << " with inconsistent flags (see HistogramMetadata::CheckFlags for detailes)";
} throw std::runtime_error(msg.str());
vHistCfgs.emplace_back(h.GetName() + "!" + h.GetMetadataString(), fsName); }
}; vHistCfgs.emplace_back(h.GetName() + "!" + h.GetMetadataString(), task.fsName);
};
std::for_each(fHistograms.fvH1.begin(), fHistograms.fvH1.end(), RegHist); fsTaskNames += fmt::format("{} ", task.fsName);
std::for_each(fHistograms.fvH2.begin(), fHistograms.fvH2.end(), RegHist); std::for_each(task.fRangeH1.first, task.fRangeH1.second, RegHist);
std::for_each(fHistograms.fvP1.begin(), fHistograms.fvP1.end(), RegHist); std::for_each(task.fRangeH2.first, task.fRangeH2.second, RegHist);
std::for_each(fHistograms.fvP2.begin(), fHistograms.fvP2.end(), RegHist); std::for_each(task.fRangeP1.first, task.fRangeP1.second, RegHist);
std::for_each(task.fRangeP2.first, task.fRangeP2.second, RegHist);
}
// Forming a canvas config message // Forming a canvas config message
std::vector<std::pair<std::string, std::string>> vCanvCfgs; std::vector<std::pair<std::string, std::string>> vCanvCfgs;
...@@ -63,10 +66,27 @@ try { ...@@ -63,10 +66,27 @@ try {
} }
} }
catch (const std::exception& err) { catch (const std::exception& err) {
L_(fatal) << "cbm::algo::qa::Data for " << fsName << " fatally aborted. Reason " << err.what(); L_(fatal) << "cbm::algo::qa::Data for " << fsTaskNames << " fatally aborted. Reason " << err.what();
assert(false); assert(false);
} }
// ---------------------------------------------------------------------------------------------------------------------
//
void Data::RegisterNewTask(std::string_view name)
{
auto itH1 = fHistograms.fvH1.begin();
auto itH2 = fHistograms.fvH2.begin();
auto itP1 = fHistograms.fvP1.begin();
auto itP2 = fHistograms.fvP2.begin();
fvTaskProperties.emplace_back(TaskProperties{
.fsName = {name.begin(), name.end()},
.fRangeH1 = std::make_pair(itH1, itH1),
.fRangeH2 = std::make_pair(itH2, itH2),
.fRangeP1 = std::make_pair(itP1, itP1),
.fRangeP2 = std::make_pair(itP2, itP2)
});
}
// --------------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------------
// //
void Data::Send(std::shared_ptr<HistogramSender> histoSender) void Data::Send(std::shared_ptr<HistogramSender> histoSender)
...@@ -76,7 +96,7 @@ void Data::Send(std::shared_ptr<HistogramSender> histoSender) ...@@ -76,7 +96,7 @@ void Data::Send(std::shared_ptr<HistogramSender> histoSender)
auto nH2 = std::distance(fHistograms.fvH2.begin(), fHistograms.fvH2.end()); auto nH2 = std::distance(fHistograms.fvH2.begin(), fHistograms.fvH2.end());
auto nP1 = std::distance(fHistograms.fvP1.begin(), fHistograms.fvP1.end()); auto nP1 = std::distance(fHistograms.fvP1.begin(), fHistograms.fvP1.end());
auto nP2 = std::distance(fHistograms.fvP2.begin(), fHistograms.fvP2.end()); auto nP2 = std::distance(fHistograms.fvP2.begin(), fHistograms.fvP2.end());
L_(info) << fsName << ": Published " << nH1 << " 1D- and " << nH2 << " 2D-histograms, " << nP1 << " 1D- and " << nP2 L_(info) << fsTaskNames << ": Published " << nH1 << " 1D- and " << nH2 << " 2D-histograms, " << nP1 << " 1D- and " << nP2
<< " 2D-profiles"; << " 2D-profiles";
this->Reset(); this->Reset();
} }
...@@ -10,9 +10,10 @@ ...@@ -10,9 +10,10 @@
#pragma once #pragma once
#include "AlgoFairloggerCompat.h" #include "AlgoFairloggerCompat.h"
#include "CanvasConfig.h" #include "qa/CanvasConfig.h"
#include "HistogramContainer.h" #include "qa/HistogramContainer.h"
#include "HistogramSender.h" #include "qa/TaskProperties.h"
#include "base/HistogramSender.h"
#include <boost/serialization/forward_list.hpp> #include <boost/serialization/forward_list.hpp>
...@@ -27,9 +28,12 @@ namespace cbm::algo::qa ...@@ -27,9 +28,12 @@ namespace cbm::algo::qa
/// \brief Class to handle QA-objects in the online reconstruction /// \brief Class to handle QA-objects in the online reconstruction
class Data { class Data {
public: public:
/// \brief Default constructor
Data() = default;
/// \brief Constructor /// \brief Constructor
/// \param name Name of the QA module (appears as the directory name in the output) /// \param name Name of the QA module (appears as the directory name in the output)
Data(std::string_view name) : fsName(name) {} Data(std::string_view name) { RegisterNewTask(name); }
/// \brief Copy constructor /// \brief Copy constructor
Data(const Data&) = default; Data(const Data&) = default;
...@@ -50,9 +54,6 @@ namespace cbm::algo::qa ...@@ -50,9 +54,6 @@ namespace cbm::algo::qa
/// \param canvas A CanvasConfig object /// \param canvas A CanvasConfig object
void AddCanvasConfig(const CanvasConfig& canvas) { fvsCanvCfgs.push_back(canvas.ToString()); } void AddCanvasConfig(const CanvasConfig& canvas) { fvsCanvCfgs.push_back(canvas.ToString()); }
/// \brief Gets module name
std::string_view GetName() const { return fsName; }
/// \brief Sends QA initialization information to the HistogramSender /// \brief Sends QA initialization information to the HistogramSender
/// \param histoSender A pointer to the histogram sender /// \param histoSender A pointer to the histogram sender
void Init(std::shared_ptr<HistogramSender> histoSender); void Init(std::shared_ptr<HistogramSender> histoSender);
...@@ -73,10 +74,15 @@ namespace cbm::algo::qa ...@@ -73,10 +74,15 @@ namespace cbm::algo::qa
/// \param timesliceId Timeslice index /// \param timesliceId Timeslice index
void SetTimesliceId(uint64_t timesliceId) { fHistograms.fTimesliceId = timesliceId; } void SetTimesliceId(uint64_t timesliceId) { fHistograms.fTimesliceId = timesliceId; }
/// \brief Registers a new QA task
/// \param name Name of the task
void RegisterNewTask(std::string_view name);
private: private:
std::string fsName; ///< Name of the QA module (used as a directory name) qa::HistogramContainer fHistograms; ///< Histograms container
qa::HistogramContainer fHistograms; ///< Histograms container std::string fsTaskNames; ///< A string containing names of tasks
std::vector<std::string> fvsCanvCfgs = {}; ///< Vector of canvas configs std::vector<qa::TaskProperties> fvTaskProperties; ///< A vector to store properties for multiple QA-tasks
std::vector<std::string> fvsCanvCfgs = {}; ///< Vector of canvas configs
}; };
// ------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------
...@@ -85,16 +91,24 @@ namespace cbm::algo::qa ...@@ -85,16 +91,24 @@ namespace cbm::algo::qa
Obj* Data::MakeObj(Args... args) Obj* Data::MakeObj(Args... args)
{ {
if constexpr (std::is_same_v<Obj, cbm::algo::qa::H1D>) { if constexpr (std::is_same_v<Obj, cbm::algo::qa::H1D>) {
return &(fHistograms.fvH1.emplace_front(args...)); Obj* res = &(fHistograms.fvH1.emplace_front(args...));
fvTaskProperties.back().fRangeH1.first = fHistograms.fvH1.begin();
return res;
} }
else if constexpr (std::is_same_v<Obj, cbm::algo::qa::H2D>) { else if constexpr (std::is_same_v<Obj, cbm::algo::qa::H2D>) {
return &(fHistograms.fvH2.emplace_front(args...)); Obj* res = &(fHistograms.fvH2.emplace_front(args...));
fvTaskProperties.back().fRangeH2.first = fHistograms.fvH2.begin();
return res;
} }
else if constexpr (std::is_same_v<Obj, cbm::algo::qa::Prof1D>) { else if constexpr (std::is_same_v<Obj, cbm::algo::qa::Prof1D>) {
return &(fHistograms.fvP1.emplace_front(args...)); Obj* res = &(fHistograms.fvP1.emplace_front(args...));
fvTaskProperties.back().fRangeP1.first = fHistograms.fvP1.begin();
return res;
} }
else if constexpr (std::is_same_v<Obj, cbm::algo::qa::Prof2D>) { else if constexpr (std::is_same_v<Obj, cbm::algo::qa::Prof2D>) {
return &(fHistograms.fvP2.emplace_front(args...)); Obj* res = &(fHistograms.fvP2.emplace_front(args...));
fvTaskProperties.back().fRangeP2.first = fHistograms.fvP2.begin();
return res;
} }
return nullptr; return nullptr;
} }
......
/* Copyright (C) 2025 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Sergei Zharko [committer] */
/// \file TaskProperties.h
/// \date 09.02.2025
/// \brief QA-task properties structure
/// \author Sergei Zharko <s.zharko@gsi.de>
#pragma once
#include "Histogram.h" // for H1D, H2D
#include <forward_list>
#include <string>
#include <utility>
namespace cbm::algo::qa
{
/// \struct HistogramContainer
/// \brief Structure to keep the histograms for sending them on the histogram server
struct TaskProperties {
template <class H>
using IteratorPair_t = std::pair<typename std::forward_list<H>::iterator, typename std::forward_list<H>::iterator>;
std::string fsName; ///< Name of the task
IteratorPair_t<qa::H1D> fRangeH1; ///< A pair (begin, end) for 1D-histograms in the task
IteratorPair_t<qa::H2D> fRangeH2; ///< A pair (begin, end) for 2D-histograms in the task
IteratorPair_t<qa::Prof1D> fRangeP1; ///< A pair (begin, end) for 1D-profiles in the task
IteratorPair_t<qa::Prof2D> fRangeP2; ///< A pair (begin, end) for 2D-profiles in the task
};
} // namespace cbm::algo::qa
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment