Problems with CopyTree


I do have a tree with 34 mil. entries. But with one selection i can reduce the size.
So i tried to use

in a c++ Program to get a part of the tree.
I tried this before in root and it worked. But when i use it in a c++ program I get a segmentation fault.

In RootTalk I found an error what seemed to be similar:
and i loaded my vector class at the beginning but nothing changed.
anyone an idea?

best regards

Please post the shortest possible script reproducing your problem.


#include <iostream>
#include <rootIncludes.h>

//#include <strstream>
#include <sstream>
using namespace std;

int main (int argc, char **argv)

	string inputFileName;

	// TApplication to visualize data during programm run
	TROOT _MakePad("MakePad", "Display ADC data"); // initialise ROOT
	TApplication theApp("App", &argc,argv);

	TFile* file = new TFile(inputFileName.c_str());

	TTree *tree = (TTree*)(file->Get("tree"));

	TTree *newTree = tree->CopyTree("QDC_high[4]");

rootIncludes.h includes all interesting T*.h files.
gSystem->Load(“loadClasses_C”) load a class with a vector of doubles for the tree-structure.

Problem is that this is not a script, but a part of a c+±programm


You do not open/create the output file. Thus the CloneTree is attempting to store the new TTree in the input file which is write only (so things will go wrong … even if they did not, you would at be copying the TTree into memory … and then exit the process losing that work).