get rid of raw pointers for PFourierCanvas where it makes sense.

This commit is contained in:
suter_a 2023-10-18 14:21:15 +02:00
parent 18f077c6e7
commit 1c8c1a8d0f
3 changed files with 28 additions and 144 deletions

View File

@ -55,7 +55,6 @@ ClassImpQ(PFourierCanvas)
PFourierCanvas::PFourierCanvas()
{
fTimeout = 0;
fTimeoutTimer = nullptr;
fBatchMode = false;
fValid = false;
@ -69,18 +68,10 @@ PFourierCanvas::PFourierCanvas()
fXaxisTitle = TString("");
fCurrentFourierPhase = 0.0;
fCurrentFourierPhaseText = nullptr;
fStyle = nullptr;
fImp = nullptr;
fBar = nullptr;
fPopupMain = nullptr;
fPopupFourier = nullptr;
fMainCanvas = nullptr;
fTitlePad = nullptr;
fFourierPad = nullptr;
fInfoPad = nullptr;
}
//---------------------------------------------------------------------------
@ -112,12 +103,9 @@ PFourierCanvas::PFourierCanvas(std::vector<PFourier*> &fourier, PIntVector dataS
fInitialXRange[1] = fourierXrange[1];
fTimeout = 0;
fTimeoutTimer = nullptr;
fValid = false;
fCurrentFourierPhaseText = nullptr;
// generate fMarkerList and fColorList, since they are not provided
TRandom rand;
Int_t style, color;
@ -168,12 +156,9 @@ PFourierCanvas::PFourierCanvas(std::vector<PFourier*> &fourier, PIntVector dataS
fInitialXRange[1] = fourierXrange[1];
fTimeout = 0;
fTimeoutTimer = nullptr;
fValid = false;
fCurrentFourierPhaseText = nullptr;
// generate fMarkerList and fColorList, since they are not provided
TRandom rand;
Int_t style, color;
@ -196,70 +181,6 @@ PFourierCanvas::PFourierCanvas(std::vector<PFourier*> &fourier, PIntVector dataS
gStyle->SetHistMinimumZero(kTRUE); // needed to enforce proper bar option handling
}
//---------------------------------------------------------------------------
/**
* <p>Destructor
*/
PFourierCanvas::~PFourierCanvas()
{
if (fTimeoutTimer)
delete fTimeoutTimer;
if (fCurrentFourierPhaseText)
delete fCurrentFourierPhaseText;
/*
if (fStyle) {
delete fStyle;
fStyle = 0;
}
*/
if (fTitlePad) {
fTitlePad->Clear();
delete fTitlePad;
fTitlePad = nullptr;
}
if (fFourierHistos.size() > 0) {
for (UInt_t i=0; i<fFourierHistos.size(); i++) {
delete fFourierHistos[i].dataFourierRe;
delete fFourierHistos[i].dataFourierIm;
delete fFourierHistos[i].dataFourierPwr;
delete fFourierHistos[i].dataFourierPhase;
delete fFourierHistos[i].dataFourierPhaseOptReal;
}
fFourierHistos.clear();
}
CleanupAverage();
/*
if (fFourierPad) {
fFourierPad->Clear();
delete fFourierPad;
fFourierPad = 0;
}
*/
if (fInfoPad) {
fInfoPad->Clear();
delete fInfoPad;
fInfoPad = nullptr;
}
if (fLegAvgPerDataSet) {
fLegAvgPerDataSet->Clear();
delete fLegAvgPerDataSet;
fLegAvgPerDataSet = nullptr;
}
/*
if (fMainCanvas) {
delete fMainCanvas;
fMainCanvas = nullptr;
}
*/
}
//--------------------------------------------------------------------------
// Done (SIGNAL)
//--------------------------------------------------------------------------
@ -563,11 +484,7 @@ void PFourierCanvas::SetTimeout(Int_t timeout)
if (fTimeout <= 0)
return;
if (fTimeoutTimer) {
delete fTimeoutTimer;
fTimeoutTimer = nullptr;
}
fTimeoutTimer = new TTimer();
fTimeoutTimer.reset(new TTimer());
fTimeoutTimer->Connect("Timeout()", "PFourierCanvas", this, "Done()");
@ -831,7 +748,7 @@ void PFourierCanvas::CreateXaxisTitle()
void PFourierCanvas::CreateStyle()
{
TString musrFTStyle("musrFTStyle");
fStyle = new TStyle(musrFTStyle, musrFTStyle);
fStyle = std::make_unique<TStyle>(musrFTStyle, musrFTStyle);
fStyle->SetOptStat(0); // no statistics options
fStyle->SetOptTitle(0); // no title
fStyle->cd();
@ -990,21 +907,10 @@ void PFourierCanvas::InitFourierCanvas(const Char_t* title, Int_t wtopx, Int_t w
fImp = nullptr;
fBar = nullptr;
fPopupMain = nullptr;
fPopupFourier = nullptr;
fMainCanvas = nullptr;
fTitlePad = nullptr;
fFourierPad = nullptr;
fInfoPad = nullptr;
// invoke canvas
TString canvasName = TString("fMainCanvas");
fMainCanvas = new TCanvas(canvasName.Data(), title, wtopx, wtopy, ww, wh);
if (fMainCanvas == nullptr) {
std::cerr << std::endl << "PFourierCanvas::PFourierCanvas: **PANIC ERROR**: Couldn't invoke " << canvasName.Data();
std::cerr << std::endl;
return;
}
fMainCanvas = std::make_unique<TCanvas>(canvasName.Data(), title, wtopx, wtopy, ww, wh);
// add canvas menu if not in batch mode
if (!fBatchMode) {
@ -1012,9 +918,9 @@ void PFourierCanvas::InitFourierCanvas(const Char_t* title, Int_t wtopx, Int_t w
fBar = fImp->GetMenuBar();
fPopupMain = fBar->AddPopup("MusrFT");
fPopupFourier = new TGPopupMenu();
fPopupFourier = std::make_unique<TGPopupMenu>();
fPopupMain->AddPopup("&Fourier", fPopupFourier);
fPopupMain->AddPopup("&Fourier", fPopupFourier.get());
fPopupFourier->AddEntry("Show Real", P_MENU_ID_FOURIER+P_MENU_ID_FOURIER_REAL);
fPopupFourier->AddEntry("Show Imag", P_MENU_ID_FOURIER+P_MENU_ID_FOURIER_IMAG);
fPopupFourier->AddEntry("Show Real+Imag", P_MENU_ID_FOURIER+P_MENU_ID_FOURIER_REAL_AND_IMAG);
@ -1067,39 +973,25 @@ void PFourierCanvas::InitFourierCanvas(const Char_t* title, Int_t wtopx, Int_t w
// divide the canvas into sub pads
// title pad
fTitlePad = new TPaveText(0.0, YTITLE, 1.0, 1.0, "NDC");
if (fTitlePad == nullptr) {
std::cerr << std::endl << "PFourierCanvas::PFourierCanvas: **PANIC ERROR**: Couldn't invoke fTitlePad";
std::cerr << std::endl;
return;
}
fTitlePad = std::make_unique<TPaveText>(0.0, YTITLE, 1.0, 1.0, "NDC");
fTitlePad->SetFillColor(TColor::GetColor(255,255,255));
fTitlePad->SetTextAlign(12); // middle, left
fTitlePad->AddText(title);
fTitlePad->Draw();
// fourier pad
fFourierPad = new TPad("fFourierPad", "fFourierPad", 0.0, YINFO, 1.0, YTITLE);
if (fFourierPad == nullptr) {
std::cerr << std::endl << "PFourierCanvas::PFourierCanvas: **PANIC ERROR**: Couldn't invoke fFourierPad";
std::cerr << std::endl;
return;
}
fFourierPad = std::make_unique<TPad>("fFourierPad", "fFourierPad", 0.0, YINFO, 1.0, YTITLE);
fFourierPad->SetFillColor(TColor::GetColor(255,255,255));
fFourierPad->Draw();
// info pad
fInfoPad = new TLegend(0.0, 0.0, 1.0, YINFO, "NDC");
if (fInfoPad == nullptr) {
std::cerr << std::endl << "PFourierCanvas::PFourierCanvas: **PANIC ERROR**: Couldn't invoke fInfoPad";
std::cerr << std::endl;
return;
}
fInfoPad = std::make_unique<TLegend>(0.0, 0.0, 1.0, YINFO, "NDC");
fInfoPad->SetFillColor(TColor::GetColor(255,255,255));
fInfoPad->SetTextAlign(12); // middle, left
fLegAvgPerDataSet = nullptr;
fValid = true;
if ((fFourier.size() != fDataSetTag.size()) && fAveragedViewPerDataSet) {
@ -1629,12 +1521,6 @@ void PFourierCanvas::PlotFourier()
*/
void PFourierCanvas::PlotFourierPhaseValue()
{
// check if phase TLatex object is present
if (fCurrentFourierPhaseText) {
delete fCurrentFourierPhaseText;
fCurrentFourierPhaseText = nullptr;
}
Double_t x, y;
TString str;
@ -1643,7 +1529,7 @@ void PFourierCanvas::PlotFourierPhaseValue()
str += fCurrentFourierPhase;
x = 0.7;
y = 0.85;
fCurrentFourierPhaseText = new TLatex();
fCurrentFourierPhaseText.reset(new TLatex());
fCurrentFourierPhaseText->SetNDC(kTRUE);
fCurrentFourierPhaseText->SetText(x, y, str.Data());
fCurrentFourierPhaseText->SetTextFont(62);
@ -1675,10 +1561,8 @@ void PFourierCanvas::PlotAverage()
xmax = fInitialXRange[1];
Double_t ymin=0.0, ymax=0.0;
if (fLegAvgPerDataSet) {
if (fLegAvgPerDataSet.get()) {
fLegAvgPerDataSet->Clear();
delete fLegAvgPerDataSet;
fLegAvgPerDataSet = nullptr;
}
switch (fCurrentPlotView) {
@ -1799,7 +1683,7 @@ void PFourierCanvas::PlotAverage()
}
if (fAveragedViewPerDataSet) { // plot all the rest
fLegAvgPerDataSet = new TLegend(0.55, 0.4, 0.85, 0.6);
fLegAvgPerDataSet = std::make_unique<TLegend>(0.55, 0.4, 0.85, 0.6);
TString str = GetDataSetName(fFourierAverage[0].dataFourierPwr->GetTitle());
TString label = TString::Format("<%s>", str.Data());
fLegAvgPerDataSet->AddEntry(fFourierAverage[0].dataFourierPwr, label.Data());

View File

@ -31,6 +31,7 @@
#define _PFOURIERCANVAS_H_
#include <vector>
#include <memory>
#include <TObject.h>
#include <TQObject.h>
@ -99,7 +100,6 @@ class PFourierCanvas : public TObject, public TQObject
const Int_t fourierPlotOpt, Double_t fourierXrange[2], Double_t phase,
Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh,
const PIntVector markerList, const PIntVector colorList, const Bool_t batch);
virtual ~PFourierCanvas();
virtual void Done(Int_t status=0); // *SIGNAL*
virtual void HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected); // SLOT
@ -133,27 +133,27 @@ class PFourierCanvas : public TObject, public TQObject
PFourierCanvasDataList fFourierHistos; ///< keeps all the Fourier histos
PFourierCanvasDataList fFourierAverage; ///< keeps the average of the Fourier histos
Double_t fCurrentFourierPhase; ///< keeps the current Fourier phase (real/imag)
TLatex *fCurrentFourierPhaseText; ///< used in Re/Im Fourier to show the current phase in the pad
std::unique_ptr<TLatex> fCurrentFourierPhaseText; ///< used in Re/Im Fourier to show the current phase in the pad
TStyle *fStyle; ///< A collection of all graphics attributes
std::unique_ptr<TStyle> fStyle; ///< A collection of all graphics attributes
TTimer *fTimeoutTimer; ///< timeout timer in order to terminate if no action is taking place for too long
std::unique_ptr<TTimer> fTimeoutTimer; ///< timeout timer in order to terminate if no action is taking place for too long
PIntVector fMarkerList; ///< list of markers
PIntVector fColorList; ///< list of colors
// canvas menu related variables
TRootCanvas *fImp; ///< ROOT native GUI version of main window with menubar and drawing area
TGMenuBar *fBar; ///< menu bar
TGPopupMenu *fPopupMain; ///< popup menu MusrFT in the main menu bar
TGPopupMenu *fPopupFourier; ///< popup menu of the MusrFT/Fourier sub menu
TRootCanvas *fImp; ///< ROOT native GUI version of main window with menubar and drawing area
TGMenuBar *fBar; ///< menu bar
TGPopupMenu *fPopupMain; ///< popup menu MusrFT in the main menu bar
std::unique_ptr<TGPopupMenu> fPopupFourier; ///< popup menu of the MusrFT/Fourier sub menu
// canvas related variables
TCanvas *fMainCanvas; ///< main canvas
TPaveText *fTitlePad; ///< title pad used to display a title
TPad *fFourierPad; ///< fourier pad used to display the fourier
TLegend *fInfoPad; ///< info pad used to display a legend of the data plotted
TLegend *fLegAvgPerDataSet; ///< legend used for averaged per data set view
std::unique_ptr<TCanvas> fMainCanvas; ///< main canvas
std::unique_ptr<TPaveText> fTitlePad; ///< title pad used to display a title
std::unique_ptr<TPad> fFourierPad; ///< fourier pad used to display the fourier
std::unique_ptr<TLegend> fInfoPad; ///< info pad used to display a legend of the data plotted
std::unique_ptr<TLegend> fLegAvgPerDataSet; ///< legend used for averaged per data set view
virtual void CreateXaxisTitle();
virtual void CreateStyle();

View File

@ -1540,7 +1540,7 @@ Int_t main(Int_t argc, Char_t *argv[])
}
// check that everything is ok
if (ok)
app.Run(true); // true needed that Run will return after quit so that cleanup works
app.Run();
}
return PMUSR_SUCCESS;