14 #include "BoostSerializer.h"
15 #include "FairLogger.h"
16 #include "FairMQProgOptions.h"
17 #include "RootSerializer.h"
23 #include "THttpServer.h"
25 #include "TObjArray.h"
27 #include "TRootSniffer.h"
29 #include <boost/serialization/utility.hpp>
38 , fsChannelNameHistosInput(
"histogram-in")
39 , fsChannelNameHistosConfig(
"histo-conf")
40 , fsChannelNameCanvasConfig(
"canvas-conf")
41 , fsHistoFileName(
"HistosMonitorPulser.root")
42 , fuHttpServerPort(8098)
50 , fStopThread(false) {}
56 LOG(info) <<
"Init options for CbmMqHistoServer.";
70 fServer->GetSniffer()->SetScanGlobalDir(kFALSE);
72 fServer->RegisterCommand(
"/Reset_Hist",
"bMqHistoServerResetHistos=kTRUE");
73 fServer->RegisterCommand(
"/Save_Hist",
"bMqHistoServerSaveHistos=kTRUE");
75 fServer->Restrict(
"/Reset_Moni_Hist",
"allow=admin");
76 fServer->Restrict(
"/Save_Pulser_Hist",
"allow=admin");
80 TObject* tempObject =
nullptr;
82 Deserialize<RootSerializer>(*msg, tempObject);
84 if (TString(tempObject->ClassName()).EqualTo(
"TObjArray")) {
85 std::lock_guard<std::mutex> lk(
mtx);
86 TObjArray* arrayHisto =
static_cast<TObjArray*
>(tempObject);
87 for (Int_t
i = 0;
i < arrayHisto->GetEntriesFast();
i++) {
88 TObject* pObj = arrayHisto->At(
i);
90 if (
nullptr !=
dynamic_cast<TProfile*
>(pObj)) {
91 if (!ReadHistogram<TProfile>(
dynamic_cast<TProfile*
>(pObj)))
94 else if (
nullptr !=
dynamic_cast<TH2*
>(pObj)) {
95 if (!ReadHistogram<TH2>(
dynamic_cast<TH2*
>(pObj)))
return false;
97 else if (
nullptr !=
dynamic_cast<TH1*
>(pObj)) {
98 if (!ReadHistogram<TH1>(
dynamic_cast<TH1*
>(pObj)))
return false;
101 LOG(warning) <<
"Unsupported object type for " << pObj->GetName();
105 arrayHisto->Delete();
121 <<
"CbmMqHistoServer::ReceiveData => Wrong object type at input: "
122 << tempObject->ClassName();
126 if (
nullptr != tempObject)
delete tempObject;
131 std::lock_guard<std::mutex> lk(
mtx);
138 std::lock_guard<std::mutex> lk(
mtx);
149 std::pair<std::string, std::string> tempObject;
151 Deserialize<BoostSerializer<std::pair<std::string, std::string>>>(*msg,
154 LOG(info) <<
" Received configuration for histo " << tempObject.first <<
" : "
155 << tempObject.second;
159 UInt_t uPrevHist = 0;
165 LOG(info) <<
" Ignored new configuration for histo " << tempObject.first
166 <<
" due to previously received one: " << tempObject.second;
171 fvHistos.push_back(std::pair<TNamed*, std::string>(
nullptr,
""));
181 std::pair<std::string, std::string> tempObject;
183 Deserialize<BoostSerializer<std::pair<std::string, std::string>>>(*msg,
186 LOG(info) <<
" Received configuration for canvas " << tempObject.first
187 <<
" : " << tempObject.second;
191 uint32_t uPrevCanv = 0;
197 LOG(warning) <<
" Ignored new configuration for histo " << tempObject.first
198 <<
" due to previously received one: " << tempObject.second;
206 fvCanvas.push_back(std::pair<TCanvas*, std::string>(
nullptr,
""));
220 std::this_thread::sleep_for(std::chrono::milliseconds(10));
221 std::lock_guard<std::mutex> lk(
mtx);
232 template<
class HistoT>
236 HistoT* histogram_new =
static_cast<HistoT*
>(pHist->Clone());
239 LOG(info) <<
"Received new histo " << pHist->GetName();
249 fvHistos[uHist] = std::pair<TNamed*, std::string>(
255 LOG(info) <<
"registered histo " <<
fvHistos[uHist].first->GetName()
256 <<
" in folder " <<
fvHistos[uHist].second;
274 HistoT* histogram_existing =
dynamic_cast<HistoT*
>(
fArrayHisto.At(index1));
275 if (
nullptr == histogram_existing) {
276 LOG(error) <<
"CbmMqHistoServer::ReadHistogram => "
277 <<
"Incompatible type found during update for histo "
282 histogram_existing->Add(pHist);
288 for (
int iHist = 0; iHist <
fArrayHisto.GetEntriesFast(); ++iHist) {
290 if (TString(obj->GetName()).EqualTo(name)) {
298 for (
int iHist = 0; iHist <
fArrayHisto.GetEntriesFast(); ++iHist) {
299 dynamic_cast<TH1*
>(
fArrayHisto.At(iHist))->Reset();
309 for (uint32_t uPadIdx = 0; uPadIdx < uNbPads; ++uPadIdx) {
311 for (uint32_t uObjIdx = 0; uObjIdx < uNbObj; ++uObjIdx) {
312 std::string sName(conf.
GetObjName(uPadIdx, uObjIdx));
314 if (
"nullptr" != sName) {
328 for (uint32_t uPadIdx = 0; uPadIdx < uNbPads; ++uPadIdx) {
329 pNewCanv->cd(1 + uPadIdx);
333 gPad->SetLogx(conf.
GetLogx(uPadIdx));
334 gPad->SetLogy(conf.
GetLogy(uPadIdx));
335 gPad->SetLogz(conf.
GetLogz(uPadIdx));
339 for (uint32_t uObjIdx = 0; uObjIdx < uNbObj; ++uObjIdx) {
340 std::string sName(conf.
GetObjName(uPadIdx, uObjIdx));
341 if (
"nullptr" != sName) {
344 if (
nullptr !=
dynamic_cast<TProfile*
>(pObj)) {
345 dynamic_cast<TProfile*
>(pObj)->Draw(
346 conf.
GetOption(uPadIdx, uObjIdx).data());
348 else if (
nullptr !=
dynamic_cast<TH2*
>(pObj)) {
349 dynamic_cast<TH2*
>(pObj)->Draw(
350 conf.
GetOption(uPadIdx, uObjIdx).data());
352 else if (
nullptr !=
dynamic_cast<TH1*
>(pObj)) {
353 dynamic_cast<TH1*
>(pObj)->Draw(
354 conf.
GetOption(uPadIdx, uObjIdx).data());
357 LOG(warning) <<
"Unsupported object type for " << sName
358 <<
" when preparing canvas " << conf.
GetName();
363 fvCanvas[uCanvIdx] = std::pair<TCanvas*, std::string>(pNewCanv,
"canvases");
368 LOG(info) <<
"registered canvas " <<
fvCanvas[uCanvIdx].first->GetName()
369 <<
" in folder " <<
fvCanvas[uCanvIdx].second;
385 TDirectory* oldDir = NULL;
386 TFile* histoFile = NULL;
392 if (
nullptr == histoFile)
return false;
395 for (UInt_t uHisto = 0; uHisto <
fvHistos.size(); ++uHisto) {
397 TString sFolder =
fvHistos[uHisto].second.data();
398 if (
nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
399 gDirectory->cd(sFolder);
407 for (UInt_t uCanvas = 0; uCanvas <
fvCanvas.size(); ++uCanvas) {
409 TString sFolder =
fvCanvas[uCanvas].second.data();
410 if (
nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
411 gDirectory->cd(sFolder);