switched PRunDataHandler where possible to smart pointers.
This commit is contained in:
parent
890d48a95c
commit
8e7fda92e1
@ -41,6 +41,7 @@
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
|
||||
#include <TROOT.h>
|
||||
#include <TSystem.h>
|
||||
@ -1713,7 +1714,7 @@ Bool_t PRunDataHandler::ReadRootFile()
|
||||
}
|
||||
} else { // MusrRoot file
|
||||
// invoke the MusrRoot header object
|
||||
TMusrRunHeader *header = new TMusrRunHeader(true); // read quite
|
||||
std::unique_ptr<TMusrRunHeader> header = std::make_unique<TMusrRunHeader>(true); // read quiet
|
||||
if (header == nullptr) {
|
||||
std::cerr << std::endl << ">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't invoke MusrRoot RunHeader in file:" << fRunPathName;
|
||||
std::cerr << std::endl;
|
||||
@ -2080,12 +2081,6 @@ Bool_t PRunDataHandler::ReadRootFile()
|
||||
histoData.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// clean up
|
||||
if (header) {
|
||||
delete header;
|
||||
header=nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
f.Close();
|
||||
@ -2122,7 +2117,7 @@ Bool_t PRunDataHandler::ReadNexusFile()
|
||||
Double_t dval;
|
||||
bool ok;
|
||||
|
||||
PNeXus *nxs_file = new PNeXus(fRunPathName.Data());
|
||||
std::unique_ptr<PNeXus> nxs_file = std::make_unique<PNeXus>(fRunPathName.Data());
|
||||
if (!nxs_file->IsValid()) {
|
||||
std::cerr << std::endl << ">> PRunDataHandler::ReadNexusFile(): Not a valid NeXus file.";
|
||||
std::cerr << std::endl << ">> Error Message: " << nxs_file->GetErrorMsg().data() << std::endl;
|
||||
@ -2454,12 +2449,6 @@ Bool_t PRunDataHandler::ReadNexusFile()
|
||||
} else {
|
||||
std::cout << std::endl << ">> PRunDataHandler::ReadNexusFile(): IDF version " << nxs_file->GetIdfVersion() << ", not implemented." << std::endl;
|
||||
}
|
||||
|
||||
// clean up
|
||||
if (nxs_file) {
|
||||
delete nxs_file;
|
||||
nxs_file = nullptr;
|
||||
}
|
||||
#else
|
||||
std::cout << std::endl << ">> PRunDataHandler::ReadNexusFile(): Sorry, not enabled at configuration level, i.e. --enable-NeXus when executing configure" << std::endl << std::endl;
|
||||
#endif
|
||||
@ -4531,7 +4520,7 @@ Bool_t PRunDataHandler::WriteMusrRootFile(TString fln)
|
||||
|
||||
runHeader = gROOT->GetRootFolder()->AddFolder("RunHeader", "MusrRoot Run Header Info");
|
||||
gROOT->GetListOfBrowsables()->Add(runHeader, "RunHeader");
|
||||
TMusrRunHeader *header = new TMusrRunHeader(true);
|
||||
std::unique_ptr<TMusrRunHeader> header = std::make_unique<TMusrRunHeader>(true);
|
||||
gROOT->GetListOfBrowsables()->Add(runHeader, "RunHeader");
|
||||
|
||||
// feed header info
|
||||
@ -4691,7 +4680,7 @@ Bool_t PRunDataHandler::WriteMusrRootFile(TString fln)
|
||||
decayAnaModule->Add(histos[i]);
|
||||
|
||||
// write file
|
||||
TFile *fout = new TFile(fln, "RECREATE", fln);
|
||||
std::unique_ptr<TFile> fout = std::make_unique<TFile>(fln, "RECREATE", fln);
|
||||
if (fout == nullptr) {
|
||||
std::cerr << std::endl << "PRunDataHandler::WriteMusrRootFile(): **ERROR** Couldn't create ROOT file '" << fln << "'" << std::endl;
|
||||
return false;
|
||||
@ -4703,6 +4692,12 @@ Bool_t PRunDataHandler::WriteMusrRootFile(TString fln)
|
||||
histosFolder->Write();
|
||||
fout->Close();
|
||||
|
||||
// cleanup
|
||||
for (UInt_t i=0; i<histos.size(); i++) {
|
||||
if (histos[i])
|
||||
delete histos[i];
|
||||
}
|
||||
|
||||
// check if root file shall be streamed to stdout
|
||||
if (fAny2ManyInfo->useStandardOutput && (fAny2ManyInfo->compressionTag == 0)) {
|
||||
// stream file to stdout
|
||||
@ -4782,7 +4777,7 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln)
|
||||
|
||||
runInfo = gROOT->GetRootFolder()->AddFolder("RunInfo", "LEM RunInfo");
|
||||
gROOT->GetListOfBrowsables()->Add(runInfo, "RunInfo");
|
||||
TLemRunHeader *header = new TLemRunHeader();
|
||||
std::unique_ptr<TLemRunHeader> header = std::make_unique<TLemRunHeader>();
|
||||
gROOT->GetListOfBrowsables()->Add(runInfo, "RunInfo");
|
||||
|
||||
// feed header info
|
||||
@ -4821,7 +4816,7 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln)
|
||||
tt0[i] = dataSet->GetTimeZeroBin()/fAny2ManyInfo->rebin;
|
||||
}
|
||||
header->SetTimeZero(tt0);
|
||||
runInfo->Add(header); // add header to RunInfo folder
|
||||
runInfo->Add(header.get()); // add header to RunInfo folder
|
||||
|
||||
// feed histos
|
||||
std::vector<TH1F*> histos;
|
||||
@ -4875,7 +4870,7 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln)
|
||||
decayAnaModule->Add(histos[i]);
|
||||
|
||||
// write file
|
||||
TFile *fout = new TFile(fln, "RECREATE", fln);
|
||||
std::unique_ptr<TFile> fout = std::make_unique<TFile>(fln, "RECREATE", fln);
|
||||
if (fout == nullptr) {
|
||||
std::cerr << std::endl << "PRunDataHandler::WriteRootFile(): **ERROR** Couldn't create ROOT file '" << fln << "'" << std::endl;
|
||||
return false;
|
||||
@ -4891,9 +4886,7 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln)
|
||||
delete histos[i];
|
||||
}
|
||||
histos.clear();
|
||||
delete fout;
|
||||
delete [] tt0;
|
||||
delete header;
|
||||
|
||||
// check if root file shall be streamed to stdout
|
||||
if (fAny2ManyInfo->useStandardOutput && (fAny2ManyInfo->compressionTag == 0)) {
|
||||
@ -4964,7 +4957,7 @@ Bool_t PRunDataHandler::WriteNexusFile(TString fln)
|
||||
std::cout << std::endl << ">> PRunDataHandler::WriteNexusFile(): writing a NeXus data file (" << fln.Data() << ") ... " << std::endl;
|
||||
|
||||
// create NeXus object
|
||||
PNeXus *nxs = new PNeXus();
|
||||
std::unique_ptr<PNeXus> nxs = std::make_unique<PNeXus>();
|
||||
if (nxs == nullptr) {
|
||||
std::cerr << std::endl << ">> PRunDataHandler::WriteNexusFile(): **ERROR** couldn't invoke the NeXus object." << std::endl;
|
||||
return false;
|
||||
@ -5244,11 +5237,6 @@ Bool_t PRunDataHandler::WriteNexusFile(TString fln)
|
||||
if (fgb) delete [] fgb;
|
||||
if (lgb) delete [] lgb;
|
||||
} else {
|
||||
// clean up
|
||||
if (nxs != 0) {
|
||||
delete nxs;
|
||||
nxs = nullptr;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -5264,20 +5252,11 @@ Bool_t PRunDataHandler::WriteNexusFile(TString fln)
|
||||
else {
|
||||
std::cerr << std::endl << ">> PRunDataHandler::WriteNexusFile(): **ERROR** undefined output NeXus format " << fAny2ManyInfo->outFormat.Data() << " found.";
|
||||
std::cerr << std::endl << ">> Allowed are: hdf4, hdf5, xml" << std::endl;
|
||||
if (nxs != 0) {
|
||||
delete nxs;
|
||||
nxs = nullptr;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// write file
|
||||
nxs->WriteFile(fln, fileType, fAny2ManyInfo->idf);
|
||||
|
||||
if (nxs != 0) {
|
||||
delete nxs;
|
||||
nxs = nullptr;
|
||||
}
|
||||
#else
|
||||
std::cout << std::endl << ">> PRunDataHandler::WriteNexusFile(): Sorry, not enabled at configuration level, i.e. --enable-NeXus when executing configure" << std::endl << std::endl;
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user