Thanks again for your great support.
I have an Event class and I’d like to hide the constructor by making it protected. However, at that point I can’t add that Event as a branch in my TTree because it needs a public default constructor. How can I work around this? Which ROOT classes would need to be friended in order for the Event class’s protected/private constructor to be called? I tried to friend TTree, but that didn’t seem to work. My Event class contains a few Header classes as data members and a few TClonesArrays. Do all of the classes that are data members of the Event class need to be-friend TTree? Or do I need a list of classes to friend, like TTree, TBranch, TBranchElement… etc…?
Out of curiosity, why do you want to make the constructor for you object protected?
If you need the default constructor to be protected you can create an public constructor to be used specifically for the I/O ; For this can implement as a public member the constructor:
MyClass(TRootIOCtor *)The type itself can even be customized by
#pragma link C++ ioctortype UserClass1;
You will need to have a public default constructor or a public I/O constructor for all the classes that root I/O will to construct; this includes the top level class (Event in your case), the classes held in a TClonesArray and the classes help by pointer in other classes).
PS. And no there is no ROOT class you can befriend to avoid having to add a public I/O constructor.
Thanks for your reply. Basically, my idea was to hide the constructor from the user and force them to use a factory object to build event classes. My data structure is set up to eventually become a multi-tiered data structure, having a RAW layer of ROOT files and then a “high level” analysis layer of ROOT files that contain events with data members that are calculated from the raw data and linked to via TRefs. I built a base event class, from which the raw event class the and the high level event class are derived, in order to utilize polymorphism and allow people to write some partially generic analysis code. So, I wanted the constructor to be protected (instead of private), so that my derived event classes can access the constructors as needed, and so the user would have to use the factory to create an event class. The whole point really being to improve memory management when we build our data files from out data acquisition systems output. Perhaps this is all overkill… but I hope this code can be around for a while and be useful for the next generation of our experiment, which I plan to be a part of.
So, if I have a constructor with an argument for TRootIOCtor*, what do I do with the pointer that is passed into that constructor? What would a customized io constructor type do?
[quote]So, if I have a constructor with an argument for TRootIOCtor*, what do I do with the pointer that is passed into that constructor? What would a customized io constructor type do? [/quote]The argument is used solely to differentiate this constructor from other constructors and thus the implementation the constructor should ignore the value being passed (which is always zero anyway). The I/O constructor should initialize all the data member to the default value just as a default constructor would do.