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

[DF] Crash when running a custom action on a cached RDF

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 6.18/00, 6.16/02
    • Fix Version/s: 6.18/00, 6.16/02
    • Component/s: None
    • Labels:
      None
    • Environment:

      any

      Description

      Reproducer:

      #include <ROOT/RDataFrame.hxx>
      #include <memory>
       
      template <typename T>
      class KahanSum final : public ROOT::Detail::RDF::RActionImpl<class KahanSum<T>>  {
      public:
         /// This type is a requirement for every helper.
         using Result_t = T;
       
      private:
         std::vector<T> fPartialSums;
         std::vector<T> fCompensations;
         int fNSlots;
       
         std::shared_ptr<T> fResultSum;
       
         void KahanAlgorithm(const T &x, T &sum, T &compensation){
            T y = x - compensation;
            T t = sum + y;
            compensation = (t - sum) - y;
            sum = t;
         }
       
      public:
         KahanSum(KahanSum &&) = default;
         KahanSum(const KahanSum &) = delete;
       
         KahanSum(const std::shared_ptr<T> &r) : fResultSum(r)
         {
            static_assert(std::is_floating_point<T>::value, "Kahan sum makes sense only on floating point numbers");
       
            fNSlots = ROOT::IsImplicitMTEnabled() ? ROOT::GetImplicitMTPoolSize() : 1;
            fPartialSums.resize(fNSlots, 0.);
            fCompensations.resize(fNSlots, 0.);
         }
       
         std::shared_ptr<Result_t> GetResultPtr() const { return fResultSum; }
       
         void Initialize() {}
         void InitTask(TTreeReader *, unsigned int) {}
       
         void Exec(unsigned int slot, T x)
         {
            KahanAlgorithm(x, fPartialSums[slot], fCompensations[slot]);
         }
       
         template <typename V=T, typename std::enable_if<ROOT::TypeTraits::IsContainer<V>::value, int>::type = 0>
         void Exec(unsigned int slot, const T &vs)
         {
            for (auto &&v : vs) {
               Exec(slot, v);
            }
         }
       
         void Finalize()
         {
            T sum(0) ;
            T compensation(0);
            for (int i = 0; i < fNSlots; ++i) {
               KahanAlgorithm(fPartialSums[i], sum, compensation);
            }
            *fResultSum = sum;
         }
       
         std::string GetActionName(){
            return "THnHelper";
         }
       
      };
       
      int main()
      {
         auto cached = ROOT::RDataFrame("t", "f.root").Cache({"x"});
         KahanSum<double> helper(std::make_shared<double>());
         auto kahanResult = cached.Book<double>(std::move(helper), {"x"});
         std::cout << *kahanResult << std::endl;
         return 0;
      }
      

      Stacktrace:

      Error in <TTreeReaderValue::Get()>: Value reader not properly initialized, did you remember to call TTreeReader.Set(Next)Entry()? 
                                                                                                            
       *** Break *** segmentation violation
       
      #0  0x00005555555ba00a in ROOT::Internal::RDF::RAction<KahanSum<double>, ROOT::Detail::RDF::RLoopManager, ROOT::TypeTraits::TypeList<double> >::Exec<0ul> (this=0x5555596ba200, slot=0, entry=0) at /home/eguiraud/ROOT/build/include/ROOT/RDF/RAction.hxx:235
      #1  0x00005555555b9256 in ROOT::Internal::RDF::RActionCRTP<ROOT::Internal::RDF::RAction<KahanSum<double>, ROOT::Detail::RDF::RLoopManager, ROOT::TypeTraits::TypeList<double> > >::Run (this=0x5555596ba200, slot=0, entry=0) at /home/eguiraud/ROOT/build/include/ROOT/RDF/RAction.hxx:147
      #2  0x00007ffff66d8da3 in ROOT::Detail::RDF::RLoopManager::RunAndCheckFilters(unsigned int, long long) () from /home/eguiraud/ROOT/build/lib/libROOTDataFrame.so
      #3  0x00007ffff66d94fd in ROOT::Detail::RDF::RLoopManager::RunDataSource() () from /home/eguiraud/ROOT/build/lib/libROOTDataFrame.so
      #4  0x00007ffff66dda05 in ROOT::Detail::RDF::RLoopManager::Run() () from /home/eguiraud/ROOT/build/lib/libROOTDataFrame.so
      #5  0x00005555555ac1b7 in ROOT::RDF::RResultPtr<double>::TriggerRun (this=0x7fffffffe160) at /home/eguiraud/ROOT/build/include/ROOT/RResultPtr.hxx:299
      #6  0x00005555555a9800 in ROOT::RDF::RResultPtr<double>::Get (this=0x7fffffffe160) at /home/eguiraud/ROOT/build/include/ROOT/RResultPtr.hxx:131
      #7  0x00005555555a7306 in ROOT::RDF::RResultPtr<double>::operator* (this=0x7fffffffe160) at /home/eguiraud/ROOT/build/include/ROOT/RResultPtr.hxx:171
      #8  0x00005555555a48b8 in main () at test_book_after_cache.cpp:76
      

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Actual Start:
                  Actual End: