Commit 82cfca57 authored by Locatelli's avatar Locatelli
Browse files

do process instead of thread(remove memory problem)

parent 3c1325e9
INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/../NomadServer/src -I/usr/include/python3.5m -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtGui -I/usr/include/x86_64-linux-gnu/qt5/QtCore
bin_PROGRAMS = ploty2 mplplot test test2 test3
bin_PROGRAMS = ploty2 mplplot offscreenplot
#export QT_SELECT=5
QT = \
......@@ -118,6 +118,31 @@ mplplot_LDADD = $(LIBS) $(RM_LIBS) \
$(BOOST_FILESYSTEM_LIB) \
$(BOOST_THREAD_LIB)
offscreenplot_SOURCES = \
mainoffscreenplot.cpp \
manager/ThreadPoolManager.cpp \
manager/RequestDealerManager.cpp \
manager/ServerSubscriberManager.cpp \
manager/AnalysisRequesterManager.cpp \
manager/ServerRequesterManager.cpp \
manager/PlotManager.cpp \
manager/InterfaceManager.cpp \
manager/OffScreenPlotManager.cpp \
manager/mpl/MplEventManager.cpp \
$(PLOT) \
$(PROTOBUF) \
$(DATACONT) \
$(MPLCPP) \
$(QT) \
$(JSON)
offscreenplot_CPPFLAGS = $(RM_CXXFLAGS) -DOFFSCREEN -DTRACEDEBUG
offscreenplot_LDFLAGS = $(RM_LDFLAGS)
offscreenplot_LDADD = $(LIBS) $(RM_LIBS) \
$(BOOST_SYSTEM_LIB) \
$(BOOST_FILESYSTEM_LIB) \
$(BOOST_THREAD_LIB)
test_SOURCES = \
maintest.cpp \
manager/ThreadPoolManager.cpp \
......@@ -131,7 +156,6 @@ test_SOURCES = \
manager/mpl/MplEventManager.cpp \
$(PLOT) \
$(PROTOBUF) \
$(DATACONT) \
$(MPLCPP) \
$(QT) \
$(JSON)
......
......@@ -21,26 +21,26 @@
#include <unistd.h>
#include <fstream>
#include <cstdlib>
#include <memory>
#include <signal.h>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include "Common.h"
#include "common/protobuf/generated/NotificationMessages.pb.h"
#include "protobuf/generated/AcquisitionSerializer.pb.h"
#include "view/mpl/Mpl.h"
#include "view/mpl/MplFigure.h"
#include "Trace.h"
#include "Error.h"
#include "view/mpl/Mpl.h"
#include "plot/offscreen/OffScreenEmptyPlot.h"
#include "plot/offscreen/OffScreenPlot1D.h"
#include "plot/offscreen/OffScreenPlot2D.h"
#include "manager/ServerRequesterManager.h"
#include "json/LogSender.h"
using namespace std;
using namespace cameo;
unique_ptr<application::Instance> nomadserver; //! Instance of nomad server
/*!
* \brief crash handler method
......@@ -55,138 +55,102 @@ void crash_handler(int32 sig) {
*/
int32 main(int32 argc, char* argv[]) {
for (int32 i = 0; i < argc; ++i) {
DBGMSG(argv[i]);
}
if (argc < 5) {
Error("mainoffscreenplot", "Missing arguments need 6 got", argc);
if (argc < 3) {
Error("mainoffscreenplot", "Missing arguments, need 2 : got ", argc);
return EXIT_FAILURE;
}
// Create and init the Matplolib module
view::mpl::Mpl* mpl = new view::mpl::Mpl();
// Init cameo application
int32 err = EXIT_SUCCESS;
application::This::init(1, &argv[4]);
{
// Get nomad server instance
nomadserver = getNomadInstance(application::This::getServer());
if (nomadserver.get() == 0) {
Error("mainoffscreenplot", "No nomad server instance");
err = EXIT_FAILURE;
goto exit;
}
DBGMSG("Connected to " << *nomadserver);
// create a requester on the nomad server database
unique_ptr<application::Requester> requesterdb = application::Requester::create(*nomadserver, "database");
if (requesterdb.get() == 0) {
Error("mainoffscreenplot", "Connection problem on database");
err = EXIT_FAILURE;
goto exit;
}
DBGMSG("Created requester " << *requesterdb);
// Manage application signal
// signal(SIGABRT, crash_handler);
signal(SIGHUP, crash_handler);
// signal(SIGSEGV, crash_handler);
signal(SIGPIPE, crash_handler);
signal(SIGINT, crash_handler);
std::string pbfilename = argv[1];
std::string path = argv[2];
// Init the nomad server requester manager
manager::ServerRequesterManager::getInstance()->init(requesterdb.get());
// Set cameo application running
application::This::setRunning();
// Create and init the Matplolib module
unique_ptr<view::mpl::Mpl> mpl(new view::mpl::Mpl());
boost::filesystem::path pbfile = argv[3];
pbfile /= argv[2];
try {
unique_ptr<view::mpl::MplFigure> figure(new view::mpl::MplFigure(*mpl.get(), false));
boost::filesystem::path pbfile = path;
pbfile /= pbfilename;
pbfile.replace_extension("pb");
DBGMSG("file : " << pbfile.string().c_str());
uint32 size = (uint32) boost::filesystem::file_size(pbfile);
ifstream inputMessage(pbfile.string().c_str(), fstream::binary);
if (inputMessage.is_open() == false) {
Error("mainoffscreenplot", "Failed to open temporary file wich contains ploty::PlotPropertyDataMessage", argv[2]);
err = EXIT_FAILURE;
Error("OffScreenPlotManager", "savePlot",
"Failed to open temporary file which contains ploty::PlotPropertyDataMessage", pbfilename);
} else {
uint32 size = boost::filesystem::file_size(pbfile);
char buffer[size];
inputMessage.read(buffer, size);
buffer::Data data;
data.ParseFromArray(buffer, size);
DBGMSG("type = " << data.type());
DBGMSG("buffer = " << size);
DBGMSG("numor = " << data.numor());
DBGMSG("dataxArray = " << data.xdata_size());
DBGMSG("datayArray = " << data.ydata_size());
DBGMSG("datazArray = " << data.zdata_size());
// DBGMSG("buffer = " << size);
// DBGMSG("numor = " << data.numor());
// DBGMSG("dataxArray = " << data.xdata_size());
// DBGMSG("datayArray = " << data.ydata_size());
// DBGMSG("datazArray = " << data.zdata_size());
inputMessage.close();
view::mpl::MplFigure* figure = new view::mpl::MplFigure(mpl);
ostringstream plotkey;
plotkey << argv[2];
plotkey << pbfilename;
uint32 dpi = 100;
float64 pad = 1;
if (data.type() == buffer::Data::Spy) {
dpi = 30;
pad = 0;
} else if (data.type() == buffer::Data::Multiplot) {
dpi = 30;
}
if ((data.xdata_size() > 0) && (data.ydata_size() > 0) && (data.zdata_size() > 0)) {
// 2D
for (int32 i = 0; i < data.xdata_size(); ++i) {
try {
plot::offscreen::OffScreenPlot2D plot(figure, plotkey.str(), mpl, &data);
plot::offscreen::OffScreenPlot2D plot(*figure, plotkey.str(), *mpl.get(), data);
plot.display();
plot.save(pbfile.parent_path().parent_path().string(), 300, 1);
plot.save(pbfile.parent_path().parent_path().string(), dpi, pad);
} catch (Error& e) {
Error("mainoffscreenplot", "Failed create 2d plot", plotkey.str());
Error("OffScreenPlotManager", "savePlot", "Failed create 2d plot", plotkey.str());
}
}
} else if ((data.xdata_size() > 0) && (data.ydata_size() > 0)) {
// 1D
for (int32 i = 0; i < data.xdata_size(); ++i) {
try {
plot::offscreen::OffScreenPlot1D plot(figure, plotkey.str(), mpl, &data);
plot::offscreen::OffScreenPlot1D plot(*figure, plotkey.str(), *mpl.get(), data);
plot.display();
plot.save(pbfile.parent_path().parent_path().string(), 300, 1);
plot.save(pbfile.parent_path().parent_path().string(), dpi, pad);
} catch (Error& e) {
Error("mainoffscreenplot", "Failed create 1d plot", plotkey.str());
Error("OffScreenPlotManager", "savePlot", "Failed create 1d plot", plotkey.str());
}
}
} else {
try {
plot::offscreen::OffScreenEmptyPlot plot(figure, plotkey.str(), mpl, &data);
plot::offscreen::OffScreenEmptyPlot plot(*figure, plotkey.str(), *mpl.get(), data);
plot.display();
plot.save(pbfile.parent_path().parent_path().string(), 300 , 1);
plot.save(pbfile.parent_path().parent_path().string(), dpi, pad);
} catch (Error& e) {
Error("mainoffscreenplot", "Failed create empty plot", plotkey.str());
Error("OffScreenPlotManager", "savePlot", "Failed create empty plot", plotkey.str());
}
}
delete figure;
// delete file
boost::filesystem::remove(pbfile);
if (data.type() == buffer::Data::Log) {
// delete file
boost::filesystem::remove(pbfile);
// Send image to log database system
json::LogSender sender(&data);
sender.postMessage();
boost::filesystem::path pngfile = argv[3];
boost::filesystem::path pngfile = path;
pngfile = pngfile.parent_path().parent_path();
pngfile /= argv[2];
DBGMSG("remove -> " << pngfile.string());
pngfile /= pbfilename;
// delete image file
boost::filesystem::remove(pngfile);
}
}
DBGMSG("ServerRequester::resetInstance");
// Clean manager
manager::ServerRequesterManager::resetInstance();
} catch (boost::filesystem::filesystem_error& e) {
Error("OffScreenPlotManager", "savePlot",
"Failed to open temporary file which contains ploty::PlotPropertyDataMessage", pbfilename);
}
exit:
// delete mpl;
// Terminate cameo application
application::This::terminate();
return err;
return EXIT_SUCCESS;
}
......@@ -102,14 +102,9 @@ void OffScreenPlotManager::loop(std::shared_ptr<cameo::application::Subscriber>
notification::ImageDataReady messageImageReady;
try {
messageImageReady.ParseFromString(data2);
// run(messageImageReady.imagename(), messageImageReady.imagepath());
ThreadPoolManager::getInstance()->addJob(
bind(&OffScreenPlotManager::run, m_Instance, messageImageReady.imagename(),
messageImageReady.imagepath()));
//boost::thread td(boost::bind(&OffScreenPlotManager::run, m_Instance, messageImageReady.imagename(), messageImageReady.imagepath()));
//td.detach();
// thread td(&OffScreenPlotManager::run, m_Instance, messageImageReady.imagename(), messageImageReady.imagepath());
// addThreadMapElement(m_Mpl, m_CounterId++, messageImageReady.imagename(), messageImageReady.imagepath());
} catch (std::bad_alloc &e) {
Error("OffScreenPlotManager", "loop", "Bad parsing of ImageDataReady");
}
......@@ -148,91 +143,95 @@ void OffScreenPlotManager::loop(std::shared_ptr<cameo::application::Subscriber>
* OffScreenPlotManager
*/
void OffScreenPlotManager::run(std::string pbfilename, std::string path) {
try {
unique_ptr<view::mpl::MplFigure> figure(new view::mpl::MplFigure(*m_Mpl, false));
boost::filesystem::path pbfile = path;
pbfile /= pbfilename;
pbfile.replace_extension("pb");
uint32 size = (uint32) boost::filesystem::file_size(pbfile);
ifstream inputMessage(pbfile.string().c_str(), fstream::binary);
if (inputMessage.is_open() == false) {
Error("OffScreenPlotManager", "savePlot",
"Failed to open temporary file which contains ploty::PlotPropertyDataMessage", pbfilename);
} else {
char buffer[size];
inputMessage.read(buffer, size);
buffer::Data data;
data.ParseFromArray(buffer, size);
DBGMSG("pbfilename = " << path << "/" << pbfilename);
// DBGMSG("buffer = " << size);
// DBGMSG("numor = " << data.numor());
// DBGMSG("dataxArray = " << data.xdata_size());
// DBGMSG("datayArray = " << data.ydata_size());
// DBGMSG("datazArray = " << data.zdata_size());
inputMessage.close();
ostringstream plotkey;
plotkey << pbfilename;
uint32 dpi = 100;
float64 pad = 1;
if (data.type() == buffer::Data::Spy) {
dpi = 30;
pad = 0;
} else if (data.type() == buffer::Data::Multiplot) {
dpi = 30;
}
if ((data.xdata_size() > 0) && (data.ydata_size() > 0) && (data.zdata_size() > 0)) {
// 2D
for (int32 i = 0; i < data.xdata_size(); ++i) {
try {
plot::offscreen::OffScreenPlot2D plot(*figure, plotkey.str(), *m_Mpl, data);
plot.display();
plot.save(pbfile.parent_path().parent_path().string(), dpi, pad);
} catch (Error& e) {
Error("OffScreenPlotManager", "savePlot", "Failed create 2d plot", plotkey.str());
}
}
} else if ((data.xdata_size() > 0) && (data.ydata_size() > 0)) {
// 1D
for (int32 i = 0; i < data.xdata_size(); ++i) {
try {
plot::offscreen::OffScreenPlot1D plot(*figure, plotkey.str(), *m_Mpl, data);
plot.display();
plot.save(pbfile.parent_path().parent_path().string(), dpi, pad);
} catch (Error& e) {
Error("OffScreenPlotManager", "savePlot", "Failed create 1d plot", plotkey.str());
}
}
} else {
try {
plot::offscreen::OffScreenEmptyPlot plot(*figure, plotkey.str(), *m_Mpl, data);
plot.display();
plot.save(pbfile.parent_path().parent_path().string(), dpi, pad);
} catch (Error& e) {
Error("OffScreenPlotManager", "savePlot", "Failed create empty plot", plotkey.str());
}
}
if (data.type() == buffer::Data::Log) {
// delete file
boost::filesystem::remove(pbfile);
// Send image to log database system
json::LogSender sender(&data);
sender.postMessage();
boost::filesystem::path pngfile = path;
pngfile = pngfile.parent_path().parent_path();
pngfile /= pbfilename;
// delete image file
boost::filesystem::remove(pngfile);
}
}
} catch (boost::filesystem::filesystem_error& e) {
Error("OffScreenPlotManager", "savePlot",
"Failed to open temporary file which contains ploty::PlotPropertyDataMessage", pbfilename);
}
ostringstream com;
com << "./offscreenplot " << pbfilename << " " << path;
system(com.str().c_str());
// try {
// unique_ptr<view::mpl::MplFigure> figure(new view::mpl::MplFigure(*m_Mpl, false));
// boost::filesystem::path pbfile = path;
// pbfile /= pbfilename;
// pbfile.replace_extension("pb");
// uint32 size = (uint32) boost::filesystem::file_size(pbfile);
// ifstream inputMessage(pbfile.string().c_str(), fstream::binary);
// if (inputMessage.is_open() == false) {
// Error("OffScreenPlotManager", "savePlot",
// "Failed to open temporary file which contains ploty::PlotPropertyDataMessage", pbfilename);
// } else {
// char buffer[size];
// inputMessage.read(buffer, size);
// buffer::Data data;
// data.ParseFromArray(buffer, size);
//
// DBGMSG("pbfilename = " << path << "/" << pbfilename);
// // DBGMSG("buffer = " << size);
// // DBGMSG("numor = " << data.numor());
// // DBGMSG("dataxArray = " << data.xdata_size());
// // DBGMSG("datayArray = " << data.ydata_size());
// // DBGMSG("datazArray = " << data.zdata_size());
// inputMessage.close();
//
// ostringstream plotkey;
// plotkey << pbfilename;
//
// uint32 dpi = 100;
// float64 pad = 1;
// if (data.type() == buffer::Data::Spy) {
// dpi = 30;
// pad = 0;
// } else if (data.type() == buffer::Data::Multiplot) {
// dpi = 30;
// }
// if ((data.xdata_size() > 0) && (data.ydata_size() > 0) && (data.zdata_size() > 0)) {
// // 2D
// for (int32 i = 0; i < data.xdata_size(); ++i) {
// try {
// plot::offscreen::OffScreenPlot2D plot(*figure, plotkey.str(), *m_Mpl, data);
// plot.display();
// plot.save(pbfile.parent_path().parent_path().string(), dpi, pad);
// } catch (Error& e) {
// Error("OffScreenPlotManager", "savePlot", "Failed create 2d plot", plotkey.str());
// }
// }
// } else if ((data.xdata_size() > 0) && (data.ydata_size() > 0)) {
// // 1D
// for (int32 i = 0; i < data.xdata_size(); ++i) {
// try {
// plot::offscreen::OffScreenPlot1D plot(*figure, plotkey.str(), *m_Mpl, data);
// plot.display();
// plot.save(pbfile.parent_path().parent_path().string(), dpi, pad);
// } catch (Error& e) {
// Error("OffScreenPlotManager", "savePlot", "Failed create 1d plot", plotkey.str());
// }
// }
// } else {
// try {
// plot::offscreen::OffScreenEmptyPlot plot(*figure, plotkey.str(), *m_Mpl, data);
// plot.display();
// plot.save(pbfile.parent_path().parent_path().string(), dpi, pad);
// } catch (Error& e) {
// Error("OffScreenPlotManager", "savePlot", "Failed create empty plot", plotkey.str());
// }
// }
//
// if (data.type() == buffer::Data::Log) {
// // delete file
// boost::filesystem::remove(pbfile);
//
// // Send image to log database system
// json::LogSender sender(&data);
// sender.postMessage();
// boost::filesystem::path pngfile = path;
// pngfile = pngfile.parent_path().parent_path();
// pngfile /= pbfilename;
// // delete image file
// boost::filesystem::remove(pngfile);
// }
// }
// } catch (boost::filesystem::filesystem_error& e) {
// Error("OffScreenPlotManager", "savePlot",
// "Failed to open temporary file which contains ploty::PlotPropertyDataMessage", pbfilename);
// }
}
}
......@@ -76,12 +76,12 @@ MplFigure::~MplFigure() {
m_Canvas.reset();
m_Toolbar.reset();
try {
m_Mpl.garbageCollect();
}
catch(...) {
}
// try {
// m_Mpl.garbageCollect();
// }
// catch(...) {
//
// }
}
/*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment