Variable length arrays as leaves

Hi,

I’m currently trying to create a branch which stores variable sized arrays. My problem is that root somehow can’t read the correct values out of the arrays, but just writes some completely random numbers into my leaves. I’ve also tried different ways of dynamically creating my array (as seen below). The code is fully functional when I my array size isn’t variable. Is it just my method or is this kind of branch creation not possible at all? How can I fix this?

[code] Int_t entry = 10;
Int_t *dataT = new Int_t[entry]; //not working

//Int_t *dataT;      //not working
//dataT = (Int_t*) malloc(entry * sizeof(Int_t));

//Int_t dataT[10];  //working

TFile *f = new TFile("TestTree.root", "RECREATE");
TTree *tree = new TTree("TestTree", "Messing around and stuff...");

tree -> Branch("Branch1", &dataT, "dataT[10]/I");

for (int i = 0; i < entry; i++)
	dataT[i] = i;

for(int i=0;i<entry;i++)
	printf("%d\n", dataT[i]);

tree -> Fill();
tree -> Write();[/code]

Thanks in advance!

Hi,

When defining the branch with a leaflist (the /I part), you must pass the address of the data (as opposed to the case where you use an object where you need to pass either the address of pointer or the address of the data).

So use:Int_t entry = 10; Int_t *dataT = new Int_t[entry]; //not working ... tree -> Branch("Branch1", dataT, "dataT[10]/I"); // or &(dataT[0])

Cheers,
Philippe.