Display members of class in TClonesArray in TBrowser

Hi,

I want to create a tree which contains a class as a branch. Class contains TClonesArray member which contains variable number of objects inside.

How to make the members of class stored in TClonesArray visible in the TBrowser?

Here is my code which use to test it:

#include <TObject.h>
#include <TTree.h>
#include <TBranch.h>
#include <TFile.h>
#include <TClonesArray.h>

#include <iostream>

class Test : public TObject
{
public:
        Test() : TObject() { t = 0; }
        void setT(int _t) { t = _t; }
        Int_t getT() const { return t; }
        void print() { std::cout << "t=" << getT() << " at " << this << std::endl; }

        void Clear(Option_t * options = "") {}

private:
        int t;

        ClassDef(Test,1);
};

class Event : public TObject
{
public:
        Event() : TObject()
        {
                cnt = 0;
                data = new TClonesArray("Test", 10);
        }
        virtual ~Event() {}
        void add()
        {
                Test * tt = (Test*) data->ConstructedAt(cnt);
                tt->setT(cnt * 2);
                ++cnt;
                tt->print();
        }
        void print()
        {
                std::cout << "Size of data = " << data->GetEntries() << std::endl;
        }
        void Clear(Option_t * options = "") { data->Clear("C"); cnt = 0; }

private:
        TClonesArray * data;
        Int_t cnt;

        ClassDef(Event,1)
};

ClassImp(Test);
ClassImp(Event);

void cat_test()
{
        TFile * f = TFile::Open("d.root", "RECREATE");
        TTree * t = new TTree("d", "d");
        Event * event = new Event;
        t->Branch("Event", event, 1600, 0);

        event->add();
        event->add();
        event->add();
        event->print();

        t->Fill();
        t->Print();
        event->Clear();

        event->add();
        event->add();
        event->print();

        t->Fill();
        t->Print();
        event->Clear();

        t->Write();
}

int main()
{
        cat_test();
        return 0;
}

Code can be executed using Aclic:
root cat_test.C+

And then inside the root interpreter
d->Draw("Event.data.t")

I would like to be able to exand d->Event->data to see also ->t in the TBrowser.

Regards,
Rafal

Ok, stupid mistake. Setting splitlevel to 2 fixed the problem.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.