Serialize a class structure to a Root Tree

Hello Rooters,

I have a question concerning Root Trees. My Problem is the following. I have a class Structure that I want to serialize into a Root Tree.
I have been reading the User Manual and serveral tutorials, but I did not find the answer to my specific question.

My Class Structure is as follows:
I have a class MyEvent that contains a std::vector containing Channels. Each Channel has a vector
containing pointers to MyPuls. Each MyPuls has an array of chars. Here is the code

class MyEvent 
{	//several other data members and member functions//
	std::vector<MyChannel*> channels;		//vector of Pointers to MyChannel
}

class MyChannel 
{	//several other data members and member functions//
	std::vector<MyPuls*> pulses;		//vector containing pointers to pulses
}

class MyPuls 
{	//several other data members and member functions//
	void * data;						//pointer to the waveform
	long length;						//length of the waveform
}

Most of the other data Members I want to store in a Header, since they won’t change and I don’t
want to store them for each event to reduce memory space.

If I would serialize this structure to a binary file I would do the following:
first store a header with all the information from MyEvent, MyChannel, MyPuls

void MyEvent::serialize()
{
	out << channels.size();				// the current nbr of channels
	for (int i=0; i<channels.size();++i)
		channels[i]->serialize();
}

void MyChannel::serialize()
{
	out <<  pulses.size();				//current nbr of Pulses in Channel
	for (int i=0; i<pulses.size(); ++i)	
		pulses[i]->serialize();
}

void MyPuls::serialize()
{
	out <<  length;				//the waveform length
	out.write((char*)data,length);
}

How do I have to modify the serialize functions in order to serialize this structure to a Root Tree?
Unfortunatly I cannot do it the way that is described in Tutorial root.cern.ch/root/html/examples/ … t.cxx.html, because
the Data Members in this structure will change very often, and if one wants to read the root file
one has to have the version of the structure when the root file was written. To avoid this problem, it would
be nice if one could extract the data without knowing the data structure by just going through the branches
and get the data members.
Is this possible and how can I do that?

Thank you,
Lutz

class MyPuls
{ //several other data members and member functions//
int length; // length of the waveform
char* data; //[length] pointer to the waveform
};[code][quote]if one wants to read the root file
one has to have the version of the structure when the root file was written.[/quote]Not quite true (if I understood you correctly). See the chapter on schema evolution in the User’s Guide.[quote]To avoid this problem, it would
be nice if one could extract the data without knowing the data structure by just going through the branches
and get the data members. [/quote]This is one of the feature of the TTree. You can access to the data without any of your code (of course, then you only have access to the data and not to the function).
Re-read the chapter on TTree analysis, in particular about TTree::Draw and TTree::MakeSelector.

Cheers,
Philippe