TTrees not saving out of cpp executable

Hello all,

This is my first time posting so apologies if I have placed this in the wrong section.

Setup: I am running PYTHIA stand-alone (HEp event generator). To drive the PYTHIA software, I have a c++ executable. Inside the c++ executable, I try to load root, generate a root ntuple with the data from PYTHIA, and then save the root ntuple.

The problem: The output root file exists. It has the correct naming conventions. But it has no trees and no data.
root [0]
Attaching file test.root as _file0…

root [1] _file0->ls()
TFile** test.root
TFile* test.root
KEY: TTree Default;1

root [2] Default->Print()
OBJ: TStyle Default Default Style

//Completely empty, if you open in TBrowser there are no trees displayed.

The code: Since this exists inside a larger c++ executable, I’m not sure that you would want to see all the code. I have extracted all the relevant root commands below:

Two quick notes - The output statements shows that I am pushing back numbers into the vector that make sense. And, the TTree-Print() command that I issue near the end of .exe also shows an empty tree…strange?

Thanks very much,

string nametemp = “test.root”;
TFile* file = TFile::Open(nametemp.c_str(),“RECREATE”);
TTree* TreeD = new TTree(“Default”,"");

vector* _mc_px;
_mc_px = new vector();

//these lines (below) inside event loop

cout << endl << "TESTING push back "<< px << endl;
//lines (above) inside event loop

//The tree is empty at this print!


Hello to all,

I have been able to find out more specifics on what the problem is.

It seems I am unable to save branches that are vectors. I am able to save branches that are not vectors. I tried including the lines

#pragma link C++ class vector+;

But this gives me the same results. When I open my output root file and do Tree->Print(), I see the tree, and then all branches that are not vectors. The branches that are vectors do not appear at all.

Thanks very much,


Those lines would need to be included in a linkdef file being passed to rootcint.

For a simple case like that use instead the following line of code early on in your main function:gROOT->ProcessLine("#include <vector>"); which will load the pre-generated dictionary for the vector of simple types.