Commit e9fcdbf8 authored by Locatelli's avatar Locatelli
Browse files

Add ploty2 recovery option

parent 7b84e689
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 offscreenplot
bin_PROGRAMS = ploty2 mplplot offscreenplot recovery
#export QT_SELECT=5
QT = \
......@@ -152,6 +152,32 @@ offscreenplot_LDADD = $(LIBS) $(RM_LIBS) \
$(BOOST_FILESYSTEM_LIB) \
$(BOOST_THREAD_LIB)
recovery_SOURCES = \
mainrecovery.cpp \
PlotId.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)
recovery_CPPFLAGS = $(RM_CXXFLAGS) -DOFFSCREEN -DTRACEDEBUG
recovery_LDFLAGS = $(RM_LDFLAGS)
recovery_LDADD = $(LIBS) $(RM_LIBS) \
$(BOOST_SYSTEM_LIB) \
$(BOOST_FILESYSTEM_LIB) \
$(BOOST_THREAD_LIB)
test_SOURCES = \
maintest.cpp \
PlotId.cpp \
......
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include <iostream>
#include <termios.h>
#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 "PlotId.h"
#include "plot/offscreen/OffScreenEmptyPlot.h"
#include "plot/offscreen/OffScreenPlot1D.h"
#include "plot/offscreen/OffScreenPlot2D.h"
#include "json/LogSender.h"
using namespace std;
using namespace cameo;
/*!
* \brief crash handler method
* \param[in] sig the signal number which calling this method
*/
void crash_handler(int32 sig) {
}
/*!
* \brief main program function
* \return error code
*/
int32 main(int32 argc, char* argv[]) {
// Init cameo application
application::This::init(1, &argv[2]);
{
// Set cameo application running
application::This::setRunning();
boost::filesystem::path path = getenv("HOME");
path /= "offscreenImages/log/pb";
// Create and init the Matplolib module
unique_ptr<view::mpl::Mpl> mpl(new view::mpl::Mpl());
for(auto & pbfilename : boost::filesystem::directory_iterator( path ))
{
if (is_regular_file(pbfilename)) {
std::cout << pbfilename << std::endl;
try {
unique_ptr<view::mpl::MplFigure> figure(new view::mpl::MplFigure(*mpl.get(), false));
uint32 size = (uint32) boost::filesystem::file_size(pbfilename);
ifstream inputMessage(pbfilename.path().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("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.path().filename().replace_extension("png").string();
cout << "plot key = " << plotkey.str() << endl;
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(PlotId::id, *figure, plotkey.str(), *mpl.get(), data);
plot.display();
plot.save(pbfilename.path().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(PlotId::id, *figure, plotkey.str(), *mpl.get(), data);
plot.display();
plot.save(pbfilename.path().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(PlotId::id ,*figure, plotkey.str(), *mpl.get(), data);
plot.display();
plot.save(pbfilename.path().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(pbfilename);
// Send image to log database system
json::LogSender sender(&data);
sender.postMessage();
boost::filesystem::path pngfile = path.parent_path();
pngfile /= plotkey.str();
// 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);
}
}
}
}
application::This::terminate();
return EXIT_SUCCESS;
}
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