Dictionary review

Dear all,

I would like to revise the meaning and the use of the dictionary, because after having read all the documentation at my disposal I feel quite confused. So, feel free to complete my observations and correct my mistakes (answering true or false to my statements). As an example consider a custom class MyClass

Statement: dictionary is necessary to access MyClass during an interactive session using the interpreter. I am also supposing that MyClass is NOT inheriting from TObject, and also that I don’t want to use RTTI and I/O feature.

Let’s abandon now the interpreter. From now on, I only refer to compiled programs and libraries.

Statement: dictionary is necessary if MyClass inherits from TObject. Can I have MyClass : public TObject and not to create a dictionary, if I do not want RTTI and I/O? And if I do want?

Statement: dictionary is necessary if I want to store MyClass inside a TCollection. This is a consequence of the previous because I know that only TObject descendent can be stored in a TCollection.

Statement: dictionary is necessary if I want to store MyClass inside a TTree. In this case, is MyClass obliged to inherit from TObject?

As you can see, the core of my questions is always to clearly define the difference between using ROOT as a framework (e.g inheriting from TObject) or simply as a library.

Thank you in advance to all the people who will answer to my question.

Paolo Adragna

Paolo,

A short reply

-you need the dictionary if you want to do I/O or/and use CINT with your class.
-you do not need the dictionary to simply add a MyClass/TObject in a collection.
-you do not need to derive from TObject to store an object in a file, either as a TKey or a TTree (you need 4.00/08 or newer to do so)

Rene

[quote]Statement: dictionary is necessary if MyClass inherits from TObject. Can I have MyClass : public TObject and not to create a dictionary, if I do not want RTTI and I/O? And if I do want?
[/quote]
When deriving from TObject, the dictionary is not per se necessary. The dictionary becomes necessary if and only if you add the ClassDef macro.
Without the ClassDef macro in a class inheriting from TObject, the main consequence is that the return value from “yourobject->IsA()” is incorrect (i.e. it returns TObject::Class). This obviously break the RTTI (and the I/O) for your class.
So to sum-up the answer to these 2 question are repectively: NO and YES.

[quote]Statement: dictionary is necessary if I want to store MyClass inside a TCollection. This is a consequence of the previous because I know that only TObject descendent can be stored in a TCollection.
[/quote]
See previous answer.

Yes

[quote]In this case, is MyClass obliged to inherit from TObject?
[/quote]
No.

Cheers,
Philippe.