<commit_before>// @(#)root/tmva $Id$   
// Author: <NAME>
/*************************************************************************
 * Copyright (C) 2019, ROOT/TMVA                                         *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//
//  Defining Executor classes to be used in TMVA
// wrapping the functionality of the ROOT TThreadExecutor and
// ROOT TSequential Executor 
//  
/////////////////////////////////////////////////////////////////////////
#ifndef ROOT_TMVA_Executor
#define ROOT_TMVA_Executor

#include <memory>

#include <ROOT/TSequentialExecutor.hxx>
#ifdef R__USE_IMT
#include <ROOT/TThreadExecutor.hxx>
#endif


namespace TMVA {


/// Base Excutor class
class Executor {

public:

   template< class F, class... T>
   using noReferenceCond = typename std::enable_if<"Function can't return a reference" &&
                                                   !(std::is_reference<typename std::result_of<F(T...)>::type>::value)>::type;

  

   //////////////////////////////////////
   /// constructor of TMVA Executor class
   /// if ROOT::EnableIMplicitMT has not been called then by default a serial executor will be created
   /// A user can create a thread pool and enable multi-thread excution by calling TMVA::Config::Instance()::EnableMT(nthreads)
   /// FOr releasing the thread pool used by TMVA one can do it by calling  TMVA::Config::Instance()::DisableMT() or
   /// calling TMVA::Config::Instance()::EnableMT with only one thread 
   ////////////////////////////////////////////
   explicit Executor(int nthreads  = 0) {
      if (ROOT::IsImplicitMTEnabled() || nthreads > 1 ) {
#ifdef R__USE_IMT 
         fMTExecImpl = (nthreads == 0) ? std::unique_ptr< ROOT::TThreadExecutor>(new ROOT::TThreadExecutor()) :
            std::unique_ptr< ROOT::TThreadExecutor>(new ROOT::TThreadExecutor(nthreads));
#else
         ::Error("Executor","Cannot have multi threads when ROOT is built without IMT");
#endif
      }
      // case of single thread usage
      if (!fMTExecImpl)
         fSeqExecImpl = std::unique_ptr<ROOT::TSequentialExecutor>(new ROOT::TSequentialExecutor());
   }

#ifdef R__USE_IMT
   ROOT::TThreadExecutor * GetMultiThreadExecutor() {
      if (fMTExecImpl) return fMTExecImpl.get();
      else {
         fMTExecImpl =  std::unique_ptr< ROOT::TThreadExecutor>(new ROOT::TThreadExecutor());
         Info("GetThreadExecutor","Creating a TThread executor with a pool with a defult size of %d",fMTExecImpl->GetPoolSize()); 
         return fMTExecImpl.get();
      }
   }
#endif

   unsigned int GetPoolSize() const {
      if (!fMTExecImpl) return 1;
      return fMTExecImpl->GetPoolSize(); 
   }

   /// wrap TExecutor::Foreach
   template<class Function> 
   void Foreach(Function func, unsigned int nTimes, unsigned nChunks = 0) {
      if (fMTExecImpl) fMTExecImpl->Foreach(func,nTimes, nChunks);
      else fSeqExecImpl->Foreach(func,nTimes); 
   }
   template<class Function, class T> 
   void Foreach(Function func, std::vector<T> & args, unsigned nChunks = 0) {
      if (fMTExecImpl) fMTExecImpl->Foreach(func,args, nChunks);
      else fSeqExecImpl->Foreach(func, args); 
   }
   template<class Function, class INTEGER>
   void Foreach(Function func, ROOT::TSeq<INTEGER> args, unsigned nChunks = 0){
      if (fMTExecImpl) fMTExecImpl->Foreach(func,args, nChunks);
      else fSeqExecImpl->Foreach(func, args); 
   }<commit_msg>fix GetPoolSize for noimt<commit_after>// @(#)root/tmva $Id$   
// Author: <NAME>
/*************************************************************************
 * Copyright (C) 2019, ROOT/TMVA                                         *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//
//  Defining Executor classes to be used in TMVA
// wrapping the functionality of the ROOT TThreadExecutor and
// ROOT TSequential Executor 
//  
/////////////////////////////////////////////////////////////////////////
#ifndef ROOT_TMVA_Executor
#define ROOT_TMVA_Executor

#include <memory>

#include <ROOT/TSequentialExecutor.hxx>
#ifdef R__USE_IMT
#include <ROOT/TThreadExecutor.hxx>
#endif


namespace TMVA {


/// Base Excutor class
class Executor {

public:

   template< class F, class... T>
   using noReferenceCond = typename std::enable_if<"Function can't return a reference" &&
                                                   !(std::is_reference<typename std::result_of<F(T...)>::type>::value)>::type;

  

   //////////////////////////////////////
   /// constructor of TMVA Executor class
   /// if ROOT::EnableIMplicitMT has not been called then by default a serial executor will be created
   /// A user can create a thread pool and enable multi-thread excution by calling TMVA::Config::Instance()::EnableMT(nthreads)
   /// FOr releasing the thread pool used by TMVA one can do it by calling  TMVA::Config::Instance()::DisableMT() or
   /// calling TMVA::Config::Instance()::EnableMT with only one thread 
   ////////////////////////////////////////////
   explicit Executor(int nthreads  = 0) {
      if (ROOT::IsImplicitMTEnabled() || nthreads > 1 ) {
#ifdef R__USE_IMT 
         fMTExecImpl = (nthreads == 0) ? std::unique_ptr< ROOT::TThreadExecutor>(new ROOT::TThreadExecutor()) :
            std::unique_ptr< ROOT::TThreadExecutor>(new ROOT::TThreadExecutor(nthreads));
#else
         ::Error("Executor","Cannot have multi threads when ROOT is built without IMT");
#endif
      }
      // case of single thread usage
      if (!fMTExecImpl)
         fSeqExecImpl = std::unique_ptr<ROOT::TSequentialExecutor>(new ROOT::TSequentialExecutor());
   }

#ifdef R__USE_IMT
   ROOT::TThreadExecutor * GetMultiThreadExecutor() {
      if (fMTExecImpl) return fMTExecImpl.get();
      else {
         fMTExecImpl =  std::unique_ptr< ROOT::TThreadExecutor>(new ROOT::TThreadExecutor());
         Info("GetThreadExecutor","Creating a TThread executor with a pool with a defult size of %d",fMTExecImpl->GetPoolSize()); 
         return fMTExecImpl.get();
      }
   }
#endif

   unsigned int GetPoolSize() const {
      if (!fMTExecImpl) return 1;
#ifdef R__USE_IMT
      return fMTExecImpl->GetPoolSize();
#else
      return 1;
#endif
   }

   /// wrap TExecutor::Foreach
   template<class Function> 
   void Foreach(Function func, unsigned int nTimes, unsigned nChunks = 0) {
      if (fMTExecImpl) fMTExecImpl->Foreach(func,nTimes, nChunks);
      else fSeqExecImpl->Foreach(func,nTimes); 
   }
   template<class Function, class T> 
   void Foreach(Function func, std::vector<T> & args, unsigned nChunks = 0) {
      if (fMTExecImpl) fMTExecImpl->Foreach(func,args, nChunks);
      else fSeqExecImpl->Foreach(func, args); 
   }
   template<class Function, class INTEGER>
   void Foreach(Function func, ROOT::TSeq<INTEGER> args, unsigned nChunks = 0){
      if (fMTExecImpl) fMTExecImpl->Foreach(func,args, nChunks);
      else fSeqExecImpl->Foreach(func, args); 
   }
{'fraction_non_alphanumeric': 0.19947916666666668, 'fraction_numerical': 0.002994791666666667, 'mean_word_length': 2.3122035360068995, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1052482', 'n_tokens_mistral': 2148, 'n_tokens_neox': 2046, 'n_words': 555}