Crash with TTree::Drawing vector<float> in own main program


I have my own main program vecDraw.cxx using ROOT. A simple TTree::Draw crashes for vector, but no problem with vector or vector.

#include <TSystem.h>
#include <TFile.h>
#include <TTree.h>
#include <TROOT.h>
#include <iostream>

using namespace std;

int main(int argc, char** argv)
  //usage information
  if(argc < 4) 
      cout << "Usage: " << argv[0] << " filename treename varname1 varname2" << endl;
      cout << "  or   " << argv[0] << " filename treename varname" << endl;
      cout << "\nEXITING!" << endl;

  const char* filename = argv[1];
  const char* treeName = argv[2];
  const char* var1  = argv[3];
  const char* var2 = 0;
  if (argc > 4) var2  = argv[4];

  // gROOT->ProcessLine("#include <vector>");

  TFile *rfile = TFile::Open(filename);
  TTree *tree = 0;
  if (rfile) {
     tree = (TTree*)rfile->Get(treeName);

     cout << "Drawing " << var1 << endl;
     cout << "After drawing " << var1 << endl;

     if (var2) {
       cout << "Drawing " << var2 << endl;
       cout << "After drawing " << var2 << endl;
  return 0;

If I Draw first any variable other than vetor, the following drawing of vector will already crash.

The root file treeVector.root contains a TTree “tvec” which is composed of branches:
[] nvec: nvec/I [/]
[] vFloat: vector [/]
[] vDouble: vector [/]
[] vInt: vector [/]

I checked the list of gROOT->GetListOfTypes(), and found both types vector and vector, but no vector. However this crash can be removed by adding the following line in my code:

gROOT->ProcessLine("#include <vector>");

Should vector be included automatically in a ROOT main program as for vector and vector?


[quote]Should vector be included automatically in a ROOT main program as for vector and vector?[/quote]No. And a-priori you should not rely on the other two being automatically added either. (I.e. the gROOT->ProcessLine is compulsory in your case).


Dear Philippe,

thanks for the fast reply!

I am afraid I do not fully understand why a

line is necessary to prevent the compiled
program from crashing at runtime, in particular
when the code already has an

statement included. This issue was really tricky to pin down!
Any further explanation would be highly appreciated to
avoid similar pitfalls in the future.



When you have the direct '#include ', the compiler sees it and uses appropriately.
When you use: gROOT->ProcessLine("#include <vector>");then the run-time engine of ROOT and CINT sees it and takes it as instruction to load the library that include the CINT and I/O dictionary for some of the vector instances (vector, vector, etc.). The direct #include ’ can not be seen by the run-time engine of ROOT and CINT and thus does not help forcing the loading of the dictionary.