From 9ef5c5cac6a00f7727d41e6b94b8f0040b79037a Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Sat, 21 Oct 2023 11:21:27 +0200 Subject: [PATCH] switched PMsrHandler where possible to smart pointers. --- src/classes/PMsrHandler.cpp | 24 +++++------------------- src/include/PMsrHandler.h | 3 ++- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/classes/PMsrHandler.cpp b/src/classes/PMsrHandler.cpp index a1e536eb..258848c2 100644 --- a/src/classes/PMsrHandler.cpp +++ b/src/classes/PMsrHandler.cpp @@ -66,8 +66,6 @@ PMsrHandler::PMsrHandler(const Char_t *fileName, PStartupOptions *startupOptions fStatistic.fMinExpectedPerHisto.clear(); fStatistic.fNdfPerHisto.clear(); - fFuncHandler = nullptr; - // check if the file name given is a path-file-name, and if yes, split it into path and file name. if (fFileName.Contains("/")) { Int_t idx = -1; @@ -99,11 +97,6 @@ PMsrHandler::~PMsrHandler() fStatistic.fMinExpectedPerHisto.clear(); fStatistic.fNdfPerHisto.clear(); fParamInUse.clear(); - - if (fFuncHandler) { - delete fFuncHandler; - fFuncHandler = nullptr; - } } //-------------------------------------------------------------------------- @@ -2941,11 +2934,7 @@ Bool_t PMsrHandler::HandleFunctionsEntry(PMsrLines &lines) fFunctions = lines; // create function handler - fFuncHandler = new PFunctionHandler(fFunctions); - if (fFuncHandler == nullptr) { - std::cerr << std::endl << ">> PMsrHandler::HandleFunctionsEntry: **ERROR** Couldn't invoke PFunctionHandler." << std::endl; - return false; - } + fFuncHandler = std::make_unique(fFunctions); // do the parsing if (!fFuncHandler->DoParse()) { @@ -3545,7 +3534,7 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) } else { PUIntVector group; str = iter->fLine; - PStringNumberList *rl = new PStringNumberList(str.Data()); + std::unique_ptr rl = std::make_unique(str.Data()); std::string errorMsg(""); if (rl->Parse(errorMsg, true)) { group = rl->GetList(); @@ -3555,7 +3544,6 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) } else { error = true; } - delete rl; group.clear(); } } @@ -3570,7 +3558,7 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) } else { PUIntVector group; str = iter->fLine; - PStringNumberList *rl = new PStringNumberList(str.Data()); + std::unique_ptr rl = std::make_unique(str.Data()); std::string errorMsg(""); if (rl->Parse(errorMsg, true)) { group = rl->GetList(); @@ -3580,7 +3568,6 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) } else { error = true; } - delete rl; group.clear(); } } @@ -4634,7 +4621,7 @@ Bool_t PMsrHandler::HandlePlotEntry(PMsrLines &lines) param.fLifeTimeCorrection = true; } else if (line.Contains("runs", TString::kIgnoreCase)) { // handle plot runs TComplex run; - PStringNumberList *rl; + std::unique_ptr rl; std::string errorMsg; PUIntVector runList; switch (param.fPlotType) { @@ -4648,7 +4635,7 @@ Bool_t PMsrHandler::HandlePlotEntry(PMsrLines &lines) case MSR_PLOT_ASYM_RRF: case MSR_PLOT_NON_MUSR: case MSR_PLOT_MU_MINUS: - rl = new PStringNumberList(line.Data()); + rl = std::make_unique(line.Data()); if (!rl->Parse(errorMsg, true)) { std::cerr << std::endl << ">> PMsrHandler::HandlePlotEntry: **SEVERE ERROR** Couldn't tokenize PLOT in line " << iter1->fLineNo; std::cerr << std::endl << ">> Error Message: " << errorMsg; @@ -4662,7 +4649,6 @@ Bool_t PMsrHandler::HandlePlotEntry(PMsrLines &lines) } // clean up runList.clear(); - delete rl; break; default: error = true; diff --git a/src/include/PMsrHandler.h b/src/include/PMsrHandler.h index eff5ca6d..a3c7c10b 100644 --- a/src/include/PMsrHandler.h +++ b/src/include/PMsrHandler.h @@ -31,6 +31,7 @@ #define _PMSRHANDLER_H_ #include +#include #include #include @@ -134,7 +135,7 @@ class PMsrHandler Int_t fMsrBlockCounter; ///< used to select the proper msr-block - PFunctionHandler *fFuncHandler; ///< needed to parse functions + std::unique_ptr fFuncHandler; ///< needed to parse functions PIntVector fParamInUse; ///< array holding the information if a particular parameter is used at all, i.e. if the theory is using it (perhaps via maps or functions)