replaced raw pointers by smart pointers for addRun.cpp.
This commit is contained in:
parent
8f2891c0a7
commit
31761e1eca
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
@ -535,40 +536,22 @@ 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 << ">> addRun **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data();
|
std::cerr << std::endl << ">> addRun **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 << ">> addRun **WARNING** Reading/parsing musrfit_startup.xml failed.";
|
std::cerr << std::endl << ">> addRun **WARNING** Reading/parsing musrfit_startup.xml failed.";
|
||||||
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();
|
||||||
}
|
}
|
||||||
@ -639,12 +622,12 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// load the files
|
// load the files
|
||||||
std::vector<PRunDataHandler*> runDataHandler;
|
std::vector< std::unique_ptr<PRunDataHandler> > runDataHandler;
|
||||||
runDataHandler.resize(addRunInfo.size());
|
runDataHandler.resize(addRunInfo.size());
|
||||||
Bool_t isGood{true};
|
Bool_t isGood{true};
|
||||||
for (UInt_t i=0; i<runDataHandler.size(); i++) {
|
for (UInt_t i=0; i<runDataHandler.size(); i++) {
|
||||||
if (startupHandler != nullptr) {
|
if (startupHandler != nullptr) {
|
||||||
runDataHandler[i] = new PRunDataHandler(addRunInfo[i].fPathFileName, addRunInfo[i].fFileFormat, startupHandler->GetDataPathList());
|
runDataHandler[i] = std::unique_ptr<PRunDataHandler>(new PRunDataHandler(addRunInfo[i].fPathFileName, addRunInfo[i].fFileFormat, startupHandler->GetDataPathList()));
|
||||||
if (runDataHandler[i] == nullptr) {
|
if (runDataHandler[i] == nullptr) {
|
||||||
isGood = false;
|
isGood = false;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
@ -661,7 +644,7 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
runDataHandler[i] = new PRunDataHandler(addRunInfo[i].fPathFileName, addRunInfo[i].fFileFormat);
|
runDataHandler[i] = std::unique_ptr<PRunDataHandler>(new PRunDataHandler(addRunInfo[i].fPathFileName, addRunInfo[i].fFileFormat));
|
||||||
if (runDataHandler[i] == nullptr) {
|
if (runDataHandler[i] == nullptr) {
|
||||||
isGood = false;
|
isGood = false;
|
||||||
std::cerr << std::endl;
|
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
|
// 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)
|
// 1st make sure all the runs have the same number run data (==1 here)
|
||||||
PAny2ManyInfo *info{nullptr};
|
std::unique_ptr<PAny2ManyInfo> info;
|
||||||
PRunDataHandler *dataOut{nullptr};
|
std::unique_ptr<PRunDataHandler> dataOut;
|
||||||
if (isGood) {
|
if (isGood) {
|
||||||
for (UInt_t i=1; i<runDataHandler.size(); i++) {
|
for (UInt_t i=1; i<runDataHandler.size(); i++) {
|
||||||
if (runDataHandler[0]->GetNoOfRunData() != runDataHandler[i]->GetNoOfRunData()) {
|
if (runDataHandler[0]->GetNoOfRunData() != runDataHandler[i]->GetNoOfRunData()) {
|
||||||
@ -695,7 +678,7 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
info = new PAny2ManyInfo();
|
info = std::unique_ptr<PAny2ManyInfo>(new PAny2ManyInfo());
|
||||||
if (info == nullptr) {
|
if (info == nullptr) {
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
std::cerr << "**ERROR** couldn't invoke PAny2ManyInfo." << 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->outFormat = format;
|
||||||
info->year = year;
|
info->year = year;
|
||||||
info->outFileName = flnOut;
|
info->outFileName = flnOut;
|
||||||
dataOut = new PRunDataHandler(info);
|
dataOut = std::unique_ptr<PRunDataHandler>(new PRunDataHandler(info.get()));
|
||||||
if (dataOut == nullptr) {
|
if (dataOut == nullptr) {
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
std::cerr << "**ERROR** couldn't invoke PRunDataHandler for the output file." << 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
|
// feed all the necessary information for the data file
|
||||||
PRawRunData *rawRunData = new PRawRunData();
|
std::unique_ptr<PRawRunData> rawRunData = std::unique_ptr<PRawRunData>(new PRawRunData());
|
||||||
rawRunData = runDataHandler[0]->GetRunData(); // copy all
|
rawRunData = std::unique_ptr<PRawRunData>(runDataHandler[0]->GetRunData()); // copy all
|
||||||
rawRunData->SetGenerator("addRun");
|
rawRunData->SetGenerator("addRun");
|
||||||
// overwrite the t0 values with the new ones
|
// overwrite the t0 values with the new ones
|
||||||
for (UInt_t i=0; i<rawRunData->GetNoOfHistos(); i++) {
|
for (UInt_t i=0; i<rawRunData->GetNoOfHistos(); i++) {
|
||||||
@ -825,27 +808,11 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// feed run data handler with new data
|
// feed run data handler with new data
|
||||||
if (dataOut->SetRunData(rawRunData)) {
|
if (dataOut->SetRunData(rawRunData.get())) {
|
||||||
// write output file
|
// write output file
|
||||||
dataOut->WriteData();
|
dataOut->WriteData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// clean up
|
|
||||||
if (startupHandler) {
|
|
||||||
delete startupHandler;
|
|
||||||
}
|
|
||||||
if (info) {
|
|
||||||
delete info;
|
|
||||||
}
|
|
||||||
if (dataOut) {
|
|
||||||
delete dataOut;
|
|
||||||
}
|
|
||||||
for (int i=0; i<runDataHandler.size(); i++) {
|
|
||||||
if (runDataHandler[i])
|
|
||||||
delete runDataHandler[i];
|
|
||||||
}
|
|
||||||
runDataHandler.clear();
|
|
||||||
|
|
||||||
return PMUSR_SUCCESS;
|
return PMUSR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user