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

TDF: bad interaction between multi-thread execution and separate output TFile

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: 6.11/02
    • Fix Version/s: 6.12/06, 6.14/00
    • Component/s: Other
    • Labels:
      None
    • Environment:

      any

      Description

      Reproducer:

      #include <ROOT/TDataFrame.hxx>
      using namespace ROOT::Experimental;
       
      void writeHistNoInputFile()
      {
         std::cout << "write hist no input file" << std::endl;
         ROOT::EnableImplicitMT();
         TDataFrame d(10);
         auto counter = 0;
         auto dd = d.Define("x", [&counter]() { return counter++; });
         auto h = dd.Histo1D("x");
       
         TFile f("f1.root", "RECREATE");
         h->SetDirectory(&f);
         h->Write();
      }
       
      void makeDataSet()
      {
         std::cout << "make dataset" << std::endl;
         TDataFrame d(10);
         auto counter = 0;
         auto dd = d.Define("x", [&counter]() { return counter++; });
         dd.Snapshot<int>("t", "f.root", {"x"});
      }
       
      void writeHistWithInputFile()
      {
         std::cout << "write hist with input file" << std::endl;
         TDataFrame d("t", "f.root");
         auto h = d.Histo1D("x");
       
         TFile f("f2.root", "RECREATE");
         h->SetDirectory(&f);
         h->Write();
      }
       
      int main()
      {
         writeHistNoInputFile();
         makeDataSet();
         writeHistWithInputFile();
         return 0;
      }

      The output ROOT file f2.root is empty instead of containing a TDF result histogram.
      An error is printed on the console:

      write hist no input file
      make dataset
      write hist with input file
      Error in <TROOT::WriteTObject>: The current directory (root) is not associated with a file. The object () has not been written.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Actual End: