Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions structure/feature_flag/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Unknown feature flag set

An empty RNTuple with feature flag 137 (>62) set in the header. Reading should fail accordingly.
The error message should indicate the feature flag.

A later version of this test should set the flag in the footer.
6 changes: 6 additions & 0 deletions structure/feature_flag/read.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "../read_structure.hxx"

void read(std::string_view input = "structure.feature_flag.root",
std::string_view output = "structure.feature_flag.json") {
read_structure(input, output);
}
49 changes: 49 additions & 0 deletions structure/feature_flag/write.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <ROOT/RField.hxx>
#include <ROOT/RMiniFile.hxx>
#include <ROOT/RNTupleDescriptor.hxx>
#include <ROOT/RNTupleSerialize.hxx>
#include <ROOT/RNTupleWriteOptions.hxx>

#include <memory>
#include <string_view>
#include <utility>

using ROOT::Experimental::RFieldZero;
using ROOT::Experimental::RNTupleDescriptor;
using ROOT::Experimental::RNTupleWriteOptions;
using ROOT::Experimental::Internal::RFieldDescriptorBuilder;
using ROOT::Experimental::Internal::RNTupleDescriptorBuilder;
using ROOT::Experimental::Internal::RNTupleFileWriter;
using ROOT::Experimental::Internal::RNTupleSerializer;

void write(std::string_view filename = "structure.feature_flag.root") {
// Note that we are writing a file with a so-far unused feature flag. This cannot use the regular
// production API but we have to use the internal, low-level classes to create the file.

RNTupleDescriptorBuilder descBuilder;
// The following line will be required as of ROOT v6.36
// descBuilder.SetVersionForWriting();
descBuilder.SetNTuple("ntpl", "");
descBuilder.SetFeature(RNTupleDescriptor::kFeatureFlagTest);
descBuilder.AddField(RFieldDescriptorBuilder::FromField(RFieldZero()).FieldId(0).MakeDescriptor().Unwrap());

RNTupleWriteOptions options;
auto writer =
RNTupleFileWriter::Recreate("ntpl", filename, RNTupleFileWriter::EContainerFormat::kTFile, RNTupleWriteOptions());

RNTupleSerializer serializer;

auto ctx = serializer.SerializeHeader(nullptr, descBuilder.GetDescriptor());
auto buffer = std::make_unique<unsigned char[]>(ctx.GetHeaderSize());
ctx = serializer.SerializeHeader(buffer.get(), descBuilder.GetDescriptor());
writer->WriteNTupleHeader(buffer.get(), ctx.GetHeaderSize(), ctx.GetHeaderSize());

auto szFooter = serializer.SerializeFooter(nullptr, descBuilder.GetDescriptor(), ctx);
buffer = std::make_unique<unsigned char[]>(szFooter);
serializer.SerializeFooter(buffer.get(), descBuilder.GetDescriptor(), ctx);
writer->WriteNTupleFooter(buffer.get(), szFooter, szFooter);

writer->Commit();
// Call destructor to flush data to disk
writer.reset();
}
17 changes: 15 additions & 2 deletions structure/read_structure.hxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <ROOT/REntry.hxx>
#include <ROOT/RError.hxx>
#include <ROOT/RNTupleReader.hxx>

using ROOT::Experimental::RException;
using ROOT::Experimental::RNTupleReader;

#include <cstdint>
Expand All @@ -11,9 +13,20 @@ using ROOT::Experimental::RNTupleReader;

void read_structure(std::string_view input, std::string_view output) {
std::ofstream os(std::string{output});
os << "[\n";

auto reader = RNTupleReader::Open("ntpl", input);
std::unique_ptr<RNTupleReader> reader;
try {
reader = RNTupleReader::Open("ntpl", input);
} catch (const RException &e) {
std::string msgWithoutStacktrace;
std::getline(std::istringstream(e.what()), msgWithoutStacktrace);
os << "{\n";
os << " \"error\": \"" << msgWithoutStacktrace << "\"\n";
os << "}\n";
return;
}

os << "[\n";
auto Int32 =
reader->GetModel().GetDefaultEntry().GetPtr<std::int32_t>("Int32");
bool first = true;
Expand Down