Dear Rooters,
I would like to use a 2-dim. array of variable size
within a class which is used for ROOT I/O.
Some simple codes are listed below to show what I want to do.
(A 2-dim. array is declared in MyClass.h.)
These codes were compiled successfully and the application
run without error. But the 2-dim. array was not stored
in the ROOT file.
I'm afraid the expression, "double (*pp)[2];//[size]" ,
is not supported.
Could you tell me how to do ?
Best Regards,
Hajime
////////////////////////////////
g++ `root-config --cflags` -c MyClass.C
rootcint -f MyClassDict.C -c MyClass.h MyClassLinkDef.h
g++ `root-config --cflags` -c MyClassDict.C
g++ -shared -O MyClass.o MyClassDict.o -o libMyClass.so
g++ `root-config --cflags` -c write.C
g++ write.o libMyClass.so `root-config --libs` -o write
./write
////////////////////////////////
// MyClass.h
#ifndef MyClass_HH
#define MyClass_HH
#include "TObject.h"
class MyClass: public TObject
{
public:
MyClass();
~MyClass();
void Init(int s);
void Fin();
public:
int size;
double *p;//[size]
double (*pp)[2];//[size]
// ^^^^^^^^^^^^^^^^
// such kind of expression is supported?
ClassDef(MyClass,1) //MyClass
};
#endif
////////////////////////////////
// MyClass.C
#include "MyClass.h"
#if !defined(__CINT__)
ClassImp(MyClass);
#endif
MyClass::MyClass() {
size=0;
p=0;
pp=0;
}
MyClass::~MyClass() {
;
}
void MyClass::Init(int s) {
size=s;
p = new double[s];
pp = new double[s][2];
}
void MyClass::Fin() {
delete [] p;
delete [] pp;
p=0;
pp=0;
size=0;
}
////////////////////////////////
// MyClassLinkDef.h
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class MyClass+;
#endif
////////////////////////////////
// write.C
#include "TApplication.h"
#include "TFile.h"
#include "TTree.h"
#include "MyClass.h"
int main(int argc,char** argv)
{
TApplication app("app", &argc, argv);
TFile *tf = new TFile("tmp.root","RECREATE");
TTree *tree = new TTree("tree","tmp");
MyClass *data = new MyClass();
tree->Branch("data","MyClass",&data);
for (int i=0;i<5;++i) {
data->Init(i+1);
for(int j=0;j<data->size;j++) {
data->p[j] = j*10.+i;
data->pp[j][0] = j*10.+i;
data->pp[j][1] = j*10.+i+1;
}
tree->Fill();
data->Fin();
}
tf->Write();
delete data;
return 0;
}
////////////////////////////////
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:13 MET