From e72ff508d9ecef54dd40889636e08e81f2da7e3e Mon Sep 17 00:00:00 2001
From: Danilo Piparo <danilo.piparo@cern.ch>
Date: Wed, 12 Jul 2017 18:11:49 +0200
Subject: [PATCH] TThreadedObject: detach slots' histograms from directories

and don't create fake directories to store histograms.
---
 core/thread/inc/ROOT/TThreadedObject.hxx | 33 +++++++++++++++++++-----
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/core/thread/inc/ROOT/TThreadedObject.hxx b/core/thread/inc/ROOT/TThreadedObject.hxx
index dc5638f6424..8078a6664b0 100644
--- a/core/thread/inc/ROOT/TThreadedObject.hxx
+++ b/core/thread/inc/ROOT/TThreadedObject.hxx
@@ -26,6 +26,8 @@
 #include "ROOT/TSpinMutex.hxx"
 #include "TROOT.h"
 
+class TH1;
+
 namespace ROOT {
 
    namespace Internal {
@@ -67,6 +69,29 @@ namespace ROOT {
             }
          };
 
+         template<class T, bool ISHISTO = std::is_base_of<TH1,T>::value>
+         struct DirCreator{
+            static std::vector<TDirectory*> Create(unsigned maxSlots) {
+               std::string dirName = "__TThreaded_dir_";
+               dirName += std::to_string(ROOT::Internal::TThreadedObjectUtils::GetTThreadedObjectIndex()) + "_";
+               std::vector<TDirectory*> dirs;
+               dirs.reserve(maxSlots);
+               for (unsigned i=0; i< maxSlots;++i) {
+                  auto dir = gROOT->mkdir((dirName+std::to_string(i)).c_str());
+                  dirs.emplace_back(dir);
+               }
+               return dirs;
+            }
+         };
+
+         template<class T>
+         struct DirCreator<T, true>{
+            static std::vector<TDirectory*> Create(unsigned maxSlots) {
+               std::vector<TDirectory*> dirs(maxSlots, nullptr);
+               return dirs;
+            }
+         };
+
       } // End of namespace TThreadedObjectUtils
    } // End of namespace Internals
 
@@ -114,13 +139,7 @@ namespace ROOT {
       template<class ...ARGS>
       TThreadedObject(ARGS&&... args): fObjPointers(fgMaxSlots, nullptr)
       {
-         fDirectories.reserve(fgMaxSlots);
-
-         std::string dirName = "__TThreaded_dir_";
-         dirName += std::to_string(ROOT::Internal::TThreadedObjectUtils::GetTThreadedObjectIndex()) + "_";
-         for (unsigned i=0; i< fgMaxSlots;++i) {
-            fDirectories.emplace_back(gROOT->mkdir((dirName+std::to_string(i)).c_str()));
-         }
+         fDirectories = Internal::TThreadedObjectUtils::DirCreator<T>::Create(fgMaxSlots);
 
          TDirectory::TContext ctxt(fDirectories[0]);
          fModel.reset(new T(std::forward<ARGS>(args)...));
-- 
GitLab