Best performance when reading TTree into an array

Hello,

I’m trying to read a fairly large (500 col, 2e6 rows) TTree into an array.
The performance is slower than I’d expect, and I was hoping to get advice on the how to improve performance.

Here is a snippet of code.
The outer loop reads entries.
The inner loop uses the branch names to put the values for that ttree row into the appropriate columns of the array.

Is there a high-performance way of doing this?

thanks for any thoughts on this,
Jesse

P.S. The entries in the ttree are currently a mix of floats and ints, but I could make them all ints if that would help.

P.P.S. Notice that the entries to the array are set using a “set” method.
Unfortunately, I can’t get direct access to the array, and so that is a constraint on any solution.

[code]
for (long iEvent = 0 ; iEvent < nEventsToProcess ; iEvent++)
{
chain->GetEntry(iEvent);
long varCounter = 0;
for (vector::iterator it = varNames.begin ();
it != varNames.end (); ++it)
{
int varValue = (int)chain->GetLeaf(it->c_str())->GetValue();
memData_->set(varCounter,iEvent,varValue);
varCounter ++;

      } // loop over variables
  } // loop over events[/code]

Hi,

Try something like:long nvar = varNames.size(); int *staging = new int[nvar]; long count = 0; for (vector<string>::iterator it = varNames.begin (); it != varNames.end (); ++it, ++count) { chain->SetBranchAddress( it->c_str(), &(staging[count]); } for (long iEvent = 0 ; iEvent < nEventsToProcess ; iEvent++) { chain->GetEntry(iEvent); for(long varCounter = 0; varCounter < nvar; ++varCounter) { memData_->set(varCounter,iEvent,staging[varCounter]); } } chain->ResetBranchAddresses(); delete [] staging; and for maximun performance, you should compile this code (via ACLiC for example).

Cheers,
Philippe.

That’s a great help. Thanks!