switched PMusrT0 where possible to smart pointers.

This commit is contained in:
suter_a 2023-10-21 18:34:55 +02:00
parent 282ed68b61
commit a66a5e3c70
2 changed files with 33 additions and 144 deletions

View File

@ -245,20 +245,11 @@ ClassImpQ(PMusrT0)
PMusrT0::PMusrT0() PMusrT0::PMusrT0()
{ {
fTimeout = 0; fTimeout = 0;
fTimeoutTimer = nullptr;
fValid = false; fValid = false;
fStatus = 0; // default is quit locally fStatus = 0; // default is quit locally
fMainCanvas = nullptr;
fHisto = nullptr;
fData = nullptr;
fBkg = nullptr;
fToDoInfo = nullptr;
fDataAndBkgEnabled = false; fDataAndBkgEnabled = false;
fT0Enabled = false; fT0Enabled = false;
fShowT0DataChannel = false; fShowT0DataChannel = false;
@ -267,13 +258,6 @@ PMusrT0::PMusrT0()
fDataRange[1] = 0; fDataRange[1] = 0;
fBkgRange[0] = 0; fBkgRange[0] = 0;
fBkgRange[1] = 0; fBkgRange[1] = 0;
fT0Line = nullptr;
fT0DataLine = nullptr;
fFirstBkgLine = nullptr;
fLastBkgLine = nullptr;
fFirstDataLine = nullptr;
fLastDataLine = nullptr;
} }
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
@ -287,20 +271,11 @@ PMusrT0::PMusrT0()
PMusrT0::PMusrT0(PMusrT0Data &data) : fMusrT0Data(data) PMusrT0::PMusrT0(PMusrT0Data &data) : fMusrT0Data(data)
{ {
fTimeout = 0; fTimeout = 0;
fTimeoutTimer = nullptr;
fValid = true; fValid = true;
fStatus = 0; // default is quit locally fStatus = 0; // default is quit locally
fMainCanvas = nullptr;
fHisto = nullptr;
fData = nullptr;
fBkg = nullptr;
fToDoInfo = nullptr;
fDataAndBkgEnabled = false; fDataAndBkgEnabled = false;
fT0Enabled = false; fT0Enabled = false;
fShowT0DataChannel = false; fShowT0DataChannel = false;
@ -310,13 +285,6 @@ PMusrT0::PMusrT0(PMusrT0Data &data) : fMusrT0Data(data)
fBkgRange[0] = 0; fBkgRange[0] = 0;
fBkgRange[1] = 0; fBkgRange[1] = 0;
fT0Line = nullptr;
fT0DataLine = nullptr;
fFirstBkgLine = nullptr;
fLastBkgLine = nullptr;
fFirstDataLine = nullptr;
fLastDataLine = nullptr;
// feed necessary objects // feed necessary objects
TString str; TString str;
@ -347,7 +315,7 @@ PMusrT0::PMusrT0(PMusrT0Data &data) : fMusrT0Data(data)
Int_t noOfBins = rawRunData->GetDataBin(histoNo)->size(); Int_t noOfBins = rawRunData->GetDataBin(histoNo)->size();
Double_t start = -0.5; Double_t start = -0.5;
Double_t end = noOfBins - 0.5; // -0.5 is correct since the data start at 0.0 Double_t end = noOfBins - 0.5; // -0.5 is correct since the data start at 0.0
fHisto = new TH1F("fHisto", str.Data(), noOfBins, start, end); fHisto = std::make_unique<TH1F>("fHisto", str.Data(), noOfBins, start, end);
fHisto->SetMarkerStyle(21); fHisto->SetMarkerStyle(21);
fHisto->SetMarkerSize(0.5); fHisto->SetMarkerSize(0.5);
fHisto->SetMarkerColor(TColor::GetColor(0,0,0)); // black fHisto->SetMarkerColor(TColor::GetColor(0,0,0)); // black
@ -382,7 +350,7 @@ PMusrT0::PMusrT0(PMusrT0Data &data) : fMusrT0Data(data)
Int_t noOfBins = rawRunData->GetDataBin(histoNo)->size(); Int_t noOfBins = rawRunData->GetDataBin(histoNo)->size();
Double_t start = -0.5; Double_t start = -0.5;
Double_t end = noOfBins - 0.5; // -0.5 is correct since the data start at 0.0 Double_t end = noOfBins - 0.5; // -0.5 is correct since the data start at 0.0
fHisto = new TH1F("fHisto", str.Data(), noOfBins, start, end); fHisto = std::make_unique<TH1F>("fHisto", str.Data(), noOfBins, start, end);
fHisto->SetMarkerStyle(21); fHisto->SetMarkerStyle(21);
fHisto->SetMarkerSize(0.5); fHisto->SetMarkerSize(0.5);
fHisto->SetMarkerColor(TColor::GetColor(0,0,0)); // black fHisto->SetMarkerColor(TColor::GetColor(0,0,0)); // black
@ -517,7 +485,7 @@ PMusrT0::PMusrT0(PMusrT0Data &data) : fMusrT0Data(data)
} }
// generate canvas etc // generate canvas etc
fMainCanvas = new TCanvas("fMainCanvas", str); fMainCanvas = std::make_unique<TCanvas>("fMainCanvas", str);
fMainCanvas->SetFillColor(TColor::GetColor(255,255,255)); fMainCanvas->SetFillColor(TColor::GetColor(255,255,255));
@ -545,7 +513,7 @@ PMusrT0::PMusrT0(PMusrT0Data &data) : fMusrT0Data(data)
if (fMusrT0Data.GetCmdTag() == PMUSRT0_GET_T0) { if (fMusrT0Data.GetCmdTag() == PMUSRT0_GET_T0) {
str = "please set t0 bin only."; str = "please set t0 bin only.";
fToDoInfo = new TLatex(); fToDoInfo = std::make_unique<TLatex>();
fToDoInfo->SetTextFont(51); fToDoInfo->SetTextFont(51);
fToDoInfo->SetTextSize(0.030); fToDoInfo->SetTextSize(0.030);
fToDoInfo->SetLineWidth(2); fToDoInfo->SetLineWidth(2);
@ -554,7 +522,7 @@ PMusrT0::PMusrT0(PMusrT0Data &data) : fMusrT0Data(data)
} }
if (fMusrT0Data.GetCmdTag() == PMUSRT0_GET_DATA_AND_BKG_RANGE) { if (fMusrT0Data.GetCmdTag() == PMUSRT0_GET_DATA_AND_BKG_RANGE) {
str = "please set data and bkg range."; str = "please set data and bkg range.";
fToDoInfo = new TLatex(); fToDoInfo = std::make_unique<TLatex>();
fToDoInfo->SetTextFont(51); fToDoInfo->SetTextFont(51);
fToDoInfo->SetTextSize(0.030); fToDoInfo->SetTextSize(0.030);
fToDoInfo->SetLineWidth(2); fToDoInfo->SetLineWidth(2);
@ -563,64 +531,6 @@ PMusrT0::PMusrT0(PMusrT0Data &data) : fMusrT0Data(data)
} }
} }
//--------------------------------------------------------------------------
// Destructor
//--------------------------------------------------------------------------
/**
* <p>Destructor.
*/
PMusrT0::~PMusrT0()
{
if (fTimeoutTimer) {
delete fTimeoutTimer;
fTimeoutTimer = nullptr;
}
if (fHisto) {
delete fHisto;
fHisto = nullptr;
}
if (fData) {
delete fData;
fData = nullptr;
}
if (fBkg) {
delete fBkg;
fBkg = nullptr;
}
if (fToDoInfo) {
delete fToDoInfo;
fToDoInfo = nullptr;
}
if (fT0Line) {
delete fT0Line;
fT0Line = nullptr;
}
if (fT0DataLine) {
delete fT0DataLine;
fT0DataLine = nullptr;
}
if (fFirstBkgLine) {
delete fFirstBkgLine;
fFirstBkgLine = nullptr;
}
if (fLastBkgLine) {
delete fLastBkgLine;
fLastBkgLine = nullptr;
}
if (fFirstDataLine) {
delete fFirstDataLine;
fFirstDataLine = nullptr;
}
if (fLastDataLine) {
delete fLastDataLine;
fLastDataLine = nullptr;
}
if (fMainCanvas && (fStatus != 2)) {
delete fMainCanvas;
fMainCanvas = nullptr;
}
}
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Done (SIGNAL) // Done (SIGNAL)
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
@ -724,11 +634,7 @@ void PMusrT0::SetTimeout(Int_t timeout)
if (fTimeout <= 0) if (fTimeout <= 0)
return; return;
if (fTimeoutTimer) { fTimeoutTimer.reset(new TTimer());
delete fTimeoutTimer;
fTimeoutTimer = nullptr;
}
fTimeoutTimer = new TTimer();
fTimeoutTimer->Connect("Timeout()", "PMusrT0", this, "Quit()"); fTimeoutTimer->Connect("Timeout()", "PMusrT0", this, "Quit()");
@ -782,7 +688,7 @@ void PMusrT0::InitT0()
} }
Double_t max = fHisto->GetMaximum(); Double_t max = fHisto->GetMaximum();
fT0Line = new TLine((Double_t)t0Bin, 0.0, (Double_t)t0Bin, max); fT0Line = std::make_unique<TLine>((Double_t)t0Bin, 0.0, (Double_t)t0Bin, max);
fT0Line->SetLineStyle(1); // solid fT0Line->SetLineStyle(1); // solid
fT0Line->SetLineColor(TColor::GetColor(0,255,0)); // green fT0Line->SetLineColor(TColor::GetColor(0,255,0)); // green
fT0Line->SetLineWidth(2); fT0Line->SetLineWidth(2);
@ -815,7 +721,7 @@ void PMusrT0::InitDataAndBkg()
Int_t noOfBins = fDataRange[1]-fDataRange[0]+1; Int_t noOfBins = fDataRange[1]-fDataRange[0]+1;
Double_t start = fDataRange[0] - 0.5; Double_t start = fDataRange[0] - 0.5;
Double_t end = fDataRange[1] + 0.5; Double_t end = fDataRange[1] + 0.5;
fData = new TH1F("fData", "fData", noOfBins, start, end); fData = std::make_unique<TH1F>("fData", "fData", noOfBins, start, end);
fData->SetMarkerStyle(21); fData->SetMarkerStyle(21);
fData->SetMarkerSize(0.5); fData->SetMarkerSize(0.5);
fData->SetMarkerColor(TColor::GetColor(0,0,255)); // blue fData->SetMarkerColor(TColor::GetColor(0,0,255)); // blue
@ -843,7 +749,7 @@ void PMusrT0::InitDataAndBkg()
noOfBins = fBkgRange[1]-fBkgRange[0]+1; noOfBins = fBkgRange[1]-fBkgRange[0]+1;
start = fBkgRange[0] - 0.5; start = fBkgRange[0] - 0.5;
end = fBkgRange[1] + 0.5; end = fBkgRange[1] + 0.5;
fBkg = new TH1F("fBkg", "fBkg", noOfBins, start, end); fBkg = std::make_unique<TH1F>("fBkg", "fBkg", noOfBins, start, end);
fBkg->SetMarkerStyle(21); fBkg->SetMarkerStyle(21);
fBkg->SetMarkerSize(0.5); fBkg->SetMarkerSize(0.5);
fBkg->SetMarkerColor(TColor::GetColor(255,0,0)); // red fBkg->SetMarkerColor(TColor::GetColor(255,0,0)); // red
@ -857,26 +763,26 @@ void PMusrT0::InitDataAndBkg()
Double_t max = fHisto->GetMaximum(); Double_t max = fHisto->GetMaximum();
// data lines // data lines
fFirstDataLine = new TLine(static_cast<Double_t>(fDataRange[0]), 0.0, static_cast<Double_t>(fDataRange[0]), max); fFirstDataLine = std::make_unique<TLine>(static_cast<Double_t>(fDataRange[0]), 0.0, static_cast<Double_t>(fDataRange[0]), max);
fFirstDataLine->SetLineStyle(3); // doted fFirstDataLine->SetLineStyle(3); // doted
fFirstDataLine->SetLineColor(TColor::GetColor(0,0,255)); // blue fFirstDataLine->SetLineColor(TColor::GetColor(0,0,255)); // blue
fFirstDataLine->SetLineWidth(2); fFirstDataLine->SetLineWidth(2);
fFirstDataLine->Draw(); fFirstDataLine->Draw();
fLastDataLine = new TLine(static_cast<Double_t>(fDataRange[1]), 0.0, static_cast<Double_t>(fDataRange[1]), max); fLastDataLine = std::make_unique<TLine>(static_cast<Double_t>(fDataRange[1]), 0.0, static_cast<Double_t>(fDataRange[1]), max);
fLastDataLine->SetLineStyle(3); // doted fLastDataLine->SetLineStyle(3); // doted
fLastDataLine->SetLineColor(TColor::GetColor(0,0,255)); // blue fLastDataLine->SetLineColor(TColor::GetColor(0,0,255)); // blue
fLastDataLine->SetLineWidth(2); fLastDataLine->SetLineWidth(2);
fLastDataLine->Draw(); fLastDataLine->Draw();
// bkg lines // bkg lines
fFirstBkgLine = new TLine(static_cast<Double_t>(fBkgRange[0]), 0.0, static_cast<Double_t>(fBkgRange[0]), max); fFirstBkgLine = std::make_unique<TLine>(static_cast<Double_t>(fBkgRange[0]), 0.0, static_cast<Double_t>(fBkgRange[0]), max);
fFirstBkgLine->SetLineStyle(6); // _..._... fFirstBkgLine->SetLineStyle(6); // _..._...
fFirstBkgLine->SetLineColor(TColor::GetColor(255,0,0)); // red fFirstBkgLine->SetLineColor(TColor::GetColor(255,0,0)); // red
fFirstBkgLine->SetLineWidth(2); fFirstBkgLine->SetLineWidth(2);
fFirstBkgLine->Draw(); fFirstBkgLine->Draw();
fLastBkgLine = new TLine(static_cast<Double_t>(fBkgRange[1]), 0.0, static_cast<Double_t>(fBkgRange[1]), max); fLastBkgLine = std::make_unique<TLine>(static_cast<Double_t>(fBkgRange[1]), 0.0, static_cast<Double_t>(fBkgRange[1]), max);
fLastBkgLine->SetLineStyle(6); // _..._... fLastBkgLine->SetLineStyle(6); // _..._...
fLastBkgLine->SetLineColor(TColor::GetColor(255,0,0)); // red fLastBkgLine->SetLineColor(TColor::GetColor(255,0,0)); // red
fLastBkgLine->SetLineWidth(2); fLastBkgLine->SetLineWidth(2);
@ -898,7 +804,7 @@ void PMusrT0::ShowDataFileT0Channel()
Double_t max = fHisto->GetMaximum(); Double_t max = fHisto->GetMaximum();
if (!fT0DataLine) { if (!fT0DataLine) {
fT0DataLine = new TLine(static_cast<Double_t>(t0Bin), 0.0, static_cast<Double_t>(t0Bin), max); fT0DataLine = std::make_unique<TLine>(static_cast<Double_t>(t0Bin), 0.0, static_cast<Double_t>(t0Bin), max);
fT0DataLine->SetLineStyle(1); // solid fT0DataLine->SetLineStyle(1); // solid
fT0DataLine->SetLineColor(kOrange-3); fT0DataLine->SetLineColor(kOrange-3);
fT0DataLine->SetLineWidth(2); fT0DataLine->SetLineWidth(2);
@ -917,8 +823,7 @@ void PMusrT0::ShowDataFileT0Channel()
void PMusrT0::HideDataFileT0Channel() void PMusrT0::HideDataFileT0Channel()
{ {
if (fT0DataLine) { if (fT0DataLine) {
delete fT0DataLine; fT0DataLine.reset();
fT0DataLine = nullptr;
} }
fMainCanvas->Update(); fMainCanvas->Update();
} }
@ -1036,15 +941,11 @@ void PMusrT0::SetDataFirstChannel()
fFirstDataLine->SetX1(x); fFirstDataLine->SetX1(x);
fFirstDataLine->SetX2(x); fFirstDataLine->SetX2(x);
// recreate data histo
delete fData;
fData = nullptr;
// refill data histo // refill data histo
Int_t noOfBins = fDataRange[1]-fDataRange[0]+1; Int_t noOfBins = fDataRange[1]-fDataRange[0]+1;
Double_t start = fDataRange[0] - 0.5; Double_t start = fDataRange[0] - 0.5;
Double_t end = fDataRange[1] + 0.5; Double_t end = fDataRange[1] + 0.5;
fData = new TH1F("fData", "fData", noOfBins, start, end); fData.reset(new TH1F("fData", "fData", noOfBins, start, end));
fData->SetMarkerStyle(21); fData->SetMarkerStyle(21);
fData->SetMarkerSize(0.5); fData->SetMarkerSize(0.5);
fData->SetMarkerColor(TColor::GetColor(0,0,255)); // blue fData->SetMarkerColor(TColor::GetColor(0,0,255)); // blue
@ -1086,15 +987,11 @@ void PMusrT0::SetDataLastChannel()
fLastDataLine->SetX1(x); fLastDataLine->SetX1(x);
fLastDataLine->SetX2(x); fLastDataLine->SetX2(x);
// recreate data histo
delete fData;
fData = nullptr;
// refill data histo // refill data histo
Int_t noOfBins = fDataRange[1]-fDataRange[0]+1; Int_t noOfBins = fDataRange[1]-fDataRange[0]+1;
Double_t start = fDataRange[0] - 0.5; Double_t start = fDataRange[0] - 0.5;
Double_t end = fDataRange[1] + 0.5; Double_t end = fDataRange[1] + 0.5;
fData = new TH1F("fData", "fData", noOfBins, start, end); fData.reset(new TH1F("fData", "fData", noOfBins, start, end));
fData->SetMarkerStyle(21); fData->SetMarkerStyle(21);
fData->SetMarkerSize(0.5); fData->SetMarkerSize(0.5);
fData->SetMarkerColor(TColor::GetColor(0,0,255)); // blue fData->SetMarkerColor(TColor::GetColor(0,0,255)); // blue
@ -1136,15 +1033,11 @@ void PMusrT0::SetBkgFirstChannel()
fFirstBkgLine->SetX1(x); fFirstBkgLine->SetX1(x);
fFirstBkgLine->SetX2(x); fFirstBkgLine->SetX2(x);
// recreate data histo
delete fBkg;
fBkg = nullptr;
// refill data histo // refill data histo
Int_t noOfBins = fBkgRange[1]-fBkgRange[0]+1; Int_t noOfBins = fBkgRange[1]-fBkgRange[0]+1;
Double_t start = fBkgRange[0] - 0.5; Double_t start = fBkgRange[0] - 0.5;
Double_t end = fBkgRange[1] + 0.5; Double_t end = fBkgRange[1] + 0.5;
fBkg = new TH1F("fBkg", "fBkg", noOfBins, start, end); fBkg.reset(new TH1F("fBkg", "fBkg", noOfBins, start, end));
fBkg->SetMarkerStyle(21); fBkg->SetMarkerStyle(21);
fBkg->SetMarkerSize(0.5); fBkg->SetMarkerSize(0.5);
fBkg->SetMarkerColor(TColor::GetColor(255,0,0)); // red fBkg->SetMarkerColor(TColor::GetColor(255,0,0)); // red
@ -1186,15 +1079,11 @@ void PMusrT0::SetBkgLastChannel()
fLastBkgLine->SetX1(x); fLastBkgLine->SetX1(x);
fLastBkgLine->SetX2(x); fLastBkgLine->SetX2(x);
// recreate data histo
delete fBkg;
fBkg = nullptr;
// refill data histo // refill data histo
Int_t noOfBins = fBkgRange[1]-fBkgRange[0]+1; Int_t noOfBins = fBkgRange[1]-fBkgRange[0]+1;
Double_t start = fBkgRange[0] - 0.5; Double_t start = fBkgRange[0] - 0.5;
Double_t end = fBkgRange[1] + 0.5; Double_t end = fBkgRange[1] + 0.5;
fBkg = new TH1F("fBkg", "fBkg", noOfBins, start, end); fBkg.reset(new TH1F("fBkg", "fBkg", noOfBins, start, end));
fBkg->SetMarkerStyle(21); fBkg->SetMarkerStyle(21);
fBkg->SetMarkerSize(0.5); fBkg->SetMarkerSize(0.5);
fBkg->SetMarkerColor(TColor::GetColor(255,0,0)); // red fBkg->SetMarkerColor(TColor::GetColor(255,0,0)); // red

View File

@ -30,6 +30,8 @@
#ifndef _PMUSRT0_H_ #ifndef _PMUSRT0_H_
#define _PMUSRT0_H_ #define _PMUSRT0_H_
#include <memory>
#include <TObject.h> #include <TObject.h>
#include <TQObject.h> #include <TQObject.h>
#include <TStyle.h> #include <TStyle.h>
@ -122,8 +124,6 @@ class PMusrT0 : public TObject, public TQObject
PMusrT0(); PMusrT0();
PMusrT0(PMusrT0Data &data); PMusrT0(PMusrT0Data &data);
virtual ~PMusrT0();
virtual Bool_t IsValid() { return fValid; } virtual Bool_t IsValid() { return fValid; }
virtual void Done(Int_t status=0); // *SIGNAL* virtual void Done(Int_t status=0); // *SIGNAL*
@ -156,23 +156,23 @@ class PMusrT0 : public TObject, public TQObject
Int_t fT0Estimated; ///< estimated t0 value (in bins) Int_t fT0Estimated; ///< estimated t0 value (in bins)
Bool_t fShowT0DataChannel; Bool_t fShowT0DataChannel;
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
// canvas related variables // canvas related variables
TCanvas *fMainCanvas; ///< main canvas for the graphical user interface std::unique_ptr<TCanvas> fMainCanvas; ///< main canvas for the graphical user interface
TH1F *fHisto; ///< full raw data histogram std::unique_ptr<TH1F> fHisto; ///< full raw data histogram
TH1F *fData; ///< ranged raw data histogram (first good bin, last good bin) std::unique_ptr<TH1F> fData; ///< ranged raw data histogram (first good bin, last good bin)
TH1F *fBkg; ///< histogram starting from 'bkg start' up to 'bkg end' std::unique_ptr<TH1F> fBkg; ///< histogram starting from 'bkg start' up to 'bkg end'
TLatex *fToDoInfo; ///< clear text user instruction string std::unique_ptr<TLatex> fToDoInfo; ///< clear text user instruction string
TLine *fT0Line; ///< line showing the position of t0 std::unique_ptr<TLine> fT0Line; ///< line showing the position of t0
TLine *fT0DataLine; ///< line showing the position of t0 found in the data file std::unique_ptr<TLine> fT0DataLine; ///< line showing the position of t0 found in the data file
TLine *fFirstBkgLine; ///< line showing the start of the background std::unique_ptr<TLine> fFirstBkgLine; ///< line showing the start of the background
TLine *fLastBkgLine; ///< line showing the end of the background std::unique_ptr<TLine> fLastBkgLine; ///< line showing the end of the background
TLine *fFirstDataLine; ///< line showing the start of the data (first good data bin) std::unique_ptr<TLine> fFirstDataLine; ///< line showing the start of the data (first good data bin)
TLine *fLastDataLine; ///< line showing the end of the data (last good data bin) std::unique_ptr<TLine> fLastDataLine; ///< line showing the end of the data (last good data bin)
Int_t fPx; ///< x-position of the cursor Int_t fPx; ///< x-position of the cursor
Int_t fPy; ///< y-position of the cursor Int_t fPy; ///< y-position of the cursor