TTree and vectors of vectors

Hello,

I have the following problem : I would like to write a vector of vectors of floats in a TTree (this is not really a matrix since all the rows don´t have the same length).
As the length depends on the event (let say the entry in the TTree) and is not known when I do the m_tree->Branch(…), what I thought I could do was to add a Branch containing a TObjArray of TVectors.

I´m not sure that what I do is correct and I don´t manage to read the objects again. What I have is :
TObjArray * m_Cells_ratioEovNoise_EM;
m_Cells_ratioEovNoise_EM = new TObjArray() ;
m_tree->Branch(“m_Cells_ratioEovNoise_EM”, “TObjArray”, &m_Cells_ratioEovNoise_EM);

and for each event,
TVectorF * vecCellsEM = new TVectorF(NColForRow);
m_Cells_ratioEovNoise_EM->AddAt(vecCellsEM, NRowsForEvent);

//loop on nbcellsEM
(*vecCellsEM)(nbcellsEM) = mynumber;

m_tree->Fill();

Could someone please help me to find what is wrong in that ?
Thank you, Olivier.

[quote]and I don´t manage to read the objects again.

Could someone please help me to find what is wrong in that ? [/quote]What did you try? How does it fail?

Philippe.

[quote=“pcanal”][quote]and I don´t manage to read the objects again.

Could someone please help me to find what is wrong in that ? [/quote]What did you try? How does it fail?

Philippe.[/quote]

It does run for creating the TTree but I didn´t find any way to read it :wink:.

I tried :
TObjArray * arr;
TBranch *branch = MyTree.GetBranch(“m_Cells_ratioEovNoise_EM”);
branch->SetAddress(&arr);
MyTree->GetEntry(0);

and I got :
Error in TExMap::Remove: key 1033027369 not found at 173
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=1033027369 pointer will be 0
Error in TExMap::Remove: key 19564 not found at 451
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=19564 pointer will be 0
Error in TExMap::Remove: key 2 not found at 3
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=2 pointer will be 0
Error in TExMap::Remove: key 872431616 not found at 249
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=872431616 pointer will be 0
Error in TExMap::Remove: key 93 not found at 93
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=93 pointer will be 0
Error in TBufferFile::CheckByteCount: object of class TCollection read too many bytes: 21987 instead of 21963
Warning in TBufferFile::CheckByteCount: TCollection::Streamer() not in sync with data on file /afs/cern.ch/user/a/arnaez/testarea/13.0.30/groups/LAPP/NTuplesESD/cmt/WZ_hists.root, fix Streamer()
Error in TExMap::Remove: key 196609 not found at 439
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=196609 pointer will be 0
Error in TExMap::Remove: key 50331648 not found at 463
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=50331648 pointer will be 0
Error in TExMap::Remove: key 272629761 not found at 240
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=272629761 pointer will be 0
Error in TExMap::Remove: key 436207615 not found at 482
Warning in TBufferFile::CheckObject: reference to unavailable class TObject, pointers of this type will be 0
Error in TExMap::Remove: key 1668575090 not found at 353
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=1668575090 pointer will be 0
Error in TExMap::Remove: key 1868657726 not found at 152
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=1868657726 pointer will be 0
Error in TExMap::Remove: key 4194305 not found at 291
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=4194305 pointer will be 0
Error in TExMap::Remove: key 16778240 not found at 173
Warning in TBufferFile::CheckObject: reference to unavailable class TObject, pointers of this type will be 0
Error in TExMap::Remove: key 16777216 not found at 155
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=16777216 pointer will be 0
Error in TExMap::Remove: key 196608 not found at 440
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=196608 pointer will be 0
Error in TBufferFile::CheckByteCount: object of class TCollection read too many bytes: 1463 instead of 1395
Warning in TBufferFile::CheckByteCount: TCollection::Streamer() not in sync with data on file /afs/cern.ch/user/a/arnaez/testarea/13.0.30/groups/LAPP/NTuplesESD/cmt/WZ_hists.root, fix Streamer()

I also tried to “cast” the type of the TObjArray object but got the same error.
I´m almost sure that the problem is in reading but how to correct it…

Thank you for any help, Olivier.

Hi,

