Re: How do I make my object "browsable"

From: Axel Naumann <Axel.Naumann_at_cern.ch>
Date: Tue, 25 Mar 2008 16:13:30 +0100


Hi Tobias,

you would need to implement your own version of TParameter with its own Browse method that e.g. creates a histo, fills it, and draws it. You can also call Inspect() from your object's Browse() methods - just give it a try, maybe it does what you want.

Cheers, Axel.

Tobias Raufer wrote:
> Hi Axel & Christian,
>
> Thanks a lot for your quick replies.
>
> I had hoped that this would be a bit simpler. It seems rather cumbersome
> to have to explicitly wrap each data member in a TParameter.
> Nonetheless, it seems to work. I can now see the data members in the
> TBrowser.
>
> One more question: How can I get ROOT to either:
>
> draw the value of the data member in a histogram
>
> or
>
> write out the value to the command line.
>
> I would like on of these actions to be performed when clicking on the
> entry in the browser.
>
> Cheers,
> Tobi
>
>
> -----Original Message-----
> From: Christian Holm Christensen [mailto:cholm_at_nbi.dk]
> Sent: Tue 3/25/2008 12:11
> To: Axel Naumann
> Cc: Tobias Raufer; roottalk_at_cern.ch
> Subject: Re: [ROOT] How do I make my object "browsable"
>
> 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 - 16:13:41 CET

This archive was generated by hypermail 2.2.0 : Wed Mar 26 2008 - 11:50:02 CET