Adding std::array to a TTree

I have to write a std::array to a ttree, but I am facing some problems.

When I run the following Code:

void CreateTreeWithStdArray(){
    TFile f("test.root", "RECREATE");
    TTree t("tree", "tree");
    std::array<Double_t,3> arr;
    arr[0] = 10.1;
    t.Branch("arr", &arr);
    t.Fill();
    t.Write();
}

I get this error:

Error in <TBranchElement::InitializeOffsets>: Could not find the real data member '_M_elems[3]' when constructing the branch 'arr' [Likely missing ShowMember].

I can not create a dictonary, because I am getting this error:

Error: It is not necessary to explicitly select class array<double,3>. I/O is supported for it transparently.

Am I missing something?


ROOT Version: 6.12.06
Platform: Ubuntu 18.04
Compiler: gcc 7.4


I can reproduce this with the master. @pcanal - why doesn’t our “hey that’s just a special array case” hit here?

Is there any news about this problem?

I have pinged our I/O expert again, I hope you’ll see a reply soon…

Hi,

Until we had the proper overload, you can work around the issue with:

void CreateTreeWithStdArray(){
    TFile f("test.root", "RECREATE");
    TTree t("tree", "tree");
    std::array<Double_t,3> arr;
    arr[0] = 10.1;
    t.Branch("arr", &arr, "arr[3]/D");
    t.Fill();
    t.Write();
}

Cheers,
Philippe.

Thanks for the response,

the reason I am using std::array is, that I want to be able to change the size of the array at exactly one position and everything else to adapt automatically.

Your workaround needs one addition step for this, which makes it a bit ugly.

Thank you very much for your help!

This is implemented in the master (v6.20), see https://github.com/root-project/root/pull/4425.

Cheers,
Philippe.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.