Genreflex or rootcint for streamable custom class

Hello,

I want to create a custom class that will have a few standard c++ library types in it as data members (e.g. a few maps, a few vectors). I want this object to be writeable to a root file, and also I want hadd to be able to merge these objects for me. So I know this means I need to implement the Merge method, which I can do.

What is not clear to me is how I should create my class. Should I inherit it from a TObject, TNamed, something else, or nothing at all? Do I need the ClassDef and/or ClassImp? I clearly also need a rootmap file so that my class gets auto-loaded when I use hadd.

There seems to be two ways to make the necessary .so file. genreflex and rootcint. Which one should I be using for this sort of task, I don’t totally understand the advantage or disadavantage? Or even what the differences are?

cheers,
Will

Hi,

The main difference between genreflex and rootcint is the parser used to look at the header file. genreflex uses gcc (outputing a xml file) while rootcint uses CINT. In addition, when using genreflex you will also need the reflex and cintex libraries (which introduces additional run-time penalty).

We recommend to use rootcint (unless your code use C++ feature not supported by CINT).

Technically you do not need to inherit from TObject nor add ClassDef. However we still recommend that you do both as it improve the I/O performance somewhat.

Cheers,
Philippe.

Hi Philippe,

If the dictionary for the custom classes (inside a namespace) were generated with genreflex
(this is what I do within CMSSW), can I still use rootcint + Linkdef.h
to read them back correctly in my compiled analysis program outside of CMSSW?
I’ve not yet managed to make my custom classes known to the analysis program with
genreflex, but with rootcint I can get my analysis going, at least technically.

Thanks a lot,

  • Subir

Hi Subdir,

yes, in most cases the dictionary generated by genreflex and rootcint are functionally equivalent (except for the rootcint dictionary not filling the Reflex database).

Cheers,
Philippe.