Uploaded image for project: 'ROOT'
  1. ROOT
  2. ROOT-8595

Under certain circumstances streaming of std::arrays in a columnwise fashion is not supported

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: 6.08/04
    • Fix Version/s: None
    • Component/s: I/O
    • Labels:
      None
    • Environment:

      all

      Description

      The reproducer is simple and can be found here:

      #include "TFile.h"
      #include "TTreeReader.h"
      #include "TTreeReaderArray.h"
       
      #include <array>
      #include <iostream>
       
      class ArrayHolder {
        public:
          ArrayHolder(int a, int b, int c){m_a[0]=a;m_a[1]=b;m_a[2]=c;};
          void Set(int a, int b, int c) {m_a[0]=a;m_a[1]=b;m_a[2]=c;};
          ArrayHolder() {};
          std::array<int, 3> m_a {{0,0,0}};
      //     int m_a[3] {0,0,0};
      };
       
       
      void test_macro() {
      //    auto file = TFile::Open("myfile.root", "RECREATE");
      //    auto tree = new TTree("bla", "bla");
      //
      //    ArrayHolder a_holder;
      //
      //    tree->Branch("testarrayholder2", &a_holder);
      //    for (int i=0;i<10;++i) {
      //       a_holder.Set(i,i+1,i+2);
      //       std::cout << a_holder.m_a[0] << " " << a_holder.m_a[1] << " " << a_holder.m_a[2] << std::endl;
      //       tree->Fill();
      //    }
      //    file->Write();
      //    file->Close();
       
         std::cout << "Read\n";
       
         auto file_read = TFile::Open("myfile.root");
         TTreeReader myReader("bla", file_read);
         TTreeReaderValue<ArrayHolder> r(myReader, "testarrayholder2");
         while(myReader.Next()) {
            std::cout << r->m_a[0] << " " << r->m_a[1] << " " << r->m_a[2] << std::endl;
         }
       
         file_read->Close();
      }
       

      Thanks to J. Lingemann for this report

        Attachments

          Activity

            People

            • Assignee:
              dpiparo Danilo Piparo
              Reporter:
              dpiparo Danilo Piparo
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: