Use hadd with custom classes


ROOT Version: 5.34.34
Platform: Debian
Compiler: g++ 4.9.2


Hi all,

I’m currently struggeling with getting the hadd program to merge classes which contain custom files.
The reason is that I wanted to store my macros sourcecode in the rootfiles. Therefore I created a custom class “TTextFile” which stores file information like last modified timestamp and also the files content of ASCII files.
Because my macro is being run parallel on a cluster, I implemented the “Int_t TTextFile::Merge(TCollection* tc)” function so that only one object is kept during merging. The class is fully compiled to a shared library called “libTTextFile.so” which is stored in a directory that is added to $LD_LIBRARY_PATH during my custom defall.sh script. Furthermore the library is automatically loaded in a rootlogon.C macro so it is always available when I start root.
The class also contains the ClassDef and ClassImp macros and can be written to and read from a file without any problems. The problem is whenever I try to merge two files containing this class with hadd I get the error message “Info in TFileMerger::MergeRecursive: cannot indentify object type (TTextFile)”. I looked up the sourcecode of TFileMerger and figured out that “TClass::GetClass(“TTextFile”)” returns a NULL pointer, so the class cannot be found by the TFileMerger. From the default parameters of TClass::GetClass I figured out that root attempts to load Classes it does’nt find by default, but I don’t know why it cannot load my custom class.

If neccessary I can provide more information on this.
Any help is desired.
Thanks in advance.

Dear Triple_S,

Would you be able to provide a reproducer or more details about your code and workflow?
Also, unless you have a very special reason to work with v5, I would suggest to move to v6, where we can give better support.

G Ganis

1 Like

Hi G Ganis,

thanks for your answer.
I think providing a reproducer will be quite complicated since in my working group we use our very own analysis toolkit based on the root toolkit. This is also the reason I’m still working with v5, because the introduction of C++11 with v6 causes a lot of troubles and at the moment we don’t have the time porting our analysis toolkit completly to v6 and C++11.
I attached the sourcecode.

Maybe this helps, but I think it’s a more general problem.
Spoken naivly I think that root does not “know” that the class TTextFile can be loaded from the libTTextFile.so file and I’m looking for a way to tell root: “If you need the class TTextFile simply load libTTextFile.so”.

Thanks for your help,
Triple_S

ttextfile.cc (3.4 KB)
ttextfile.h (1.1 KB)

OK, I found it out myself.
The problem was that I was missing a .rootmap file in my lib folder which links the classnames with the .so files.
For all having the same problem: The .rootmap file has to be in the same directory where the .so files are located and which is included in the $LD_LIBRARY_PATH variable. Each line corresponds to one entry and reads “Library.: <.so File1> <.so File2> …”
I suggest to add a hint to these information to https://root.cern.ch/merging-customized-classes because it was not easy to find them on the internet.

Dear Triple_S,

Yes, that can explain. I have added some documentation line.
Thanks for reporting and sorry for the inconvenience.

G Ganis

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.