Beginner's questions to creating TObject derived classes?

I would like to save some non-Histogram data in a .root file (analysis tags, which cuts were used etc). I found out the way to do this is to make a class that can carry all this data (a string & maybe an array or a vector) and it has to inherit from TObject.

Question: How is this done?

Here’s what I’ve tried:
I created MyObject.h:

#include <TROOT.h>
#include <TObject.h>
class MyObject: public TObject{
  Int_t fMyNumber;

From what I’ve been able to find on the net I then need my own Streamer method to be able to Read() and Write() the file. I found that this could be generated by something like:

But that gives me an error:

Can someone please point me in the right direction or just tell me how to get started on this.


A class derived from TObject must have a ClassDef macro in it:#include <TROOT.h> #include <TObject.h> class MyObject: public TObject{ public: Int_t fMyNumber; ClassDef(MyObject,1); // A value of 1 indicates that this class is streamable. }; When using rootcint you need to tell it that your source is C++ with the -c options, the -f options allows to overwrite any existing source file:rootcint -f Generated.C -c MyObject.h MyLinkDef.hwhere MyLinkDef.h contains:#ifdef __MAKECINT__ #pragma link C++ class MyObject+; #endif.

See the User’s Guide for many more details and explanations on this subject.


It works. Thank you for your help.

For anyone else reading this: Read the chapter “Adding a Class” in the Root Users manual.
And: The code that you final analysis has to include is the one in Generated.C.