Re: persistent C structures?

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Mar 12 1998 - 10:50:48 MET


I have been away in the past two days. Sorry if you see long delays
to answer your questions. I have a long long list of mails.
I take this opportunity to remind you the intention of this
list "roottalk". It should be reserved to mails of general interest,
discussions, questions for which you may expect an answer useful
to many other people (like this one). Other questions should be
addressed to rootdev@hpsalo.cern.ch. A mail to roottalk is today
dispatched to more than 500 people.


Paolo Calafiura wrote:
> 
> Hi,
>  I have an Event class that is a copy element by element of a C data
> structure:
> struct cmpEvent {
>         int n;
>         int trigword;
>         int timestamp;
>         int recflag;
>         float evtfspare[10];
>         int evtispare[10];
>         struct RNDMsummary rndm;
>         u_int Ntstamp;
>         struct EVTtimestamp tstamp[MAX_TS]      ;
>         struct PMBscaler KLmon;
>     ..... more stuff
> };
>  becomes
> class Event : public TObject {
> protected:
>         int n;
>         int trigword;
>         int timestamp;
>         int recflag;
>         float evtfspare[10];
>         int evtispare[10];
>         struct RNDMsummary rndm;
>         u_int Ntstamp;
>         struct EVTtimestamp tstamp[MAX_TS]      ;
>         struct PMBscaler KLmon;
>           .... as above
> public:
>         void Dump();
>       .... some other member functions
> };
> The idea is to keep the same memory layout as in the C structure for the
> data members, so that I can "fill" an Event object in the functions
> that were prepared to fill the C structure just by passing a
> pointer to the object. This works fine as I checked Dumping the C
> structure I read and the Event I want to write.
> 
> Even before trying to read back the Event.root out file, if I browse the
> class Event, using the Object Browser, I see that, for example,
> the structure  "rndm" is not among the "Real Data Members". Oddly enough,
> the array of structures tstamp[MAX_TS] is there...
> 
> Now if I look into the "event" tree of Event.root (I wrote in split mode).
> I see only the data members of type "intrinsic": I don't see rndm and all
> other members of type structure or array of structures: even tstamp[]
> that was among the "Real Data Members" of the class did not make it to the
> file.
> 
> When I read  back the files using a standalone program I see, using Dump()
> that for all events, all the members of type structure are left 0.
> 
> How should I handle that? Is default Write() unable to deal with
> structures inside an object? Do I have to provide my own Write()?
> Or maybe I messed up something trivial?
> 

No, you do not have to provide your own Write. I suggest you read
the following two pages related to your problem.
   http://root.cern.ch/root/HowtoWrite.html
   http://root.cern.ch/root/HowtoWriteTree.html

The first page explains how to implement your own Streamer function
for a class using C structures.
The second page list the restrictions to the use of the split mode.

> 
> P.S. I am using the beta of version 2 on Solaris, and it looks fine.
>      Thanks Fons for fixing the name clash with gzip routines!!!

This was a "bit" more work than initially expected. I had to change
the definition of several global variables used in this piece of
C code. The previous ZIP package was effectively clashing with
other C-based packages using the XDR system in particular.

Rene Brun



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:31 MET