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

Occasional streamer type mismatch in multi-thread TTree writing

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: master
    • Fix Version/s: 6.22/00, 6.20/06
    • Component/s: I/O
    • Labels:
      None
    • Environment:

      any

      Description

      The reproducer below, based on TBufferMerger, prints error messages such as these in at least one in 5 runs on my machine (ROOT debug build, running on 8 cores):

      Error in <TBranchElement::SetAddress>: Branch m_vector is a split STL container (fStreamerType is: 500), the address can not be set directly.
      

      The relevant data and the FCS_Cell.h header are available from https://cernbox.cern.ch/index.php/s/c509o7IlvCqkkd4

      The problem is also discussed here on the forum.

      #include <TTree.h>
      #include <TTreeReader.h>
      #include <TTreeReaderValue.h>
      #include <TInterpreter.h>
      #include <ROOT/TBufferMerger.hxx>
      #include <ROOT/RMakeUnique.hxx>
      #include <ROOT/TThreadExecutor.hxx>
       
      #include <string>
      #include <iostream>
      #include <thread>
      #include <memory>
       
      #include "FCS_Cell.h"
       
      int main()
      {
         ROOT::EnableThreadSafety();
       
         gInterpreter->ProcessLine(".L FCS_Cell.h+");
         gInterpreter->Declare("#include \"FCS_Cell.h\"");
       
         const auto ntasks = 16;
         std::vector<std::unique_ptr<ROOT::Experimental::TBufferMerger>> mergers;
         for (auto i = 0; i < ntasks; ++i) {
            const auto fname = "out" + std::to_string(i) + ".root";
            mergers.emplace_back(std::make_unique<ROOT::Experimental::TBufferMerger>(fname.c_str()));
         }
         
         auto task = [&] (int i) {
            ::TDirectory::TContext c;
       
            TFile in_f("files/file1.root");
            auto *in_t = in_f.Get<TTree>("FCS_ParametrizationInput");
            TTreeReader r(in_t);
            TTreeReaderValue<FCS_matchedcellvector> rv(r, "Sampling_1");
       
            auto f = mergers[i]->GetFile();
            auto out_t = std::make_unique<TTree>("t", "t");
            out_t->SetImplicitMT(false);
       
            bool firstEvent = true;
            while (r.Next()) {
               if (firstEvent) {
                  auto *p = static_cast<FCS_matchedcellvector*>(rv.GetAddress());
                  out_t->Branch("FCS_ParametrizationInput", p);
                  firstEvent = false;
               }
               out_t->Fill();
            }
         };
       
         ROOT::TThreadExecutor pool;
         std::vector<int> idxs(ntasks);
         std::iota(idxs.begin(), idxs.end(), 0);
         pool.Foreach(task, idxs);
       
         return 0;
      }
      

        Attachments

          Activity

            People

            • Assignee:
              pcanal Philippe Canal
              Reporter:
              eguiraud Enrico Guiraud
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: