7 #include "TDirectory.h"
12 std::unique_ptr<TH1>
GetClonedTH1(TFile* file, std::string
const& path) {
14 throw std::runtime_error(
FNERROR(
"Supplied ROOT file pointer is null"));
16 TDirectory* backup_dir = gDirectory;
18 bool cur_status = TH1::AddDirectoryStatus();
19 TH1::AddDirectory(kFALSE);
20 TObject *obj = gDirectory->Get(path.c_str());
22 gDirectory = backup_dir;
23 throw std::runtime_error(
24 FNERROR(
"TH1 " + path +
" not found in " + file->GetName()));
26 std::unique_ptr<TH1> res(
27 dynamic_cast<TH1*
>(obj));
28 TH1::AddDirectory(cur_status);
30 gDirectory = backup_dir;
31 throw std::runtime_error(
FNERROR(
"Object " + path +
" in " +
32 file->GetName() +
" is not of type TH1"));
35 gDirectory = backup_dir;
std::unique_ptr< TH1 > GetClonedTH1(TFile *file, std::string const &path)