From eea1bee7bf3c114f2e96190f790eca1f27e727ef Mon Sep 17 00:00:00 2001
From: "P.-A. Loizeau" <p.-a.loizeau@gsi.de>
Date: Fri, 1 Jul 2022 14:57:05 +0200
Subject: [PATCH] [MQ] In histo server device, save histos to root file on
 shutdown (from NH changes)

---
 MQ/histoServer/CbmMqHistoServer.cxx | 14 ++---------
 MQ/histoServer/CbmMqHistoServer.h   | 36 ++++++++++++++---------------
 2 files changed, 20 insertions(+), 30 deletions(-)

diff --git a/MQ/histoServer/CbmMqHistoServer.cxx b/MQ/histoServer/CbmMqHistoServer.cxx
index ce1a896110..21009b9f89 100644
--- a/MQ/histoServer/CbmMqHistoServer.cxx
+++ b/MQ/histoServer/CbmMqHistoServer.cxx
@@ -35,19 +35,7 @@ Bool_t bMqHistoServerSaveHistos  = kFALSE;
 */
 CbmMqHistoServer::CbmMqHistoServer()
   : FairMQDevice()
-  , fsChannelNameHistosInput("histogram-in")
-  , fsChannelNameHistosConfig("histo-conf")
-  , fsChannelNameCanvasConfig("canvas-conf")
-  , fsHistoFileName("MqHistos.root")
-  , fuHttpServerPort(8098)
   , fArrayHisto()
-  , fvpsHistosFolder()
-  , fvpsCanvasConfig()
-  , fvHistos()
-  , fvCanvas()
-  , fNMessages(0)
-  , fServer(nullptr)
-  , fStopThread(false)
 {
 }
 
@@ -308,8 +296,10 @@ void CbmMqHistoServer::UpdateHttpServer()
 
 void CbmMqHistoServer::PostRun()
 {
+  SaveHistograms();
   fStopThread = true;
   fThread.join();
+  SaveHistograms();
 }
 
 template<class HistoT>
diff --git a/MQ/histoServer/CbmMqHistoServer.h b/MQ/histoServer/CbmMqHistoServer.h
index b2cd3c0cb1..5cbd8cdf08 100644
--- a/MQ/histoServer/CbmMqHistoServer.h
+++ b/MQ/histoServer/CbmMqHistoServer.h
@@ -42,37 +42,37 @@ protected:
 
 private:
   /// Parameters
-  std::string fsChannelNameHistosInput;
-  std::string fsChannelNameHistosConfig;
-  std::string fsChannelNameCanvasConfig;
-  std::string fsHistoFileName;
-  uint32_t fuHttpServerPort;
+  std::string fsChannelNameHistosInput  = "histogram-in";
+  std::string fsChannelNameHistosConfig = "histo-conf";
+  std::string fsChannelNameCanvasConfig = "canvas-conf";
+  std::string fsHistoFileName           = "MqHistos.root";
+  uint32_t fuHttpServerPort             = 8098;
 
   /// Array of histograms with unique names
   TObjArray fArrayHisto;
   /// Vector of string with ( HistoName, FolderPath ) to send to the histogram server
-  std::vector<std::pair<std::string, std::string>> fvpsHistosFolder;
+  std::vector<std::pair<std::string, std::string>> fvpsHistosFolder = {};
   /// Vector of string pairs with ( CanvasName, CanvasConfig ) to send to the histogram server
   /// Format of Can config is "Name;Title;NbPadX(U);NbPadY(U);ConfigPad1(s);....;ConfigPadXY(s)"
   /// Format of Pad config is "GrixX(b),GridY(b),LogX(b),LogY(b),LogZ(b),HistoName(s),DrawOptions(s)"
-  std::vector<std::pair<std::string, std::string>> fvpsCanvasConfig;
-  std::vector<bool> fvbCanvasReady;
-  bool fbAllCanvasReady;
+  std::vector<std::pair<std::string, std::string>> fvpsCanvasConfig = {};
+  std::vector<bool> fvbCanvasReady                                  = {};
+  bool fbAllCanvasReady                                             = false;
 
-  std::vector<std::pair<TNamed*, std::string>> fvHistos;  //! Vector of Histos pointers and folder path
-  std::vector<bool> fvbHistoRegistered;
-  bool fbAllHistosRegistered;
-  std::vector<std::pair<TCanvas*, std::string>> fvCanvas;  //! Vector of Canvas pointers and folder path
-  std::vector<bool> fvbCanvasRegistered;
-  bool fbAllCanvasRegistered;
+  std::vector<std::pair<TNamed*, std::string>> fvHistos  = {};  //! Vector of Histos pointers and folder path
+  std::vector<bool> fvbHistoRegistered                   = {};
+  bool fbAllHistosRegistered                             = false;
+  std::vector<std::pair<TCanvas*, std::string>> fvCanvas = {};  //! Vector of Canvas pointers and folder path
+  std::vector<bool> fvbCanvasRegistered                  = {};
+  bool fbAllCanvasRegistered                             = false;
 
   /// Internal status
-  int fNMessages;
+  int fNMessages = 0;
 
-  THttpServer* fServer;
+  THttpServer* fServer = nullptr;
 
   std::thread fThread;
-  bool fStopThread;
+  bool fStopThread = false;
 
   template<class HistoT>
   bool ReadHistogram(HistoT* pHist);
-- 
GitLab