[ROOT] root vs c++

From: Kareem Kazkaz (kareem@u.washington.edu)
Date: Mon Mar 26 2001 - 19:54:54 MEST


Hello rooters.

I am running a C++ program to take a simple root ntuple and convert it
to hbook format, but I am running into difficulties reading in the
ntuple.  (Root version 3.00/06, compiled locally.)

Here's the relevant C++ code:

    gROOT = ::new TROOT("gROOT","root2h");

    TFile fin(argv[1],"READ");
    if (!(fin.IsOpen()) ) {
      printf("Error in root2h: could not open file %s\n",argv[1]);
      exit(-1);
    }

    TKey *firstKey = (TKey *)fin.GetListOfKeys()->At(0);
    if ( !firstKey ) printf("Error in root2h: could not find ntuple in
file %s\n"$
    TNtuple *theNtuple = (TNtuple *)fin.Get(firstKey->GetName());

    if ( !theNtuple ) {
      printf("Error in root2h: could not find Ntuple in file
%s\n",argv[1]);
      exit (-1);
    }

When I run the program, I get the following error message:

    marie:~/source/smear % root2h sumall_0201_smeared.root
sumall_0201_smeared.hbk
    Error in <TKey::ReadObj>: Unknown class TNtuple
    Error in root2h: could not find Ntuple in file
sumall_0201_smeared.root

Now here is a root transcript where I enter the commands via root
directly, and the ntuple is correctly read in:

    root [0] TFile fin("sumall_0201_smeared.root","READ")
    root [1] fin.IsOpen()
    (const unsigned char)1
    root [2] TKey *firstKey = (TKey *)fin.GetListOfKeys()->At(0)
    root [3] firstKey->GetName()
    (const char* 0x14097c38c)"ntuple"
    root [4] TNtuple *theNtuple = (TNtuple
*)fin.Get(firstKey->GetName())
    root [5] theNtuple
    (class TNtuple*)0x140a05000

Any suggestions would be greatly appreciated.

                        Kareem



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:40 MET