CbmRoot
Loading...
Searching...
No Matches
QaData.cxx
Go to the documentation of this file.
1/* Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10#include "QaData.h"
11
12#include <algorithm>
13
15
16// ---------------------------------------------------------------------------------------------------------------------
17//
18void Data::Init(std::shared_ptr<HistogramSender> histSender)
19try {
20 if (histSender.get()) {
21 // Forming a histogram config message
22 std::vector<std::pair<std::string, std::string>> vHistCfgs;
23 size_t nHistograms = 0;
24 // NOTE: Important to keep the order of filling the histograms: 1D -> 2D -> ..
25 nHistograms += std::distance(fHistograms.fvH1.begin(), fHistograms.fvH1.end());
26 nHistograms += std::distance(fHistograms.fvH2.begin(), fHistograms.fvH2.end());
27 nHistograms += std::distance(fHistograms.fvP1.begin(), fHistograms.fvP1.end());
28 nHistograms += std::distance(fHistograms.fvP2.begin(), fHistograms.fvP2.end());
29 vHistCfgs.reserve(nHistograms);
30
31 auto RegHist = [&](const auto& h) {
32 if (!h.GetMetadata().CheckFlags()) {
33 std::stringstream msg;
34 msg << "attempt to pass a histogram " << h.GetName()
35 << " with inconsistent flags (see HistogramMetadata::CheckFlags for detailes)";
36 throw std::runtime_error(msg.str());
37 }
38 vHistCfgs.emplace_back(h.GetName() + "!" + h.GetMetadataString(), fsName);
39 };
40
41 std::for_each(fHistograms.fvH1.begin(), fHistograms.fvH1.end(), RegHist);
42 std::for_each(fHistograms.fvH2.begin(), fHistograms.fvH2.end(), RegHist);
43 std::for_each(fHistograms.fvP1.begin(), fHistograms.fvP1.end(), RegHist);
44 std::for_each(fHistograms.fvP2.begin(), fHistograms.fvP2.end(), RegHist);
45
46 // Forming a canvas config message
47 std::vector<std::pair<std::string, std::string>> vCanvCfgs;
48 vCanvCfgs.reserve(fvsCanvCfgs.size());
49 for (const auto& canv : fvsCanvCfgs) {
50 vCanvCfgs.emplace_back(std::make_pair(canv.substr(0, canv.find_first_of(';')), canv));
51 }
52
53 histSender->PrepareAndSendMsg(std::pair<uint32_t, uint32_t>(vHistCfgs.size(), vCanvCfgs.size()),
54 zmq::send_flags::sndmore);
55
56 auto RegCfg = [&](const auto& cfg) { histSender->PrepareAndSendMsg(cfg, zmq::send_flags::sndmore); };
57
58 std::for_each(vHistCfgs.begin(), vHistCfgs.end(), RegCfg);
59 std::for_each(vCanvCfgs.begin(), vCanvCfgs.end(), RegCfg);
60
61 // Histograms serialization and emission to close multi-part message
62 histSender->PrepareAndSendMsg(qa::HistogramContainer{}, zmq::send_flags::none);
63 }
64}
65catch (const std::exception& err) {
66 L_(fatal) << "cbm::algo::qa::Data for " << fsName << " fatally aborted. Reason " << err.what();
67 assert(false);
68}
69
70// ---------------------------------------------------------------------------------------------------------------------
71//
72void Data::Send(std::shared_ptr<HistogramSender> histoSender)
73{
74 histoSender->PrepareAndSendMsg(fHistograms, zmq::send_flags::none);
75 auto nH1 = std::distance(fHistograms.fvH1.begin(), fHistograms.fvH1.end());
76 auto nH2 = std::distance(fHistograms.fvH2.begin(), fHistograms.fvH2.end());
77 auto nP1 = std::distance(fHistograms.fvP1.begin(), fHistograms.fvP1.end());
78 auto nP2 = std::distance(fHistograms.fvP2.begin(), fHistograms.fvP2.end());
79 L_(info) << fsName << ": Published " << nH1 << " 1D- and " << nH2 << " 2D-histograms, " << nP1 << " 1D- and " << nP2
80 << " 2D-profiles";
81 this->Reset();
82}
#define L_(level)
Data class with information on a STS local track.
Class to handle QA-objects in the online reconstruction.
Definition QaData.h:28
void Send(std::shared_ptr< HistogramSender > histoSender)
Sends QA data to the HistogramSender.
Definition QaData.cxx:72
void Init(std::shared_ptr< HistogramSender > histoSender)
Sends QA initialization information to the HistogramSender.
Definition QaData.cxx:18
std::string fsName
Name of the QA module (used as a directory name)
Definition QaData.h:77
void Reset()
Resets the histograms.
Definition QaData.h:65
qa::HistogramContainer fHistograms
Histograms container.
Definition QaData.h:78
std::vector< std::string > fvsCanvCfgs
Vector of canvas configs.
Definition QaData.h:79
Structure to keep the histograms for sending them on the histogram server.
std::forward_list< qa::Prof1D > fvP1
List of 1D-profiles.
std::forward_list< qa::Prof2D > fvP2
List of 2D-profiles.
std::forward_list< qa::H1D > fvH1
List of 1D-histograms.
std::forward_list< qa::H2D > fvH2
List of 2D-histograms.