CbmRoot
Loading...
Searching...
No Matches
services/histserv/app/Application.h
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#ifndef CBM_SERVICES_HISTSERV_APP_APPLICATION_H
6#define CBM_SERVICES_HISTSERV_APP_APPLICATION_H 1
7
8#include "Histogram.h"
9#include "ProgramOptions.h"
10#include "THttpServer.h"
11#include "TObjArray.h"
12#include "ui_callbacks.h"
13
14#include <csignal>
15#include <forward_list>
16#include <memory>
17#include <string>
18#include <string_view>
19#include <thread>
20#include <zmq.hpp>
21
22class TCanvas;
23class TNamed;
24
26{
29 struct AppConfig {
30 int fNofTsToStore = 400;
31 };
32
34
35 public:
38 explicit Application(ProgramOptions const& opt, volatile sig_atomic_t* signalStatus);
39
41 Application(const Application&) = delete;
42
44 void operator=(const Application&) = delete;
45
48
50 void Exec();
51
52 void UpdateHttpServer();
53
54 private:
58 //template<class HistoSrc>
59 //bool CollectHistograms(const std::forward_list<HistoSrc>& container);
60
61 //const std::string& ConfigFile() const;
63 int FindHistogram(const std::string& name);
64
66 bool ResetHistograms();
67
72 template<class HistoDst, class HistoSrc>
73 bool ReadHistogram(const HistoSrc& rHist);
74
79 template<class HistoSrc>
80 bool ReadHistogramExtendedTsId(const HistoSrc& pHistSrc, uint64_t tsIndex);
81
84 bool ReceiveData(zmq::message_t& msg);
85
87 bool ReceiveHistoConfig(zmq::message_t& msg);
88
90 bool ReceiveCanvasConfig(zmq::message_t& msg);
91
94 bool ReceiveConfigAndData(std::vector<zmq::message_t>& vMsg);
95
100 bool RegisterHistoConfig(const std::pair<std::string, std::string>& config);
101
104 bool RegisterHistogram(const TNamed* hist);
105
108 bool PrepareCanvas(uint32_t uCanvIdx);
109
111 bool SaveHistograms();
112
115 //static void SignalHandler(int signal);
116
117 private:
119 volatile sig_atomic_t* fSignalStatus;
120 THttpServer* fServer = nullptr;
121 std::thread fThread;
122 bool fStopThread = false;
123
124 std::unique_ptr<UiCmdActor> fUiCmdActor;
125
127 zmq::context_t fZmqContext {1};
128 zmq::socket_t fZmqSocket {fZmqContext, ZMQ_PULL};
129
131 TObjArray fArrayHisto;
133 std::vector<std::pair<std::string, std::string>> fvpsHistosFolder = {};
137 std::vector<std::pair<std::string, std::string>> fvpsCanvasConfig = {};
138 std::vector<bool> fvbCanvasReady = {};
139 bool fbAllCanvasReady = false;
141
142 std::vector<std::pair<TNamed*, std::string>> fvHistos = {};
143 std::vector<bool> fvbHistoRegistered = {};
145 std::vector<std::pair<TCanvas*, std::string>> fvCanvas = {};
146 std::vector<bool> fvbCanvasRegistered = {};
148
150 uint32_t fNMessages = 0;
151 };
152
153} // namespace cbm::services::histserv
154
155#endif /* CBM_SERVICES_HISTSERV_APP_APPLICATION_H */
ROOT-free implementation of a histogram.
void operator=(const Application &)=delete
Assignment operator forbidden.
bool ReadHistogram(const HistoSrc &rHist)
Read a histogram.
bool ReceiveCanvasConfig(zmq::message_t &msg)
Receives canvas configuration.
int FindHistogram(const std::string &name)
Collects histograms of the same type from the histogram list.
ProgramOptions const & fOpt
A handler for system signals.
std::vector< std::pair< TCanvas *, std::string > > fvCanvas
Vector of Canvas pointers and folder path.
Application(const Application &)=delete
Copy constructor forbidden.
TObjArray fArrayHisto
Array of histograms with unique names.
volatile sig_atomic_t * fSignalStatus
Global signal status.
bool RegisterHistoConfig(const std::pair< std::string, std::string > &config)
Register a histogram config in the histogram server.
bool ReadHistogramExtendedTsId(const HistoSrc &pHistSrc, uint64_t tsIndex)
Reads a histogram slice for an extended histogram with the TS ID.
std::vector< std::pair< TNamed *, std::string > > fvHistos
Vector of Histos pointers and folder path.
bool ReceiveData(zmq::message_t &msg)
Find histogram index in the histogram array.
Application(ProgramOptions const &opt, volatile sig_atomic_t *signalStatus)
Standard constructor, initialises the application.
bool PrepareCanvas(uint32_t uCanvIdx)
Prepares canvases using received canvas configuration.
std::vector< std::pair< std::string, std::string > > fvpsCanvasConfig
void Exec()
Run the application.
THttpServer * fServer
ROOT Histogram server (JSroot)
bool ReceiveConfigAndData(std::vector< zmq::message_t > &vMsg)
Receives a list of canvases and histograms.
bool RegisterHistogram(const TNamed *hist)
Register a histogram in the histogram server.
bool ReceiveHistoConfig(zmq::message_t &msg)
Receives histogram configuration.
std::vector< std::pair< std::string, std::string > > fvpsHistosFolder
Vector of string with ( HistoName, FolderPath ) to configure the histogram.
int fNofTsToStore
Number of consequent timeslices to store.