Std::bad_alloc

Hello, thank you very much for you last suggestion!
I have another problem :blush:
At the moment I write the new tree on a new file I get the message:

[color=blue]terminate called after throwing an instance of 'std::bad_alloc’
what(): std::bad_alloc
Aborted (core dumped)[/color]

What can I do?

My program is very simple, it opens a chain of files and loops on all the events.
When an event satisfies my
[color=blue]if (//conditions)[/color]
the new tree is filled:
[color=blue]new->Fill(); [/color]

I’m compiling with the command:
[color=blue]c++ name.C -o name.exe root-config --libs --cflags -Wall[/color]

Thank you!
Elena

Hi Elena,

When did you create the output file compare to when you create the output TTree? (Most likely the tree ‘new’ is not associated with a file and fill up you RAM).

Cheers,
Philippe.

Thank you very much Philippe for your reply.
In my program I open a new file just after the loop on the events is finished and try to write my new tree on it using:
[color=blue]newtree->Write(); [/color]
Perhaps the program is written in a too much naive way…
I attach it, if somebody can have a look you are very kind.
Elena
svenTrees.C (21.3 KB)

Hi,

Indeed, you must create/open the file before you call to CloneTree: TFile *f = new TFile("sel8-03_dqcuts_1.root","recreate"); TTree *qt = chain.CloneTree(0);Otherwise you dataset will be fully loaded in memory and this will failed if your machine does not have enough memory.

Cheers,
Philippe.

Thank you very much!
It works fine now!
Elena