Skip to content
Snippets Groups Projects
Commit 455213f3 authored by adrien-matta's avatar adrien-matta
Browse files

* NPOnline now working with non c++11 compiler

parent bbbc68a8
No related branches found
No related tags found
No related merge requests found
add_custom_command(OUTPUT TAsciiFileDict.cxx TAsciiFileDict_rdict.pcm TAsciiFile.rootmap COMMAND ../scripts/build_dict.sh TAsciiFile.h TAsciiFileDict.cxx TAsciiFile.rootmap libNPCore.so)
add_custom_command(OUTPUT NPVDetectorDict.cxx NPVDetectorDict_rdict.pcm NPVDetector.rootmap COMMAND ../scripts/build_dict.sh NPVDetector.h NPVDetectorDict.cxx NPVDetector.rootmap libNPCore.so NPCoreLinkdef.h)
add_custom_command(OUTPUT NPOnlineDict.cxx NPOnlineDict_rdict.pcm NPOnline.rootmap COMMAND ../scripts/build_dict.sh NPOnline.h NPOnlineDict.cxx NPOnline.rootmap libNPOnline.dylib NPOnlineLinkDef.h DEPENDS NPOnline.h)
add_library(NPCore SHARED NPVAnalysis.cxx NPAnalysisFactory.cxx NPCalibrationManager.cxx NPOptionManager.cxx RootOutput.cxx RootInput.cxx TAsciiFile.cxx TAsciiFileDict.cxx NPDetectorManager.cxx NPVDetector.cxx NPVDetectorDict.cxx NPVSpectra.cxx NPDetectorFactory.cxx NPOnline.cxx NPOnlineDict.cxx NPSpectraServer)
add_custom_command(OUTPUT NPSpectraServerDict.cxx NPSpectraServerDict_rdict.pcm NPSpectraServer.rootmap COMMAND ../scripts/build_dict.sh NPSpectraServer.h NPSpectraServerDict.cxx NPSpectraServer.rootmap libNPSpectraServer.dylib NPSpectraServerLinkDef.h DEPENDS NPSpectraServer.h)
add_library(NPCore SHARED NPVAnalysis.cxx NPAnalysisFactory.cxx NPCalibrationManager.cxx NPOptionManager.cxx RootOutput.cxx RootInput.cxx TAsciiFile.cxx TAsciiFileDict.cxx NPDetectorManager.cxx NPVDetector.cxx NPVDetectorDict.cxx NPVSpectra.cxx NPDetectorFactory.cxx NPOnline.cxx NPOnlineDict.cxx NPSpectraServer.cxx NPSpectraServerDict.cxx)
target_link_libraries(NPCore ${ROOT_LIBRARIES})
install(FILES NPVAnalysis.h NPAnalysisFactory.h NPCalibrationManager.h NPOptionManager.h RootInput.h RootOutput.h TAsciiFile.h NPDetectorManager.h NPVDetector.h NPGlobalSystemOfUnits.h NPPhysicalConstants.h NPSystemOfUnits.h NPVSpectra.h NPDetectorFactory.h NPOnline.h NPSpectraServer.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
......@@ -33,10 +33,9 @@
#include "RootInput.h"
#include "NPOptionManager.h"
#include "NPCalibrationManager.h"
#include "NPSpectraServer.h"
//Root
#include"TCanvas.h"
/////////////////////////////////////////////////////////////////////////////////////////////////
// Default Constructor
NPL::DetectorManager::DetectorManager(){
......@@ -45,7 +44,7 @@ NPL::DetectorManager::DetectorManager(){
m_ClearEventDataPtr = &NPL::VDetector::ClearEventData ;
m_FillSpectra = NULL;
m_CheckSpectra = NULL;
m_SpectraServer = NULL;
if(NPOptionManager::getInstance()->GetGenerateHistoOption()){
m_FillSpectra = &NPL::VDetector::FillSpectra ;
if(NPOptionManager::getInstance()->GetCheckHistoOption())
......@@ -60,7 +59,8 @@ NPL::DetectorManager::~DetectorManager(){
#if __cplusplus > 199711L
StopThread();
#endif
if(m_SpectraServer)
m_SpectraServer->Destroy();
}
/////////////////////////////////////////////////////////////////////////////////////////////////
......@@ -429,23 +429,29 @@ bool NPL::DetectorManager::IsDone(){
}
return true;
}
#endif
////////////////////////////////////////////////////////////////////////////////
void NPL::DetectorManager::SetSpectraServer(){
NPL::SpectraServer* s = NPL::SpectraServer::getInstance();
m_SpectraServer = NPL::SpectraServer::getInstance();
map<string,VDetector*>::iterator it;
for (it = m_Detector.begin(); it != m_Detector.end(); ++it){
vector<TCanvas*> canvas = it->second->GetCanvas();
size_t mysize = canvas.size();
for (size_t i = 0 ; i < mysize ; i++)
s->AddCanvas(canvas[i]);
m_SpectraServer->AddCanvas(canvas[i]);
}
thread t( &NPL::SpectraServer::Start,s);
t.detach();
system("nponline localhost 9090 &");
system("nponline localhost 9090 & ");
m_SpectraServer->CheckRequest();
}
////////////////////////////////////////////////////////////////////////////////
void NPL::DetectorManager::StopSpectraServer(){
m_SpectraServer->Destroy();
}
////////////////////////////////////////////////////////////////////////////////
void NPL::DetectorManager::CheckSpectraServer(){
m_SpectraServer->CheckRequest();
}
#endif
......@@ -22,7 +22,7 @@
*****************************************************************************/
// NPL
#include "NPVDetector.h"
#include "NPSpectraServer.h"
// ROOT
#include "TH1.h"
......@@ -60,6 +60,13 @@ namespace NPL{
vector< map< vector<string>, TH1* > > GetSpectra();
vector<string> GetDetectorList();
public: // for online spectra server
void SetSpectraServer();
void StopSpectraServer();
void CheckSpectraServer();
private :
NPL::SpectraServer* m_SpectraServer;
private:
// The map containning all detectors
// Using a Map one can access to any detector using its name
......@@ -71,7 +78,7 @@ namespace NPL{
VDetector_FuncPtr m_ClearEventDataPtr;
VDetector_FuncPtr m_FillSpectra;
VDetector_FuncPtr m_CheckSpectra;
#if __cplusplus > 199711L
private: // Thread Pool defined if C++11 is available
vector<thread> m_ThreadPool;
......@@ -84,9 +91,7 @@ namespace NPL{
void InitThreadPool();
bool IsDone();
public: // for online spectra server
void SetSpectraServer();
#endif
#endif
private:
double m_TargetThickness;
......
......@@ -6,7 +6,7 @@
#include <dirent.h>
// Root
#include "TRoot.h"
#include "TROOT.h"
#include "TColor.h"
#include "TSystem.h"
#include "TString.h"
......@@ -64,7 +64,6 @@ void NPL::NPOnline::MakeGui(string address,int port){
m_Main->SetName("nponline");
m_Main->SetBackgroundColor(m_BgColor);
m_Main->SetForegroundColor(m_FgColor);
// m_Main->SetLayoutBroken(kTRUE);
// Button bar to hold the button
m_ButtonBar= new TGVerticalFrame(m_Main,10000,42,kFixedSize);
......@@ -218,9 +217,8 @@ void NPL::NPOnline::MakeGui(string address,int port){
m_Main->Resize(m_Main->GetDefaultSize());
m_Main->MapWindow();
m_Main->MoveResize(0,0,2000,1000);
m_Main->MoveResize(0,0,1000,500);
m_Main->SetLayoutBroken(kFALSE);
}
////////////////////////////////////////////////////////////////////////////////
......@@ -240,6 +238,12 @@ NPL::NPOnline::~NPOnline(){
////////////////////////////////////////////////////////////////////////////////
void NPL::NPOnline::Connect(){
// Connect to SpectraServer
if(m_Sock){
m_Sock->Close("force");
delete m_Sock;
m_Sock = NULL;
}
m_Sock = new TSocket(m_Address->GetDisplayText(),(Int_t) m_Port->GetNumber());
if(m_Sock->IsValid()){
m_Connect->SetState(kButtonDisabled);
......@@ -253,7 +257,11 @@ void NPL::NPOnline::Connect(){
////////////////////////////////////////////////////////////////////////////////
void NPL::NPOnline::Update(){
if(!m_Sock || !(m_Sock->IsValid())){
cout << "Spectra server not connected" << endl;
if(m_Sock){
m_Sock->Close("force");
delete m_Sock;
m_Sock = NULL;
}
m_Connect->SetState(kButtonUp);
return;
}
......@@ -262,10 +270,15 @@ void NPL::NPOnline::Update(){
m_Sock->Send("RequestSpectra");
if(m_Sock->Recv(message)<=0){
cout << "Spectra request failed " << endl;
if(m_Sock){
m_Sock->Close("force");
delete m_Sock;
m_Sock = NULL;
}
m_Connect->SetState(kButtonUp);
return;
}
m_CanvasListTree->Clear();
m_CanvasList = (TList*) message->ReadObject(message->GetClass());
......@@ -277,13 +290,13 @@ void NPL::NPOnline::Update(){
TGCompositeFrame* tab = m_Tab->GetTabContainer(c->GetName());
if(tab){
tab->RemoveAll();
TRootEmbeddedCanvas* canvas = new TRootEmbeddedCanvas("Canvas",tab,700,490,!kSunkenFrame);
TRootEmbeddedCanvas* canvas = new TRootEmbeddedCanvas(c->GetName(),tab,100,100,!kSunkenFrame);
c->UseCurrentStyle();
c->SetMargin(0,0,0,0);
canvas->AdoptCanvas(c);
tab->AddFrame(canvas,new TGLayoutHints(kLHintsLeft | kLHintsBottom | kLHintsExpandX | kLHintsExpandY));
tab->SetLayoutManager(new TGVerticalLayout(tab));
tab->SetLayoutManager(new TGHorizontalLayout(tab));
ExecuteMacro(c->GetName());
}
}
......
#include "NPSpectraServer.h"
#include <unistd.h>
#include<cstdlib>
#include<unistd.h>
#include<iostream>
NPL::SpectraServer* NPL::SpectraServer::instance = 0 ;
////////////////////////////////////////////////////////////////////////////////
......@@ -9,15 +10,18 @@ NPL::SpectraServer* NPL::SpectraServer::getInstance(){
return instance;
}
////////////////////////////////////////////////////////////////////////////////
void NPL::SpectraServer::Destroy(){
delete instance ;
instance = 0 ;
}
////////////////////////////////////////////////////////////////////////////////
NPL::SpectraServer::SpectraServer(){
m_Server= new TServerSocket(9090,true);
if(!m_Server->IsValid())
exit(1);
m_stop = false;
m_Server->SetCompressionSettings(1);
// Add server socket to monitor so we are notified when a client needs to be
// accepted
m_Monitor = new TMonitor;
......@@ -35,39 +39,21 @@ void NPL::SpectraServer::AddCanvas(TCanvas* c){
}
////////////////////////////////////////////////////////////////////////////////
void NPL::SpectraServer::Start(){
void NPL::SpectraServer::CheckRequest(){
if(m_Server){
while(!m_stop){
if(!m_Server)
return;
TSocket* s ;
if((s=m_Monitor->Select(20))!=(TSocket*)-1)
if((s=m_Monitor->Select(1))!=(TSocket*)-1)
HandleSocket(s);
}
}
}
////////////////////////////////////////////////////////////////////////////////
NPL::SpectraServer::~SpectraServer(){
std::cout << 1 << std::endl;
// tell the socket to stop
m_stop = true;
// wait for it to be stopped
sleep(100);
std::cout << 2 << std::endl;
m_Server->Close("force");
std::cout << 3 << std::endl;
delete m_Server;
std::cout << 4 << std::endl;
m_Server=0;
delete m_Monitor;
std::cout << 5 << std::endl;
m_Monitor = 0;
instance = 0 ;
}
......
......@@ -11,7 +11,7 @@ namespace NPL{
class SpectraServer{
public:
static SpectraServer* getInstance();
void Destroy();
private:
SpectraServer();
~SpectraServer();
......@@ -22,7 +22,7 @@ namespace NPL{
public:
void HandleSocket(TSocket* s);
void AddCanvas(TCanvas* c);
void Start();
void CheckRequest();
private:
bool m_stop;
TServerSocket* m_Server;
......
......@@ -102,7 +102,6 @@ int main(int argc , char** argv){
if(myOptionManager->GetOnline()){
// Request Detector manager to give the Spectra to the server
myDetector->SetSpectraServer();
}
std::cout << std::endl << "///////// Starting Analysis ///////// "<< std::endl;
......@@ -132,6 +131,10 @@ int main(int argc , char** argv){
// Fill the tree
tree->Fill();
ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed);
if(myOptionManager->GetOnline() && i%5000==0){
myDetector->CheckSpectraServer();
}
}
}
......@@ -153,6 +156,9 @@ int main(int argc , char** argv){
// Fill the tree
tree->Fill();
ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed);
if(myOptionManager->GetOnline() && i%5000==0){
myDetector->CheckSpectraServer();
}
}
}
......@@ -165,6 +171,9 @@ int main(int argc , char** argv){
// Fill the tree
tree->Fill();
ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed);
if(myOptionManager->GetOnline() && i%5000==0){
myDetector->CheckSpectraServer();
}
}
}
UserAnalysis->End();
......@@ -174,11 +183,18 @@ int main(int argc , char** argv){
myDetector->StopThread();
#endif
ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed);
if(myOptionManager->GetOnline()){
myDetector->CheckSpectraServer();
}
if(myOptionManager->GetGenerateHistoOption())
myDetector->WriteSpectra();
RootOutput::getInstance()->Destroy();
RootInput::getInstance()->Destroy();
return 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment