diff --git a/algo/qa/QaData.cxx b/algo/qa/QaData.cxx index 1ead168f18ca4bd8296c2a2d97db00a91725d75d..235bb3ddbf520a14a154e4e0e7aea14f54641cb0 100644 --- a/algo/qa/QaData.cxx +++ b/algo/qa/QaData.cxx @@ -13,6 +13,7 @@ using cbm::algo::qa::Data; + // --------------------------------------------------------------------------------------------------------------------- // void Data::Init(std::shared_ptr<HistogramSender> histSender) @@ -28,20 +29,22 @@ try { nHistograms += std::distance(fHistograms.fvP2.begin(), fHistograms.fvP2.end()); vHistCfgs.reserve(nHistograms); - auto RegHist = [&](const auto& h) { - if (!h.GetMetadata().CheckFlags()) { - std::stringstream msg; - msg << "attempt to pass a histogram " << h.GetName() - << " with inconsistent flags (see HistogramMetadata::CheckFlags for detailes)"; - throw std::runtime_error(msg.str()); - } - vHistCfgs.emplace_back(h.GetName() + "!" + h.GetMetadataString(), fsName); - }; - - std::for_each(fHistograms.fvH1.begin(), fHistograms.fvH1.end(), RegHist); - std::for_each(fHistograms.fvH2.begin(), fHistograms.fvH2.end(), RegHist); - std::for_each(fHistograms.fvP1.begin(), fHistograms.fvP1.end(), RegHist); - std::for_each(fHistograms.fvP2.begin(), fHistograms.fvP2.end(), RegHist); + for (const auto& task: fvTaskProperties) { + auto RegHist = [&](const auto& h) { + if (!h.GetMetadata().CheckFlags()) { + std::stringstream msg; + msg << "attempt to pass a histogram " << h.GetName() + << " with inconsistent flags (see HistogramMetadata::CheckFlags for detailes)"; + throw std::runtime_error(msg.str()); + } + vHistCfgs.emplace_back(h.GetName() + "!" + h.GetMetadataString(), task.fsName); + }; + fsTaskNames += fmt::format("{} ", task.fsName); + std::for_each(task.fRangeH1.first, task.fRangeH1.second, RegHist); + std::for_each(task.fRangeH2.first, task.fRangeH2.second, 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 std::vector<std::pair<std::string, std::string>> vCanvCfgs; @@ -63,10 +66,27 @@ try { } } 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); } +// --------------------------------------------------------------------------------------------------------------------- +// +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) @@ -76,7 +96,7 @@ void Data::Send(std::shared_ptr<HistogramSender> histoSender) auto nH2 = std::distance(fHistograms.fvH2.begin(), fHistograms.fvH2.end()); auto nP1 = std::distance(fHistograms.fvP1.begin(), fHistograms.fvP1.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"; this->Reset(); } diff --git a/algo/qa/QaData.h b/algo/qa/QaData.h index 0c87df69c5ff5eb5ffcc0664b8a0454358814b56..fcb1afced29bce62d00a9136c1e769d2f808ff23 100644 --- a/algo/qa/QaData.h +++ b/algo/qa/QaData.h @@ -10,9 +10,10 @@ #pragma once #include "AlgoFairloggerCompat.h" -#include "CanvasConfig.h" -#include "HistogramContainer.h" -#include "HistogramSender.h" +#include "qa/CanvasConfig.h" +#include "qa/HistogramContainer.h" +#include "qa/TaskProperties.h" +#include "base/HistogramSender.h" #include <boost/serialization/forward_list.hpp> @@ -27,9 +28,12 @@ namespace cbm::algo::qa /// \brief Class to handle QA-objects in the online reconstruction class Data { public: + /// \brief Default constructor + Data() = default; + /// \brief Constructor /// \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 Data(const Data&) = default; @@ -50,9 +54,6 @@ namespace cbm::algo::qa /// \param canvas A CanvasConfig object 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 /// \param histoSender A pointer to the histogram sender void Init(std::shared_ptr<HistogramSender> histoSender); @@ -73,10 +74,15 @@ namespace cbm::algo::qa /// \param timesliceId Timeslice index 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: - std::string fsName; ///< Name of the QA module (used as a directory name) - qa::HistogramContainer fHistograms; ///< Histograms container - std::vector<std::string> fvsCanvCfgs = {}; ///< Vector of canvas configs + qa::HistogramContainer fHistograms; ///< Histograms container + std::string fsTaskNames; ///< A string containing names of tasks + 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 Obj* Data::MakeObj(Args... args) { 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>) { - 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>) { - 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>) { - return &(fHistograms.fvP2.emplace_front(args...)); + Obj* res = &(fHistograms.fvP2.emplace_front(args...)); + fvTaskProperties.back().fRangeP2.first = fHistograms.fvP2.begin(); + return res; } return nullptr; } diff --git a/algo/qa/TaskProperties.h b/algo/qa/TaskProperties.h new file mode 100644 index 0000000000000000000000000000000000000000..377be8d7777bc2e26e5b10afd7a77eb96bed8dde --- /dev/null +++ b/algo/qa/TaskProperties.h @@ -0,0 +1,33 @@ +/* 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 +