Re: [ROOT] variable-size array of compiled class in a branch?

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Jun 15 2004 - 17:02:49 MEST


Why do you do?

      foo->Set(foo->iEv,foo->nMod);

Remove this line and the script will work correctly.
The version 4 I/O subsystem supports  variable length arrays of objects like 
arrays of basic types. In this example:

	Int_t nMod;
	Bar **modules;    //[nMod]         : "nMod" of modules


Rene Brun

Carlos Muņoz Camacho wrote:
> 
> Hi,
> 
> I thought only variable size arrays of simple types were allowed (p.177 of
> User's Guide). Is this no longer a restriction ?
> 
> Actually when I modify your read.C as follows to print out the data
> members of foo, it doesn't seem to work :
> 
> {
>    gSystem->Load("libfoo");
>    Foo *foo=0;
>    TFile f("xxxxx.root");
>    tree.SetBranchAddress("foo",&foo);
>    Int_t nentries=tree.GetEntries();
>    Int_t nb=0;
>    for (Int_t i=0;i<nentries;i++) {
>       nb += tree.GetEntry(i);
>       foo->Set(foo->iEv,foo->nMod);
>       if(foo->nMod>0){
>         cout<<foo->modules[0]->adc[0]<<endl;
>       }
>       foo->Set(0,0);
>    }
>    printf("nb=%d\n",nb);
> }
> 
> Carlos
> 
> On Mon, 14 Jun 2004, Rene Brun wrote:
> 
> >Hi,
> >
> >See the tar file in attachement with your classes modified to run
> >correctly. I also added a small reader example.
> >
> >Rene Brun
> >
> >Yiqun Wang wrote:
> >>
> >> Hi, ROOTers:
> >>
> >> In Guide (3.10), I see one can have a variable-size array for a simple
> >> type (Int_t, Float_t, etc.). Can we do that for a compiled class? I tried
> >> the attached program, but got many errors (mismatched size) when reading
> >> the root file in an interactive session. Any suggestions?
> >>
> >> The motivation is to save disk space. Events I have may have interesting
> >> data in only one module, or multiple modules. If possible, I don't want to
> >> write all modules when some of them do not contain interesting data.
> >>
> >> To run my simplied example, untar the attached "test.tar.gz" in an empty
> >> directory, and run "make all". After that, run "./test" and generate the
> >> root file "xxxxx.root". This file has one tree "tree", which contains a
> >> branch "foo" (of class "Foo"). The leaf "modules" is the variable-size
> >> array of compiled class "Bar".
> >>
> >> Thanks!
> >>
> >> Yiqun Wang
> >>
> >>   --------------------------------------------------------------------------------
> >>                   Name: test.tar.gz
> >>    test.tar.gz    Type: Unix Tape Archive (application/x-tar)
> >>               Encoding: base64



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:08 MET