Newer
Older
/* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Florian Uhlig [committer] */
//#include "CbmHistoCanvasDrawer.h"
#include "TH1.h"
#include "THttpServer.h"
std::mutex mtx;
CbmHistoServer::CbmHistoServer()
: FairMQDevice()
, fInputChannelName("histogram-in")
, fArrayHisto()
, fNMessages(0)
, fServer("http:8088")
// , fCanvasDrawer(nullptr)
CbmHistoServer::~CbmHistoServer() {}
void CbmHistoServer::InitTask()
{
if (fCanvasDrawer)
{
fCanvasDrawer->CreateCanvases(fServer);
}
*/
}
bool CbmHistoServer::ReceiveData(FairMQMessagePtr& msg, int /*index*/)
{

Pierre-Alain Loizeau
committed
RootSerializer().Deserialize(*msg, tempObject);
if (TString(tempObject->ClassName()).EqualTo("TObjArray")) {
std::lock_guard<std::mutex> lk(mtx);
TObjArray* arrayHisto = static_cast<TObjArray*>(tempObject);
TH1* histogram_new;
TH1* histogram_existing;
for (Int_t i = 0; i < arrayHisto->GetEntriesFast(); i++) {
TObject* obj = arrayHisto->At(i);
TH1* histogram = static_cast<TH1*>(obj);
int index1 = FindHistogram(histogram->GetName());
if (-1 == index1) {
histogram_new = static_cast<TH1*>(histogram->Clone());
fArrayHisto.Add(histogram_new);
fServer.Register("Histograms", histogram_new);
histogram_existing = static_cast<TH1*>(fArrayHisto.At(index1));
histogram_existing->Add(histogram);
}
void CbmHistoServer::PreRun()
{
fStopThread = false;
fThread = std::thread(&CbmHistoServer::UpdateHttpServer, this);
void CbmHistoServer::UpdateHttpServer()
{
while (!fStopThread) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
std::lock_guard<std::mutex> lk(mtx);
if (fCanvasDrawer)
{
fCanvasDrawer->DrawHistograms(fArrayHisto);
}
*/
void CbmHistoServer::PostRun()
{
int CbmHistoServer::FindHistogram(const std::string& name)
{
for (int i = 0; i < fArrayHisto.GetEntriesFast(); i++) {
TObject* obj = fArrayHisto.At(i);
if (TString(obj->GetName()).EqualTo(name)) { return i; }
}
return -1;