Skip to content
Snippets Groups Projects
Commit badc7ba4 authored by Jakob Blomer's avatar Jakob Blomer Committed by Philippe Canal
Browse files

[rawfile] return unique pointer from Create()

parent 71c42aca
No related branches found
No related tags found
No related merge requests found
...@@ -143,7 +143,7 @@ public: ...@@ -143,7 +143,7 @@ public:
virtual std::unique_ptr<RRawFile> Clone() const = 0; virtual std::unique_ptr<RRawFile> Clone() const = 0;
/// Factory method that returns a suitable concrete implementation according to the transport in the url /// 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 /// Returns only the file location, e.g. "server/file" for http://server/file
static std::string GetLocation(std::string_view url); static std::string GetLocation(std::string_view url);
/// Returns only the transport protocol in lower case, e.g. "http" for HTTP://server/file /// Returns only the transport protocol in lower case, e.g. "http" for HTTP://server/file
......
...@@ -69,21 +69,21 @@ ROOT::Internal::RRawFile::~RRawFile() ...@@ -69,21 +69,21 @@ ROOT::Internal::RRawFile::~RRawFile()
delete[] fBufferSpace; delete[] fBufferSpace;
} }
ROOT::Internal::RRawFile * std::unique_ptr<ROOT::Internal::RRawFile>
ROOT::Internal::RRawFile::Create(std::string_view url, ROptions options) ROOT::Internal::RRawFile::Create(std::string_view url, ROptions options)
{ {
std::string transport = GetTransport(url); std::string transport = GetTransport(url);
if (transport == "file") { if (transport == "file") {
#ifdef _WIN32 #ifdef _WIN32
return new RRawFileWin(url, options); return std::unique_ptr<RRawFile>(new RRawFileWin(url, options));
#else #else
return new RRawFileUnix(url, options); return std::unique_ptr<RRawFile>(new RRawFileUnix(url, options));
#endif #endif
} }
if (transport == "http" || transport == "https") { if (transport == "http" || transport == "https") {
if (TPluginHandler *h = gROOT->GetPluginManager()->FindHandler("ROOT::Internal::RRawFile")) { if (TPluginHandler *h = gROOT->GetPluginManager()->FindHandler("ROOT::Internal::RRawFile")) {
if (h->LoadPlugin() == 0) { 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"); throw std::runtime_error("Cannot load plugin handler for RRawFileDavix");
} }
......
...@@ -80,7 +80,7 @@ public: ...@@ -80,7 +80,7 @@ public:
TEST(RRawFile, Empty) TEST(RRawFile, Empty)
{ {
FileRaii emptyGuard("testEmpty", ""); FileRaii emptyGuard("testEmpty", "");
std::unique_ptr<RRawFile> f(RRawFile::Create("testEmpty")); auto f = RRawFile::Create("testEmpty");
EXPECT_TRUE(f->GetFeatures() & RRawFile::kFeatureHasSize); EXPECT_TRUE(f->GetFeatures() & RRawFile::kFeatureHasSize);
EXPECT_EQ(0u, f->GetSize()); EXPECT_EQ(0u, f->GetSize());
EXPECT_EQ(0u, f->Read(nullptr, 0)); EXPECT_EQ(0u, f->Read(nullptr, 0));
...@@ -93,7 +93,7 @@ TEST(RRawFile, Empty) ...@@ -93,7 +93,7 @@ TEST(RRawFile, Empty)
TEST(RRawFile, Basic) TEST(RRawFile, Basic)
{ {
FileRaii basicGuard("testBasic", "foo\nbar"); FileRaii basicGuard("testBasic", "foo\nbar");
std::unique_ptr<RRawFile> f(RRawFile::Create("testBasic")); auto f = RRawFile::Create("testBasic");
EXPECT_EQ(7u, f->GetSize()); EXPECT_EQ(7u, f->GetSize());
std::string line; std::string line;
EXPECT_TRUE(f->Readln(line)); EXPECT_TRUE(f->Readln(line));
...@@ -106,10 +106,10 @@ TEST(RRawFile, Basic) ...@@ -106,10 +106,10 @@ TEST(RRawFile, Basic)
EXPECT_TRUE(clone->Readln(line)); EXPECT_TRUE(clone->Readln(line));
EXPECT_STREQ("foo", line.c_str()); 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); 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_EQ(7u, f3->GetSize());
EXPECT_THROW(RRawFile::Create("://testBasic"), std::runtime_error); EXPECT_THROW(RRawFile::Create("://testBasic"), std::runtime_error);
...@@ -120,7 +120,7 @@ TEST(RRawFile, Basic) ...@@ -120,7 +120,7 @@ TEST(RRawFile, Basic)
TEST(RRawFile, Remote) TEST(RRawFile, Remote)
{ {
#ifdef R__HAS_DAVIX #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; std::string line;
EXPECT_TRUE(f->Readln(line)); EXPECT_TRUE(f->Readln(line));
EXPECT_STREQ("Hello, World", line.c_str()); EXPECT_STREQ("Hello, World", line.c_str());
...@@ -133,7 +133,7 @@ TEST(RRawFile, Remote) ...@@ -133,7 +133,7 @@ TEST(RRawFile, Remote)
TEST(RRawFile, Readln) TEST(RRawFile, Readln)
{ {
FileRaii linebreakGuard("testLinebreak", "foo\r\none\nline\r\n\r\n"); 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; std::string line;
EXPECT_TRUE(f->Readln(line)); EXPECT_TRUE(f->Readln(line));
EXPECT_STREQ("foo", line.c_str()); EXPECT_STREQ("foo", line.c_str());
...@@ -148,7 +148,7 @@ TEST(RRawFile, Readln) ...@@ -148,7 +148,7 @@ TEST(RRawFile, Readln)
TEST(RRawFile, ReadV) TEST(RRawFile, ReadV)
{ {
FileRaii readvGuard("test_rawfile_readv", "Hello, World"); 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]; char buffer[2];
buffer[0] = buffer[1] = 0; buffer[0] = buffer[1] = 0;
...@@ -186,7 +186,7 @@ TEST(RRawFile, ReadDirect) ...@@ -186,7 +186,7 @@ TEST(RRawFile, ReadDirect)
char buffer; char buffer;
RRawFile::ROptions options; RRawFile::ROptions options;
options.fBlockSize = 0; 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(0u, f->Read(&buffer, 0));
EXPECT_EQ(1u, f->Read(&buffer, 1)); EXPECT_EQ(1u, f->Read(&buffer, 1));
EXPECT_EQ('a', buffer); EXPECT_EQ('a', buffer);
...@@ -248,7 +248,7 @@ TEST(RRawFile, Mmap) ...@@ -248,7 +248,7 @@ TEST(RRawFile, Mmap)
void *region; void *region;
FileRaii basicGuard("test_rawfile_mmap", "foo"); 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)) if (!(f->GetFeatures() & RRawFile::kFeatureHasMmap))
return; return;
region = f->Map(2, 1, mapdOffset); region = f->Map(2, 1, mapdOffset);
......
...@@ -210,7 +210,7 @@ ROOT::Experimental::Detail::RPageSourceFile::RPageSourceFile(std::string_view nt ...@@ -210,7 +210,7 @@ ROOT::Experimental::Detail::RPageSourceFile::RPageSourceFile(std::string_view nt
const RNTupleReadOptions &options) const RNTupleReadOptions &options)
: RPageSourceFile(ntupleName, 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); R__ASSERT(fFile);
fReader = Internal::RMiniFileReader(fFile.get()); fReader = Internal::RMiniFileReader(fFile.get());
} }
......
...@@ -48,7 +48,7 @@ TEST(MiniFile, Raw) ...@@ -48,7 +48,7 @@ TEST(MiniFile, Raw)
auto offFooter = writer->WriteNTupleFooter(&footer, 1, 1); auto offFooter = writer->WriteNTupleFooter(&footer, 1, 1);
writer->Commit(); writer->Commit();
auto rawFile = std::unique_ptr<RRawFile>(RRawFile::Create(fileGuard.GetPath())); auto rawFile = RRawFile::Create(fileGuard.GetPath());
RMiniFileReader reader(rawFile.get()); RMiniFileReader reader(rawFile.get());
auto ntuple = reader.GetNTuple("MyNTuple"); auto ntuple = reader.GetNTuple("MyNTuple");
EXPECT_EQ(offHeader, ntuple.fSeekHeader); EXPECT_EQ(offHeader, ntuple.fSeekHeader);
...@@ -78,7 +78,7 @@ TEST(MiniFile, Stream) ...@@ -78,7 +78,7 @@ TEST(MiniFile, Stream)
auto offFooter = writer->WriteNTupleFooter(&footer, 1, 1); auto offFooter = writer->WriteNTupleFooter(&footer, 1, 1);
writer->Commit(); writer->Commit();
auto rawFile = std::unique_ptr<RRawFile>(RRawFile::Create(fileGuard.GetPath())); auto rawFile = RRawFile::Create(fileGuard.GetPath());
RMiniFileReader reader(rawFile.get()); RMiniFileReader reader(rawFile.get());
auto ntuple = reader.GetNTuple("MyNTuple"); auto ntuple = reader.GetNTuple("MyNTuple");
EXPECT_EQ(offHeader, ntuple.fSeekHeader); EXPECT_EQ(offHeader, ntuple.fSeekHeader);
...@@ -114,7 +114,7 @@ TEST(MiniFile, Proper) ...@@ -114,7 +114,7 @@ TEST(MiniFile, Proper)
auto offFooter = writer->WriteNTupleFooter(&footer, 1, 1); auto offFooter = writer->WriteNTupleFooter(&footer, 1, 1);
writer->Commit(); writer->Commit();
auto rawFile = std::unique_ptr<RRawFile>(RRawFile::Create(fileGuard.GetPath())); auto rawFile = RRawFile::Create(fileGuard.GetPath());
RMiniFileReader reader(rawFile.get()); RMiniFileReader reader(rawFile.get());
auto ntuple = reader.GetNTuple("MyNTuple"); auto ntuple = reader.GetNTuple("MyNTuple");
EXPECT_EQ(offHeader, ntuple.fSeekHeader); EXPECT_EQ(offHeader, ntuple.fSeekHeader);
...@@ -154,7 +154,7 @@ TEST(MiniFile, Multi) ...@@ -154,7 +154,7 @@ TEST(MiniFile, Multi)
writer1->Commit(); writer1->Commit();
writer2->Commit(); writer2->Commit();
auto rawFile = std::unique_ptr<RRawFile>(RRawFile::Create(fileGuard.GetPath())); auto rawFile = RRawFile::Create(fileGuard.GetPath());
RMiniFileReader reader(rawFile.get()); RMiniFileReader reader(rawFile.get());
auto ntuple1 = reader.GetNTuple("FirstNTuple"); auto ntuple1 = reader.GetNTuple("FirstNTuple");
EXPECT_EQ(offHeader1, ntuple1.fSeekHeader); EXPECT_EQ(offHeader1, ntuple1.fSeekHeader);
...@@ -196,7 +196,7 @@ TEST(MiniFile, Failures) ...@@ -196,7 +196,7 @@ TEST(MiniFile, Failures)
writer->WriteNTupleFooter(&footer, 1, 1); writer->WriteNTupleFooter(&footer, 1, 1);
writer->Commit(); writer->Commit();
auto rawFile = std::unique_ptr<RRawFile>(RRawFile::Create(fileGuard.GetPath())); auto rawFile = RRawFile::Create(fileGuard.GetPath());
RMiniFileReader reader(rawFile.get()); RMiniFileReader reader(rawFile.get());
EXPECT_DEATH(reader.GetNTuple("No such NTiple"), ".*"); EXPECT_DEATH(reader.GetNTuple("No such NTiple"), ".*");
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment