root-project / root

The official repository for ROOT: analyzing, storing and visualizing big data, scientifically
https://root.cern
Other
2.64k stars 1.26k forks source link

Add official support of C++ annotation to specify ROOT IO attribute for data members. #12012

Open pcanal opened 1 year ago

pcanal commented 1 year ago

As seen in https://github.com/cms-sw/cmssw/pull/40435, ROOT I/O annotation can be moved from the comments to using C++ attributes (in particular because support for the comment is implemented internally through the same mechanics).

To quote the referred pull request:

The way dictionary information are propagated from the C++ code or XML dictionaries to reflex and cling is rather roundabout:

This approach does not work well with macro-generated data members:

However, it turns out that dictionaries can bypass the comments and use LLVM annotations directly within the C++ code. So

private:
  int size_;
  float* data_;       //[size_]
  float* transient_;  //!

can be also expressed as

private:
  int size_;
  float* data_ [[clang::annotate("[size_]")]];
  float* transient_ [[clang::annotate("!")]];

and annotations can be generated by macros.

In order to avoid spurious warnings when compiling the header, we should offer a (set of) macro(s), eg:

The advantage of the earlier case would be to (possibly) allow simplification of the internal parsing, by using:

  float* data_ [[rootio::size("size_")]];
  float* transient_ [[rootio::transient]];
Axel-Naumann commented 1 year ago

We should not use the internal names here, but dedicated ROOT I/O attribute names.

If that's not possible then we should at least allow for future cling attributes that are not I/O comments, i.e. some form of scoping of attribute names. (And yes I now see that you already stated that, sorry!)

pcanal commented 1 year ago

If/when we officially support the annotation as input we need to resolve/decide/do-something the potential conflict between the input from comments, selection xml and the annotation.

fwyzard commented 1 year ago

How do you deal now with conflicts between the comments and the xml selection ?

pcanal commented 1 year ago

Currently genreflex (mostly) wins. The comment tag has priority over the comment in the C++ code but the transient and persistent tag do not.

pcanal commented 1 year ago

And for completeness sake's, currently the clang::annotate wins over both.