Raw -> Smart Pointers for mupp_plotter, qt5/qt6.

This commit is contained in:
suter_a 2023-10-24 16:07:56 +02:00
parent 9911d88889
commit e676d3c045
6 changed files with 48 additions and 160 deletions

View File

@ -58,15 +58,9 @@ ClassImpQ(PMuppCanvas)
PMuppCanvas::PMuppCanvas()
{
fFtokName = TString("");
fCheckMsgQueue = 0;
fStyle = 0;
fImp = 0;
fBar = 0;
fPopupMain = 0;
fMainCanvas = 0;
fMultiGraph = 0;
fImp = nullptr;
fBar = nullptr;
fPopupMain = nullptr;
gStyle->SetHistMinimumZero(kTRUE); // needed to enforce proper bar option handling
}
@ -97,11 +91,10 @@ PMuppCanvas::PMuppCanvas(const Char_t *title, Int_t wtopx, Int_t wtopy,
fValid = true;
fFtokName = TString("");
fCheckMsgQueue = 0;
// install IPC message queue timer
fCheckMsgQueue = new TTimer();
if (fCheckMsgQueue == 0) {
fCheckMsgQueue = std::make_unique<TTimer>();
if (fCheckMsgQueue == nullptr) {
fValid = false;
std::cerr << "**ERROR** couldn't start IPC message queue timer..." << std::endl;
return;
@ -113,25 +106,6 @@ PMuppCanvas::PMuppCanvas(const Char_t *title, Int_t wtopx, Int_t wtopy,
InitMuppCanvas(title, wtopx, wtopy, ww, wh);
}
//--------------------------------------------------------------------------
// Destructor
//--------------------------------------------------------------------------
/**
* @brief PMuppCanvas::~PMuppCanvas
*/
PMuppCanvas::~PMuppCanvas()
{
if (fMainCanvas) {
delete fMainCanvas;
}
if (fMultiGraph) {
delete fMultiGraph;
}
if (fStyle) {
delete fStyle;
}
}
//--------------------------------------------------------------------------
// Done (SIGNAL)
//--------------------------------------------------------------------------
@ -217,7 +191,7 @@ void PMuppCanvas::LastCanvasClosed()
*/
void PMuppCanvas::WindowClosed()
{
gROOT->GetListOfCanvases()->Remove(fMainCanvas);
gROOT->GetListOfCanvases()->Remove(fMainCanvas.get());
LastCanvasClosed();
}
@ -230,7 +204,7 @@ void PMuppCanvas::WindowClosed()
void PMuppCanvas::CreateStyle()
{
TString muppStyle("muppStyle");
fStyle = new TStyle(muppStyle, muppStyle);
fStyle = std::make_unique<TStyle>(muppStyle, muppStyle);
fStyle->SetOptStat(0); // no statistics options
fStyle->SetOptTitle(0); // no title
// set margins
@ -257,8 +231,8 @@ void PMuppCanvas::InitMuppCanvas(const Char_t *title, Int_t wtopx, Int_t wtopy,
// invoke canvas
TString canvasName = TString("fMuppCanvas");
fMainCanvas = new TCanvas(canvasName.Data(), title, wtopx, wtopy, ww, wh);
if (fMainCanvas == 0) {
fMainCanvas = std::make_unique<TCanvas>(canvasName.Data(), title, wtopx, wtopy, ww, wh);
if (fMainCanvas == nullptr) {
std::cerr << std::endl << ">> PMuppCanvas::InitMuppCanvas(): **PANIC ERROR** Couldn't invoke " << canvasName.Data();
std::cerr << std::endl;
return;
@ -266,8 +240,6 @@ void PMuppCanvas::InitMuppCanvas(const Char_t *title, Int_t wtopx, Int_t wtopy,
fMainCanvas->SetFillColor(0);
fMultiGraph = 0;
fImp = (TRootCanvas*)fMainCanvas->GetCanvasImp();
fImp->Connect("CloseWindow()", "PMuppCanvas", this, "WindowClosed()");
fBar = fImp->GetMenuBar();
@ -536,17 +508,14 @@ void PMuppCanvas::UpdateGraphs()
}
fGraphE.clear();
if (fMultiGraph) {
delete fMultiGraph;
fMultiGraph = 0;
}
fMultiGraph.reset();
// second: create all the necessary graphs
TGraphAsymmErrors *gg = 0;
UInt_t idxS = 0, idxC = 0;
Int_t color;
TString str;
if (fMultiGraph == 0) { // first time called
if (fMultiGraph == nullptr) { // first time called
for (UInt_t i=0; i<fPlotData.size(); i++) { // loop over all collections
for (UInt_t j=0; j<fPlotData[i].yValue.size(); j++) { // loop over all graph's within the collection
gg = new TGraphAsymmErrors(fPlotData[i].xValue.size());
@ -594,8 +563,8 @@ void PMuppCanvas::UpdateGraphs()
}
}
fMultiGraph = new TMultiGraph();
if (fMultiGraph == 0) {
fMultiGraph = std::make_unique<TMultiGraph>();
if (fMultiGraph == nullptr) {
std::cerr << "**ERROR** couldn't create necessary TMultiGraph object." << std::endl;
return;
}

View File

@ -31,6 +31,7 @@
#define _PMUPPCANVAS_H_
#include <vector>
#include <memory>
#include <TObject.h>
#include <TQObject.h>
@ -76,7 +77,6 @@ public:
const PIntVector markerSytleList, const PDoubleVector markerSizeList,
const PIntVector colorList,
const int mupp_instance);
virtual ~PMuppCanvas();
virtual Bool_t IsValid() { return fValid; }
@ -93,11 +93,11 @@ private:
Int_t fMuppInstance;
TString fFtokName;
TTimer *fCheckMsgQueue; ///< timer needed to check if a message in the IPC message queue is pending
std::unique_ptr<TTimer> fCheckMsgQueue; ///< timer needed to check if a message in the IPC message queue is pending
std::vector<PDataCollection> fPlotData;
TStyle *fStyle; ///< A collection of all graphics attributes
std::unique_ptr<TStyle> fStyle; ///< A collection of all graphics attributes
// canvas menu related variables
TRootCanvas *fImp; ///< ROOT native GUI version of main window with menubar and drawing area
@ -105,8 +105,8 @@ private:
TGPopupMenu *fPopupMain; ///< popup menu mupp in the main menu bar
// canvas related variables
TCanvas *fMainCanvas; ///< main canvas
TMultiGraph *fMultiGraph; ///< main multi graph
std::unique_ptr<TCanvas> fMainCanvas; ///< main canvas
std::unique_ptr<TMultiGraph> fMultiGraph; ///< main multi graph
std::vector<TGraphAsymmErrors*> fGraphE; ///< all error graphs
// perdefined markers, colors

View File

@ -28,6 +28,7 @@
***************************************************************************/
#include <iostream>
#include <memory>
#include <TApplication.h>
#include <TSAXParser.h>
@ -55,40 +56,22 @@ int main(int argc, char *argv[])
// read startup file
char startup_path_name[128];
TSAXParser *saxParser = new TSAXParser();
PMuppStartupHandler *startupHandler = new PMuppStartupHandler();
std::unique_ptr<TSAXParser> saxParser = std::make_unique<TSAXParser>();
std::unique_ptr<PMuppStartupHandler> startupHandler = std::make_unique<PMuppStartupHandler>();
if (!startupHandler->StartupFileFound()) {
std::cerr << std::endl << ">> mupp_plot **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data();
std::cerr << std::endl;
// clean up
if (saxParser) {
delete saxParser;
saxParser = 0;
}
if (startupHandler) {
delete startupHandler;
startupHandler = 0;
}
} else {
strcpy(startup_path_name, startupHandler->GetStartupFilePath().Data());
saxParser->ConnectToHandler("PMuppStartupHandler", startupHandler);
saxParser->ConnectToHandler("PMuppStartupHandler", startupHandler.get());
// parsing the file as above seems to lead to problems in certain environments;
// use the parseXmlFile function instead (see PMuppStartupHandler.cpp for the definition)
Int_t status = parseXmlFile(saxParser, startup_path_name);
Int_t status = parseXmlFile(saxParser.get(), startup_path_name);
// check for parse errors
if (status) { // error
std::cerr << std::endl << ">> mupp_plot **WARNING** Reading/parsing mupp_startup.xml failed.";
std::cerr << std::endl << ">> Graph will appear with random symbols and colors!";
std::cerr << std::endl;
// clean up
if (saxParser) {
delete saxParser;
saxParser = 0;
}
if (startupHandler) {
delete startupHandler;
startupHandler = 0;
}
} else {
startupHandler->CheckLists();
}
@ -103,7 +86,7 @@ int main(int argc, char *argv[])
startupHandler->GetColorList(),
mupp_instance);
if (muppCanvas != 0) {
if (muppCanvas != nullptr) {
if (muppCanvas->IsValid()) {
// connect signal/slot
TQObject::Connect("TCanvas", "Closed()", "PMuppCanvas", muppCanvas, "LastCanvasClosed()");
@ -125,14 +108,6 @@ int main(int argc, char *argv[])
app.Run(true); // true needed that Run will return after quit so that cleanup works
// clean up
if (saxParser) {
delete saxParser;
saxParser = 0;
}
if (startupHandler) {
delete startupHandler;
startupHandler = 0;
}
if (muppCanvas) {
delete muppCanvas;
muppCanvas = 0;

View File

@ -58,15 +58,9 @@ ClassImpQ(PMuppCanvas)
PMuppCanvas::PMuppCanvas()
{
fFtokName = TString("");
fCheckMsgQueue = 0;
fStyle = 0;
fImp = 0;
fBar = 0;
fPopupMain = 0;
fMainCanvas = 0;
fMultiGraph = 0;
fImp = nullptr;
fBar = nullptr;
fPopupMain = nullptr;
gStyle->SetHistMinimumZero(kTRUE); // needed to enforce proper bar option handling
}
@ -97,11 +91,10 @@ PMuppCanvas::PMuppCanvas(const Char_t *title, Int_t wtopx, Int_t wtopy,
fValid = true;
fFtokName = TString("");
fCheckMsgQueue = 0;
// install IPC message queue timer
fCheckMsgQueue = new TTimer();
if (fCheckMsgQueue == 0) {
fCheckMsgQueue = std::make_unique<TTimer>();
if (fCheckMsgQueue == nullptr) {
fValid = false;
std::cerr << "**ERROR** couldn't start IPC message queue timer..." << std::endl;
return;
@ -113,25 +106,6 @@ PMuppCanvas::PMuppCanvas(const Char_t *title, Int_t wtopx, Int_t wtopy,
InitMuppCanvas(title, wtopx, wtopy, ww, wh);
}
//--------------------------------------------------------------------------
// Destructor
//--------------------------------------------------------------------------
/**
* @brief PMuppCanvas::~PMuppCanvas
*/
PMuppCanvas::~PMuppCanvas()
{
if (fMainCanvas) {
delete fMainCanvas;
}
if (fMultiGraph) {
delete fMultiGraph;
}
if (fStyle) {
delete fStyle;
}
}
//--------------------------------------------------------------------------
// Done (SIGNAL)
//--------------------------------------------------------------------------
@ -217,7 +191,7 @@ void PMuppCanvas::LastCanvasClosed()
*/
void PMuppCanvas::WindowClosed()
{
gROOT->GetListOfCanvases()->Remove(fMainCanvas);
gROOT->GetListOfCanvases()->Remove(fMainCanvas.get());
LastCanvasClosed();
}
@ -230,7 +204,7 @@ void PMuppCanvas::WindowClosed()
void PMuppCanvas::CreateStyle()
{
TString muppStyle("muppStyle");
fStyle = new TStyle(muppStyle, muppStyle);
fStyle = std::make_unique<TStyle>(muppStyle, muppStyle);
fStyle->SetOptStat(0); // no statistics options
fStyle->SetOptTitle(0); // no title
// set margins
@ -257,8 +231,8 @@ void PMuppCanvas::InitMuppCanvas(const Char_t *title, Int_t wtopx, Int_t wtopy,
// invoke canvas
TString canvasName = TString("fMuppCanvas");
fMainCanvas = new TCanvas(canvasName.Data(), title, wtopx, wtopy, ww, wh);
if (fMainCanvas == 0) {
fMainCanvas = std::make_unique<TCanvas>(canvasName.Data(), title, wtopx, wtopy, ww, wh);
if (fMainCanvas == nullptr) {
std::cerr << std::endl << ">> PMuppCanvas::InitMuppCanvas(): **PANIC ERROR** Couldn't invoke " << canvasName.Data();
std::cerr << std::endl;
return;
@ -266,8 +240,6 @@ void PMuppCanvas::InitMuppCanvas(const Char_t *title, Int_t wtopx, Int_t wtopy,
fMainCanvas->SetFillColor(0);
fMultiGraph = 0;
fImp = (TRootCanvas*)fMainCanvas->GetCanvasImp();
fImp->Connect("CloseWindow()", "PMuppCanvas", this, "WindowClosed()");
fBar = fImp->GetMenuBar();
@ -536,17 +508,14 @@ void PMuppCanvas::UpdateGraphs()
}
fGraphE.clear();
if (fMultiGraph) {
delete fMultiGraph;
fMultiGraph = 0;
}
fMultiGraph.reset();
// second: create all the necessary graphs
TGraphAsymmErrors *gg = 0;
UInt_t idxS = 0, idxC = 0;
Int_t color;
TString str;
if (fMultiGraph == 0) { // first time called
if (fMultiGraph == nullptr) { // first time called
for (UInt_t i=0; i<fPlotData.size(); i++) { // loop over all collections
for (UInt_t j=0; j<fPlotData[i].yValue.size(); j++) { // loop over all graph's within the collection
gg = new TGraphAsymmErrors(fPlotData[i].xValue.size());
@ -594,8 +563,8 @@ void PMuppCanvas::UpdateGraphs()
}
}
fMultiGraph = new TMultiGraph();
if (fMultiGraph == 0) {
fMultiGraph = std::make_unique<TMultiGraph>();
if (fMultiGraph == nullptr) {
std::cerr << "**ERROR** couldn't create necessary TMultiGraph object." << std::endl;
return;
}

View File

@ -31,6 +31,7 @@
#define _PMUPPCANVAS_H_
#include <vector>
#include <memory>
#include <TObject.h>
#include <TQObject.h>
@ -76,7 +77,6 @@ public:
const PIntVector markerSytleList, const PDoubleVector markerSizeList,
const PIntVector colorList,
const int mupp_instance);
virtual ~PMuppCanvas();
virtual Bool_t IsValid() { return fValid; }
@ -93,11 +93,11 @@ private:
Int_t fMuppInstance;
TString fFtokName;
TTimer *fCheckMsgQueue; ///< timer needed to check if a message in the IPC message queue is pending
std::unique_ptr<TTimer> fCheckMsgQueue; ///< timer needed to check if a message in the IPC message queue is pending
std::vector<PDataCollection> fPlotData;
TStyle *fStyle; ///< A collection of all graphics attributes
std::unique_ptr<TStyle> fStyle; ///< A collection of all graphics attributes
// canvas menu related variables
TRootCanvas *fImp; ///< ROOT native GUI version of main window with menubar and drawing area
@ -105,8 +105,8 @@ private:
TGPopupMenu *fPopupMain; ///< popup menu mupp in the main menu bar
// canvas related variables
TCanvas *fMainCanvas; ///< main canvas
TMultiGraph *fMultiGraph; ///< main multi graph
std::unique_ptr<TCanvas> fMainCanvas; ///< main canvas
std::unique_ptr<TMultiGraph> fMultiGraph; ///< main multi graph
std::vector<TGraphAsymmErrors*> fGraphE; ///< all error graphs
// perdefined markers, colors

View File

@ -28,6 +28,7 @@
***************************************************************************/
#include <iostream>
#include <memory>
#include <TApplication.h>
#include <TSAXParser.h>
@ -55,40 +56,22 @@ int main(int argc, char *argv[])
// read startup file
char startup_path_name[128];
TSAXParser *saxParser = new TSAXParser();
PMuppStartupHandler *startupHandler = new PMuppStartupHandler();
std::unique_ptr<TSAXParser> saxParser = std::make_unique<TSAXParser>();
std::unique_ptr<PMuppStartupHandler> startupHandler = std::make_unique<PMuppStartupHandler>();
if (!startupHandler->StartupFileFound()) {
std::cerr << std::endl << ">> mupp_plot **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data();
std::cerr << std::endl;
// clean up
if (saxParser) {
delete saxParser;
saxParser = 0;
}
if (startupHandler) {
delete startupHandler;
startupHandler = 0;
}
} else {
strcpy(startup_path_name, startupHandler->GetStartupFilePath().Data());
saxParser->ConnectToHandler("PMuppStartupHandler", startupHandler);
saxParser->ConnectToHandler("PMuppStartupHandler", startupHandler.get());
// parsing the file as above seems to lead to problems in certain environments;
// use the parseXmlFile function instead (see PMuppStartupHandler.cpp for the definition)
Int_t status = parseXmlFile(saxParser, startup_path_name);
Int_t status = parseXmlFile(saxParser.get(), startup_path_name);
// check for parse errors
if (status) { // error
std::cerr << std::endl << ">> mupp_plot **WARNING** Reading/parsing mupp_startup.xml failed.";
std::cerr << std::endl << ">> Graph will appear with random symbols and colors!";
std::cerr << std::endl;
// clean up
if (saxParser) {
delete saxParser;
saxParser = 0;
}
if (startupHandler) {
delete startupHandler;
startupHandler = 0;
}
} else {
startupHandler->CheckLists();
}
@ -103,7 +86,7 @@ int main(int argc, char *argv[])
startupHandler->GetColorList(),
mupp_instance);
if (muppCanvas != 0) {
if (muppCanvas != nullptr) {
if (muppCanvas->IsValid()) {
// connect signal/slot
TQObject::Connect("TCanvas", "Closed()", "PMuppCanvas", muppCanvas, "LastCanvasClosed()");
@ -125,14 +108,6 @@ int main(int argc, char *argv[])
app.Run(true); // true needed that Run will return after quit so that cleanup works
// clean up
if (saxParser) {
delete saxParser;
saxParser = 0;
}
if (startupHandler) {
delete startupHandler;
startupHandler = 0;
}
if (muppCanvas) {
delete muppCanvas;
muppCanvas = 0;