Skip to content

Add test for attributes#77

Open
undefined-panda wants to merge 1 commit into
root-project:mainfrom
undefined-panda:attributes-test
Open

Add test for attributes#77
undefined-panda wants to merge 1 commit into
root-project:mainfrom
undefined-panda:attributes-test

Conversation

@undefined-panda

Copy link
Copy Markdown
Contributor

Skip write.C for versions that don't support attributes (everything before 6.40) and read.C if binary for attributes doesn't exist.

@jblomer jblomer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle looks good to me. Since we are at it, I think we should make the test slightly more interesting and write three entries, with one attribute attached to the first entry and another attribute attached to the second and third entry.

And then, for a corner case, also test an attribute for an empty RNTuple.

Comment thread structure/attributes/write.C Outdated
#include <ROOT/RNTupleModel.hxx>
#include <ROOT/RNTupleWriteOptions.hxx>
#include <ROOT/RNTupleWriter.hxx>
#include <TFile.h>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put in include block after the <ROOT/...> includes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved include block

Comment thread structure/attributes/read.C Outdated
@@ -0,0 +1,70 @@
#include <ROOT/RNTupleReader.hxx>
#include <iostream>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to include block after the ROOT includes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved include block

Comment thread structure/attributes/read.C Outdated
#include <ROOT/RNTupleReader.hxx>
#include <iostream>
#include <ROOT/RVersion.hxx>
using namespace std;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't put using namespace std into new code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed using namespace

Comment thread structure/attributes/read.C Outdated
std::string_view output = "structure.attributes.json") {
#if ROOT_VERSION_CODE < ROOT_VERSION(6, 40, 0)
cout << "Skipped structure/attributes/read.C - ROOT version too old." << endl;
return void();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just

Suggested change
return void();
return;

(or actually nothing at all, since the rest of the code is behind preprocessor guards)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed return

Comment thread structure/attributes/read.C Outdated
Comment on lines +53 to +55
for (auto idx : reader->GetEntryRange()) {
for (auto attrIdx : attrSet->GetAttributes()) {
attrSet->LoadEntry(attrIdx, *attrEntry);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prints all attributes for all entries in the main RNTuple. That's probably not what we want, also in light of Jakob's comment to have multiple attribute entries. We also need to print the attribute range(s)

Comment thread structure/attributes/read.C Outdated
os << "}\n";
return;
} catch (const runtime_error &e) {
cout << "Skipped structure/attributes/read.C - " << e.what() << endl;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we handle the case of missing structure.attributes.root more explicitly? That is the only error that I think is permissable, all others should make the test fail.

Comment thread structure/attributes/README.md Outdated
@@ -0,0 +1,3 @@
# Attributes

A RNTuple with a regular field and a attribute field.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please describe at least the attribute name and its field in more detail, similar to the explanations for other tests.

Comment thread structure/attributes/read.C Outdated

void read(std::string_view input = "structure.attributes.root",
std::string_view output = "structure.attributes.json") {
#if ROOT_VERSION_CODE < ROOT_VERSION(6, 40, 0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, please run clang-format on the C++ code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants