How to Fill() Tree with vector< vector<long> >

Hi,

I have problems adding vectors of vectors into a Tree. I am not using cint but included all necessary libraries into my c++ project. It also shows no errors but the data is not inserted into the Tree.
I did try two different possibilities.
Here is an example.

typedef std::vector< std::vector<long> > LongMatrix; LongMatrix fadcRawData_;

I fill the array.

then I try to add the data into the tree by doing:

TTree* outputTree_; outputTree_->Branch("fadcRawData_tree",&fadcRawData_); outputTree->Fill();

it doesnt work.

when I use

TTree* outputTree_; outputTree_->Branch("fadcRawData_tree",&fadcRawData_,"fadcRawdata[size]/i"); outputTree->Fill();

it inputs data but I get some strange errors not while compiling but after running the program.

*** glibc detected *** ./hat: double free or corruption (!prev): 0x097f0bd0 *** ======= Backtrace: ========= /lib/tls/i686/cmov/libc.so.6(+0x6b591)[0x3c9f591] /lib/tls/i686/cmov/libc.so.6(+0x6cde8)[0x3ca0de8] /lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0x3ca3ecd] /usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x4a16741] ./hat(_ZN9__gnu_cxx13new_allocatorIlE10deallocateEPlj+0x11)[0x805b5bf] ./hat(_ZNSt12_Vector_baseIlSaIlEE13_M_deallocateEPlj+0x25)[0x805b257] ./hat(_ZNSt12_Vector_baseIlSaIlEED2Ev+0x38)[0x805ae12] ./hat(_ZNSt6vectorIlSaIlEED1Ev+0x39)[0x805a955] ./hat(_ZSt8_DestroyISt6vectorIlSaIlEEEvPT_+0x11)[0x805b903] ./hat(_ZNSt12_Destroy_auxILb0EE9__destroyIPSt6vectorIlSaIlEEEEvT_S6_+0x13)[0x805b687] ./hat(_ZSt8_DestroyIPSt6vectorIlSaIlEEEvT_S4_+0x18)[0x805b35c] ./hat(_ZSt8_DestroyIPSt6vectorIlSaIlEES2_EvT_S4_RSaIT0_E+0x18)[0x805b002] ./hat(_ZNSt6vectorIS_IlSaIlEESaIS1_EED1Ev+0x2e)[0x805aa40] ./hat(_ZN14TRawDataReaderD1Ev+0x21)[0x8060a9d] ./hat(main+0x2a7)[0x8063b27] /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0x3c4abd6] ./hat[0x8057d71] ======= Memory map: ======== 00110000-002a0000 r-xp 00000000 08:06 660685 /libs/root_5.27_2/lib/libRIO.so 002a0000-002a3000 r--p 00190000 08:06 660685 /libs/root_5.27_2/lib/libRIO.so 002a3000-002a5000 rw-p 00193000 08:06 660685 /libs/root_5.27_2/lib/libRIO.so 002a5000-002a6000 rw-p 00000000 00:00 0 002a6000-00481000 r-xp 00000000 08:06 660693 /libs/root_5.27_2/lib/libGraf.so 00481000-0048a000 r--p 001db000 08:06 660693 /libs/root_5.27_2/lib/libGraf.so 0048a000-0048d000 rw-p 001e4000 08:06 660693 /libs/root_5.27_2/lib/libGraf.so 0048d000-00494000 rw-p 00000000 00:00 0 00494000-00594000 r-xp 00000000 08:06 660733 /libs/root_5.27_2/lib/libGraf3d.so 00594000-00595000 ---p 00100000 08:06 660733 /libs/root_5.27_2/lib/libGraf3d.so 00595000-0059a000 r--p 00100000 08:06 660733 /libs/root_5.27_2/lib/libGraf3d.so 0059a000-0059c000 rw-p 00105000 08:06 660733 /libs/root_5.27_2/lib/libGraf3d.so 0059c000-0059e000 rw-p 00000000 00:00 0 0059e000-005cb000 r-xp 00000000 08:06 660694 /libs/root_5.27_2/lib/libRint.so 005cb000-005cc000 r--p 0002c000 08:06 660694 /libs/root_5.27_2/lib/libRint.so 005cc000-005cd000 rw-p 0002d000 08:06 660694 /libs/root_5.27_2/lib/libRint.so 005cd000-005cf000 r-xp 00000000 08:06 1052317 /lib/tls/i686/cmov/libdl-2.11.1.so 005cf000-005d0000 r--p 00001000 08:06 1052317 /lib/tls/i686/cmov/libdl-2.11.1.so 005d0000-005d1000 rw-p 00002000 08:06 1052317 /lib/tls/i686/cmov/libdl-2.11.1.so 005d1000-005f5000 r-xp 00000000 08:06 1052318 /lib/tls/i686/cmov/libm-2.11.1.so 005f5000-005f6000 r--p 00023000 08:06 1052318 /lib/tls/i686/cmov/libm-2.11.1.so 005f6000-005f7000 rw-p 00024000 08:06 1052318 /lib/tls/i686/cmov/libm-2.11.1.so 005f7000-005fd000 r-xp 00000000 08:06 1052321 /lib/tls/i686/cmov/libnss_compat-2.11.1.so 005fd000-005fe000 r--p 00006000 08:06 1052321 /lib/tls/i686/cmov/libnss_compat-2.11.1.so 005fe000-005ff000 rw-p 00007000 08:06 1052321 /lib/tls/i686/cmov/libnss_compat-2.11.1.so 00600000-0061b000 r-xp 00000000 08:06 1044618 /lib/ld-2.11.1.so 0061b000-0061c000 r--p 0001a000 08:06 1044618 /lib/ld-2.11.1.so 0061c000-0061d000 rw-p 0001b000 08:06 1044618 /lib/ld-2.11.1.so 0061d000-006ef000 r-xp 00000000 08:06 660649 /libs/root_5.27_2/lib/libGpad.so 006ef000-006f4000 r--p 000d1000 08:06 660649 /libs/root_5.27_2/lib/libGpad.so 006f4000-006f5000 rw-p 000d6000 08:06 660649 /libs/root_5.27_2/lib/libGpad.so 006f5000-006f7000 rw-p 00000000 00:00 0 006f7000-0073e000 r-xp 00000000 08:06 660648 /libs/root_5.27_2/lib/libPostscript.so 0073e000-0073f000 r--p 00047000 08:06 660648 /libs/root_5.27_2/lib/libPostscript.so 0073f000-00740000 rw-p 00048000 08:06 660648 /libs/root_5.27_2/lib/libPostscript.so 00740000-007cf000 r-xp 00000000 08:06 660656 /libs/root_5.27_2/lib/libPhysics.so 007cf000-007d1000 r--p 0008f000 08:06 660656 /libs/root_5.27_2/lib/libPhysics.so 007d1000-007d2000 rw-p 00091000 08:06 660656 /libs/root_5.27_2/lib/libPhysics.so 007d2000-007d3000 rw-p 00000000 00:00 0 007d3000-0081b000 r-xp 00000000 08:06 660731 /libs/root_5.27_2/lib/libThread.so 0081b000-0081d000 r--p 00047000 08:06 660731 /libs/root_5.27_2/lib/libThread.so 0081d000-0081e000 rw-p 00049000 08:06 660731 /libs/root_5.27_2/lib/libThread.so 0081e000-0081f000 rw-p 00000000 00:00 0 0081f000-00828000 r-xp 00000000 08:06 1052316 /lib/tls/i686/cmov/libcrypt-2.11.1.so 00828000-00829000 r--p 00008000 08:06 1052316 /lib/tls/i686/cmov/libcrypt-2.11.1.so 00829000-0082a000 rw-p 00009000 08:06 1052316 /lib/tls/i686/cmov/libcrypt-2.11.1.so 0082a000-00851000 rw-p 00000000 00:00 0 00858000-0086d000 r-xp 00000000 08:06 1052328 /lib/tls/i686/cmov/libpthread-2.11.1.so 0086d000-0086e000 r--p 00014000 08:06 1052328 /lib/tls/i686/cmov/libpthread-2.11.1.so 0086e000-0086f000 rw-p 00015000 08:06 1052328 /lib/tls/i686/cmov/libpthread-2.11.1.so 0086f000-00871000 rw-p 00000000 00:00 0 00871000-00884000 r-xp 00000000 08:06 1052320 /lib/tls/i686/cmov/libnsl-2.11.1.so 00884000-00885000 r--p 00012000 08:06 1052320 /lib/tls/i686/cmov/libnsl-2.11.1.soAborted

