# Problem with Writing Class Objects to TTrees that contain std::tuple\<double, double, double\> varialbes

**URL:** <https://root-forum.cern.ch/t/problem-with-writing-class-objects-to-ttrees-that-contain-std-tuple-double-double-double-varialbes/48749>\
**Category:** Newbie\
**Tags:** tree\
**Created:** [February 10, 2022, 3:28pm UTC](https://root-forum.cern.ch/t/problem-with-writing-class-objects-to-ttrees-that-contain-std-tuple-double-double-double-varialbes/48749 "2022-02-10T15:28:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrew](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@andrew](https://root-forum.cern.ch/u/andrew)\
**Post date:** [February 10, 2022, 3:28pm UTC](https://root-forum.cern.ch/t/problem-with-writing-class-objects-to-ttrees-that-contain-std-tuple-double-double-double-varialbes/48749/1 "2022-02-10T15:28:27Z")

</div>

Greetings,

I am currently facing a problem with regards to writing class objects that contain the STL class object `std::tuple<double, double, double>` to TTrees. I have recreated the essence of my problem in the following short snippets:

**Event.hpp**

```auto
#pragma once
#include <tuple>
#include <iostream>
#include <utility>

class Event
{
        public:
                Event();
                ~Event();
                void Set(std::tuple<double, double, double>, std::pair<double, double>);
                void Print();
        private:
                std::tuple<double, double, double> lPosition;
                std::pair<double, double> lTrigger;
};

```

and **Event.cpp**

```auto
#include <iostream>
#include <tuple>
#include <utility>
#include "Event.hpp"

Event::Event(){}
Event::~Event(){}
void Event::Set(std::tuple<double, double, double> _lPos, std::pair<double, double> _lTrig)
{
        lPosition = _lPos;
        lTrigger = _lTrig;
}
void Event::Print()
{
        std::cout << "Triple: (" << std::get<0>(lPosition) << ", " << std::get<1>(lPosition) << ", " << std::get<2>(lPosition) << ")" << std::endl;
        std::cout << "Pair: (" << lTrigger.first << ", " << lTrigger.second << ")" << std::endl;
}

```

I am compiling the .cpp file above via:

```auto
root -L Event.cpp+

```

and I load the `Event_cpp.so` library inside a `rootlogon.C` file. Now, if I run the following macro, inside the same folder as all the files mentioned above:

**fill.cpp**

```auto
#include <iostream>
#include "Event.hpp"
#include <TFile.h>
#include <TTree.h>
#include <TSystem.h>

int fill()
{

        if (gSystem->AccessPathName("output.root"))
        {
                std::cout << "\033[1;32m[SUCCESS]: \033[0;37mThe default output file \"output.root\" does not exist. Proceeding." << std::endl;
        }
        else
        {
                std::cout << "\033[1;31m[FATAL]\033[0;37m: The default output file \"output.root\" already exists. Aborting (exit code := 1)." << std::endl; std::exit(1);
        }

        TFile* _output = new TFile("output.root", "NEW");
        TTree* _main = new TTree("T", "DataTree");
        Event* _event = nullptr;
        _main->Branch("Event", &_event);
        std::tuple<double, double, double> A_Tuple(1,1,1);
        std::pair<double, double> A_Pair(1,1);
        _event->Set(A_Tuple, A_Pair);
        _event->Print();
        _main->Fill();
        _output->cd();
        _main->Write();
        _output->Close();
        return 0;

}

```

I get:

```auto
[SUCCESS]: The default output file "output.root" does not exist. Proceeding.
Warning in <TStreamerInfo::Build>: Event: tuple<double,double,double> has no streamer or dictionary, data member "lPosition" will not be saved
Triple: (1, 1, 1)
Pair: (1, 1)
(int) 0

```

which is where the problem appears to be: The object `std::tuple` cannot be written inside the TTree, while the object `std::pair` can without any problem. As far as I understand, ROOT does not have a way to “write” the object in the TTree via a TStreamer (which is explained in the warning message). Any help on this issue would be greatly appreciated.

Many Thanks,

Andy

* * *

\_ROOT Version: 6.24/06  
_Platform:_ Centos8  
_Compiler:_ g++ 11

* * *

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [February 10, 2022, 7:13pm UTC](https://root-forum.cern.ch/t/problem-with-writing-class-objects-to-ttrees-that-contain-std-tuple-double-double-double-varialbes/48749/2 "2022-02-10T19:13:54Z")

</div>

In **Event.hpp** add

```auto
#ifdef __ROOTCLING__
#pragma link C++ class std::tuple<double,double,double>+;
#endif

```

to request the dictionary for that class.

---

<div class="post-metadata">

**Author:** ![andrew](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@andrew](https://root-forum.cern.ch/u/andrew)\
**Post date:** [February 11, 2022, 9:41am UTC](https://root-forum.cern.ch/t/problem-with-writing-class-objects-to-ttrees-that-contain-std-tuple-double-double-double-varialbes/48749/3 "2022-02-11T09:41:35Z")

</div>

Hi @pcanal,

Thank you very much!! It works flawlessly!

Andy