You must initialize the your pointer. The parameter to SetBranchAddress and SetAddress are not the same (SetBranchAddress expect the address of the pointer while SetAddress is more finicky and should only be used if really necessary.

TryTObjArray * arr = 0; TBranch *branch 0; MyTree.SetBranchAddress("m_Cells_ratioEovNoise_EM",&arr,branch); MyTree->GetEntry(0);

Cheers,
Philippe.

[quote=“pcanal”]Hi,

You must initialize the your pointer. The parameter to SetBranchAddress and SetAddress are not the same (SetBranchAddress expect the address of the pointer while SetAddress is more finicky and should only be used if really necessary.

TryTObjArray * arr = 0; TBranch *branch 0; MyTree.SetBranchAddress("m_Cells_ratioEovNoise_EM",&arr,branch); MyTree->GetEntry(0); [/quote]

Hello Philippe,

So, I tried different without full success.
First attempt :
TObjArray * arr = 0;
TBranch * branch = 0;
MyTree->SetBranchAddress(“m_Cells_ratioEovNoise_EM”,&arr,branch);
MyTree->GetEntry(0);
I guess that a “&” was missing.

Second attempt :
TObjArray * arr = 0;
TBranch * branch = 0;
MyTree->SetBranchAddress(“m_Cells_ratioEovNoise_EM”,&arr,&branch);
MyTree->GetEntry(0);

Both gave me the same kind of error as previously.

I have a few things to check but it seems that this latter try gives me better results For the moment I checked that for the first entry the TObjArray contains a TVectorF and the TVectorF contains the right number of “cells”. Anyway, when I try to navigate within the events, ROOT exists sometimes…

Any idea ?

Cheers, Olivier.

P.S.: error message :
Error in TExMap::Remove: key 1033027369 not found at 173
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=1033027369 pointer will be 0
Error in TExMap::Remove: key 19564 not found at 451
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=19564 pointer will be 0
Error in TExMap::Remove: key 2 not found at 3
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=2 pointer will be 0
Error in TExMap::Remove: key 872431616 not found at 249
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=872431616 pointer will be 0
Error in TExMap::Remove: key 93 not found at 93
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=93 pointer will be 0
Error in TBufferFile::CheckByteCount: object of class TCollection read too many bytes: 21987 instead of 21963
Warning in TBufferFile::CheckByteCount: TCollection::Streamer() not in sync with data on file WZ_hists.root, fix Streamer()
Error in TExMap::Remove: key 196609 not found at 439
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=196609 pointer will be 0
Error in TExMap::Remove: key 50331648 not found at 463
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=50331648 pointer will be 0
Error in TExMap::Remove: key 272629761 not found at 240
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=272629761 pointer will be 0
Error in TExMap::Remove: key 436207615 not found at 482
Warning in TBufferFile::CheckObject: reference to unavailable class TObject, pointers of this type will be 0
Error in TExMap::Remove: key 1668575090 not found at 353
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=1668575090 pointer will be 0
Error in TExMap::Remove: key 1868657726 not found at 152
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=1868657726 pointer will be 0
Error in TExMap::Remove: key 4194305 not found at 291
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=4194305 pointer will be 0
Error in TExMap::Remove: key 16778240 not found at 173
Warning in TBufferFile::CheckObject: reference to unavailable class TObject, pointers of this type will be 0
Error in TExMap::Remove: key 16777216 not found at 155
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=16777216 pointer will be 0
Error in TExMap::Remove: key 196608 not found at 440
Warning in TBufferFile::CheckObject: reference to object of unavailable class TObject, offset=196608 pointer will be 0
Error in TBufferFile::CheckByteCount: object of class TCollection read too many bytes: 1463 instead of 1395
Warning in TBufferFile::CheckByteCount: TCollection::Streamer() not in sync with data on file WZ_hists.root, fix Streamer()

Hi,

Humm the default branch split level does not work for TObjArray.
You can work-around problem by using:t->Branch("m_Cells_ratioEovNoise_EM", "TObjArray", &m_Cells_ratioEovNoise_EM,32000,-1 /* select split level */);

Cheers,
Philipppe

[quote=“pcanal”]Hi,
Humm the default branch split level does not work for TObjArray.
You can work-around problem by using:t->Branch("m_Cells_ratioEovNoise_EM", "TObjArray", &m_Cells_ratioEovNoise_EM,32000,-1 /* select split level */);[/quote]

Ouah ! It seems to work correctly. I have no more error message and I can now access different events.

You´re the boss Philippe ! :wink:
Thank you very much. Regards,
Olivier.