Pleas help.

BR

Erik

Hi,

The interface you used here does not check its input. The leaflist that is passed tells it that the address it receives points to a C-style array of int and unconditionally treats it that way … with catastrophic consequence in your case (since it is not a C-style array of int).

[quote]outputTree_->Branch(“fadcRawData_tree”,&fadcRawData_);

it doesnt work.[/quote]It should work (assuming you generated the dictionary for vector<vector >). How does it fail for you?

Cheers,
Philippe

Hi,

how do I create the dictionary for vector<vector > when not using cint? Actually I am using KDevelop 4.

outputTree_->Branch(“fadcRawData_tree”,&fadcRawData_); fails with not adding the data to the tree. So I assume I did not create the dictionary as I didnt do anything.

Thanks so far.

Hi,

I am not familiar with KDevelop4. See the User’s Guide chapter on adding a user class for all the details. You have several options. With v5.27/05 and up, you can call from your code:gInterpreter->GenerateDictionary("vector<vector<long> >","vector");(for older version see for example this [url=https://root-forum.cern.ch/t/vector-of-vector-in-a-tree-filling-clone-tree/10020/6 )

From a development environment / makefile, to create the dictionary you need to run rootcint:

rootcint -f mydict.cxx -c myheader.h myLinkDef.h which will create a source file named mydict.cxx that you can compile and link as any of your other source file. The file myLinkDef.h is where you typically put the line

#ifdef __MAKECINT__ #pragma link C++ class vector<vector<long> >+; #endif

Cheers,
Philippe

Thank you very much and sorry for my late answer.

I did generate the mydict.cxx with the parameters you describe and added it to my makefile. For myheader.h I used the header file of the class which uses the vector< vector >. Everything is compiling fine but now I am getting a different error:

Error in <TTree::SetBranchAddress>: The address for "fadcRawdata" should be the address of a pointer!

I dont know. What am I doing wrong now?

BR

Hi,

What is the ‘type’ of the variable that you passed as the 2nd parameter to SetBranchAddress?

Cheers,
Philippe

It is of type LongMatrix.

typedef std::vector< std::vector<long> > LongMatrix; LongMatrix fadcRawData_;

Do I have to use

?

BR

[quote]Do I have to use [/quote]Yes, you do (at least in the ROOT Version you have).

Cheers,
Philippe.

Thanks, I understand.
At the moment I am not really ROOT version dependent. So if I change to version 5.27/05 or higher, would it work without stack allocation?

BR

EDIT Where do I find version 5.27/05? As far as I can see only /04 is available for download.

[quote] So if I change to version 5.27/05 or higher, would it work without stack allocation?[/quote]Unfortunately no, the required modifications have not yet been finished (my apologies for the inaccurate information).

[quote]Where do I find version 5.27/05? As far as I can see only /04 is available for download.[/quote]The version number convention is that if the last digit is odd, this indicates that it is the trunk of the subversion repository. So you can download it using svn (see root.cern.ch/drupal/content/inst … oot-source)

Cheers,
Philippe.

Ah … thats a pity. Any information on when this feature will be available?
Thanks for all the great help.

BR

[quote]Any information on when this feature will be available?[/quote]Not really. It is currently on the back burner due to enhancements that also touches the same area of code.

Cheers,
Philippe.

So I see that version 5.27/06 is available now. Is the feature integrated in this version?
Thank’s.

Hi,

No it has not. The other projects are still ongoing.

Cheers,
Philippe.