Dear Rooters,
I have a question about how to access a class member for the ROOT I/O
from the command "tree->Draw(...)".
I made two simple classes, A and B with a member 'int val'.
Then the ROOT file with the two classes was created as follows.
******************************************************************************
*Tree :tree : test *
*Entries : 10 : Total = 6018 bytes File Size = 1093 *
* : : Tree compression factor = 1.00 *
******************************************************************************
*Branch :A *
*Entries : 10 : BranchElement (see below) *
*............................................................................*
*Br 0 :fUniqueID : *
*Entries : 10 : Total Size= 634 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 1 :fBits : *
*Entries : 10 : Total Size= 610 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 2 :val : *
*Entries : 10 : Total Size= 598 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Branch :B *
*Entries : 10 : BranchElement (see below) *
*............................................................................*
*Br 3 :fUniqueID : *
*Entries : 10 : Total Size= 634 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 4 :fBits : *
*Entries : 10 : Total Size= 610 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 5 :val : *
*Entries : 10 : Total Size= 598 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
.
Then I performed 3 kinds of tree->Draw() as,
1.) tree->Draw("val");
2.) tree->Draw("A.val");
3.) tree->Draw("B.val");
But I only got the same results (I can't get access to the B's 'val').
Could you tell me how to draw the B's 'val'.
I used ROOT on current CVS under RH9 with gcc3.2.2.
The simple codes are as follows.
///////////////////////////////////////////////
//A.h
///////////////////////////////////////////////
#ifndef A_h
#define A_h 1
#include "TObject.h"
class A : public TObject
{
public:
A();
~A();
int val;
ClassDef(A,1)
};
#endif
///////////////////////////////////////////////
//A.C
///////////////////////////////////////////////
#include "A.h"
#if !defined(__CINT__)
ClassImp(A);
#endif
A::A() {;}
A::~A() {;}
///////////////////////////////////////////////
//B.h
///////////////////////////////////////////////
#ifndef B_h
#define B_h 1
#include "TObject.h"
class B : public TObject
{
public:
B();
~B();
int val;
ClassDef(B,1)
};
#endif
///////////////////////////////////////////////
//B.C
///////////////////////////////////////////////
#include "B.h"
#if !defined(__CINT__)
ClassImp(B);
#endif
B::B() {;}
B::~B() {;}
///////////////////////////////////////////////
//ALinkDef.h
///////////////////////////////////////////////
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class A+;
#endif
///////////////////////////////////////////////
//BLinkDef.h
///////////////////////////////////////////////
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class B+;
#endif
///////////////////////////////////////////////
//write.C
///////////////////////////////////////////////
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include "TApplication.h"
#include "TFile.h"
#include "TTree.h"
#include "A.h"
#include "B.h"
int main(int argc,char** argv) {
TApplication theApp("App", &argc, argv);
gApplication->Init();
argc=theApp.Argc();
argv=theApp.Argv();
//clonedummy input.root output.root
if(argc!=2) {
std::cout << "Argument Error!" << std::endl;
std::exit(1);
}
std::cout << "Output file : " << argv[1] << std::endl;
TFile* tfo = new TFile(argv[1],"RECREATE");
TTree* tree = new TTree("tree","test");
A* a = new A();
B* b = new B();
tree->Branch("A","A",&a);
tree->Branch("B","B",&b);
for (Int_t jentry=0; jentry<10;jentry++) {
a->val=1;
b->val=10;
tree->Fill();
}
tree->Write();
tfo->Close();
return 0;
}
///////////////////////////////////////////////
//make.sh
///////////////////////////////////////////////
rootcint -f ADict.C -c A.h ALinkDef.h
rootcint -f BDict.C -c B.h BLinkDef.h
g++ -o write `rootconf ` *.C
g++ --shared `root-config --cflags` `root-config --libs` -I. \
-o libData.so \
A.C ADict.C B.C BDict.C
///////////////////////////////////////////////
//run.sh
///////////////////////////////////////////////
./write test.root
///////////////////////////////////////////////
//read.C
///////////////////////////////////////////////
{
gSystem->Load("libData.so");
TFile* tf = new TFile("test.root");
tree->Print();
tree->Draw("val");
tree->Draw("A.val");
tree->Draw("B.val");
}
///////////////////////////////////////////////
Best Regards,
Hajime
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:08 MET