Stl containers of basic types

Hi,

I added a std::vector<Float_t> to my tree.
When I try to read it back I get:

root [7] bxtree->GetEntry(10) Error in <TBuffer::CheckByteCount>: object of class times read too few bytes: 2 instead of 10 (Int_t)78136

where “times” is name of my vector.

Now, since I have many parallel vectors of my user defined classes and I manage to read them very well (after loading a compiled library), I decided to add to my LinkDef.hh file the following line:

analogous to the one I use for vectors of my own classes.

rootcint moderately complains with:

and the problem in reading back persists.

In the user’s guide I couldn’ t find anything on stl containers, where should I look for help?

I take the chance to wish you all a Merry Christmas
bye
Davide

P.S.: I’m using root v4.02.00

I investigated a little further.

I attach a script version which illustrates the problem.

Actually, the problem, as usual, is only with nested vectors, where also vectors of user defined classes cannot be put (see my post “collections of collections”).
Here I don’t get the error message reported above as in the compiled case, but still the size of the innermost vector<Float_t> is 0.
Other similar vector<Float_t> placed outside the vector of user defined objects are fine.
sample_writer_new.C (587 Bytes)
sample_bx_classes_nohits.C (1.94 KB)

Hi,

How to you assert that the inner most array is empty?

With your example and adding a print method, I see that the content is correct!

Cheers,
Philippe

simply by reading back the tree from file and checking the size of the vector.
For example with the few lines I attach.

Thanks, bye
Davide
sample_reader.C (413 Bytes)

With ROOT 4.01/04 and ROOT 4.03/01 I get:

root [0] #include <vector> root [1] .x sample_reader.C Size of L: 3 Size of C: 3
Note that I had to make sure to load the vector library.

Which version of ROOT are you using? Were the cintdlls built (this is essential for the interpreter to work)? Which platform are you running on?

If you are already using a recent version of ROOT and the cintdlls have been built, please re-submit a full tar file to reproduce the problem including you resulting (faulty) root file.

Cheers,
Philippe.

I’m running on linux mandrake 9.1 with a 2.4.21 kernel
gcc is 3.2.2
Root was installed as binary as I did many times.
I don’t know what cintdlls, are but “dll” sounds like windows to me and anyhow I didn’t compile root by myself. If I’m wrong and I’m missing a step, please send me a link with doc.

You see here root version and output.

[code]ddangelo@isengard:~$ root
Warning in TEnvRec::ChangeValue: duplicate entry <Library.TArrowEditor=libGed.so libHist.so libGpad.so libGraf.so libGui.so libTree.so libTreePlayer.so> for level 0; ignored


  •                                     *
    
  •    W E L C O M E  to  R O O T       *
    
  •                                     *
    
  • Version 4.02/00 16 December 2004 *
  •                                     *
    
  • You are welcome to visit our Web site *
  •      http://root.cern.ch            *
    
  •                                     *
    

FreeType Engine v2.1.3 used to render TrueType fonts.
Compiled for linux with thread support.

CINT/ROOT C/C++ Interpreter version 5.15.159, Nov 14 2004
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] #include
root [1] .x sample_reader.C
Size of L: 3
Size of C: 0
root [2]
[/code]

I just noticed the initial warning now, but it doesn’t look related to the problem to me.

I also include the tar file as requested
faulty_float_vector.tar.gz (8.74 KB)

Hi,

The cintdlls are simply the shared library used by CINT to provided the dictionary for the typical stl container (vector, vector, etc.)

The problem is that you do not have the dictionary for vector. This lead to the result of e->GetLaben().GetClusters()[0] being sometime wrong.

To solve the problem simply add:

#ifdef __MAKECINT__ #pragma link C++ class std::vector<BxLabenCluster>; #endif
to your sample_bx_classes_nohits.C file.

Cheers,
Philippe.

this helps only with this sample macro, but in my compiled program this line is of course already present in the LinkDef file.

I attach it.

Actually I’m using the control macro “CINT” there, while you mentioned “MAKECINT” are they equivalent?

thanks, bye
Davide
BxEventLinkDef.h (3.67 KB)

Hi,

In your linkdef I recommend that you replace all the line like

by

CINT is on when ever the file is processed by cint.
MAKECINT is on only when the file is processed by rootcint (or makecint).

Cheers,
Philippe.

Dear Philippe,

sorry for such a delayed answer but was on other things for a while.
I implemented your modifications, thank you.

The situation now is the following:
The BxLabenCluster vector can have size =0 or !=0 depending on event typology.
Now, when 1 or more cluster exist also the vector<Float_t> within them is handled correctly. When no clusters are present, the bxtree->GetEntry() produces the ususal error message:

where “times” is the name of the std::vector<Float_t>.

Of course a huge amount of such errors (1 per event) is produced by TTree::Draw() or by a TBrowser click, though in both cases plots are correct.

Thanks
Davide

Hi Davide,

Please provide me with your latest code showing this problem.

Cheers,
Philippe

Dear Philippe,

sorry for late answering.
I prepared simple files reproducing the issue.
You should run from CINT first the writer and then the reader.
The clusters vector is filled only in half of the cases and in those also the vector of float “times” within cluster object has the right size.
In the other cases TTree::GetEntry() produces the error message I mentioned before.

thanks, ciao
Davide
sample_bx_classes.C (1.77 KB)
sample_writer.C (581 Bytes)
sample_reader.C (612 Bytes)

Hi Davide,

Thanks for your succint example. The problem (which was only in the reading part) will be solved shortly in the CVS repository.

Cheers,
Philippe.