I would be very thankful if someone could give me a hint whats wrong in my program…
TASK
To read TObjects (calibrations) from a TList saved in a TFile, add new calibrations to the list and save the list back to the file again
PROBLEM
When I read the TObjects from the list they are empty
CODE
The interface to the TList and TFile is below, I use the functions:
//To initialise the TFile and TList (only done once)
void ListHandler::Init(TString filename)
{
printf(“Creating TFile %s and TList\n”,filename.Data());
calib_file = new TFile(filename.Data(),“NEW”);
calib_list = new TList();
calib_file->WriteObject(calib_list,“list”,“SingleKey,Overwrite”);
calib_file->Close();
}
//To open the TFile and read in the TList
int ListHandler::ReadList(TString filename)
{
calib_file = new TFile(filename.Data(),“UPDATE”);
calib_list = new TList();
if(calib_file->IsZombie())
return 0;
else{
calib_file->GetObject(“list”,calib_list);
if(calib_list)
return 1;
else
return 0;
}
}
//To write the TList back to the file and close the file
int ListHandler::WriteList()
{
calib_file->WriteObject(calib_list,“list”,“SingleKey,Overwrite”);//,TObject::kOverwrite);
calib_file->Write();
calib_file->Close();
return 0;
}
//To save a TObject (calibevent) in the TList
int ListHandler::SaveEvent(calibEvent *event)
{
if(calib_file->IsOpen() && calib_list){
calib_list->Add(event);
return 1;
}
else
return 0;
}
Hi Petter,
you must compile your code (rootcint generate the dictionary file and myobject::Streamer() ).In your second exam simple add two lines: #include <TFile.h>
ClassDef(myobject, 1); // very important
[quote]root [0] .L wtf.C+
Info in TUnixSystem::ACLiC: creating shared library /home/mucha/./wtf_C.so
root [1] wtf()
flag0 1
flag1 1
flag2 1
(int)0
root [2][/quote]For more info see UserGuide chapters Input/Output and Adding a Class.
By the way, try too ClassDef(myobject, 0)
But, the program in the first post (the actual program Im working on) will be compiled with a makefile. When I include the ClassDef in the classes in this case, the compiler complains with
[pamela@localhost testarea]$ make TestList
g++ -c -o TestList.o TestList.cpp -Iroot-config --incdir -I/home/pamela/src/testarea
g++ -c -o ListHandler.o ListHandler.cpp -Iroot-config --incdir -I/home/pamela/src/testarea
g++ -o TestList TestList.o ListHandler.o root-config --libs
ListHandler.o: In function ListHandler::ListHandler()': ListHandler.cpp:(.text+0x4): undefined reference tovtable for ListHandler’
ListHandler.o: In function ListHandler::ListHandler()': ListHandler.cpp:(.text+0x14): undefined reference tovtable for ListHandler’
ListHandler.o: In function ListHandler::~ListHandler()': ListHandler.cpp:(.text+0x24): undefined reference tovtable for ListHandler’
ListHandler.o: In function ListHandler::~ListHandler()': ListHandler.cpp:(.text+0x34): undefined reference tovtable for ListHandler’
ListHandler.o: In function calibEvent::calibEvent(float, float (*) [12], int (*) [12])': ListHandler.cpp:(.text+0x152): undefined reference tovtable for calibEvent’
ListHandler.o: In function calibEvent::calibEvent(float, float (*) [12], int (*) [12])': ListHandler.cpp:(.text+0x23a): undefined reference tovtable for calibEvent’
collect2: ld returned 1 exit status
make: *** [TestList] Error 1
[pamela@localhost testarea]$
Do I have to inlcude any other headerfiles to make this work?!