diff --git a/src/addRun.cpp b/src/addRun.cpp index 2cf7ea37..7ad8cf6f 100644 --- a/src/addRun.cpp +++ b/src/addRun.cpp @@ -37,6 +37,7 @@ #include #include +#include #include #include @@ -535,40 +536,22 @@ int main(int argc, char *argv[]) // read startup file char startup_path_name[128]; - TSAXParser *saxParser = new TSAXParser(); - PStartupHandler *startupHandler = new PStartupHandler(); + std::unique_ptr saxParser = std::unique_ptr(new TSAXParser()); + std::unique_ptr startupHandler = std::unique_ptr(new PStartupHandler()); if (!startupHandler->StartupFileFound()) { std::cerr << std::endl << ">> addRun **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data(); std::cerr << std::endl; - // clean up - if (saxParser) { - delete saxParser; - saxParser = nullptr; - } - if (startupHandler) { - delete startupHandler; - startupHandler = nullptr; - } } else { strcpy(startup_path_name, startupHandler->GetStartupFilePath().Data()); - saxParser->ConnectToHandler("PStartupHandler", startupHandler); + saxParser->ConnectToHandler("PStartupHandler", startupHandler.get()); //status = saxParser->ParseFile(startup_path_name); // parsing the file as above seems to lead to problems in certain environments; // use the parseXmlFile function instead (see PStartupHandler.cpp for the definition) - status = parseXmlFile(saxParser, startup_path_name); + status = parseXmlFile(saxParser.get(), startup_path_name); // check for parse errors if (status) { // error std::cerr << std::endl << ">> addRun **WARNING** Reading/parsing musrfit_startup.xml failed."; std::cerr << std::endl; - // clean up - if (saxParser) { - delete saxParser; - saxParser = nullptr; - } - if (startupHandler) { - delete startupHandler; - startupHandler = nullptr; - } } else { startupHandler->CheckLists(); } @@ -639,12 +622,12 @@ int main(int argc, char *argv[]) } // load the files - std::vector runDataHandler; + std::vector< std::unique_ptr > runDataHandler; runDataHandler.resize(addRunInfo.size()); Bool_t isGood{true}; for (UInt_t i=0; iGetDataPathList()); + runDataHandler[i] = std::unique_ptr(new PRunDataHandler(addRunInfo[i].fPathFileName, addRunInfo[i].fFileFormat, startupHandler->GetDataPathList())); if (runDataHandler[i] == nullptr) { isGood = false; std::cerr << std::endl; @@ -661,7 +644,7 @@ int main(int argc, char *argv[]) break; } } else { - runDataHandler[i] = new PRunDataHandler(addRunInfo[i].fPathFileName, addRunInfo[i].fFileFormat); + runDataHandler[i] = std::unique_ptr(new PRunDataHandler(addRunInfo[i].fPathFileName, addRunInfo[i].fFileFormat)); if (runDataHandler[i] == nullptr) { isGood = false; std::cerr << std::endl; @@ -683,8 +666,8 @@ int main(int argc, char *argv[]) // make sure that the number of provided t0's are matching the number of histos from the run-file // 1st make sure all the runs have the same number run data (==1 here) - PAny2ManyInfo *info{nullptr}; - PRunDataHandler *dataOut{nullptr}; + std::unique_ptr info; + std::unique_ptr dataOut; if (isGood) { for (UInt_t i=1; iGetNoOfRunData() != runDataHandler[i]->GetNoOfRunData()) { @@ -695,7 +678,7 @@ int main(int argc, char *argv[]) break; } } - info = new PAny2ManyInfo(); + info = std::unique_ptr(new PAny2ManyInfo()); if (info == nullptr) { std::cerr << std::endl; std::cerr << "**ERROR** couldn't invoke PAny2ManyInfo." << std::endl; @@ -709,7 +692,7 @@ int main(int argc, char *argv[]) info->outFormat = format; info->year = year; info->outFileName = flnOut; - dataOut = new PRunDataHandler(info); + dataOut = std::unique_ptr(new PRunDataHandler(info.get())); if (dataOut == nullptr) { std::cerr << std::endl; std::cerr << "**ERROR** couldn't invoke PRunDataHandler for the output file." << std::endl; @@ -812,8 +795,8 @@ int main(int argc, char *argv[]) } // feed all the necessary information for the data file - PRawRunData *rawRunData = new PRawRunData(); - rawRunData = runDataHandler[0]->GetRunData(); // copy all + std::unique_ptr rawRunData = std::unique_ptr(new PRawRunData()); + rawRunData = std::unique_ptr(runDataHandler[0]->GetRunData()); // copy all rawRunData->SetGenerator("addRun"); // overwrite the t0 values with the new ones for (UInt_t i=0; iGetNoOfHistos(); i++) { @@ -825,27 +808,11 @@ int main(int argc, char *argv[]) } // feed run data handler with new data - if (dataOut->SetRunData(rawRunData)) { + if (dataOut->SetRunData(rawRunData.get())) { // write output file dataOut->WriteData(); } } - // clean up - if (startupHandler) { - delete startupHandler; - } - if (info) { - delete info; - } - if (dataOut) { - delete dataOut; - } - for (int i=0; i