Error in <TBufferFile::CheckByteCount> and GCC Compiled Code

Hi,

I am trying to loop over a ROOT file that contains some vector<vector > branches. Since I have a Makefile that I use to generate my code, I decided to use the Embedding the rootcint call into a GNU Makefile prescription to generate a dictionary for this type. However doing so gives me a lot of “Error in TBufferFile::CheckByteCount: object of class vector<vector > read too few bytes: 6 instead of 38” errors. I am using ROOT version 5.30/02 from ATLAS software.

The following is a simple example that demonstrates this problem. Commenting out the loading of the libdict.so gets rid of the error messages, but complains when I try to set the branch address. Also there are no issues when I run this as a macro (ie: root test.C+, where test.C is the same as test.cpp with with a test() function instead of main()). Any suggestions as to what I am doing wrong?

test.cpp

#include <TTree.h>
#include <TLorentzVector.h>
#include <TFile.h>
#include <TSystem.h>

#include <vector>

int main(int argc, char* argv[])
{ 
  gSystem->Load("libdict.so");

  TFile *f=TFile::Open("root://xrddc.mwt2.org:1096/pnfs/uchicago.edu/atlaslocalgroupdisk/data12_8TeV/NTUP_JETMET/f489_m1261_p1344_p1345/data12_8TeV.00214680.physics_Egamma.merge.NTUP_JETMET.f489_m1261_p1344_p1345_tid01148265_00/NTUP_JETMET.01148265._000215.root.1");

  TTree *t=(TTree*)f->Get("qcd");

  std::vector<std::vector<float> > *jet_AntiKt10TrackZ_jvtxfFull=new std::vector<std::vector<float> >();
  t->SetBranchAddress("jet_AntiKt10TrackZ_jvtxfFull",&jet_AntiKt10TrackZ_jvtxfFull);

  for(int i=0;i<1/*t->GetEntries()*/;i++)
    { 
      printf("%d\n",i);
      t->GetEntry(i);
    }
  f->Close();
  return 0;
}

LinkDef.h

// LinkDef.h
#include <vector>
#include <string>
#include <TLorentzVector.h>

#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclasses;

#pragma extra_include "vector";
#pragma extra_include "TLorentzVector.h";

#pragma link C++ class vector< TLorentzVector >;
#pragma link C++ class vector< vector<float> >;
#pragma link C++ class vector<vector<vector<float> > >;
#pragma link C++ class pair< string,string >;

#else 
template class std::vector< TLorentzVector >;
template class std::vector< std::vector<float> >;
template class std::vector<std::vector<std::vector<float> > >
template class std::pair < std::string,std::string >;

#endif

compile.sh (This is what I use to compile and run this example)

#!/bin/bash
rootcint -f dict.cpp -c -I${ROOTSYS}/include -p LinkDef.h
g++ `root-config --cflags --ldflags --libs` -fPIC -g -shared -o libdict.so dict.cpp
g++ `root-config --cflags --ldflags --libs` -fPIC -g -o test test.cpp
./test

Running this gives me the following errors

[kkrizka@uct3-s1 test]$ ./compile.sh
0
Error in <TBufferFile::CheckByteCount>: object of class vector<vector<float> > read too few bytes: 6 instead of 446
Error in <TBufferFile::CheckByteCount>: object of class vector<vector<float> > read too few bytes: 6 instead of 22
Error in <TBufferFile::CheckByteCount>: object of class vector<vector<float> > read too few bytes: 6 instead of 22
Error in <TBufferFile::CheckByteCount>: object of class vector<vector<float> > read too few bytes: 6 instead of 22
...

Try to add to your “main”: [code]// …

#include “TApplication.h”

int main(int argc, char* argv[])
{
TApplication theApp(“My App”, 0, 0); // theApp(“My App”, &argc, argv)

// …[/code]

Thank you for the suggestion, but that did not seem to fix the problem.

Then try this: [code]// …

#include “TApplication.h”
#include “TInterpreter.h”
#include “TSystem.h”

int main(int argc, char* argv[])
{
TApplication theApp(“My App”, 0, 0); // theApp(“My App”, &argc, argv)

if (!(gInterpreter->IsLoaded(“vector”)))
gInterpreter->ProcessLine("#include ");
gSystem->Exec(“rm -f AutoDictvectorvectorfloat”);
gInterpreter->GenerateDictionary(“vector<vector >;vector<vector<vector > >”, “vector”);

// …[/code]

That seemed to have fixed it. Thanks!

All that was necessary was:

if (!(gInterpreter->IsLoaded("vector")))
  gInterpreter->ProcessLine("#include <vector>");

gSystem->Load("libdict.so")