Commit ad085027 authored by Locatelli's avatar Locatelli
Browse files

Improvements:

- Scan plots with repeater
- Multiplots
- Offscreen
parent 072ad007
......@@ -4,15 +4,17 @@
* 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:
- 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
\ No newline at end of file
......@@ -47,32 +47,38 @@ void crash_handler(int32 sig) {
*/
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) {
cout << argv[i] << endl;
}
if (argc < 3) {
cerr << "mainoffscreenplot Missing arguments, need 2 : got " << argc;
// cerr << "mainoffscreenplot Missing arguments, need 2 : got " << argc;
return EXIT_FAILURE;
}
std::string pbfilename = argv[1];
std::string path = argv[2];
// Create and init the Matplolib module
shared_ptr<view::mpl::Mpl> mpl = make_shared<view::mpl::Mpl>();
// Create the publisher.
std::shared_ptr<cameo::application::Publisher> spypublisher = application::Publisher::create("spy_publisher");
cout << "Created publisher " << *spypublisher;
if (spypublisher.get() == 0) {
// TODO Error
cout << "spypublisher error" << endl;
return EXIT_FAILURE;
}
// Ne marche pas pour une application non cameo-iser
// out << "try Created publisher " << endl;
//// Create the publisher.
// std::shared_ptr<cameo::application::Publisher> spypublisher = application::Publisher::create("spy_publisher");
// out << "Created publisher " << *spypublisher;
// if (spypublisher.get() == 0) {
// // 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);
// out << "finished" << endl;
return EXIT_SUCCESS;
}
......@@ -24,6 +24,7 @@
#include <boost/filesystem/path.hpp>
#include <thread>
#include <boost/thread.hpp>
//#include <chrono>
#include "plot/offscreen/OffScreenEmptyPlot.h"
#include "plot/offscreen/OffScreenPlot1D.h"
......@@ -105,10 +106,10 @@ 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()));
run(messageImageReady.imagename(), messageImageReady.imagepath());
// ThreadPoolManager::getInstance()->addJob(
// bind(&OffScreenPlotManager::run, m_Instance, messageImageReady.imagename(),
// messageImageReady.imagepath()));
// ostringstream com;
// com << "./offscreenplot " << messageImageReady.imagename() << " " << messageImageReady.imagepath();
// system(com.str().c_str());
......@@ -151,6 +152,17 @@ void OffScreenPlotManager::loop(std::shared_ptr<cameo::application::Subscriber>
*/
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 {
unique_ptr<view::mpl::MplFigure> figure(new view::mpl::MplFigure(*m_Mpl, false));
boost::filesystem::path pbfile = path;
......@@ -167,12 +179,12 @@ void OffScreenPlotManager::run(std::string pbfilename, std::string path) {
buffer::Data data;
data.ParseFromArray(buffer, size);
DBGMSG("pbfilename = " << path << "/" << pbfilename);
// 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());
// DBGMSG("dataxArray = " << data.xdata_size());
// DBGMSG("datayArray = " << data.ydata_size());
// DBGMSG("datazArray = " << data.zdata_size());
inputMessage.close();
ostringstream plotkey;
......@@ -188,7 +200,6 @@ void OffScreenPlotManager::run(std::string pbfilename, std::string path) {
}
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(0, *figure, plotkey.str(), *m_Mpl, data);
plot.display();
......@@ -196,10 +207,8 @@ void OffScreenPlotManager::run(std::string pbfilename, std::string path) {
} 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(0, *figure, plotkey.str(), *m_Mpl, data);
plot.display();
......@@ -207,7 +216,6 @@ void OffScreenPlotManager::run(std::string pbfilename, std::string path) {
} catch (Error& e) {
Error("OffScreenPlotManager", "savePlot", "Failed create 1d plot", plotkey.str());
}
}
} else {
try {
plot::offscreen::OffScreenEmptyPlot plot(0, *figure, plotkey.str(), *m_Mpl, data);
......@@ -230,7 +238,7 @@ void OffScreenPlotManager::run(std::string pbfilename, std::string path) {
json::LogSender sender(&data);
sender.postMessage();
// delete image file
// boost::filesystem::remove(pngfile);
boost::filesystem::remove(pngfile);
}
else {
if (m_Remote == false) {
......@@ -271,6 +279,12 @@ void OffScreenPlotManager::run(std::string pbfilename, std::string path) {
Error("OffScreenPlotManager", "savePlot",
"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:
std::mutex m_SpyMutex;
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;
// ThreadMap m_ThreadMap;
// std::mutex m_ThreadMapMutex;
......
......@@ -87,7 +87,6 @@ void ThreadPoolManager::infiniteLoopFunction() {
m_Job = m_Queue.front();
m_Queue.pop();
}
DBGMSG("Execute JOB");
m_Job(); // function<void()> type
}
}
......
......@@ -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) :
Plot(plotid, plotkey, mpl, plotwindow, figure, PlotType::PLOT_1D), m_MplPlot1D(mpl, figure) {
m_NbPlots = 0;
m_ShowTitle = true;
m_ShowXLabel = true;
m_ShowYLabel = true;
m_ShowLegend = true;
}
/*
......@@ -55,7 +59,7 @@ void Plot1D::display() throw (Error) {
//// Creat subplot
////
try {
m_MplPlot1D.subplots();
m_MplPlot1D.subplots(m_PlotWindow == nullptr);
} catch (Error& e) {
throw Error("Plot1D", "display", "Failed to do subplot");
}
......@@ -74,6 +78,7 @@ void Plot1D::display() throw (Error) {
getYData(i);
}
// Check if all colors are the same
for (uint32 i = 0; i < m_NbPlots; ++i) {
localplot(i);
}
......@@ -85,11 +90,13 @@ void Plot1D::display() throw (Error) {
*/
void Plot1D::localplot(uint32 numplot) throw (Error) {
if ((m_PlotXArrays[numplot].size() != 0) && (m_PlotYArrays[numplot].size() != 0)) {
////
//// Set plot parameters
////
string label = getLegendKey(numplot);
string color = string("#") + getColor(numplot);
////
//// Plot arrays
////
......@@ -144,6 +151,7 @@ void Plot1D::localplot(uint32 numplot) throw (Error) {
///////////////////////////////////////////////////////////////////////////////////////
//// Set Title
////
if (m_ShowTitle == true) {
string title = getPlotTitle();
try {
m_MplPlot1D.title(title);
......@@ -158,35 +166,42 @@ void Plot1D::localplot(uint32 numplot) throw (Error) {
Warning("Plot1D", "localplot", "Failed to set window title", title);
}
}
}
///////////////////////////////////////////////////////////////////////////////////////
//// Set x label
////
if (m_ShowXLabel == true) {
string xlabel = getXLabel();
try {
m_MplPlot1D.xlabel(xlabel);
} catch (Error& e) {
Warning("Plot1D", "localplot", "Failed to set x label", xlabel);
}
}
///////////////////////////////////////////////////////////////////////////////////////
//// Set y label
////
if (m_ShowYLabel == true) {
string ylabel = getYLabel();
try {
m_MplPlot1D.ylabel(ylabel);
} catch (Error& e) {
Warning("Plot1D", "localplot", "Failed to set y label", ylabel);
}
}
///////////////////////////////////////////////////////////////////////////////////////
//// set legend
////
if (m_ShowLegend == true) {
try {
m_MplPlot1D.legend("xx-small", "upper right");
m_MplPlot1D.legend("xx-small", "upper right", m_PlotWindow == nullptr);
} catch (Error& e) {
Warning("Plot1D", "localplot", "Failed to create plot legend");
}
}
///////////////////////////////////////////////////////////////////////////////////////
//// check grid
......@@ -209,6 +224,7 @@ void Plot1D::localplot(uint32 numplot) throw (Error) {
} catch (Error& e) {
Warning("Plot1D", "localplot", "Failed to activate log");
}
}
}
/*
......@@ -379,7 +395,6 @@ vector<Stats> Plot1D::updateStats(const RectangleCoord& rect) throw (Error) {
*/
void Plot1D::dismissStats() throw (Error) {
m_MplPlot1D.dismissFitPlots();
m_PlotWindow->repaint();
Plot::dismissStats();
}
......@@ -437,11 +452,14 @@ vector<FitGaussianStats> Plot1D::updateGaussianFitStats(const RectangleCoord& re
for(auto val : fitData.fitydata()) {
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);
}
else {
m_MplPlot1D.dismissFitPlots();
m_MplPlot1D.dismissFitPlot((uint32) i);
m_PlotWindow->repaint();
}
}
......@@ -503,11 +521,14 @@ vector<FitGaussianStats> Plot1D::updateMultiGaussianFitStats(const RectangleCoor
for(auto val : fitData.fitydata()) {
y.push_back(val);
}
m_MplPlot1D.fitPlot((uint32) i, xfit, y, "Fit Multi Gaussian", string("#0ef139"), 0.5);
ostringstream fitname;
fitname << "Fit Multi 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);
}
else {
m_MplPlot1D.dismissFitPlots();
m_MplPlot1D.dismissFitPlot((uint32) i);
m_PlotWindow->repaint();
}
}
......@@ -568,11 +589,14 @@ vector<CenterOfMassStats> Plot1D::updateCenterOfMassStats(const RectangleCoord&
for(auto val : fitData.fitydata()) {
y.push_back(val);
}
m_MplPlot1D.fitPlot((uint32) i, xfit, y, "Center Of Mass", string("#0ef139"), 0.5);
ostringstream fitname;
fitname << "Center Of Mass " << 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);
}
else {
m_MplPlot1D.dismissFitPlots();
m_MplPlot1D.dismissFitPlot((uint32) i);
m_PlotWindow->repaint();
}
}
......
......@@ -198,19 +198,19 @@ protected:
* \brief Get Data array this index
* \param[in] index The index in the data array of array
*/
virtual void getDataArray(int32 index) = 0;
virtual void getDataArray(uint32 index) = 0;
/*!
* \brief Get X data
* \param[in] index The index in the x data array of array
*/
virtual void getXData(int32 index) = 0;
virtual void getXData(uint32 index) = 0;
/*!
* \brief Get Y data
* \param[in] index The index in the y data array of array
*/
virtual void getYData(int32 index) = 0;
virtual void getYData(uint32 index) = 0;
/*!
* \brief plot data with one dimension (y)
......@@ -304,6 +304,11 @@ protected:
view::mpl::MplPlot1D m_MplPlot1D; //! Mpl plot1d view object
bool m_ShowTitle; //! Show Plot Title flag
bool m_ShowXLabel; //! Show plot x label flag
bool m_ShowYLabel; //! Show plot y label flag
bool m_ShowLegend; //! Show plor legend flag
};
}
......
......@@ -37,14 +37,18 @@ namespace plot {
/*
* constructor
*/
Plot2D::Plot2D(uint32 plotid, const std::string& plotkey, view::mpl::Mpl& mpl, window::PlotWindow* plotwindow, view::mpl::MplFigure& figure, bool doProjections) :
Plot(plotid, plotkey, mpl, plotwindow, figure, PlotType::PLOT_2D), m_MplPlot2D(mpl, figure), m_DoProjections(doProjections) {
Plot2D::Plot2D(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_2D), m_MplPlot2D(mpl, figure) {
m_MinColorLim = 100.;
m_MaxColorLim = 100.;
m_XPhysicalSize = 1.;
m_YPhysicalSize = 1.;
m_Space = 0.1;
m_Log = false;
m_DoProjections = true;
m_ShowTitle = true;
m_ShowXLabel = true;
m_ShowYLabel = true;
}
/*
......@@ -86,10 +90,10 @@ void Plot2D::display() throw (Error) {
////
try {
if (m_DoProjections == true) {
m_MplPlot2D.subplots(m_PlotWindow != nullptr, 1, 4, 0, 2);
m_MplPlot2D.subplots(m_PlotWindow == nullptr, 1, 4, 0, 2);
}
else {
m_MplPlot2D.subplots(m_PlotWindow != nullptr, 0);
m_MplPlot2D.subplots(m_PlotWindow == nullptr, 0);
}
} catch (Error& e) {
throw Error("Plot2D", "display", "Failed to do subplots");
......@@ -98,6 +102,7 @@ void Plot2D::display() throw (Error) {
///////////////////////////////////////////////////////////////////////////////////////
//// Set Title
////
if (m_ShowTitle == true) {
string title = getPlotTitle();
try {
m_MplPlot2D.title(title);
......@@ -112,6 +117,7 @@ void Plot2D::display() throw (Error) {
Warning("Plot2D", "display", "Failed to set window title", title);
}
}
}
///////////////////////////////////////////////////////////////////////////////////////
//// Get server Data
......@@ -144,7 +150,7 @@ void Plot2D::display() throw (Error) {
throw Error("Plot2D", "display", "Failed to do plot");
}
if (m_DoProjections == true) {
if (m_ShowXLabel == true) {
///////////////////////////////////////////////////////////////////////////////////////
//// Set x label
////
......@@ -154,7 +160,8 @@ void Plot2D::display() throw (Error) {
} catch (Error& e) {
Warning("Plot2D", "display", "Failed to set x label", xlabel);
}
}
if (m_ShowYLabel == true) {
///////////////////////////////////////////////////////////////////////////////////////
//// Set y label
////
......
......@@ -43,9 +43,8 @@ public:
* \param[in] mpl The mpl object
* \param[in] plotwindow The plot window object which containing this plot
* \param[in] figure The mpl figure object
* \param[in] doProjections Do projections
*/
Plot2D(uint32 plotid, const std::string& plotkey, view::mpl::Mpl& mpl, window::PlotWindow* plotwindow, view::mpl::MplFigure& figure, bool doProjections);
Plot2D(uint32 plotid, const std::string& plotkey, view::mpl::Mpl& mpl, window::PlotWindow* plotwindow, view::mpl::MplFigure& figure);
/*!
* \brief destructor
......@@ -270,11 +269,15 @@ protected:
int32 m_XPhysicalSize; // X physical size for ratio
int32 m_YPhysicalSize; // Y physical size for ratio
bool m_DoProjections; //! Do the projections
float64 m_Space; //! Space between sub plots of the grid
bool m_Log;
bool m_DoProjections; //! Do the projections
bool m_ShowTitle; //! Show Plot Title flag
bool m_ShowXLabel; //! Show plot x label flag
bool m_ShowYLabel; //! Show plot y label flag
//! Ratio of spec grid constants
static const int32 PLOT2D_WIDTH_RATIO = 30;
static const int32 PROJY_WIDTH_RATIO = 3;
......
......@@ -61,7 +61,7 @@ size_t CutPlot1D::getNbPlots() {
/*
* getDataArray
*/
void CutPlot1D::getDataArray(int32 index) {
void CutPlot1D::getDataArray(uint32 index) {
m_PlotXPropertyTypes[index] = "float64array";
m_PlotYPropertyTypes[index] = "float64array";
}
......@@ -109,14 +109,14 @@ void CutPlot1D::update(int32 id) {
/*
* getXData
*/
void CutPlot1D::getXData(int32 index){
void CutPlot1D::getXData(uint32 index){
// Empty
}
/*
* getYData
*/
void CutPlot1D::getYData(int32 index) {
void CutPlot1D::getYData(uint32 index) {
// Empty
}
......
......@@ -119,19 +119,19 @@ private:
* \brief Get Data array this index
* \param[in] index The index in the data array of array
*/
virtual void getDataArray(int32 index);
virtual void getDataArray(uint32 index);
/*!
* \brief Get X data
* \param[in] index The index in the x data array of array
*/
virtual void getXData(int32 index);
virtual void getXData(uint32 index);
/*!
* \brief Get Y data
* \param[in] index The index in the y data array of array
*/
virtual void getYData(int32 index);
virtual void getYData(uint32 index);
/*!
* \brief Resise Y dimension
......
......@@ -45,13 +45,34 @@ OffScreenPlot1D::~OffScreenPlot1D() {
*/
void OffScreenPlot1D::display() throw (Error) {
if (m_Data.type() == buffer::Data::Spy) {
m_ShowTitle = false;
m_ShowXLabel = false;
m_ShowYLabel = false;
m_ShowLegend = false;
}
else if (m_Data.type() == buffer::Data::Multiplot) {
m_ShowTitle = false;
m_ShowXLabel = false;
m_ShowYLabel = false;
m_ShowLegend = false;
}
Plot1D::display();
if (m_Data.uselog() == true) {
log(true);
}
///////////////////////////////////////////////////////////////////////////////////////
//// reset limits
////
resetLimits();
if (m_Data.type() == buffer::Data::Spy) {
try {
m_MplPlot1D.title("");
m_MplPlot1D.hideAxis();
m_MplPlot1D.hideLegend();
}
catch(Error &e) {
Error("OffScreenPlot1D", "display", "Error when executing the title and tight layout method");
......@@ -60,15 +81,6 @@ void OffScreenPlot1D::display() throw (Error) {
else {
grid(m_Data.usegrid());
}
if (m_Data.uselog() == true) {
log(true);
}
///////////////////////////////////////////////////////////////////////////////////////
//// reset limits
////
resetLimits();
}
/*
......@@ -91,14 +103,14 @@ size_t OffScreenPlot1D::getNbPlots() {
return nb;
}
void OffScreenPlot1D::getDataArray(int32 index) {
void OffScreenPlot1D::getDataArray(uint32 index) {
////
//// Get x and y arrays id
////
if (m_Data.xdata(index).datadouble_size() > 0) {
m_PlotXPropertyTypes[index] = "float64array";
}
if (m_Data.ydata(index).datadouble_size() > 0) {
if ((m_Data.ydata(index).datadouble_size() > 0) || (m_Data.zdata_size() == 0)) {
m_PlotYPropertyTypes[index] = "float64array";
} else if (m_Data.zdata(index).dataint_size() > 0) {
m_PlotYPropertyTypes[index] = "int32array";
......@@ -108,7 +120,7 @@ void OffScreenPlot1D::getDataArray(int32 index) {
/*
* getXdata
*/
void OffScreenPlot1D::getXData(int32 index) {
void OffScreenPlot1D::getXData(uint32 index) {
copy(m_Data.xdata(index).datadouble().begin(), m_Data.xdata(index).datadouble().end(),
back_inserter(m_PlotXArrays[index]));
}
......@@ -116,7 +128,7 @@ void OffScreenPlot1D::getXData(int32 index) {
/*
* getYData
*/
void OffScreenPlot1D::getYData(int32 index) {
void OffScreenPlot1D::getYData(uint32 index) {
copy(m_Data.ydata(index).datadouble().begin(), m_Data.ydata(index).datadouble().end(),
back_inserter(m_PlotYArrays[index]));
}
......@@ -134,8 +146,13 @@ std::string OffScreenPlot1D::getLegendKey(uint32 index) {