Root tutorial codes vs manual are different!


ROOT Version: 6.12
Platform: Not Provided
Compiler: Not Provided


hi,

the codes given in the tutorial manual and the actual codes doesn’t seem to match.

For example,

https://root.cern.ch/root/htmldoc/guides/users-guide/ROOTUsersGuide.html#the-tutorials-and-tests

in section 12.2 A simple tree, there is a code staff.C which is given as

{
   // example of macro to read data from an ascii file and
   // create a root file with an histogram and a TTree
   gROOT->Reset();

   // the structure to hold the variables for the branch

   struct staff_t {
      Int_t cat;
      Int_t division;
      Int_t flag;
      Int_t age;
      Int_t service;
      Int_t children;
      Int_t grade;
      Int_t step;
      Int_t nation;
      Int_t hrweek;
      Int_t cost;
   };
   staff_t staff;
   // continued...
   // open the ASCII file
   FILE *fp = fopen("staff.dat","r");
   char line[81];
   // create a new ROOT file
   TFile *f = new TFile("staff.root","RECREATE");
   // create a TTree
   TTree *tree = new TTree("T","staff data from ascii file");
   // create one branch with all information from the stucture
   tree->Branch("staff",&staff.cat,"cat/I:division:flag:age:service:
                           children:grade:step:nation:hrweek:cost");
   // fill the tree from the values in ASCII file
   while (fgets(&line,80,fp)) {
      sscanf(&line[0],"%d%d%d%d",&staff.cat,&staff.division,
          &staff.flag,&staff.age);
      sscanf(&line[13],"%d%d%d%d",&staff.service,&staff.children,
          &staff.grade,&staff.step);
      sscanf(&line[24],"%d%d%d",&staff.nation,&staff.hrweek,
          &staff.cost);
      tree->Fill();
   }
   // check what the tree looks like
   tree->Print();
   fclose(fp);
   f->Write();
}

however in the actual code located in “$ROOTSYS/tutorials/tree”, the code is given as

void staff() {
   auto f = TFile::Open("cernstaff.root");
   TTree *T = nullptr;
   f->GetObject("T",T);
   T->Draw("Grade:Age:Cost:Division:Nation","","gl5d");
   if (gPad) gPad->Print("staff.C.png");
}

why are the codes different? where can I find the first code?
I also gave a look at the cernstaff.C code but it seems to be another different code…

please help, thanks!

The users’ guide is not updated with the same frequency as the main repository of ROOT. Please access the website if you would like to see the latest version of the code. For ROOT 6, you can look up the documentation here. You can see the same tutorial for the latest release of ROOT 5 here, which is more similar to the version you want. Cheers,

staff.C creates a plot of the data in cernstaff.root To create cernstaff.root , execute tutorial $ROOTSYS/tutorials/tree/cernbuild.C

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.