Root class

hi,
i am writing a new class Tsum

[color=red]class Tsum: public TH1F
{
private:
int x1;
public:
Tsum(){;}
Tsum(const char s[12],const char ss[12],int a, int b, int c):TH1F(s,ss,a,b,c){}
ClassDef(Tsum,1)
};[/color]Then i am calling in the main program,
[color=red]Tsum * hsum = new Tsum(“hsum”,“Tsum draw”,40,0,40)
hsum->Draw();
TFile* f= new TFile(“s.root”,“recreate”);
hsum->Write();
f.Close();[/color]
histogram is drawn on the canvas.
but the file is not saved as rootfile

when iam calling
TFile f(“s.root”)
i am getting warning
warning in TClass::TClass:no dictionary for class Tsum is available

sbh,

I can’t reproduce your problem. This code should work properly, but be sure that you load your class before calling it’s constructor. For instance, you can create a file called sbh.C:

[code]class Tsum: public TH1F
{
private:
int x1;
public:
Tsum(){;}
Tsum(const char s[12],const char ss[12],int a, int b, int c):TH1F(s,ss,a,b,c){}
ClassDef(Tsum,1)
};

void sbh() {
Tsum *hsum = new Tsum(“hsum”,“Tsum draw”,40,0,40);
hsum->Draw();
TFile *f= new TFile(“s.root”,“recreate”);
hsum->Write();
f->Close();
}[/code]
and then type:

root [0] .L sbh.C root [1] sbh()

I am loading the program in that way. everything is alright , only the problem is the file is not saved as rootfile. firstly symbol of rootfile cannot be seen and secondly when iam calling the rootfile, it is printed as “rootfile is corrupted” and " no TDictionary class is available". please help.

Hi,

Currently we do not support (but do not protect well :frowning:) storing interpreted classes.
If you use (after adding the appropriate header files)

root [0] .L sbh.C+ root [1] sbh()
It should work correctly.

Cheers,
Philippe.