replaced raw pointers by smart pointers for dump_header.cpp.
This commit is contained in:
parent
bad6812b2b
commit
4d52fa778b
@ -43,6 +43,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
@ -145,16 +146,16 @@ int dump_header_root(const std::string fileName, const bool summary, const bool
|
|||||||
fileType = DH_LEM_ROOT;
|
fileType = DH_LEM_ROOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
TMusrRunHeader *header{nullptr};
|
std::unique_ptr<TMusrRunHeader> header;
|
||||||
bool ok;
|
bool ok;
|
||||||
Int_t ival;
|
Int_t ival;
|
||||||
|
|
||||||
if (fileType == DH_LEM_ROOT) { // ROOT (LEM)
|
if (fileType == DH_LEM_ROOT) { // ROOT (LEM)
|
||||||
// read header and check if some missing run info need to be fed
|
// read header and check if some missing run info need to be fed
|
||||||
TLemRunHeader *runHeader = dynamic_cast<TLemRunHeader*>(folder->FindObjectAny("TLemRunHeader"));
|
TLemRunHeader* runHeader = dynamic_cast<TLemRunHeader*>(folder->FindObjectAny("TLemRunHeader"));
|
||||||
|
|
||||||
// check if run header is valid
|
// check if run header is valid
|
||||||
if (!runHeader) {
|
if (runHeader == nullptr) {
|
||||||
std::cerr << std::endl << "**ERROR** Couldn't obtain run header info from ROOT file " << fileName << std::endl;
|
std::cerr << std::endl << "**ERROR** Couldn't obtain run header info from ROOT file " << fileName << std::endl;
|
||||||
f.Close();
|
f.Close();
|
||||||
return 1;
|
return 1;
|
||||||
@ -197,12 +198,10 @@ int dump_header_root(const std::string fileName, const bool summary, const bool
|
|||||||
std::cout << std::endl << "First Good Bin : " << timeZero[0];
|
std::cout << std::endl << "First Good Bin : " << timeZero[0];
|
||||||
std::cout << std::endl << "Last Good Bin : " << runHeader->GetNChannels()-1;
|
std::cout << std::endl << "Last Good Bin : " << runHeader->GetNChannels()-1;
|
||||||
std::cout << std::endl << "-------------------" << std::endl << std::endl;
|
std::cout << std::endl << "-------------------" << std::endl << std::endl;
|
||||||
|
|
||||||
delete runHeader;
|
|
||||||
} else { // MusrRoot
|
} else { // MusrRoot
|
||||||
// invoke the MusrRoot header object
|
// invoke the MusrRoot header object
|
||||||
header = new TMusrRunHeader(fileName.c_str(), true); // read quite
|
header = std::unique_ptr<TMusrRunHeader>(new TMusrRunHeader(fileName.c_str(), true)); // read quite
|
||||||
if (header == 0) {
|
if (header == nullptr) {
|
||||||
std::cerr << std::endl << "**ERROR** Couldn't invoke MusrRoot RunHeader in file:" << fileName;
|
std::cerr << std::endl << "**ERROR** Couldn't invoke MusrRoot RunHeader in file:" << fileName;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
f.Close();
|
f.Close();
|
||||||
@ -306,9 +305,6 @@ int dump_header_root(const std::string fileName, const bool summary, const bool
|
|||||||
|
|
||||||
f.Close();
|
f.Close();
|
||||||
|
|
||||||
if (header)
|
|
||||||
delete header;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,7 +320,7 @@ int dump_header_root(const std::string fileName, const bool summary, const bool
|
|||||||
int dump_header_nexus(const std::string fileName, const bool counts) {
|
int dump_header_nexus(const std::string fileName, const bool counts) {
|
||||||
|
|
||||||
#ifdef PNEXUS_ENABLED
|
#ifdef PNEXUS_ENABLED
|
||||||
PNeXus *nxs_file = new PNeXus(fileName.c_str());
|
std::unique_ptr<PNeXus> nxs_file = std::unique_ptr<PNeXus>(new PNeXus(fileName.c_str()));
|
||||||
|
|
||||||
if (nxs_file == nullptr) {
|
if (nxs_file == nullptr) {
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
@ -341,9 +337,6 @@ int dump_header_nexus(const std::string fileName, const bool counts) {
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nxs_file)
|
|
||||||
delete nxs_file;
|
|
||||||
#else
|
#else
|
||||||
std::cout << std::endl << "NeXus not enabled, hence the header information cannot be dumped." << std::endl << std::endl;
|
std::cout << std::endl << "NeXus not enabled, hence the header information cannot be dumped." << std::endl << std::endl;
|
||||||
#endif
|
#endif
|
||||||
@ -937,40 +930,22 @@ int main(int argc, char *argv[])
|
|||||||
// invoke the startup handler in order to get the default search paths to the data files
|
// invoke the startup handler in order to get the default search paths to the data files
|
||||||
// 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 << ">> musrfit **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data();
|
std::cerr << std::endl << ">> musrfit **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)
|
||||||
int status = parseXmlFile(saxParser, startup_path_name);
|
int 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 << ">> musrfit **WARNING** Reading/parsing musrfit_startup.xml failed.";
|
std::cerr << std::endl << ">> musrfit **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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1034,15 +1009,5 @@ int main(int argc, char *argv[])
|
|||||||
dump_header_wkm(pathFln);
|
dump_header_wkm(pathFln);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cleanup
|
|
||||||
if (saxParser) {
|
|
||||||
delete saxParser;
|
|
||||||
saxParser = nullptr;
|
|
||||||
}
|
|
||||||
if (startupHandler) {
|
|
||||||
delete startupHandler;
|
|
||||||
startupHandler = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user