Dear Rooters
I apologize for sending the following questions again but it seems that
my message did not arrive at roottalk
Best regards
Christian Stratowa
Subject:
root file and custom classes
Date:
Sun, 02 Jul 2000 20:00:07 +0100
From:
cstrato@EUnet.at
To:
roottalk <roottalk@pcroot.cern.ch>
Dear Rooters:
Maybe you could answer the following questions regarding root files:
1, I have a function “save_data(file.root, data.txt)”, which creates
a rootfile and stores the data in a tree. When file.root does already
exist, the function should update the file and write new data into
a new tree of the same file. The skeleton of the function looks like
this:
void save_data(fileName, data)
{
TFile *f = new TFile(fileName, “CREATE”);
if (!f->Open()) {
f->Open(fileName, “UPDATE”;
//alternatively:
// delete f;
// f = new TFile(fileName, “UPDATE);
}
// call: MyClassA->SaveData(fileName, data)
f->Write();
f->Close();
}
When fileName does not exist, everything is fine, however, when
I call the function again with different data I get:
“Error in <TFile::TFile>: file fileName already exists”
However the execution continues and f->Open(..) results in:
“Warning in <TFile::Write>: file not opened in write mode”
Interestingly, the data are stored in a new tree as supposed to.
Why do I get then this warning?
I can avoid the warning by deleting the file first and creating
a new file f = new TFile(fileName, “UPDATE) as shown above.
However, this is not very elegant, so my question is:
What is the best way to solve this problem?
2, As seen above, the tree is not created in the function but in
a new class MyClassA. Furthermore, the data are described in a
class MyClassB: branchB = tree->Branch(name,”MyClassB”, &myClassB)
The tree is called from MyClassA and should also store MyClassA:
branchA = tree->Branch(name,”MyClassA”, &this)
Running root results in the errors that MyClassA and MyClassB are not
found.
When I include ClassDef() and ClassImp() then I get the following
errors:
Error: MyClass() header declared but not defined FILE:...
(class MyClass*) 0x...
!!!Dictionary position not recovered because G__unloadfile() in macro!!!
Does this mean that I have to compile the classes first to create a
dictionary?
If I consider the root test example “MainEvent.cxx”:
Is there no way to run this example using only the cint interpreter,
i.e.
without first compiling Event.h into a shared library to create a
dictionary?
This would mean that I could not test my own classes interactively, but
have to compile them everytime I find a bug or want to change/add a
method.
Is there a way to avoid this?
Thank you very much in advance for your help.
Best regards
Christian Stratowa, Vienna, Austria
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:29 MET