Commit ad085027 authored by Locatelli's avatar Locatelli
Browse files

Improvements:

- Scan plots with repeater
- Multiplots
- Offscreen
parent 072ad007
...@@ -4,15 +4,17 @@ ...@@ -4,15 +4,17 @@
* Use async method for filling data vectors for accelerating process * Use async method for filling data vectors for accelerating process
* Remove multiplot files at the start of server
* Multiplot
- Try create a plot with all plots (subplot)
- For PN do something for detecting channel problem (using CPU of mpda_dpp?) or in nomad?
* Bugs: * Bugs:
- Min and max colorlimits when update data from server during a count - Min and max colorlimits when update data from server during a count
* Does we limits x data for plot 1D (as doing in plot2d)? * Does we limits x data for plot 1D (as doing in plot2d)? -> Yes , I did it, df fipps
* OpenGL:
See writing specific backend qt - opengl (mantid already did that or plan to?)
* Remove usr1_signal for brng in front a plot. Use a cameo message instead.
* Look for memoryleaks
- Check Remove python objects after a clear for example (MplPlot1d::clear) or object ...
* Unitary tests * Unitary tests
\ No newline at end of file
...@@ -47,32 +47,38 @@ void crash_handler(int32 sig) { ...@@ -47,32 +47,38 @@ void crash_handler(int32 sig) {
*/ */
int32 main(int32 argc, char* argv[]) { int32 main(int32 argc, char* argv[]) {
// ofstream out("/users/cameo/off.log", std::ofstream::out | std::ofstream::app);
for(int32 i = 0; i < argc; ++i) { for(int32 i = 0; i < argc; ++i) {
cout << argv[i] << endl; cout << argv[i] << endl;
} }
if (argc < 3) { if (argc < 3) {
cerr << "mainoffscreenplot Missing arguments, need 2 : got " << argc; // cerr << "mainoffscreenplot Missing arguments, need 2 : got " << argc;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
std::string pbfilename = argv[1]; std::string pbfilename = argv[1];
std::string path = argv[2]; std::string path = argv[2];
// Create and init the Matplolib module
// Create and init the Matplolib module
shared_ptr<view::mpl::Mpl> mpl = make_shared<view::mpl::Mpl>(); shared_ptr<view::mpl::Mpl> mpl = make_shared<view::mpl::Mpl>();
// Create the publisher. // Ne marche pas pour une application non cameo-iser
std::shared_ptr<cameo::application::Publisher> spypublisher = application::Publisher::create("spy_publisher"); // out << "try Created publisher " << endl;
cout << "Created publisher " << *spypublisher; //// Create the publisher.
if (spypublisher.get() == 0) { // std::shared_ptr<cameo::application::Publisher> spypublisher = application::Publisher::create("spy_publisher");
// TODO Error // out << "Created publisher " << *spypublisher;
cout << "spypublisher error" << endl; // if (spypublisher.get() == 0) {
return EXIT_FAILURE; // // TODO Error
} // out << "spypublisher error" << endl;
// return EXIT_FAILURE;
// }
OffScreenPlotManager::getInstance()->init(mpl, spypublisher, false); // out << "init off manager" << endl;
OffScreenPlotManager::getInstance()->init(mpl, nullptr, false);
// out << "run" << endl;
OffScreenPlotManager::getInstance()->run(pbfilename, path); OffScreenPlotManager::getInstance()->run(pbfilename, path);
// out << "finished" << endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
#include <thread> #include <thread>
#include <boost/thread.hpp> #include <boost/thread.hpp>
//#include <chrono>
#include "plot/offscreen/OffScreenEmptyPlot.h" #include "plot/offscreen/OffScreenEmptyPlot.h"
#include "plot/offscreen/OffScreenPlot1D.h" #include "plot/offscreen/OffScreenPlot1D.h"
...@@ -105,10 +106,10 @@ void OffScreenPlotManager::loop(std::shared_ptr<cameo::application::Subscriber> ...@@ -105,10 +106,10 @@ void OffScreenPlotManager::loop(std::shared_ptr<cameo::application::Subscriber>
notification::ImageDataReady messageImageReady; notification::ImageDataReady messageImageReady;
try { try {
messageImageReady.ParseFromString(data2); messageImageReady.ParseFromString(data2);
// run(messageImageReady.imagename(), messageImageReady.imagepath()); run(messageImageReady.imagename(), messageImageReady.imagepath());
ThreadPoolManager::getInstance()->addJob( // ThreadPoolManager::getInstance()->addJob(
bind(&OffScreenPlotManager::run, m_Instance, messageImageReady.imagename(), // bind(&OffScreenPlotManager::run, m_Instance, messageImageReady.imagename(),
messageImageReady.imagepath())); // messageImageReady.imagepath()));
// ostringstream com; // ostringstream com;
// com << "./offscreenplot " << messageImageReady.imagename() << " " << messageImageReady.imagepath(); // com << "./offscreenplot " << messageImageReady.imagename() << " " << messageImageReady.imagepath();
// system(com.str().c_str()); // system(com.str().c_str());
...@@ -151,6 +152,17 @@ void OffScreenPlotManager::loop(std::shared_ptr<cameo::application::Subscriber> ...@@ -151,6 +152,17 @@ void OffScreenPlotManager::loop(std::shared_ptr<cameo::application::Subscriber>
*/ */
void OffScreenPlotManager::run(std::string pbfilename, std::string path) { void OffScreenPlotManager::run(std::string pbfilename, std::string path) {
// size_t p1 = pbfilename.find("0.0#");
// size_t p2 = pbfilename.find(".png");
// uint32 num = 0;
// if (p1 != string::npos) {
// istringstream sbuf(pbfilename.substr(p1 + 4, p2 - p1 - 4));
// sbuf >> num;
// if (num == 0) {
//// DBGMSG(pbfilename);
// start = chrono::steady_clock::now();
// }
// }
try { try {
unique_ptr<view::mpl::MplFigure> figure(new view::mpl::MplFigure(*m_Mpl, false)); unique_ptr<view::mpl::MplFigure> figure(new view::mpl::MplFigure(*m_Mpl, false));
boost::filesystem::path pbfile = path; boost::filesystem::path pbfile = path;
...@@ -167,12 +179,12 @@ void OffScreenPlotManager::run(std::string pbfilename, std::string path) { ...@@ -167,12 +179,12 @@ void OffScreenPlotManager::run(std::string pbfilename, std::string path) {
buffer::Data data; buffer::Data data;
data.ParseFromArray(buffer, size); data.ParseFromArray(buffer, size);
DBGMSG("pbfilename = " << path << "/" << pbfilename); // DBGMSG("pbfilename = " << path << "/" << pbfilename);
// DBGMSG("buffer = " << size); // DBGMSG("buffer = " << size);
// DBGMSG("numor = " << data.numor()); // DBGMSG("numor = " << data.numor());
// DBGMSG("dataxArray = " << data.xdata_size()); // DBGMSG("dataxArray = " << data.xdata_size());
// DBGMSG("datayArray = " << data.ydata_size()); // DBGMSG("datayArray = " << data.ydata_size());
// DBGMSG("datazArray = " << data.zdata_size()); // DBGMSG("datazArray = " << data.zdata_size());
inputMessage.close(); inputMessage.close();
ostringstream plotkey; ostringstream plotkey;
...@@ -188,25 +200,21 @@ void OffScreenPlotManager::run(std::string pbfilename, std::string path) { ...@@ -188,25 +200,21 @@ void OffScreenPlotManager::run(std::string pbfilename, std::string path) {
} }
if ((data.xdata_size() > 0) && (data.ydata_size() > 0) && (data.zdata_size() > 0)) { if ((data.xdata_size() > 0) && (data.ydata_size() > 0) && (data.zdata_size() > 0)) {
// 2D // 2D
for (int32 i = 0; i < data.xdata_size(); ++i) { try {
try { plot::offscreen::OffScreenPlot2D plot(0, *figure, plotkey.str(), *m_Mpl, data);
plot::offscreen::OffScreenPlot2D plot(0, *figure, plotkey.str(), *m_Mpl, data); plot.display();
plot.display(); plot.save(pbfile.parent_path().parent_path().string(), dpi, pad);
plot.save(pbfile.parent_path().parent_path().string(), dpi, pad); } catch (Error& e) {
} catch (Error& e) { Error("OffScreenPlotManager", "savePlot", "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)) { } else if ((data.xdata_size() > 0) && (data.ydata_size() > 0)) {
// 1D // 1D
for (int32 i = 0; i < data.xdata_size(); ++i) { try {
try { plot::offscreen::OffScreenPlot1D plot(0, *figure, plotkey.str(), *m_Mpl, data);
plot::offscreen::OffScreenPlot1D plot(0, *figure, plotkey.str(), *m_Mpl, data); plot.display();
plot.display(); plot.save(pbfile.parent_path().parent_path().string(), dpi, pad);
plot.save(pbfile.parent_path().parent_path().string(), dpi, pad); } catch (Error& e) {
} catch (Error& e) { Error("OffScreenPlotManager", "savePlot", "Failed create 1d plot", plotkey.str());
Error("OffScreenPlotManager", "savePlot", "Failed create 1d plot", plotkey.str());
}
} }
} else { } else {
try { try {
...@@ -230,7 +238,7 @@ void OffScreenPlotManager::run(std::string pbfilename, std::string path) { ...@@ -230,7 +238,7 @@ void OffScreenPlotManager::run(std::string pbfilename, std::string path) {
json::LogSender sender(&data); json::LogSender sender(&data);
sender.postMessage(); sender.postMessage();
// delete image file // delete image file
// boost::filesystem::remove(pngfile); boost::filesystem::remove(pngfile);
} }
else { else {
if (m_Remote == false) { if (m_Remote == false) {
...@@ -271,6 +279,12 @@ void OffScreenPlotManager::run(std::string pbfilename, std::string path) { ...@@ -271,6 +279,12 @@ void OffScreenPlotManager::run(std::string pbfilename, std::string path) {
Error("OffScreenPlotManager", "savePlot", Error("OffScreenPlotManager", "savePlot",
"Failed to open temporary file which contains ploty::PlotPropertyDataMessage", pbfilename); "Failed to open temporary file which contains ploty::PlotPropertyDataMessage", pbfilename);
} }
// if (num == 119) {
//// DBGMSG(pbfilename);
// end = chrono::steady_clock::now();
// DBGMSG("Elapse : " << chrono::duration_cast<chrono::milliseconds>(end - start).count() << " ms");
// }
} }
} }
...@@ -102,6 +102,8 @@ private: ...@@ -102,6 +102,8 @@ private:
std::mutex m_SpyMutex; std::mutex m_SpyMutex;
std::mutex m_MultiplotMutex; std::mutex m_MultiplotMutex;
// std::chrono::time_point<std::chrono::steady_clock> start;
// std::chrono::time_point<std::chrono::steady_clock> end;
// typedef std::unordered_map<uint32, std::thread> ThreadMap; // typedef std::unordered_map<uint32, std::thread> ThreadMap;
// ThreadMap m_ThreadMap; // ThreadMap m_ThreadMap;
// std::mutex m_ThreadMapMutex; // std::mutex m_ThreadMapMutex;
......
...@@ -87,7 +87,6 @@ void ThreadPoolManager::infiniteLoopFunction() { ...@@ -87,7 +87,6 @@ void ThreadPoolManager::infiniteLoopFunction() {
m_Job = m_Queue.front(); m_Job = m_Queue.front();
m_Queue.pop(); m_Queue.pop();
} }
DBGMSG("Execute JOB");
m_Job(); // function<void()> type m_Job(); // function<void()> type
} }
} }
......
...@@ -39,6 +39,10 @@ namespace plot { ...@@ -39,6 +39,10 @@ namespace plot {
Plot1D::Plot1D(uint32 plotid, const std::string& plotkey, view::mpl::Mpl& mpl, window::PlotWindow* plotwindow, view::mpl::MplFigure& figure) : Plot1D::Plot1D(uint32 plotid, const std::string& plotkey, view::mpl::Mpl& mpl, window::PlotWindow* plotwindow, view::mpl::MplFigure& figure) :
Plot(plotid, plotkey, mpl, plotwindow, figure, PlotType::PLOT_1D), m_MplPlot1D(mpl, figure) { Plot(plotid, plotkey, mpl, plotwindow, figure, PlotType::PLOT_1D), m_MplPlot1D(mpl, figure) {
m_NbPlots = 0; m_NbPlots = 0;
m_ShowTitle = true;
m_ShowXLabel = true;
m_ShowYLabel = true;
m_ShowLegend = true;
} }
/* /*
...@@ -55,7 +59,7 @@ void Plot1D::display() throw (Error) { ...@@ -55,7 +59,7 @@ void Plot1D::display() throw (Error) {
//// Creat subplot //// Creat subplot
//// ////
try { try {
m_MplPlot1D.subplots(); m_MplPlot1D.subplots(m_PlotWindow == nullptr);
} catch (Error& e) { } catch (Error& e) {
throw Error("Plot1D", "display", "Failed to do subplot"); throw Error("Plot1D", "display", "Failed to do subplot");
} }
...@@ -74,6 +78,7 @@ void Plot1D::display() throw (Error) { ...@@ -74,6 +78,7 @@ void Plot1D::display() throw (Error) {
getYData(i); getYData(i);
} }
// Check if all colors are the same
for (uint32 i = 0; i < m_NbPlots; ++i) { for (uint32 i = 0; i < m_NbPlots; ++i) {
localplot(i); localplot(i);
} }
...@@ -85,129 +90,140 @@ void Plot1D::display() throw (Error) { ...@@ -85,129 +90,140 @@ void Plot1D::display() throw (Error) {
*/ */
void Plot1D::localplot(uint32 numplot) throw (Error) { void Plot1D::localplot(uint32 numplot) throw (Error) {
//// if ((m_PlotXArrays[numplot].size() != 0) && (m_PlotYArrays[numplot].size() != 0)) {
//// Set plot parameters ////
//// //// Set plot parameters
string label = getLegendKey(numplot); ////
string color = string("#") + getColor(numplot); string label = getLegendKey(numplot);
//// string color = string("#") + getColor(numplot);
//// Plot arrays
//// ////
if (m_PlotXArrays[numplot].size() == m_PlotYArrays[numplot].size()) { //// Plot arrays
if ((m_PlotXPropertyTypes[numplot] == "int32array") && (m_PlotYPropertyTypes[numplot] == "int32array")) { ////
try { if (m_PlotXArrays[numplot].size() == m_PlotYArrays[numplot].size()) {
plot(numplot, m_PlotXArrays[numplot], m_PlotYArrays[numplot], label, color); if ((m_PlotXPropertyTypes[numplot] == "int32array") && (m_PlotYPropertyTypes[numplot] == "int32array")) {
} catch (Error& e) { try {
Error("Plot1D", "localplot", "Failed to plot data", "x = int32array , y = int32array"); plot(numplot, m_PlotXArrays[numplot], m_PlotYArrays[numplot], label, color);
} catch (Error& e) {
Error("Plot1D", "localplot", "Failed to plot data", "x = int32array , y = int32array");
}
} else if ((m_PlotXPropertyTypes[numplot] == "float64array") && (m_PlotYPropertyTypes[numplot] == "float64array")) {
try {
plot(numplot, m_PlotXArrays[numplot], m_PlotYArrays[numplot], label, color);
} catch (Error& e) {
Error("Plot1D", "localplot", "Failed to plot data", "x = float64array , y = float64array");
}
} else if ((m_PlotXPropertyTypes[numplot] == "int32array") && (m_PlotYPropertyTypes[numplot] == "float64array")) {
try {
plot(numplot, m_PlotXArrays[numplot], m_PlotYArrays[numplot], label, color);
} catch (Error& e) {
Error("Plot1D", "localplot", "Failed to plot data", "x = int32array , y = float64array");
}
} else if ((m_PlotXPropertyTypes[numplot] == "float64array") && (m_PlotYPropertyTypes[numplot] == "int32array")) {
try {
plot(numplot, m_PlotXArrays[numplot], m_PlotYArrays[numplot], label, color);
} catch (Error& e) {
Error("Plot1D", "localplot", "Failed to plot data", "x = float64array , y = int32array");
}
} else if ((m_PlotXPropertyTypes[numplot].empty() == true) && (m_PlotYPropertyTypes[numplot] == "float64array")) {
try {
plot(numplot, m_PlotYArrays[numplot], label, color);
} catch (Error& e) {
Error("Plot1D", "localplot", "Failed to plot data", "y = float64array");
}
} }
} else if ((m_PlotXPropertyTypes[numplot] == "float64array") && (m_PlotYPropertyTypes[numplot] == "float64array")) { }
///////////////////////////////////////////////////////////////////////////////////////
//// optimization Plot if there is
////
try {
optimizationPlot(numplot);
} catch (Error& e) {
Error("Plot1D", "localplot", "Failed to plot optimization y");
}
try {
optimizationResult(numplot);
} catch (Error& e) {
Error("Plot1D", "localplot", "Failed to plot optimization result");
}
///////////////////////////////////////////////////////////////////////////////////////
//// Set Title
////
if (m_ShowTitle == true) {
string title = getPlotTitle();
try { try {
plot(numplot, m_PlotXArrays[numplot], m_PlotYArrays[numplot], label, color); m_MplPlot1D.title(title);
} catch (Error& e) { } catch (Error &e) {
Error("Plot1D", "localplot", "Failed to plot data", "x = float64array , y = float64array"); Warning("Plot1D", "localplot", "Failed to set plot title", title);
} }
} else if ((m_PlotXPropertyTypes[numplot] == "int32array") && (m_PlotYPropertyTypes[numplot] == "float64array")) { if (m_PlotWindow != nullptr) {
title = getWindowTitle();
try {
m_PlotWindow->setWindowTitle(title);
} catch (Error &e) {
Warning("Plot1D", "localplot", "Failed to set window title", title);
}
}
}
///////////////////////////////////////////////////////////////////////////////////////
//// Set x label
////
if (m_ShowXLabel == true) {
string xlabel = getXLabel();
try { try {
plot(numplot, m_PlotXArrays[numplot], m_PlotYArrays[numplot], label, color); m_MplPlot1D.xlabel(xlabel);
} catch (Error& e) { } catch (Error& e) {
Error("Plot1D", "localplot", "Failed to plot data", "x = int32array , y = float64array"); Warning("Plot1D", "localplot", "Failed to set x label", xlabel);
} }
} else if ((m_PlotXPropertyTypes[numplot] == "float64array") && (m_PlotYPropertyTypes[numplot] == "int32array")) { }
///////////////////////////////////////////////////////////////////////////////////////
//// Set y label
////
if (m_ShowYLabel == true) {
string ylabel = getYLabel();
try { try {
plot(numplot, m_PlotXArrays[numplot], m_PlotYArrays[numplot], label, color); m_MplPlot1D.ylabel(ylabel);
} catch (Error& e) { } catch (Error& e) {
Error("Plot1D", "localplot", "Failed to plot data", "x = float64array , y = int32array"); Warning("Plot1D", "localplot", "Failed to set y label", ylabel);
} }
} else if ((m_PlotXPropertyTypes[numplot].empty() == true) && (m_PlotYPropertyTypes[numplot] == "float64array")) { }
///////////////////////////////////////////////////////////////////////////////////////
//// set legend
////
if (m_ShowLegend == true) {
try { try {
plot(numplot, m_PlotYArrays[numplot], label, color); m_MplPlot1D.legend("xx-small", "upper right", m_PlotWindow == nullptr);
} catch (Error& e) { } catch (Error& e) {
Error("Plot1D", "localplot", "Failed to plot data", "y = float64array"); Warning("Plot1D", "localplot", "Failed to create plot legend");
} }
} }
}
///////////////////////////////////////////////////////////////////////////////////////
//// optimization Plot if there is
////
try {
optimizationPlot(numplot);
} catch (Error& e) {
Error("Plot1D", "localplot", "Failed to plot optimization y");
}
try {
optimizationResult(numplot);
} catch (Error& e) {
Error("Plot1D", "localplot", "Failed to plot optimization result");
}
/////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////
//// Set Title //// check grid
//// ////
string title = getPlotTitle();
try {
m_MplPlot1D.title(title);
} catch (Error &e) {
Warning("Plot1D", "localplot", "Failed to set plot title", title);
}
if (m_PlotWindow != nullptr) {
title = getWindowTitle();
try { try {
m_PlotWindow->setWindowTitle(title); if (m_PlotWindow != nullptr) {
} catch (Error &e) { grid(m_PlotWindow->gridActivated());
Warning("Plot1D", "localplot", "Failed to set window title", title); }
} } catch (Error& e) {
} Warning("Plot1D", "localplot", "Failed to show plot grid");
///////////////////////////////////////////////////////////////////////////////////////
//// Set x label
////
string xlabel = getXLabel();
try {
m_MplPlot1D.xlabel(xlabel);
} catch (Error& e) {
Warning("Plot1D", "localplot", "Failed to set x label", xlabel);
}
///////////////////////////////////////////////////////////////////////////////////////
//// Set y label
////
string ylabel = getYLabel();
try {
m_MplPlot1D.ylabel(ylabel);
} catch (Error& e) {
Warning("Plot1D", "localplot", "Failed to set y label", ylabel);
}
///////////////////////////////////////////////////////////////////////////////////////
//// set legend
////
try {
m_MplPlot1D.legend("xx-small", "upper right");
} catch (Error& e) {
Warning("Plot1D", "localplot", "Failed to create plot legend");
}
///////////////////////////////////////////////////////////////////////////////////////
//// check grid
////
try {
if (m_PlotWindow != nullptr) {
grid(m_PlotWindow->gridActivated());
} }
} catch (Error& e) {
Warning("Plot1D", "localplot", "Failed to show plot grid");
}
/////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////
//// check log //// check log
//// ////
try { try {
if (m_PlotWindow != nullptr) { if (m_PlotWindow != nullptr) {
log(m_PlotWindow->logActivated()); log(m_PlotWindow->logActivated());
}
} catch (Error& e) {
Warning("Plot1D", "localplot", "Failed to activate log");
} }
} catch (Error& e) {
Warning("Plot1D", "localplot", "Failed to activate log");
} }
} }
...@@ -379,7 +395,6 @@ vector<Stats> Plot1D::updateStats(const RectangleCoord& rect) throw (Error) { ...@@ -379,7 +395,6 @@ vector<Stats> Plot1D::updateStats(const RectangleCoord& rect) throw (Error) {
*/ */
void Plot1D::dismissStats() throw (Error) { void Plot1D::dismissStats() throw (Error) {
m_MplPlot1D.dismissFitPlots(); m_MplPlot1D.dismissFitPlots();
m_PlotWindow->repaint();
Plot::dismissStats(); Plot::dismissStats();
} }
...@@ -437,11 +452,14 @@ vector<FitGaussianStats> Plot1D::updateGaussianFitStats(const RectangleCoord& re ...@@ -437,11 +452,14 @@ vector<FitGaussianStats> Plot1D::updateGaussianFitStats(const RectangleCoord& re
for(auto val : fitData.fitydata()) { for(auto val : fitData.fitydata()) {
y.push_back(val); y.push_back(val);
} }
m_MplPlot1D.fitPlot((uint32) i, xfit, y, "Fit Gaussian", string("#0ef139"), 0.5); ostringstream fitname;
fitname << "Fit Gaussian " << getLegendKey((uint32) i);
vector<string> colors = {"#0ef139", "#1ef149", "#2ef159", "#3ef169", "#4ef179", "#5ef189", "#6ef199","#7ef1A9"};
m_MplPlot1D.fitPlot((uint32) i, xfit, y, fitname.str(), colors[i], 0.5);
buf.push_back(stats); buf.push_back(stats);
} }
else { else {
m_MplPlot1D.dismissFitPlots(); m_MplPlot1D.dismissFitPlot((uint32) i);
m_PlotWindow->repaint(); m_PlotWindow->repaint();
} }