Error: invalid conversion from ‘TObject*’ to ‘TObjArray*’

Greetings all,

BEGIN EDIT - Sorry to have bothered you - I have found the solution to the problem.
My original line

TObjArray *tl=LDF->GetListOfBranches()->Clone();

should have read

TObjArray *tl=(TObjArray*)LDF->GetListOfBranches()->Clone();

END EDIT

ORIGINAL POST
This is a follow-on from a post from yesterday http://root.cern.ch/phpBB2/viewtopic.php?t=9729 in which Philippe helped me with accessing and sorting the names of branches in a tree that had been converted from a non-root format.

A short version of my current script is as follows

[code]
#include
#include
#include “TObject.h”
#include “TFile.h”
#include “TTree.h”

void LDFDisp3() {
TString fname= “te122-ti50-c.root”;
TFile* f1=TFile::Open(fname.Data(), “READ” );
TTree LDF = (TTree)f1->Get(“LDF”);
TObjArray *tl=LDF->GetListOfBranches()->Clone();
tl->SetOwner(kFALSE);
tl->Sort();
Int_t nbranch=tl->GetEntries();
cout << Form(“Input file %s has %d branches”, “te122-ti50-c.root”, nbranch) << endl;
}[/code]

The scripts runs without a problem when interpreted, but when I try to compile it I get the following error message

LDFDisp3.C:11: error: invalid conversion from ‘TObject*’ to ‘TObjArray*’

What am I doing wrong to cause this error? How can I resolve it?

Any guidance you can give will be greatly appreciated.[/code]
LDFDisp3.C (444 Bytes)
te122-ti50-c.root (505 KB)

The compiler is right. The result of Clone is a TObject*, so you should replace

TObjArray *tl=LDF->GetListOfBranches()->Clone(); by

TObjArray *tl=(TObjArray*)LDF->GetListOfBranches()->Clone();
However, I do not understand what you want to achieve. If you want to simply sort the list of branches, you only have to do

void LDFDisp3() { TString fname= "te122-ti50-c.root"; TFile* f1=TFile::Open(fname.Data(), "READ" ); TTree *LDF = (TTree*)f1->Get("LDF"); TObjArray *tl = LDF->GetListOfBranches(); tl->Sort(); Int_t nbranch=tl->GetEntries(); cout << Form("Input file %s has %d branches", "te122-ti50-c.root", nbranch) << endl; }

Rene

Dear Rene,

As noted in the related post http://root.cern.ch/phpBB2/viewtopic.php?t=9729

[quote]I have a series of particle detectors and a series of gamma detectors and some devices that relate to gating and timing.

I need to relate events in each of the particle detectors to each of the gamma detectors in ways that relate to their physical locations in the experimental setup and to the concurrent output from the gating and timing devices. In some cases the identifying details, physical locations and detector types changed between experimental runs.

In order to manipulate the data in any branch the script needs to either know each branch’s name or have some form of functional pointer based on the type of information in each branch. Because of changes in setup that were made during the collection of the data I do not have the information necessary to define these relationships a priori.

Without a listing of branches I can’t tell how many branches of each device type I have and I can’t relate branches of different type together. [/quote]

In my original script I was using the syntax that had been suggested by Philippe to achieve my purpose.

Regards