CbmRoot
Loading...
Searching...
No Matches
services/histserv/tester/Application.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau [committer] */
4
5#include "Application.h"
6
7#include "CanvasConfig.h"
9#include "Histogram.h"
10#include "PadConfig.h"
11#include "QaData.h"
12#include "ui_callbacks.h"
13
14#include <Logger.h>
15
16#include <boost/archive/binary_oarchive.hpp>
17#include <boost/iostreams/device/array.hpp>
18#include <boost/iostreams/device/back_inserter.hpp>
19#include <boost/iostreams/stream.hpp>
20#include <boost/serialization/utility.hpp>
21#include <boost/serialization/vector.hpp>
22
23#include <thread>
24
25std::mutex mtx;
26
27namespace b_io = boost::iostreams;
28namespace b_ar = boost::archive;
29using sctp = std::chrono::time_point<std::chrono::system_clock>;
30using scsc = std::chrono::system_clock;
31
33{
34
35 // ----- Constructor ---------------------------------------------------------------------------------------------
37 {
39 LOG(info) << "Options for Application.";
40 LOG(info) << " Output ZMQ channel: " << fOpt.ComChan();
41 LOG(info) << " Run time duration: " << fOpt.Runtime() << " s";
42 fpSender = std::make_shared<cbm::algo::HistogramSender>(fOpt.ComChan());
43
47 // fZmqSocket.set(zmq::sockopt::rcvhwm, int(hwm)); // FIXME: need for HWM? (NOTE: SZh 29.02.2024: if needed, move it
48 // in the HistogramSender)
49 }
50 // -------------------------------------------------------------------------------------------------------------------
51
52
53 // ----- Main Loop -----------------------------------------------------------------------------------------------
55 {
60
61 const std::chrono::milliseconds interval {250};
62 const std::chrono::seconds runtime(fOpt.Runtime());
63 const std::chrono::seconds pubint(fOpt.PubInterval());
64 sctp startTime = scsc::now();
65 sctp stopTime = startTime + runtime;
66 sctp lastPubTime = startTime;
67
68 // Init QA data helper
69 Data qaData("Test");
70 auto* pHistTest = qaData.MakeObj<H1D>("testHist", "Tester source; Runtime [s]; Entries to histo [iterations]",
71 fOpt.Runtime() + 2, -1.0, fOpt.Runtime() + 1.0);
72 auto* pHistTrans = qaData.MakeObj<H1D>(
73 "transHist", "Tester histos transmission time; Trans. time [ms]; Messages []", 1001, -0.025, 50.025);
74
77 sctp transStartTime = scsc::now();
78
79 {
80 auto canv = CanvasConfig("TestCanvas", "TestCanvas");
81 auto pad1 = PadConfig();
82 pad1.SetGrid(false, false);
83 pad1.SetLog(false, false, false);
84 pad1.RegisterHistogram(pHistTest, "hist");
85 canv.AddPadConfig(pad1);
86 auto pad2 = PadConfig();
87 pad2.SetGrid(true, true);
88 pad2.SetLog(false, false, false);
89 pad2.RegisterHistogram(pHistTest, "hist");
90 canv.AddPadConfig(pad2);
91 auto pad3 = PadConfig();
92 pad3.SetGrid(true, true);
93 pad3.SetLog(true, false, false);
94 pad3.RegisterHistogram(pHistTrans, "hist");
95 canv.AddPadConfig(pad3);
96 auto pad4 = PadConfig();
97 pad4.SetGrid(true, true);
98 pad4.SetLog(true, false, false);
99 pad4.RegisterHistogram(pHistTrans, "hist");
100 pad4.RegisterHistogram(pHistTest, "hist same");
101 canv.AddPadConfig(pad4);
102 qaData.AddCanvasConfig(canv);
103 }
104 qaData.Init(fpSender); // Init the QA data
105
106 lastPubTime = scsc::now();
107
109 pHistTrans->Fill(std::chrono::duration_cast<std::chrono::microseconds>(lastPubTime - transStartTime).count() / 1e3);
110
111 while (scsc::now() < stopTime) { //
113 pHistTest->Fill(std::chrono::duration_cast<std::chrono::milliseconds>(scsc::now() - startTime).count() / 1e3);
114
115 if (pubint < scsc::now() - lastPubTime) {
116 LOG(info) << "Pub-hist: " << scsc::now().time_since_epoch().count() << " " << pHistTest->GetEntries();
118 transStartTime = scsc::now();
119
121 qaData.Send(fpSender);
122
123 lastPubTime = scsc::now();
124
126 pHistTrans->Fill(std::chrono::duration_cast<std::chrono::microseconds>(lastPubTime - transStartTime).count()
127 / 1e3);
128 }
129
130 std::this_thread::sleep_for(interval);
131 LOG(info) << "test: " << (scsc::now() < stopTime) << " (" << scsc::now().time_since_epoch().count() << " vs "
132 << stopTime.time_since_epoch().count() << ") => "
133 << (std::chrono::duration_cast<std::chrono::milliseconds>(scsc::now() - startTime).count() / 1e3);
134 }
135
137 LOG(info) << "Pub-hist: " << scsc::now().time_since_epoch().count() << " " << pHistTest->GetEntries();
139 qaData.Send(fpSender);
140 }
141} // namespace cbm::services::histserv_tester
A class representing a canvas in the message for the Histogram server.
ROOT-free implementation of a histogram.
A class representing a pad config in the message for the Histogram server.
A canvas configuration for the histogram server.
Class to handle QA-objects in the online reconstruction.
Definition QaData.h:28
1D-histogram
A pad configuration for the histogram server.
Definition PadConfig.h:26
ProgramOptions const & fOpt
Program options object.
std::shared_ptr< cbm::algo::HistogramSender > fpSender
Interface.
Application(ProgramOptions const &opt)
Standard constructor, initialises the application.
const std::string & ComChan() const
Get interface channel name or hostname + port or whatever or ????? (FIXME: replacement of FairMQ)
const int64_t & PubInterval() const
Get histos publication interval.
std::chrono::time_point< std::chrono::system_clock > sctp
std::chrono::system_clock scsc