From 4970d355e246a4821c5f458be2ce429be37d6deb Mon Sep 17 00:00:00 2001 From: Adrien Matta <matta@lpccaen.in2p3.fr> Date: Fri, 8 Feb 2019 15:00:51 +0100 Subject: [PATCH] Updating SpectraClient --- NPLib/Online/NPSpectraClient.cxx | 39 ++++++++++++++++++++++++++++++++ NPLib/Online/NPSpectraClient.h | 3 +++ 2 files changed, 42 insertions(+) diff --git a/NPLib/Online/NPSpectraClient.cxx b/NPLib/Online/NPSpectraClient.cxx index 473b99a18..e90b5f1a2 100644 --- a/NPLib/Online/NPSpectraClient.cxx +++ b/NPLib/Online/NPSpectraClient.cxx @@ -173,6 +173,45 @@ bool NPL::SpectraClient::Update(std::string name){ return true; } } +//////////////////////////////////////////////////////////////////////////////// +TTree* NPL::SpectraClient::GetTree(){ + if(!m_Sock || !(m_Sock->IsValid())){ + if(m_Sock){ + m_Sock->Close("force"); + delete m_Sock; + m_Sock = NULL; + } + NPL::SendWarning("NPL::SpectraClient","Update failed: Connection lost"); + + return NULL; + } + + TMessage* message=NULL; + m_Sock->Send("RequestTree",kMESS_STRING||kMESS_ACK); + + if(m_Sock->Recv(message)<=0){ + if(m_Sock){ + m_Sock->Close("force"); + delete m_Sock; + m_Sock = NULL; + } + + NPL::SendWarning("NPL::SpectraClient","Update failed: message return unreadable"); + + return NULL; + } + + if(message){ + TTree* tree = (TTree*) message->ReadObject(message->GetClass()); + return tree; + } + + else{ + NPL::SendInformation("NPL::SpectraClient","Server return an empty tree"); + return NULL; + } +} + //////////////////////////////////////////////////////////////////////////////// TList* NPL::SpectraClient::GetSpectra(){ diff --git a/NPLib/Online/NPSpectraClient.h b/NPLib/Online/NPSpectraClient.h index fb67e65df..cca37e1ea 100644 --- a/NPLib/Online/NPSpectraClient.h +++ b/NPLib/Online/NPSpectraClient.h @@ -27,6 +27,7 @@ #include "TMessage.h" #include "TList.h" #include "TH1.h" +#include "TTree.h" #include "string" namespace NPL{ @@ -44,6 +45,8 @@ namespace NPL{ // Update a single spectra bool Update(std::string name); void UpdateTH1(TH1* Old, TH1* New ); + // Access the tree + TTree* GetTree(); private: // The sochet use for connection TSocket* m_Sock; std::string m_Address; -- GitLab