How to implement Merge(TCollection*) for a user class

Dear all,

after succeeded to write my class deriving from TObject to a file, i found another issue to solve.
(One solution opens a more complicated problem, often :wink:).

I have to hadd many files and of course by default my user class is not handled.
Looking into hadd.cxx i saw that i can implement a Merge(TCollections*) method to sum my class over multiple files. Can you kindly point me to an example to understand “how” i have to implement it ?

thanks!

best,
Max

see examples in TH1::Merge, TEfficiency::Merge, TProfile::Merge, TPolyLine::Merge, TTree::Merge.

Rene

Hi Rene,

thanks! I implemented them but i still get the hadd error

Cannot merge object type, …

Do i need to do something before calling hadd ? Like loading lib dictionary ?

thanks,
Max

Did you create a rootmap file for your class(es)? if not, hadd cannot dynamically link your shared lib.
An alternative for you is to use the class TFileMerger that provides the same functionality as hadd.

Rene

Hi,

i tried with TFileMerger compiling a small C++ code linking my class dictionary.
When i run it, it merges histograms but just copies my class without calling my Merge method.
Am i missing something?

Best,
Max

Hi,

What is the signature of your Merge function? Can you provide a small example reproducing the problem?

Philippe.