Commit 3c1325e9 authored by Locatelli's avatar Locatelli
Browse files

Add simple fit Gaussian

parent b060829b
......@@ -6,6 +6,7 @@ PROTO_GEN_PATH=$(top_srcdir)/src/protobuf/generated
proto:
mkdir -p $(PROTO_GEN_PATH)
protoc -I=$(NOMADSERVER_PROTO_PATH) --cpp_out=$(PROTO_GEN_PATH) $(NOMADSERVER_PROTO_PATH)/AnalysisRequests.proto
protoc -I=$(NOMADSERVER_PROTO_PATH) --cpp_out=$(PROTO_GEN_PATH) $(NOMADSERVER_PROTO_PATH)/DatabaseRequests.proto
protoc -I=$(NOMADSERVER_PROTO_PATH) --cpp_out=$(PROTO_GEN_PATH) $(NOMADSERVER_PROTO_PATH)/CommonResponses.proto
protoc -I=$(NOMADSERVER_PROTO_PATH) --cpp_out=$(PROTO_GEN_PATH) $(NOMADSERVER_PROTO_PATH)/NotificationMessages.proto
......
icons/fit.png

460 Bytes

......@@ -42,12 +42,29 @@ struct RoiRectangle {
float64 sum;
};
struct Stats {
class Stats {
public:
Stats(const std::string& aName, float64 aMin, float64 aMax, float64 anIntegral) :
name(aName), min(aMin), max(aMax), integral(anIntegral){
}
Stats() {
min = 0;
max = 0;
integral = 0;
}
std::string name;
float64 min;
float64 max;
float64 integral;
};
class FitGaussianStats : public Stats {
public:
bool converged;
float64 position;
float64 amplitude;
float64 fwhm;
};
#endif
......@@ -44,6 +44,7 @@ PLOT = \
plot/property/PropertyPlot2D.cpp
PROTOBUF = \
protobuf/generated/AnalysisRequests.pb.cc \
protobuf/generated/AcquisitionSerializer.pb.cc \
protobuf/generated/CommonResponses.pb.cc \
protobuf/generated/DatabaseRequests.pb.cc \
......@@ -77,6 +78,7 @@ ploty2_SOURCES = \
manager/ThreadPoolManager.cpp \
manager/RequestDealerManager.cpp \
manager/ServerSubscriberManager.cpp \
manager/AnalysisRequesterManager.cpp \
manager/ServerRequesterManager.cpp \
manager/PlotManager.cpp \
manager/InterfaceManager.cpp \
......@@ -98,6 +100,7 @@ ploty2_LDADD = $(LIBS) $(RM_LIBS) \
mplplot_SOURCES = \
mainplot.cpp \
manager/AnalysisRequesterManager.cpp \
manager/ServerRequesterManager.cpp \
manager/ServerSubscriberManager.cpp \
manager/InterfaceManager.cpp \
......@@ -120,6 +123,7 @@ test_SOURCES = \
manager/ThreadPoolManager.cpp \
manager/RequestDealerManager.cpp \
manager/ServerSubscriberManager.cpp \
manager/AnalysisRequesterManager.cpp \
manager/ServerRequesterManager.cpp \
manager/InterfaceManager.cpp \
manager/PlotManager.cpp \
......@@ -145,6 +149,7 @@ test2_SOURCES = \
manager/RequestDealerManager.cpp \
manager/ServerSubscriberManager.cpp \
manager/InterfaceManager.cpp \
manager/AnalysisRequesterManager.cpp \
manager/ServerRequesterManager.cpp \
manager/PlotManager.cpp \
manager/OffScreenPlotManager.cpp \
......
This diff is collapsed.
......@@ -31,7 +31,7 @@ namespace datacontainer {
/*
* constructor
*/
PropertyPlotDataContainer::PropertyPlotDataContainer(const proto::PlotPropertyDataMessage& plotMessage) {
PropertyPlotDataContainer::PropertyPlotDataContainer(const ploty::PlotPropertyDataMessage& plotMessage) {
plotKey = plotMessage.plotkey();
for (string key : plotMessage.keys()) {
keys.push_back(key);
......
......@@ -22,7 +22,7 @@
#include "datacontainer/PlotDataContainer.h"
namespace proto {
namespace ploty {
class PlotPropertyDataMessage;
}
......@@ -39,7 +39,7 @@ public:
* \brief constructor
* \param[in] plotMessage The plot message container for constructing this one
*/
PropertyPlotDataContainer(const proto::PlotPropertyDataMessage& plotMessage);
PropertyPlotDataContainer(const ploty::PlotPropertyDataMessage& plotMessage);
/*!
* \brief destructor
......
......@@ -108,7 +108,7 @@ int32 main(int32 argc, char* argv[]) {
DBGMSG("file : " << pbfile.string().c_str());
ifstream inputMessage(pbfile.string().c_str(), fstream::binary);
if (inputMessage.is_open() == false) {
Error("mainoffscreenplot", "Failed to open temporary file wich contains proto::PlotPropertyDataMessage", argv[2]);
Error("mainoffscreenplot", "Failed to open temporary file wich contains ploty::PlotPropertyDataMessage", argv[2]);
err = EXIT_FAILURE;
} else {
uint32 size = boost::filesystem::file_size(pbfile);
......
......@@ -40,6 +40,7 @@
#include "manager/RequestDealerManager.h"
#include "manager/ServerRequesterManager.h"
#include "manager/AnalysisRequesterManager.h"
#include "view/qt/QtUpdateContainer.h"
#include "view/qt/QtUpdateThread.h"
#include "manager/mpl/MplEventManager.h"
......@@ -130,6 +131,15 @@ int32 main(int32 argc, char* argv[]) {
}
DBGMSG("Created requester " << *requesterdb);
// create a requester on the nomad server database
shared_ptr<application::Requester> requesteranalysis = application::Requester::create(*nomadserver, "analysis");
if (requesteranalysis.get() == 0) {
Error("mainplot", "Connection problem on analysis");
err = EXIT_FAILURE;
goto exit;
}
DBGMSG("Created requester " << *requesteranalysis);
// Manage application signal
// signal(SIGABRT, crash_handler);
signal(SIGHUP, crash_handler);
......@@ -141,11 +151,14 @@ int32 main(int32 argc, char* argv[]) {
// Init the nomad server requester manager
manager::ServerRequesterManager::getInstance()->init(requesterdb);
// Init the nomad analysis requester manager
manager::AnalysisRequesterManager::getInstance()->init(requesteranalysis);
// Set cameo application running
application::This::setRunning();
// Read temporary file created by ploty2 process with new plot info
// Open file contained proto::message
// Open file contained ploty::message
ifstream file1(argv[2], ios::binary);
if (file1.is_open() == true) {
char c;
......@@ -154,7 +167,7 @@ int32 main(int32 argc, char* argv[]) {
part1 << c;
}
file1.close();
// Open file contained proto::PlotPropertyDataMessage
// Open file contained ploty::PlotPropertyDataMessage
ifstream file2(argv[3],ios::binary);
if (file2.is_open() == true) {
ostringstream part2;
......@@ -164,13 +177,13 @@ int32 main(int32 argc, char* argv[]) {
file2.close();
// Get the request type.
proto::Message message;
ploty::Message message;
message.ParseFromString(part1.str());
DBGMSG("receive : " << message.type());
// Switch between message type
if (message.type() == proto::Message::PlotPropertyData) {
if (message.type() == ploty::Message::PlotPropertyData) {
// Property plot
proto::PlotPropertyDataMessage plotMessage;
ploty::PlotPropertyDataMessage plotMessage;
plotMessage.ParseFromString(part2.str());
DBGMSG("key : " << plotMessage.plotkey());
......@@ -195,22 +208,26 @@ int32 main(int32 argc, char* argv[]) {
}
}
else {
Error("mainplot", "Failed to open temporary file wich contains proto::PlotPropertyDataMessage", argv[3]);
Error("mainplot", "Failed to open temporary file wich contains ploty::PlotPropertyDataMessage", argv[3]);
err = EXIT_FAILURE;
}
}
else {
Error("mainplot", "Failed to open temporary file wich contains proto::Message", argv[2]);
Error("mainplot", "Failed to open temporary file wich contains ploty::Message", argv[2]);
err = EXIT_FAILURE;
}
// Clean manager
manager::ServerRequesterManager::resetInstance();
// Clean manager
manager::AnalysisRequesterManager::resetInstance();
// Cancel subscriber
datachangesubscriber->cancel();
requesterdb.reset();
requesteranalysis.reset();
}
exit:
......
/*
* 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 "AnalysisRequesterManager.h"
using namespace std;
using namespace cameo;
namespace manager {
AnalysisRequesterManager* AnalysisRequesterManager::m_Instance = nullptr;
/*
* constructor
*/
AnalysisRequesterManager::AnalysisRequesterManager() {
}
/*
* getInstance
*/
AnalysisRequesterManager* AnalysisRequesterManager::getInstance() {
if (m_Instance == nullptr) {
m_Instance = new AnalysisRequesterManager();
}
return m_Instance;
}
/*
* init
*/
void AnalysisRequesterManager::init(std::shared_ptr<cameo::application::Requester> requester) {
m_AnalysisRequester = requester;
}
/*
* resetInstance
*/
void AnalysisRequesterManager::resetInstance() {
if (m_Instance != nullptr) {
m_Instance->reset();
delete m_Instance;
m_Instance = nullptr;
}
}
/*
* reset
*/
void AnalysisRequesterManager::reset() {
}
/*
* getSimpleGaussianFitValue
*/
analysis::FitDataMessage AnalysisRequesterManager::getSimpleGaussianFitValue(const std::vector<float64>& x, const std::vector<float64>& y) throw (Error) {
analysis::Message message;
message.set_type(analysis::Message::GetFit);
analysis::DataToFitMessage dataToFit;
dataToFit.set_type(analysis::GaussianFit);
for(auto val : x) {
dataToFit.add_xdata(val);
}
for(auto val : y) {
dataToFit.add_ydata(val);
}
std::string part1, part2;
message.SerializeToString(&part1);
dataToFit.SerializeToString(&part2);
m_AnalysisRequester->sendTwoBinaryParts(part1, part2);
std::string responseMessage;
m_AnalysisRequester->receiveBinary(responseMessage);
analysis::FitDataMessage fitData;
fitData.ParseFromString(responseMessage);
return fitData;
}
}
/*
* 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.
*/
#ifndef ANALYSISREQUESTERMANAGER_H
#define ANALYSISREQUESTERMANAGER_H
#include <cameo/cameo.h>
#include <common/base/BaseTypes.h>
#include "common/protobuf/generated/AnalysisRequests.pb.h"
#include "Error.h"
namespace manager {
/*!
* \brief This class manage request to nomad server data base
*/
class AnalysisRequesterManager {
public:
/*!
* \brief Singleton instance getter
* \return Singleton instance
*/
static AnalysisRequesterManager* getInstance();
/*!
* \brief reset instance
*/
static void resetInstance();
/*!
* \brief init the singleton
* \param[in] requester Pointer to the cameo requester on analysis responder
*/
void init(std::shared_ptr<cameo::application::Requester> requester);
/*!
* \brief Get simple gaussian fit values
* \param[in] x The data of x to fit
* \param[in] y The data of y to fit
* \return Fit y data and stats values
* \throws Error
*/
analysis::FitDataMessage getSimpleGaussianFitValue(const std::vector<float64>& x, const std::vector<float64>& y) throw (Error);
private:
/*!
* \brief constructor
*/
AnalysisRequesterManager();
/*!
* \brief reset instance
*/
void reset();
static AnalysisRequesterManager* m_Instance; //! Singleton instannce
std::shared_ptr<cameo::application::Requester> m_AnalysisRequester; //! Analysis requester pointer
};
}
#endif // ANALYSISREQUESTERMANAGER_H
......@@ -255,9 +255,9 @@ void InterfaceManager::updateRoi(int32 n, const RectangleCoord& rect) {
/*
* updateSum
*/
void InterfaceManager::updateSum(uint32 id, float64 sum) {
void InterfaceManager::updateRoiSum(uint32 id, float64 sum) {
if (m_QtWindow) {
m_QtWindow->updateSum(id, sum);
m_QtWindow->updateRoiSum(id, sum);
}
}
......@@ -292,4 +292,45 @@ void InterfaceManager::showStatsCoord(const RectangleCoord& rect) {
}
}
/*
* gaussianFitStatistic
*/
void InterfaceManager::gaussianFitStatistic(const std::string& color) throw (Error) {
if (m_PropertyPlot) {
m_PropertyPlot->gaussianFitStatistic(color);
}
}
/*
* dismissGaussianFitStats
*/
void InterfaceManager::dismissGaussianFitStats() throw (Error) {
if (m_PropertyPlot) {
m_PropertyPlot->dismissGaussianFitStats();
}
}
/*
* showGaussianFitStatsCoord
*/
void InterfaceManager::showGaussianFitStatsCoord(const RectangleCoord& rect) {
vector<FitGaussianStats> stats;
if (m_PropertyPlot) {
stats = m_PropertyPlot->updateGaussianFitStats(rect);
}
if (m_QtWindow) {
m_QtWindow->showGaussianFitCoord(rect, stats);
}
}
/*
* closeStatsWindow
*/
void InterfaceManager::closeStatsWindow() {
if (m_QtWindow) {
m_QtWindow->closeStatsWindow();
}
}
}
......@@ -28,6 +28,7 @@
namespace plot {
class PlotWindow;
class Plot;
namespace property {
class PropertyPlot;
}
......@@ -243,32 +244,53 @@ public:
* \param[in] id The roi indice
* \param[in] sum The detector sum value
*/
void updateSum(uint32 id, float64 sum);
void updateRoiSum(uint32 id, float64 sum);
/*!
* \brief Start of sequence add a roi
* \brief Show simple stats of the plot
* \param[in] color The color of the roi box
* \throws Error
*/
void statistic(const std::string& color) throw (Error);
/*!
* \brief Delete a roi
* \param[in] id The id of the roi
* \brief Dismiss Stats
* \throws Error
*/
void dismissStats() throw (Error);
/*!
* \brief Show roi coordinates
* \param[in] x0 The x0 roi coordinate
* \param[in] y0 The x1 roi coordinate
* \param[in] x1 The y0 roi coordinate
* \param[in] y1 The y1 roi coordinate
* \param[in] rects The box coordinates
* \throws Error
*/
void showStatsCoord(const RectangleCoord& rect);
/*!
* \brief Show simple gaussian fit
* \param[in] color The color of the fit
* \throws Error
*/
void gaussianFitStatistic(const std::string& color) throw (Error);
/*!
* \brief Dissimiss the gaussian fit a roi
* \param[in] id The id of the roi
* \throws Error
*/
void dismissGaussianFitStats() throw (Error);
/*!
* \brief Show fit box coordinates
* \param[in] rect The rectangle coordinate
*/
void showGaussianFitStatsCoord(const RectangleCoord& rect);
/*!
* \brief Close stats windows
*/
void closeStatsWindow();
private:
/*!
......
......@@ -157,7 +157,7 @@ void OffScreenPlotManager::run(std::string pbfilename, std::string path) {
ifstream inputMessage(pbfile.string().c_str(), fstream::binary);
if (inputMessage.is_open() == false) {
Error("OffScreenPlotManager", "savePlot",
"Failed to open temporary file which contains proto::PlotPropertyDataMessage", pbfilename);
"Failed to open temporary file which contains ploty::PlotPropertyDataMessage", pbfilename);
} else {
char buffer[size];
inputMessage.read(buffer, size);
......@@ -231,7 +231,7 @@ void OffScreenPlotManager::run(std::string pbfilename, std::string path) {
}
} catch (boost::filesystem::filesystem_error& e) {
Error("OffScreenPlotManager", "savePlot",
"Failed to open temporary file which contains proto::PlotPropertyDataMessage", pbfilename);
"Failed to open temporary file which contains ploty::PlotPropertyDataMessage", pbfilename);
}
}
......
......@@ -126,9 +126,9 @@ void PlotManager::restore() {
part2 << c;
}
file2.close();
proto::Message message;
ploty::Message message;
message.ParseFromString(part1.str());
proto::PlotPropertyDataMessage plotMessage;
ploty::PlotPropertyDataMessage plotMessage;
plotMessage.ParseFromString(part2.str());
// Display plot
......@@ -152,7 +152,7 @@ PlotManager * PlotManager::getInstance() {
/*
* displayPlot
*/
void PlotManager::displayPropertyPlot(const proto::Message& message, const proto::PlotPropertyDataMessage& plotMessage) {
void PlotManager::displayPropertyPlot(const ploty::Message& message, const ploty::PlotPropertyDataMessage& plotMessage) {
unique_lock<recursive_mutex> lock(m_PlotsMutex);
///////////////////////////////////////////////////////////////////////////////////////
//// Check if this plot key is already open or was closed
......@@ -197,7 +197,7 @@ void PlotManager::displayPropertyPlot(const proto::Message& message, const proto
string part2;
plotMessage.SerializeToString(&part2);
// Create temporary file 1 which contains proto::Message info
// Create temporary file 1 which contains ploty::Message info
ostringstream filename1;
filename1 << "/tmp/mplplot-" << plotMessage.plotkey() << ".message1";
ofstream file1(filename1.str().c_str(), ios::binary);
......@@ -206,7 +206,7 @@ void PlotManager::displayPropertyPlot(const proto::Message& message, const proto
file1.write(part1.c_str(), part1.size());
file1.close();
// Create temporary file 2 which contains proto::PlotPropertyDataMessage info
// Create temporary file 2 which contains ploty::PlotPropertyDataMessage info
ostringstream filename2;
filename2 << "/tmp/mplplot-" << plotMessage.plotkey() << ".message2";
ofstream file2(filename2.str().c_str(), ios::binary);
......
......@@ -25,7 +25,7 @@
#include <cameo/cameo.h>
#include <common/base/BaseTypes.h>
namespace proto {
namespace ploty {
class Message;
class PlotPropertyDataMessage;
}
......@@ -51,7 +51,7 @@ public:
* \brief display a plot
* \param[in] plotRequest plot info
*/
void displayPropertyPlot(const proto::Message& message, const proto::PlotPropertyDataMessage& plotMessage);
void displayPropertyPlot(const ploty::Message& message, const ploty::PlotPropertyDataMessage& plotMessage);
/*!
* \brief reset instance
......@@ -73,7 +73,7 @@ private:
static PlotManager* m_Instance; //! Pointer of singleton instance
std::map<std::string, std::shared_ptr<cameo::application::Instance> > m_PlotsProcesses; //! Map of open display plots
std::map<std::string, std::pair<proto::Message , proto::PlotPropertyDataMessage> > m_PropertyPlotsData; //! Map of open display plots properties
std::map<std::string, std::pair<ploty::Message , ploty::PlotPropertyDataMessage> > m_PropertyPlotsData; //! Map of open display plots properties
std::recursive_mutex m_PlotsMutex; //! Mutex on plots map
//! Configuration cache files
......
......@@ -76,21 +76,21 @@ void RequestDealerManager::loop(std::shared_ptr<cameo::application::Responder> r
if (responder->isCanceled() == false) {
// Get the request type.
string firstPart = request->getBinary();
proto::Message message;
ploty::Message message;
message.ParseFromString(firstPart);
// Property plot
if (message.type() == proto::Message::PlotPropertyData) {
if (message.type() == ploty::Message::PlotPropertyData) {
string secondPart = request->getSecondBinaryPart();
proto::PlotPropertyDataMessage dataMessage;
ploty::PlotPropertyDataMessage dataMessage;
dataMessage.ParseFromString(secondPart);
PlotManager::getInstance()->displayPropertyPlot(message, dataMessage);
}