TTree::Scan returns -1

Hi folks,

When I call Scan() with no arguments on a tree, I get no matching results (return value is -1), even though I’m sure that there’s data in the tree.

Here’s a minimal example

First, make the ROOT file with the TTree

{
  TFile* ff = new TFile("test.root","RECREATE");
  TTree* tt = new TTree("mytree","mytree title");
  int ii;
  double xx;
  tt->Branch("ii",&ii,"ii/I");
  tt->Branch("xx",&xx,"xx/D");

  ii=1; xx=5.0; tt->Fill();
  ii=2; xx=7.0; tt->Fill();
  ff->Write();
}

Next, read the ROOT file from disk (after quitting and restarting CINT)

root [0] TFile f("test.root")
root [1] f.ls()
TFile**		test.root	
 TFile*		test.root	
  KEY: TTree	mytree;1	mytree title
root [2] mytree->Print()
******************************************************************************
*Tree    :mytree    : mytree title                                           *
*Entries :        2 : Total =            1456 bytes  File  Size =        605 *
*        :          : Tree compression factor =   1.00                       *
******************************************************************************
*Br    0 :ii        : ii/I                                                   *
*Entries :        2 : Total  Size=        541 bytes  File Size  =         79 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    1 :xx        : xx/D                                                   *
*Entries :        2 : Total  Size=        557 bytes  File Size  =         87 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*

OK, looks good so far. Now try to print the contents of the TTree to screen with Scan()

root [3] mytree->Scan()
(Long64_t)(-1)
root [4] mytree->Scan("*")
(Long64_t)(-1)

Hmmmm… OK, well then assign a variable to a branch and pull data out that way?

root [5] int ii;
root [6] mytree->SetBranchAddress("ii",&ii);
root [7] mytree->GetEvent(0);
root [8] ii
(int)1
root [9] mytree->GetEvent(1);
root [10] ii
(int)2

So the data is in the TTree as expected. But why isn’t the data output via Scan()? Apologies in advance if there’s something obvious here. I did search online for advice, but was not able to find a solution.

For reference, here’s some information about my system setup. I installed ROOT via yum.

$ root-config --version
5.34/09
$ cat /etc/redhat-release 
Scientific Linux release 6.4 (Carbon)
$ uname -a
Linux name1.name2.edu 2.6.32-358.14.1.el6.x86_64 #1 SMP Tue Jul 16 14:24:33 CDT 2013 x86_64 x86_64 x86_64 GNU/Linux

Thank you,
James

When I run the same minimal example in the original post on a different machine, I get the expected output

root [3] mytree->Scan()
************************************
*    Row   *        ii *        xx *
************************************
*        0 *         1 *         5 *
*        1 *         2 *         7 *
************************************
(Long64_t)2

For what it’s worth, this second machine also installed ROOT via yum. Here’s more info on the second machine.

$ uname -a
Linux nameA.nameB.edu 2.6.32-279.14.1.el6.x86_64 #1 SMP Tue Nov 6 23:43:09 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/redhat-release 
CentOS release 6.3 (Final)
$ root-config --version
5.28/00h

So the second machine is an earlier version of ROOT on CentOS 6.3.

OK, I figured out the problem. Here’s the solution in case others have the same issue. When installing ROOT via yum, there are many optional packages to install. On the machine where Scan() failed, I did not have root-tree-player installed.

So the fix was to run

$ sudo yum install root-tree-player

and then Scan() worked as expected.

root [0] TFile f("test.root")
root [1] f.ls()
TFile**		test.root	
 TFile*		test.root	
  KEY: TTree	mytree;1	mytree title
root [2] mytree->Scan()
************************************
*    Row   *        ii *        xx *
************************************
*        0 *         1 *         5 *
*        1 *         2 *         7 *
************************************
(Long64_t)2

For reference, you can see what ROOT packages you have on your system with

$ yum list installed | grep root
root.x86_64             5.28.00h-2.el6  @epel                                   
root-cint.x86_64        5.28.00h-2.el6  @epel                                   
root-core.x86_64        5.28.00h-2.el6  @epel                                   
root-fftw.x86_64        5.28.00h-2.el6  @epel  
...

Hopefully these three posts will be useful to someone else in the future…