Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tutorial] How to create ROOT Dictionary for a custom class is a stand-alone C++ project #13205

Merged

Conversation

atolosadelgado
Copy link
Contributor

@atolosadelgado atolosadelgado commented Jul 7, 2023

Hi,

This Pull request:

This PR comes from this forum thread. This tutorial is a minimal working example about how to create a ROOT dictionary for a custom class, and its use for writing and reading a TTree.

Further changes may be needed before full integration into ROOT project.

Changes or fixes:

New folder added, tutorials/tree/dictionary

Checklist:

  • tested changes locally
  • updated the docs (if necessary)

@phsft-bot
Copy link
Collaborator

Can one of the admins verify this patch?

@jalopezg-git
Copy link
Collaborator

Many thanks, @atolosadelgado! This will be reviewed soon!

@github-actions
Copy link

github-actions bot commented Jul 8, 2023

Test Results

       3 files         3 suites   12h 40m 33s ⏱️
2 458 tests 2 457 ✔️ 1 💤 0
6 771 runs  6 771 ✔️ 0 💤 0

Results for commit 49ee1f3.

♻️ This comment has been updated with latest results.

Copy link
Collaborator

@jalopezg-git jalopezg-git left a comment

Choose a reason for hiding this comment

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

Many thanks for the contribution, @atolosadelgado 🙂!

I have attached some comments though to further improve the code in the PR!

tutorials/tree/dictionary/CMakeLists.txt Outdated Show resolved Hide resolved
tutorials/tree/dictionary/CMakeLists.txt Outdated Show resolved Hide resolved
tutorials/tree/dictionary/CMakeLists.txt Outdated Show resolved Hide resolved
tutorials/tree/dictionary/README.md Outdated Show resolved Hide resolved
tutorials/tree/dictionary/README.md Show resolved Hide resolved
tutorials/tree/dictionary/writeTree.cpp Outdated Show resolved Hide resolved
tutorials/tree/dictionary/writeTree.cpp Outdated Show resolved Hide resolved
tutorials/tree/dictionary/writeTree.cpp Outdated Show resolved Hide resolved
tutorials/tree/dictionary/readTree.cpp Outdated Show resolved Hide resolved
tutorials/tree/dictionary/readTree.cpp Outdated Show resolved Hide resolved
atolosadelgado and others added 12 commits July 11, 2023 11:29
Co-authored-by: Javier Lopez-Gomez <javier.lopez.gomez@cern.ch>
Co-authored-by: Javier Lopez-Gomez <javier.lopez.gomez@cern.ch>
Co-authored-by: Javier Lopez-Gomez <javier.lopez.gomez@cern.ch>
Co-authored-by: Javier Lopez-Gomez <javier.lopez.gomez@cern.ch>
Co-authored-by: Javier Lopez-Gomez <javier.lopez.gomez@cern.ch>
Co-authored-by: Javier Lopez-Gomez <javier.lopez.gomez@cern.ch>
Co-authored-by: Javier Lopez-Gomez <javier.lopez.gomez@cern.ch>
Co-authored-by: Javier Lopez-Gomez <javier.lopez.gomez@cern.ch>
@atolosadelgado
Copy link
Contributor Author

Hi,

I implemented most of the changes, but I would need some indications for the rest:

  1. Is there a standard header for ROOT files?
  2. Remove reference in CMakeLists to configure method to configure the ROOT project before building it?
  3. In general, let's also briefly describe here the steps required to read/write user-defined classes, i.e. why ROOT relies on dictionaries for class introspection, how to generate one, etc. Is a link to the ROOT documentation enough? In addition, I am not expert on the topic, I can not expand your points.
  4. std::unique_ptr<TTree> seems to not work. Never used if before, do you have any idea what is failing?

Thank for your time and effort,
Alvaro

@atolosadelgado
Copy link
Contributor Author

Almost there +1! I have included some suggestions to apply before merging! I'll re-request review to @vepadulano and @bellenot.

Also note:

* I didn't see the changes suggested in [this comment](https://github.com/root-project/root/pull/13205#discussion_r1265655686) by @pcanal.

* `clang-format` suggestions will have to be applied before merging.

Hi Javier, thank you for your comments.

