Re: How do I make my object "browsable"

From: Christian Holm Christensen <cholm_at_nbi.dk>
Date: Tue, 25 Mar 2008 13:11:48 +0100


Hi Toby,

On Tue, 2008-03-25 at 12:13 +0100, Axel Naumann wrote:
> Hi Tobias,
>
> you'll need to re-implement Browse(TBrowser* b). Check e.g. TBranch's version
> which shows a basic example:
> <http://root.cern.ch/root/html/src/TBranch.cxx.html#pV16>

The problem is your int's and double's - they need to be wrapped in an object of a class for which there's a corresponding TClass instance in the ROOT database. Since

	Root> TClass* int_class = gROOT->GetClass("int");
	Root> TClass* double_class = gROOT->GetClass("double");

both returns null pointers, you can add these members directly - perhaps TBrowser should have the member function

	template <typename T>
	void TBrowser::Add(const char* name, const T& v);

for these kind of things.

Anyway, you need, as mentioned, to wrap your int's and double's e.g.,

        class MyClass : public TObject
        {
        public:
          virtual MyClass() { 
            fArray.Delete();
            if (fDoubleWrap) delete fDoubleWrap;
            if (fIntWrap)    delete fIntWrap;
          }
          MyClass() : fArray(0), fDoubleWrap(0), fIntWrap(0) {}
          Bool_t IsFolder() const { return kTRUE; }
          void Browse(TBrowser* b) {
             b->Add(&fArray);
             if (!fDoubleWrap) fDoubleWrap = new TParameter<double>("fDouble", fDouble);
             if (!fIntWrap)    fIntWrap    = new TParameter<int>("fInt", fInt);
             b->Add(fDoubleWrap);
             b->Add(fIntWrap);
          }
        protected:
           int                fInt;
           double             fDouble;
           TClonesArray       fArray;
           TParameter<double> fDoubleWrap; //! Transient
           TParameter<int>    fIntWrap;    //! Transient
        };
        

yours,

-- 
 ___  |  Christian Holm Christensen 
  |_| |  -------------------------------------------------------------
    | |  Address: Sankt Hansgade 23, 1. th.  Phone:  (+45) 35 35 96 91
     _|           DK-2200 Copenhagen N       Cell:   (+45) 24 61 85 91
    _|            Denmark                    Office: (+45) 353  25 447
 ____|   Email:   cholm_at_nbi.dk               Web:    www.nbi.dk/~cholm
 | |
Received on Tue Mar 25 2008 - 13:10:28 CET

This archive was generated by hypermail 2.2.0 : Tue Mar 25 2008 - 17:50:01 CET