How to read a portion of the array from the chained tree?

Here is a piece of code. My question is there a better way to load the array? Not to store whole array in the memory. I need only to make some piecewise analysis, and to store the whole array in the memory is not a efficient way.

[code]TChain chain(“TREE”);
chain.Add(“Data0.root”);
chain.Add(“Data1.root”);

Int_t N;
chain.SetBranchAddress(“sizeArrayStorage”,&N);
chain.GetEntry(0);

N=2*N; //As there are two chained files
float *T=new float [N];

chain.SetBranchAddress(“T11”,T);
chain.GetEntry(0);[/code]

[quote] My question is there a better way to load the array? Not to store whole array in the memory. I need only to make some piecewise analysis, and to store the whole array in the memory is not a efficient way.[/quote]By definition, the array is always stored as a unit (per entry). If you need to be able to retrieve only portion of the array at a time, you will need to change the way the file is written to spread the content of the array over several TTree entries.

N=2*N; //As there are two chained filesNote that this does not make sense. The array size is ‘per’ entry and when retrieving an entry (in your example you retrieve entry 0 of the file Data0.root) you only read the data for this entry and not the data for all the entries (in all the file of the chain)!!

The usual way of retrieving the data is more like:[code]
Chain chain(“TREE”);
chain.Add(“Data0.root”);
chain.Add(“Data1.root”);

Int_t N;
float T[max_number_element_per_entry];

chain.SetBranchAddress(“sizeArrayStorage”,&N);
chain.SetBranchAddress(“T11”,T);

for(Long64_t entry ; entry < chain.GetEntriesFast(); ++entry) {
chain.GetEntry(entry);
// Use the data for this entry. For example
for(Int_t i = 0; i < N ; ++i ) {
hist->Fill(T11[i]);
}
}[/code]

Cheers,
Philippe.

Thanks for the reply. Would I be right to say the entry is an array of the pointers to the objects?

Also one more question when writing an array should I always include the size?

	tree->Branch("nf",&N,"nf/i");
	tree->Branch("Frequencies",f,"Freq[nf]/D");

I mean is it possible to get the size of the array from the tree which was stored in the file before? I don’t want to store duplicated values for the sizes. I’m trying to add(update) a new branch to the tree with the same size array.

tree->Branch("Frequencies",f,"Freq[stored_value]/D");

[quote]Would I be right to say the entry is an array of the pointers to the objects?[/quote]I am not sure what you mean. Technically this is not true in general (i.e. no array of pointers unless the user data type is defined as an array of pointers). The content of the entry is entirely determined by the user provided branch definition.

[quote]Also one more question when writing an array should I always include the size?[/quote]When using a variable size array (i.e. (“Frequencies”,f,“Freq[nf]/D”); ) you always need to have a branch containing the value of nf (and in this case the information is not duplicated, the ‘Freq’ branch will use the values in the ‘nf’ branch).

[quote]I mean is it possible to get the size of the array from the tree which was stored in the file before? I don’t want to store duplicated values for the sizes. I’m trying to add(update) a new branch to the tree with the same size array.[/quote]If you are adding a branch to an existing tree (remember to call branch->Fill and not tree->Fill) you can re-use existing branches in the new branch’s definition.

Cheers,
Philippe.