Can you quote the class made by MakeClass in otherfunctions?

I discussed this with a “ROOT bug fixer”, but he just set up my post as invalid and do not reply me any more. Since it is greatly useful when making stack histogram (set up the handle of ttree so that you can load TTree from different Root files in a single C macro script), I post our discussion here.

I do think ROOT should be wildly compatible but not that limited.


OK. Here is the comment.
Where does it say that I could not define a new function to declare objects
of ROOTBUG class? // should be "I could not define a new function in which I declare objects of ROOTBUG class?"
It does work except this case.

I opened 2 bug reports related to the same thing because I cannot either post
a comment or reply the email when I post bug reports as an anonymous user at
first.

// In a ROOT session, you can do:
// Root > .L ROOTBUG.C
// Root > ROOTBUG t
// Root > t.GetEntry(12); // Fill t data members with entry number 12
// Root > t.Show(); // Show values of entry 12
// Root > t.Show(16); // Read and show values of entry 16
// Root > t.Loop(); // Loop on all entries
//

// This is the loop skeleton where:
// jentry is the global entry number in the chain
// ientry is the entry number in the current Tree
// Note that the argument to GetEntry must be:
// jentry for TChain::GetEntry
// ientry for TTree::GetEntry and TBranch::GetEntry
//
// To read only selected branches, Insert statements like:
// METHOD1:
// fChain->SetBranchStatus("*",0); // disable all branches
// fChain->SetBranchStatus(“branchname”,1); // activate branchname
// METHOD2: replace line
// fChain->GetEntry(jentry); //read all branches
//by b_branchname->GetEntry(ientry); //read only this branch
// TFile *

Submitted by: masterid2
Originator Email:
Bug / Feature: Bug report
Category: Other
Priority: 5 - Normal
Severity: 4 - Important
Status: Invalid
Privacy: Public
Assigned to: brun
Open/Closed: Closed
Release: 5.22a
Discussion Lock:
Operating System: GNU/Linux

-----Reply from Rene Brun on 2009-10-27 10:14 (GMT)-----
PLEASE do not open 2 bug reports related to the same thing!
You did not read or understand the comments in the generated file.
You SHOULD NOT IMPLEMENT the function MyMain and create an instance of the
ROOTBUG class there. This is your bug.
Proceed as indicated in the comments.

Rene

-----Reply from Jinzhong Zhang on 2009-10-27 10:09 (GMT)-----
Like that I mean:
#define ROOTBUG_cxx
#include “ROOTBUG.h”
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>

void ROOTBUG::Loop()
{
TH1D *hist1 = new TH1D(“123”,“456”,10,1,10);
if (fChain == 0) return;

Long64_t nentries = fChain->GetEntriesFast();

Long64_t nbytes = 0, nb = 0;
for (Long64_t jentry=0; jentry<nentries;jentry++) {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
// if (Cut(ientry) < 0) continue;
hist1->Fill(1.1);
}
hist1->Draw();
}
void MyMain()
{
ROOTBUG fHandle;
fHandle.Loop();
}

Then you run
.L ROOTBUG.C++
MyMain()

STILL EMPTY CANVAS!

-----Original Message-----
I removed the comments just because I do not want my post too long to be
read.
You can see that I did not use the loop in this case.

The canvas will still be empty if you declare the class in MyMain() and “Put
the creation of your histogram at the beginning of the Loop function,
fill it inside the loop and draw it after the loop.”

I tried this. It annoys me a lot.

Posted by: Rene Brun
Related to: [ROOT bugs #57659] Conflicts between TH?? and the class made by
"MakeClass"
URL: http://savannah.cern.ch/bugs/?57659

Follow-up Comment:

Why did you remove the comments at the top of the ROOTBUG.C file generated
by
MakeClass? They tell you how to use the class.
Put the creation of your histogram at the beginning of the Loop function,
fill it inside the loop and draw it after the loop.

Rene

Status: None -> Clarified ?No!!!
Assigned to: None -> brun
Open/Closed: Open -> Closed

Submitted by:
Originator Email: zhangjin@cern.ch
Bug / Feature: Bug report
Category: PROOF
Priority: 5 - Normal
Severity: 3 - Normal
Status: Clarified
Privacy: Public
Assigned to: brun
Open/Closed: Closed
Release: 5.22a
Discussion Lock:
Operating System: GNU/Linux

-----Original Message-----
The following is a modified C file made by “MakeClass” from a TTree. The
ROOTBUG is the class name.

Now first, in root , you run .L ROOTBUG.C++.
Then you run MyMain().
Nothing is made on the canvas.

I found three ways to fix this problem:

  1. comment out “ROOTBUG fHandle;”
  2. uncomment “TH1D *EmptyHist = new TH1D(“123”,“456”,10,0,1);”(root will
    always leave the last histogram empty in this case)
  3. Type all the commands in ROOT command lines.

I do not know the reason. It should be a bug.

#define ROOTBUG_cxx
#include “ROOTBUG.h”
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>

void ROOTBUG::Loop()
{
if (fChain == 0) return;

Long64_t nentries = fChain->GetEntriesFast();

Long64_t nbytes = 0, nb = 0;
for (Long64_t jentry=0; jentry<nentries;jentry++) {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
// if (Cut(ientry) < 0) continue;
}
}
void MyMain()
{
ROOTBUG fHandle;
TH1D *hist1 = new TH1D(“123”,“456”,10,1,10);
//TH1D *EmptyHist = new TH1D(“123”,“456”,10,0,1);
hist1->Fill(1.3);
hist1->Fill(1.5);
hist1->Fill(2.3);
hist1->Fill(1.6);
hist1->Draw();
}

Hi,

as Rene pointed out you’ll need to run this, without any MyMain():

// Root > .L ROOTBUG.C
// Root > typedef ROOTBUG USERERROR;
// Root > USERERROR t
// Root > t.GetEntry(12); // Fill t data members with entry number 12
// Root > t.Show(); // Show values of entry 12
// Root > t.Show(16); // Read and show values of entry 16
// Root > t.Loop(); // Loop on all entries

To run on a different tree call t.Init(tree), see the doc for TTree::MakeClass() root.cern.ch/root/html/TTree#TTree:MakeClass

Better yet, use TTree::MakeSelector(), which allows you to run tree->Process(“MySelector.C+”).

Cheers, Axel.