Implement customized code in a ROOT file

Hi everyone,

is there a best practice to implement code and header files of self-defined classes in a ROOT file? Using the example of the TMedusa class: How do you save the files TMedusa.cxx and TMedusa.h in the medusa_run78850.root file, so that you have a single file with all required information? I don’t know what keywords to search for - maybe someone can give me a tip?

ROOT Version: any
Platform: any
Compiler: any


Hello,

This is a good question.
A good way to start is this documentation: I/O Concepts - ROOT

One basically needs to construct a dictionary for the class(es) and then ROOT can do everything automatically.

Cheers,
Danilo

@Danilo, I guess the question is whether the ROOTmeta” project (i.e., “RootAnnotator” + “RootExtractor”) approach is the “right way”, or if the ROOT Team knows/provides something better (i.e., for a fully self-contained/self-sufficient ROOT file).

Assuming that you don’t want to have a proper dictionary, but just a backup of which code was used to generate these classes, then the simplest would be to follow:

together with

If you do not like TNamed, you could also use TObjString.

Then, in the TBrowser one can just right-click and dump to print all info.

Thanks for the fast replies!

@Danilo As far as I understand the I/O section, the resulting dictionary would be part of my ROOT installation/software, not the ROOT file. However, I would like to be the dictionary part of may ROOT file so that I don’t need the original .c++/.h files anymore.

@Wile_E_Coyote Yes, something in that direction. I just wonder why the custom classes doesn’t become part of the ROOT file automatically when creating the file. Is this for security reasons, i.e. to prevent code from being executed automatically when a file is opened?

@ferhue Thanks for the appropriate way to store strings in ROOT. Have TNamed and TObjString remained unchanged since the first ROOT version, i.e. can I read them independent of the ROOT version? However, that would be just a naive way to ensure that a ROOT file is re-usable/readable on the long-term since distributing important information across different files carries the risk that some of it may be lost over time.

Yes, the internal data members (relevant for I/O) have not changed probably since 1994 (27 years is the commit log).