If I understood properly, the comment by P. Canal about the dot at the end of the branch name means that it is mandatory in this case to avoid degeneracy, and a good practice in general. For that reason the branch names in this tutorial end with a dot.

Regarding the README file, I have added your suggestion about the linkdef file. Would you add something else?

The files .c and .h now follow the clang-format style.

Copy link
Collaborator

@jalopezg-git jalopezg-git left a comment

Choose a reason for hiding this comment

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

See comment. Also, I guess it builds and works out of the box, right? (didn't test it myself)

Regarding the README file, I have added your suggestion about the linkdef file. Would you add something else?

As a first version, I think it's okay as-is, but let's also see what @vepadulano and @pcanal think.

tutorials/tree/dictionary/writeTree.cxx Outdated Show resolved Hide resolved
@atolosadelgado
Copy link
Contributor Author

See comment. Also, I guess it builds and works out of the box, right? (didn't test it myself)

Regarding the README file, I have added your suggestion about the linkdef file. Would you add something else?

As a first version, I think it's okay as-is, but let's also see what @vepadulano and @pcanal think.

Hi Javier,

I have added some comments in the writeTree.cpp about the final dot in the branch name. In addition, I have added 2 sentences to the README.

Thank you for your patience.
Alvaro

Copy link
Collaborator

@jalopezg-git jalopezg-git left a comment

Choose a reason for hiding this comment

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

I think it's essentially good to go 👍; I stil have to try that it builds and compiles without any issue though!

@vepadulano, @pcanal could you take another look too? If you also think it's ready, we could merge even this week.

@jalopezg-git
Copy link
Collaborator

@phsft-bot build

@phsft-bot
Copy link
Collaborator

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac11/noimt, mac12arm/cxx20, windows10/default
How to customize builds

@phsft-bot
Copy link
Collaborator

Build failed on ROOT-ubuntu2204/nortcxxmod.
Running on root-ubuntu-2204-3.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Copy link
Member

@vepadulano vepadulano left a comment

Choose a reason for hiding this comment

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

Thanks again for this nice work! I think it's a good demonstration of the dictionary capabilities. I left a last minor comment to make a clarification in the doc.

tutorials/tree/dictionary/CMakeLists.txt Outdated Show resolved Hide resolved
@vepadulano
Copy link
Member

One other suggestion that slipped through my review. 45 commits is probably too much for this PR and they should be squashed into one or a few more.

@jalopezg-git
Copy link
Collaborator

One other suggestion that slipped through my review. 45 commits is probably too much for this PR and they should be squashed into one or a few more.

Indeed, we could squash on merge into a single commit; what do you think, @atolosadelgado?

@jalopezg-git
Copy link
Collaborator

@phsft-bot build

@phsft-bot
Copy link
Collaborator

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac11/noimt, mac12arm/cxx20, windows10/default
How to customize builds

@jalopezg-git jalopezg-git self-requested a review August 26, 2023 20:46
Copy link
Collaborator

@jalopezg-git jalopezg-git left a comment

Choose a reason for hiding this comment

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

Many thanks for the contribution! I tried the tutorial and it works without any issue 👍! The PR will be merged after the CI test results are available.

@phsft-bot
Copy link
Collaborator

@jalopezg-git jalopezg-git dismissed bellenot’s stale review August 27, 2023 17:16

Changes were addressed in one of the previous commits. Thanks for the review, Bertrand!

@jalopezg-git jalopezg-git merged commit 4993029 into root-project:master Aug 27, 2023
5 of 13 checks passed
#---Include a CMake module which makes use of the previous variables and loads modules
# with useful macros or functions such as ROOT_GENERATE_DICTIONARY
# For further details: https://root-forum.cern.ch/t/how-to-integrate-root-into-my-project-with-cmake/37175
include(${ROOT_USE_FILE})
Copy link
Collaborator

Choose a reason for hiding this comment

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

This way of including ROOT is a bit outdated, see a more modern way here: https://cliutils.gitlab.io/modern-cmake/chapters/packages/ROOT.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! I think those tips are worth to be included as part of the official ROOT documentation :)

maksgraczyk pushed a commit to maksgraczyk/root that referenced this pull request Jan 12, 2024
…d-alone C++ project (root-project#13205)

Added tutorial that illustrates how to create a ROOT dictionary for a custom class and how
to read/write objects of a user-defined class in `TTree`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants