Re: Using MakeClass output

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Oct 04 1999 - 16:45:36 MEST


Hi Michal,
I do not understand your question.
In your main program, you should simply invoke the Loop function of the
generated class:

int main(int argc, char **argv)
{
    
   TROOT test_Tree("TEST", "Tree");

   TEST_CLASS TTH(); 
   TTH.Loop();

   return 0;
}


Rene Brun


lijowski@cosray2.wustl.edu wrote:
> 
>   Hello,
> 
>   I have question regarding using MakeClass output in compiled programs
>   related to my unsufficient experience in C++.
>   Below are two small programs, one which creates a file, a tree, and
>   uses MakeClass to generate templates for the second program which
>   attempts to access this tree. I could not find any example to follow.
> 
>   Thanks and regards
> 
>   Michal Lijowski
> 
> // This program writes a Tree into the output file
> 
> #include <TROOT.h>
> #include <Rtypes.h>
> #include <TFile.h>
> #include <TTree.h>
> #include <TBranch.h>
> 
> // ----------------------------------------------------------------------
> 
> int main(int argc, char **argv)
> {
> 
>    TROOT test_Tree("TEST", "Tree");
> 
>    TFile *tfile = new TFile("TEST.root", "RECREATE", "test Tree");
> 
> // file is compressed
>     Int_t comp = 1;  // compress file
>     tfile -> SetCompressionLevel(comp);
>     Int_t bufsize = 32000;
> 
> // make TOP subdirectory
>     tfile -> mkdir("TOP");
> 
>     gDirectory -> cd("TOP");
> 
> // Create a new Tree with branches
> 
>    TTree *TT = new TTree("TT", "test data");
>    TT -> SetAutoSave(100000000); // autosave when 1000 kB is written
> 
>    Int_t  EVTNO;
>    TT -> Branch("EVTNO", &EVTNO, "EVTNO/i", bufsize);
>    for (Int_t ii = 0; ii < 50000; ii++) {
>        EVTNO = ii;
>        TT -> Fill();
>    }
>    TT -> MakeClass("TEST_CLASS");
>    tfile -> Write();
>    tfile -> Close();
> 
>    return 0;
> }
> 
> // -----------------------------------------------------------------------
> 
> // This program reads the ROOT Tree
> 
> #include <TROOT.h>
> #include <TTree.h>
> #include <TEST_CLASS.h>
> 
> void TEST_CLASS::Loop()
> {
> //   In a Root session, you can do:
> //      Root > .L TEST_CLASS.C
> //      Root > TEST_CLASS 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
> //       To read only selected branches, Insert statements like:
> // METHOD1:
> //    fTree->SetBranchStatus("*",0);  // disable all branches
> //    fTree->SetBranchStatus("branchname",1);  // activate branchname
> // METHOD2: replace line
> //    fTree->GetEntry(i);  // read all branches
> //by  b_branchname->GetEntry(i); //read only this branch
>    if (fTree == 0) return;
> 
>    Int_t nentries = Int_t(fTree->GetEntries());
> 
>    Int_t nbytes = 0, nb = 0;
>    for (Int_t i=0; i<nentries;i++) {
>       nb = fTree->GetEntry(i);   nbytes += nb;
>    }
> }
> 
> // ----------------------------------------------------------------------
> 
> int main(int argc, char **argv)
> {
> 
>    TROOT test_Tree("TEST", "Tree");
> 
>    TEST_CLASS TTH();
> 
>    return 0;
> }



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:40 MET