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

ttree data for a type with 2d arrays (via Reflex)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: 5.34/00
    • Fix Version/s: None
    • Component/s: Dictionaries
    • Labels:
      None
    • Environment:

      linux 64b

    • Development:

      Description

      trying to write this data:

      // data2darray.h
      class Data2dArray {
       public:
        long I;
        double Array [2][2];
        double Data;
      };

      with this simple program:

      // main.cxx
      #include "TTree.h"
      #include "TFile.h"
      #include "Cintex/Cintex.h"
       
      #include "data2darray.h"
       
      #include <iostream>
       
      int main(int argc, char **argv) {
        ROOT::Cintex::Cintex::Enable();
       
        TFile *f = TFile::Open("event.root", "RECREATE");
        TTree *t = new TTree("tree", "tree");
        Data2dArray *evt = new Data2dArray;
        t->Branch("evt", &evt);
        for (int i = 0; i < 10; i++) {
          evt->I = i;
          evt->Data = i;
          evt->Array[0][0] = i;
          evt->Array[0][1] = 2*i;
          evt->Array[1][0] = -i;
          evt->Array[1][1] = -2*i;
          t->Fill();
        }
        f->Write();
        f->Close();
       
        return 0;
      }

      the dictionary was created with genreflex:

      $ genreflex data2darray.h -s selection.xml --rootmap=data2darray.rootmap
      $ $(CXX) -shared -o libdict.so data2darray_rflx.cpp -lReflex -lCintex

      selection.xml:

      <lcgdict>
        <class name="Data2dArray" />
      </lcgdict>

      running main and the CINT interpreter:

      root [0]   gSystem->Load("libCintex");
      root [1]   ROOT::Cintex::Cintex::Enable();
      root [2]   gSystem->Load("libdict");
      root [3]   f = TFile::Open("event.root");
      root [4]   t = (TTree*)f->Get("tree");
      root [5]   Data2dArray *evt = NULL;
      root [6]   t->SetBranchAddress("evt", &evt);
      root [7] t->GetEntry(2);
      root [8] evt->I
      (long)2
      root [9] evt->Data
      (double)2.00000000000000000e+00
      root [10] evt->Array
      (double*)0x1302898
      root [11] evt->Array[0]
      (double)2.00000000000000000e+00
      root [12] evt->Array[1]
      (double)4.00000000000000000e+00
      root [13] evt->Array[0][0]
      Error: Array index out of range Array[0][0] -> [0]  valid upto Array[1] (tmpfile):1:
      *** Interpreter error recovered ***

      The type information in data2darray_rflx.cpp looks kosher:

      namespace {
        ::Reflex::Type type_156 = ::Reflex::TypeBuilder(Reflex::Literal("long"));
        ::Reflex::Type type_void = ::Reflex::TypeBuilder(Reflex::Literal("void"));
        ::Reflex::Type type_141 = ::Reflex::TypeBuilder(Reflex::Literal("double"));
        ::Reflex::Type type_122 = ::Reflex::TypeBuilder(Reflex::Literal("Data2dArray"));
        ::Reflex::Type type_173 = ::Reflex::ArrayBuilder(type_141, 2);
        ::Reflex::Type type_170 = ::Reflex::ArrayBuilder(type_173, 2);
        ::Reflex::Type type_171 = ::Reflex::ReferenceBuilder(type_122);
        ::Reflex::Type type_122c = ::Reflex::ConstBuilder(type_122);
        ::Reflex::Type type_172 = ::Reflex::ReferenceBuilder(type_122c);
      } // unnamed namespace
      namespace {
        ::Reflex::Type type_156 = ::Reflex::TypeBuilder(Reflex::Literal("long"));
        ::Reflex::Type type_void = ::Reflex::TypeBuilder(Reflex::Literal("void"));
        ::Reflex::Type type_141 = ::Reflex::TypeBuilder(Reflex::Literal("double"));
        ::Reflex::Type type_122 = ::Reflex::TypeBuilder(Reflex::Literal("Data2dArray"));
        ::Reflex::Type type_173 = ::Reflex::ArrayBuilder(type_141, 2);
        ::Reflex::Type type_170 = ::Reflex::ArrayBuilder(type_173, 2);
        ::Reflex::Type type_171 = ::Reflex::ReferenceBuilder(type_122);
        ::Reflex::Type type_122c = ::Reflex::ConstBuilder(type_122);
        ::Reflex::Type type_172 = ::Reflex::ReferenceBuilder(type_122c);
      } // unnamed namespace
       
      [...]
      // Shadow classes to obtain the data member offsets 
      namespace __shadow__ {
      #ifdef __Data2dArray
      #undef __Data2dArray
      #endif
      class __Data2dArray {
        public:
        __Data2dArray();
        long I;
        double Array[2][2];
        double Data;
      };
      }
       
      //------Delayed data member builder for class Data2dArray -------------------
      void __Data2dArray_db_datamem(Reflex::Class* cl) {
        ::Reflex::ClassBuilder(cl)
        .AddDataMember(type_156, Reflex::Literal("I"), OffsetOf(__shadow__::__Data2dArray, I), ::Reflex::PUBLIC)
        .AddDataMember(type_170, Reflex::Literal("Array"), OffsetOf(__shadow__::__Data2dArray, Array), ::Reflex::PUBLIC)
        .AddDataMember(type_141, Reflex::Literal("Data"), OffsetOf(__shadow__::__Data2dArray, Data), ::Reflex::PUBLIC);
      }
       

      so... what am I missing here ? (am I the first one to generate a dict for a struct holding a 2d-array ?)

      -s

        Attachments

          Activity

            People

            • Assignee:
              axel Axel Naumann
              Reporter:
              binet Sebastien Binet
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: