replaced raw pointers by smart pointers for musrview.cpp.

This commit is contained in:
suter_a 2023-10-13 12:10:06 +02:00
parent c2a2051d29
commit 2a2e2b40d5

View File

@ -36,6 +36,7 @@
#include <string.h> #include <string.h>
#include <iostream> #include <iostream>
#include <memory>
#include <TApplication.h> #include <TApplication.h>
#include <TSAXParser.h> #include <TSAXParser.h>
@ -199,48 +200,30 @@ int main(int argc, char *argv[])
// read startup file // read startup file
char startup_path_name[128]; char startup_path_name[128];
TSAXParser *saxParser = new TSAXParser(); std::unique_ptr<TSAXParser> saxParser = std::unique_ptr<TSAXParser>(new TSAXParser());
PStartupHandler *startupHandler = new PStartupHandler(); std::unique_ptr<PStartupHandler> startupHandler = std::unique_ptr<PStartupHandler>(new PStartupHandler());
if (!startupHandler->StartupFileFound()) { if (!startupHandler->StartupFileFound()) {
std::cerr << std::endl << ">> musrview **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data(); std::cerr << std::endl << ">> musrview **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data();
std::cerr << std::endl; std::cerr << std::endl;
// clean up
if (saxParser) {
delete saxParser;
saxParser = nullptr;
}
if (startupHandler) {
delete startupHandler;
startupHandler = nullptr;
}
} else { } else {
strcpy(startup_path_name, startupHandler->GetStartupFilePath().Data()); strcpy(startup_path_name, startupHandler->GetStartupFilePath().Data());
saxParser->ConnectToHandler("PStartupHandler", startupHandler); saxParser->ConnectToHandler("PStartupHandler", startupHandler.get());
//status = saxParser->ParseFile(startup_path_name); //status = saxParser->ParseFile(startup_path_name);
// parsing the file as above seems to lead to problems in certain environments; // parsing the file as above seems to lead to problems in certain environments;
// use the parseXmlFile function instead (see PStartupHandler.cpp for the definition) // 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 // check for parse errors
if (status) { // error if (status) { // error
std::cerr << std::endl << ">> musrview **WARNING** Reading/parsing musrfit_startup.xml failed."; std::cerr << std::endl << ">> musrview **WARNING** Reading/parsing musrfit_startup.xml failed.";
std::cerr << std::endl << ">> Any graph will appear with random symbols and colors!"; std::cerr << std::endl << ">> Any graph will appear with random symbols and colors!";
std::cerr << std::endl; std::cerr << std::endl;
// clean up
if (saxParser) {
delete saxParser;
saxParser = nullptr;
}
if (startupHandler) {
delete startupHandler;
startupHandler = nullptr;
}
} else { } else {
startupHandler->CheckLists(); startupHandler->CheckLists();
} }
} }
// read msr-file // read msr-file
PMsrHandler *msrHandler = new PMsrHandler(fileName); std::unique_ptr<PMsrHandler> msrHandler = std::unique_ptr<PMsrHandler>(new PMsrHandler(fileName));
status = msrHandler->ReadMsrFile(); status = msrHandler->ReadMsrFile();
if (status != PMUSR_SUCCESS) { if (status != PMUSR_SUCCESS) {
switch (status) { switch (status) {
@ -277,11 +260,11 @@ int main(int argc, char *argv[])
} }
// read all the necessary runs (raw data) // read all the necessary runs (raw data)
PRunDataHandler *dataHandler; std::unique_ptr<PRunDataHandler> dataHandler;
if (startupHandler) if (startupHandler)
dataHandler = new PRunDataHandler(msrHandler, startupHandler->GetDataPathList()); dataHandler = std::unique_ptr<PRunDataHandler>(new PRunDataHandler(msrHandler.get(), startupHandler->GetDataPathList()));
else else
dataHandler = new PRunDataHandler(msrHandler); dataHandler = std::unique_ptr<PRunDataHandler>(new PRunDataHandler(msrHandler.get()));
dataHandler->ReadData(); dataHandler->ReadData();
@ -292,10 +275,10 @@ int main(int argc, char *argv[])
} }
// generate the necessary histogramms for the view // generate the necessary histogramms for the view
PRunListCollection *runListCollection = nullptr; std::unique_ptr<PRunListCollection> runListCollection;
if (result == PMUSR_SUCCESS) { if (result == PMUSR_SUCCESS) {
// feed all the necessary histogramms for the view // feed all the necessary histogramms for the view
runListCollection = new PRunListCollection(msrHandler, dataHandler, theoAtData); runListCollection = std::unique_ptr<PRunListCollection>(new PRunListCollection(msrHandler.get(), dataHandler.get(), theoAtData));
for (unsigned int i=0; i<msrHandler->GetMsrRunList()->size(); i++) { for (unsigned int i=0; i<msrHandler->GetMsrRunList()->size(); i++) {
// if run is in plotList add it, otherwise go to the next // if run is in plotList add it, otherwise go to the next
runPresent = false; runPresent = false;
@ -356,8 +339,8 @@ int main(int argc, char *argv[])
musrCanvas->SetTimeout(timeout); musrCanvas->SetTimeout(timeout);
// ugly but rootcling cannot handle the spirit-parser framework // ugly but rootcling cannot handle the spirit-parser framework
musrCanvas->SetMsrHandler(msrHandler); musrCanvas->SetMsrHandler(msrHandler.get());
musrCanvas->SetRunListCollection(runListCollection); musrCanvas->SetRunListCollection(runListCollection.get());
musrCanvas->UpdateParamTheoryPad(); musrCanvas->UpdateParamTheoryPad();
musrCanvas->UpdateDataTheoryPad(); musrCanvas->UpdateDataTheoryPad();
@ -406,26 +389,6 @@ int main(int argc, char *argv[])
// clean up // clean up
plotList.clear(); plotList.clear();
if (saxParser) {
delete saxParser;
saxParser = nullptr;
}
if (startupHandler) {
delete startupHandler;
startupHandler = nullptr;
}
if (msrHandler) {
delete msrHandler;
msrHandler = nullptr;
}
if (dataHandler) {
delete dataHandler;
dataHandler = nullptr;
}
if (runListCollection) {
delete runListCollection;
runListCollection = nullptr;
}
return result; return result;
} }