diff --git a/tree/ntupleutil/v7/inc/ROOT/RNTupleImporter.hxx b/tree/ntupleutil/v7/inc/ROOT/RNTupleImporter.hxx index bbd0c4a0e91649165b619391cf739aeb0c7f9be2..4974c62b0ad330df73b27c00147dc2548f42a96e 100644 --- a/tree/ntupleutil/v7/inc/ROOT/RNTupleImporter.hxx +++ b/tree/ntupleutil/v7/inc/ROOT/RNTupleImporter.hxx @@ -233,7 +233,8 @@ private: std::unique_ptr<RNTupleModel> fModel; std::unique_ptr<REntry> fEntry; - ROOT::Experimental::RResult<void> SetupDestination(std::string_view destFileName); + static RResult<std::unique_ptr<RNTupleImporter>> + InitDestination(std::unique_ptr<RNTupleImporter> importer, std::string_view destFileName); void ResetSchema(); /// Sets up the connection from TTree branches to RNTuple fields, including initialization of the memory diff --git a/tree/ntupleutil/v7/src/RNTupleImporter.cxx b/tree/ntupleutil/v7/src/RNTupleImporter.cxx index 86d475f15416ca01103e415fa0dc1506abb6ca16..784486baea19653eaf43084298a49df86f0d1217 100644 --- a/tree/ntupleutil/v7/src/RNTupleImporter.cxx +++ b/tree/ntupleutil/v7/src/RNTupleImporter.cxx @@ -98,7 +98,7 @@ ROOT::Experimental::RNTupleImporter::Create(std::string_view sourceFileName, std // If we have IMT enabled, its best use is for parallel page compression importer->fSourceTreePtr->SetImplicitMT(false); - importer->SetupDestination(destFileName); + importer = InitDestination(std::move(importer), destFileName).Unwrap(); return importer; } @@ -113,21 +113,23 @@ ROOT::Experimental::RNTupleImporter::Create(TTree *sourceTree, std::string_view // If we have IMT enabled, its best use is for parallel page compression importer->fSourceTreePtr->SetImplicitMT(false); - importer->SetupDestination(destFileName); + importer = InitDestination(std::move(importer), destFileName).Unwrap(); return importer; } -ROOT::Experimental::RResult<void> ROOT::Experimental::RNTupleImporter::SetupDestination(std::string_view destFileName) +ROOT::Experimental::RResult<std::unique_ptr<ROOT::Experimental::RNTupleImporter>> +ROOT::Experimental::RNTupleImporter::InitDestination(std::unique_ptr<RNTupleImporter> importer, + std::string_view destFileName) { - fDestFileName = destFileName; - fWriteOptions.SetCompression(kDefaultCompressionSettings); - fDestFile = std::unique_ptr<TFile>(TFile::Open(fDestFileName.c_str(), "UPDATE")); - if (!fDestFile || fDestFile->IsZombie()) { - return R__FAIL("cannot open dest file " + std::string(fDestFileName)); + importer->fDestFileName = destFileName; + importer->fWriteOptions.SetCompression(kDefaultCompressionSettings); + importer->fDestFile = std::unique_ptr<TFile>(TFile::Open(importer->fDestFileName.c_str(), "UPDATE")); + if (!importer->fDestFile || importer->fDestFile->IsZombie()) { + return R__FAIL("cannot open dest file " + std::string(importer->fDestFileName)); } - return RResult<void>::Success(); + return importer; } void ROOT::Experimental::RNTupleImporter::ReportSchema()