diff --git a/io/io/inc/ROOT/RRawFile.hxx b/io/io/inc/ROOT/RRawFile.hxx index 1107ef76e9de4152b5e5b3d5577e952673c87051..12153c2369dbc6649ea8f742d7641661107d9a33 100644 --- a/io/io/inc/ROOT/RRawFile.hxx +++ b/io/io/inc/ROOT/RRawFile.hxx @@ -143,7 +143,7 @@ public: virtual std::unique_ptr<RRawFile> Clone() const = 0; /// Factory method that returns a suitable concrete implementation according to the transport in the url - static RRawFile *Create(std::string_view url, ROptions options = ROptions()); + static std::unique_ptr<RRawFile> Create(std::string_view url, ROptions options = ROptions()); /// Returns only the file location, e.g. "server/file" for http://server/file static std::string GetLocation(std::string_view url); /// Returns only the transport protocol in lower case, e.g. "http" for HTTP://server/file diff --git a/io/io/src/RRawFile.cxx b/io/io/src/RRawFile.cxx index f232e79c6aea275acd16b929de0e6b6511de9203..9a7be54206cf2bdef2a7a216a2df056675bd523e 100644 --- a/io/io/src/RRawFile.cxx +++ b/io/io/src/RRawFile.cxx @@ -69,21 +69,21 @@ ROOT::Internal::RRawFile::~RRawFile() delete[] fBufferSpace; } -ROOT::Internal::RRawFile * +std::unique_ptr<ROOT::Internal::RRawFile> ROOT::Internal::RRawFile::Create(std::string_view url, ROptions options) { std::string transport = GetTransport(url); if (transport == "file") { #ifdef _WIN32 - return new RRawFileWin(url, options); + return std::unique_ptr<RRawFile>(new RRawFileWin(url, options)); #else - return new RRawFileUnix(url, options); + return std::unique_ptr<RRawFile>(new RRawFileUnix(url, options)); #endif } if (transport == "http" || transport == "https") { if (TPluginHandler *h = gROOT->GetPluginManager()->FindHandler("ROOT::Internal::RRawFile")) { if (h->LoadPlugin() == 0) { - return reinterpret_cast<RRawFile *>(h->ExecPlugin(2, &url, &options)); + return std::unique_ptr<RRawFile>(reinterpret_cast<RRawFile *>(h->ExecPlugin(2, &url, &options))); } throw std::runtime_error("Cannot load plugin handler for RRawFileDavix"); } diff --git a/io/io/test/RRawFile.cxx b/io/io/test/RRawFile.cxx index cff11ee6859bbf68dbad179fc38b29b50bcd8827..54c953a62a1921492edbde4ee575a3b3c2168302 100644 --- a/io/io/test/RRawFile.cxx +++ b/io/io/test/RRawFile.cxx @@ -80,7 +80,7 @@ public: TEST(RRawFile, Empty) { FileRaii emptyGuard("testEmpty", ""); - std::unique_ptr<RRawFile> f(RRawFile::Create("testEmpty")); + auto f = RRawFile::Create("testEmpty"); EXPECT_TRUE(f->GetFeatures() & RRawFile::kFeatureHasSize); EXPECT_EQ(0u, f->GetSize()); EXPECT_EQ(0u, f->Read(nullptr, 0)); @@ -93,7 +93,7 @@ TEST(RRawFile, Empty) TEST(RRawFile, Basic) { FileRaii basicGuard("testBasic", "foo\nbar"); - std::unique_ptr<RRawFile> f(RRawFile::Create("testBasic")); + auto f = RRawFile::Create("testBasic"); EXPECT_EQ(7u, f->GetSize()); std::string line; EXPECT_TRUE(f->Readln(line)); @@ -106,10 +106,10 @@ TEST(RRawFile, Basic) EXPECT_TRUE(clone->Readln(line)); EXPECT_STREQ("foo", line.c_str()); - std::unique_ptr<RRawFile> f2(RRawFile::Create("NoSuchFile")); + auto f2 = RRawFile::Create("NoSuchFile"); EXPECT_THROW(f2->Readln(line), std::runtime_error); - std::unique_ptr<RRawFile> f3(RRawFile::Create("FiLE://testBasic")); + auto f3 = RRawFile::Create("FiLE://testBasic"); EXPECT_EQ(7u, f3->GetSize()); EXPECT_THROW(RRawFile::Create("://testBasic"), std::runtime_error); @@ -120,7 +120,7 @@ TEST(RRawFile, Basic) TEST(RRawFile, Remote) { #ifdef R__HAS_DAVIX - std::unique_ptr<RRawFile> f(RRawFile::Create("http://root.cern.ch/files/davix.test")); + auto f = RRawFile::Create("http://root.cern.ch/files/davix.test"); std::string line; EXPECT_TRUE(f->Readln(line)); EXPECT_STREQ("Hello, World", line.c_str()); @@ -133,7 +133,7 @@ TEST(RRawFile, Remote) TEST(RRawFile, Readln) { FileRaii linebreakGuard("testLinebreak", "foo\r\none\nline\r\n\r\n"); - std::unique_ptr<RRawFile> f(RRawFile::Create("testLinebreak")); + auto f = RRawFile::Create("testLinebreak"); std::string line; EXPECT_TRUE(f->Readln(line)); EXPECT_STREQ("foo", line.c_str()); @@ -148,7 +148,7 @@ TEST(RRawFile, Readln) TEST(RRawFile, ReadV) { FileRaii readvGuard("test_rawfile_readv", "Hello, World"); - std::unique_ptr<RRawFile> f(RRawFile::Create("test_rawfile_readv")); + auto f = RRawFile::Create("test_rawfile_readv"); char buffer[2]; buffer[0] = buffer[1] = 0; @@ -186,7 +186,7 @@ TEST(RRawFile, ReadDirect) char buffer; RRawFile::ROptions options; options.fBlockSize = 0; - std::unique_ptr<RRawFile> f(RRawFile::Create("testDirect")); + auto f = RRawFile::Create("testDirect"); EXPECT_EQ(0u, f->Read(&buffer, 0)); EXPECT_EQ(1u, f->Read(&buffer, 1)); EXPECT_EQ('a', buffer); @@ -248,7 +248,7 @@ TEST(RRawFile, Mmap) void *region; FileRaii basicGuard("test_rawfile_mmap", "foo"); - std::unique_ptr<RRawFile> f(RRawFile::Create("test_rawfile_mmap")); + auto f = RRawFile::Create("test_rawfile_mmap"); if (!(f->GetFeatures() & RRawFile::kFeatureHasMmap)) return; region = f->Map(2, 1, mapdOffset); diff --git a/tree/ntuple/v7/src/RPageStorageFile.cxx b/tree/ntuple/v7/src/RPageStorageFile.cxx index 200e2aae59e4ad8e6627d8da6cc423c31ff13d32..a5202a00c8b1132d397ac43643bbaa03eae61d75 100644 --- a/tree/ntuple/v7/src/RPageStorageFile.cxx +++ b/tree/ntuple/v7/src/RPageStorageFile.cxx @@ -210,7 +210,7 @@ ROOT::Experimental::Detail::RPageSourceFile::RPageSourceFile(std::string_view nt const RNTupleReadOptions &options) : RPageSourceFile(ntupleName, options) { - fFile = std::unique_ptr<ROOT::Internal::RRawFile>(ROOT::Internal::RRawFile::Create(path)); + fFile = ROOT::Internal::RRawFile::Create(path); R__ASSERT(fFile); fReader = Internal::RMiniFileReader(fFile.get()); } diff --git a/tree/ntuple/v7/test/ntuple_minifile.cxx b/tree/ntuple/v7/test/ntuple_minifile.cxx index 51ebb627c46091f4ef5aafb6e3a2657a65608e43..44b61cb30660ac86c824c1af0fff64b3cd841dd6 100644 --- a/tree/ntuple/v7/test/ntuple_minifile.cxx +++ b/tree/ntuple/v7/test/ntuple_minifile.cxx @@ -48,7 +48,7 @@ TEST(MiniFile, Raw) auto offFooter = writer->WriteNTupleFooter(&footer, 1, 1); writer->Commit(); - auto rawFile = std::unique_ptr<RRawFile>(RRawFile::Create(fileGuard.GetPath())); + auto rawFile = RRawFile::Create(fileGuard.GetPath()); RMiniFileReader reader(rawFile.get()); auto ntuple = reader.GetNTuple("MyNTuple"); EXPECT_EQ(offHeader, ntuple.fSeekHeader); @@ -78,7 +78,7 @@ TEST(MiniFile, Stream) auto offFooter = writer->WriteNTupleFooter(&footer, 1, 1); writer->Commit(); - auto rawFile = std::unique_ptr<RRawFile>(RRawFile::Create(fileGuard.GetPath())); + auto rawFile = RRawFile::Create(fileGuard.GetPath()); RMiniFileReader reader(rawFile.get()); auto ntuple = reader.GetNTuple("MyNTuple"); EXPECT_EQ(offHeader, ntuple.fSeekHeader); @@ -114,7 +114,7 @@ TEST(MiniFile, Proper) auto offFooter = writer->WriteNTupleFooter(&footer, 1, 1); writer->Commit(); - auto rawFile = std::unique_ptr<RRawFile>(RRawFile::Create(fileGuard.GetPath())); + auto rawFile = RRawFile::Create(fileGuard.GetPath()); RMiniFileReader reader(rawFile.get()); auto ntuple = reader.GetNTuple("MyNTuple"); EXPECT_EQ(offHeader, ntuple.fSeekHeader); @@ -154,7 +154,7 @@ TEST(MiniFile, Multi) writer1->Commit(); writer2->Commit(); - auto rawFile = std::unique_ptr<RRawFile>(RRawFile::Create(fileGuard.GetPath())); + auto rawFile = RRawFile::Create(fileGuard.GetPath()); RMiniFileReader reader(rawFile.get()); auto ntuple1 = reader.GetNTuple("FirstNTuple"); EXPECT_EQ(offHeader1, ntuple1.fSeekHeader); @@ -196,7 +196,7 @@ TEST(MiniFile, Failures) writer->WriteNTupleFooter(&footer, 1, 1); writer->Commit(); - auto rawFile = std::unique_ptr<RRawFile>(RRawFile::Create(fileGuard.GetPath())); + auto rawFile = RRawFile::Create(fileGuard.GetPath()); RMiniFileReader reader(rawFile.get()); EXPECT_DEATH(reader.GetNTuple("No such NTiple"), ".*"); }