TTree Scan/Draw data type issues using MacOSX

Hi,
The following simple macro has issues returning character arrays and unsigned integers in both
tree->Scan and Draw methods. There may be other issues, but these are the ones
I’ve seen thus far. I’m not sure if this is a bug or I’m simply doing something
incorrectly.

The quirks (described below) only seems to happen:

  • Using MacOSX
  • After reading in a root file with a tree in it (versus scanning and drawing
    right after running the macro in the same root session).
  • As a side issue, in an interactive session after running the macro, root frequently
    crashes (which may be a different pathology – i.e. a quirk in my macro?).

I’m using:
MacOSX (I have not seen this problem in Linux)
root 4.01/02 (but similar problems seen with earlier versions)

void treebug4(char* name)
{

  Char_t cHead1[9]="123456789";

  UShort_t nCh1=33000;
  UShort_t nCh2=33000; 

  //open root file for output
  Char_t rtSuff[6]=".root";
  Char_t rootname[200];
  sprintf(rootname,"%s%s",name,rtSuff);
  cout << "root file: " << rootname << endl;

  TFile *rf=new TFile(rootname,"RECREATE");

  TTree *tree=new TTree("tree","character and unsigned short int");

  tree->Branch("cHead1",&cHead1,"cHead1[9]/C");
  tree->Branch("nCh1",&nCh1,"nCh1/S");
  tree->Branch("nCh2",&nCh2,"nCh2/s");

  tree->Fill();
  rf->Write();
}

After running this macro in an interactive session, the
tree->Scan() and tree->Draw(“nCh1”,"") etc. methods return the expected
outputs if probed in the same session it was run in. e.g.
root [0] .x treebug4.C(“treebug4”);
root file: treebug4.root
root [1] tree->Scan()


  • Row * cHead1 * nCh1 * nCh2 *

  •    0 * 123456789 *    -32536 *     33000 *
    

However, if the output file is read in during another root session, the Scan and
Draw methods return spurious results. Namely, the unsigned short int nCh2 is not
recognized as such even with the “s” flag and character arrays are treated as different instances in the
tree for each element (perhaps this is expected? But then why is it different than the
above interactive session?). If the same macro is run in Linux, the outputs are the
same for both the interactive and the file-read sessions.

root [0] new TFile(“treebug4.root”);
root [1] tree->Scan()


  • Row * Instance * cHead1 * nCh1 * nCh2 *

  •    0 *        0 *        49 *    -32536 *    -32536 *
    
  •    0 *        1 *        50 *    -32536 *    -32536 *
    
  •    0 *        2 *        51 *    -32536 *    -32536 *
    
  •    0 *        3 *        52 *    -32536 *    -32536 *
    
  •    0 *        4 *        53 *    -32536 *    -32536 *
    
  •    0 *        5 *        54 *    -32536 *    -32536 *
    
  •    0 *        6 *        55 *    -32536 *    -32536 *
    
  •    0 *        7 *        56 *    -32536 *    -32536 *
    
  •    0 *        8 *        57 *    -32536 *    -32536 *
    

Any thoughts would be appreciated,
Thanks,
Tom


Thomas D. Gutierrez
Lawrence Berkeley National Laboratory
Office 50-5211
Mailstop 50R5008
Phone 510-486-7846

Hi,

This problem was a side-effect of the fact that bool on your platform are 4 bytes instead of the usal one. Thei side-effect has been removed in the ROOT 4.01/04

Cheers,
Philippe