How to optimize memory consumption when reading a tree?

Hi all,

I am trying to read some trees with a compiled script (attached). The code is running without any problems on small files. For the larger files (largest files are ~40 GB), my jobs get cancelled because the maximum resident set size (not quite sure what it means, I am interpreting it as RAM) is 4 GB. I haven’t ever had to worry about the memory usage of my scripts, so this is all very new to me. Can someone look at my script and give me any hints on how to improve the memory usage? Any help is welcome, this topic is very new to me.

Thanks,

Andrea
readTTree.cpp (8.8 KB)


ROOT Version: 6.08/06


Just had a quick look, but I would be suspicious of the TVector3 pointer in the event loop.

Seems to me you don’t need the vector anymore after filling the histograms, yet the way you did it in the attached script means the vector for each (event x array entry) is sticking around in memory way longer than it’s needed.

Deleting after you’re done with it should work, but given the way it’s used, I would make it an object instead.

Cheers,
Afiq

Hi Afiq,

Can you please elaborate on how to remove the TVector3 from memory after filling the histogram?
When you say ‘make it an object instead’, what exactly do you mean? Can you give me an example?

Thanks,
Andrea

Hi Andrea,

In the attached code, line 167, I would change this:

TVector3* v = new TVector3(); v->SetXYZ(m_posx[i], m_posy[i], m_posz[i]);

to

TVector3 v( m_posx[i], m_posy[i], m_posz[i] );

and accordingly update the operators on v in the loop (from v->DoSomething(…) to v.DoSomething(…)). This gets the vector destroyed at the end of its scope (which is at the end of the loop) so it won’t occupy the memory.

Cheers,
Afiq

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