<commit_before>/* @(#)root/multiproc:$Id$ */
// Author: <NAME> July 2015

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_PoolUtils
#define ROOT_PoolUtils

#include "TObject.h"
#include <vector>

namespace PoolCode {

   //////////////////////////////////////////////////////////////////////////
   ///
   /// An enumeration of the message codes handled by TPool, TPoolWorker and TPoolProcessor
   ///
   //////////////////////////////////////////////////////////////////////////

   enum EPoolCode : unsigned {
      //not an enum class because we want to be able to easily cast back and forth from unsigned
      /* TPool::Map */
      kExecFunc = 0,    ///< Execute function without arguments
      kExecFuncWithArg, ///< Execute function with the argument contained in the message
      kFuncResult,      ///< The message contains the result of a function execution
      /* TPool::MapReduce */
      kIdling,          ///< We are ready for the next task
      kSendResult,      ///< Ask for a kFuncResult/kProcResult
      /* TPool::Process */
      kProcFile,        ///< Tell a TPoolProcessor which tree to process. The object sent is a TreeInfo
      kProcRange,       ///< Tell a TPoolProcessor which tree and entries range to process. The object sent is a TreeRangeInfo
      kProcTree,        ///< Tell a TPoolProcessor to process the tree that was passed to it at construction time
      kProcResult,      ///< The message contains the result of the processing of a TTree
      kProcEnded,       ///< Tell the client we are done processing (i.e. we have reached the target number of entries to process)
      kProcError,       ///< Tell the client there was an error while processing
   };

}

//////////////////////////////////////////////////////////////////////////
///
/// This namespace contains pre-defined functions to be used in
/// conjuction with TPool::Map and TPool::MapReduce.
///
//////////////////////////////////////////////////////////////////////////
namespace PoolUtils {
  //////////////////////////////////////////////////////////////////////////
  /// Merge collection of TObjects.
  /// This functor looks for an implementation of the Merge method
  /// (e.g. TH1F::Merge) and calls it on the objects contained in objs.
  /// If Merge is not found, a null pointer is returned.
   template <class T>
   class ReduceObjects{
     public:
     T operator()(const std::vector<T> &objs){
      static_assert(std::is_constructible<TObject *, T>::value,
                    "The argument should be a vector of pointers to TObject or derived classes");
      if(objs.size() == 0)
         return nullptr;

      if(objs.size() == 1)
         return objs[0];

      //get first object from objs
      auto obj = objs[0];
      //get merge function
      ROOT::MergeFunc_t merge = obj->IsA()->GetMerge();
      if(!merge) {
         std::cerr << "could not find merge method for the TObject\n. Aborting operation.";
         return nullptr;
      }

      //put the rest of the objs in a list
      TList mergelist;
      unsigned NObjs = objs.size();
      for(unsigned i=1; i<NObjs; ++i) //skip first object
         mergelist.Add(objs[i]);

      //call merge<commit_msg>Fix issues in PoolUtils breaking the modules builds<commit_after>/* @(#)root/multiproc:$Id$ */
// Author: <NAME> July 2015

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_PoolUtils
#define ROOT_PoolUtils

#include "TObject.h"
#include <vector>
#include "TList.h"
#include "TError.h"

namespace PoolCode {

   //////////////////////////////////////////////////////////////////////////
   ///
   /// An enumeration of the message codes handled by TPool, TPoolWorker and TPoolProcessor
   ///
   //////////////////////////////////////////////////////////////////////////

   enum EPoolCode : unsigned {
      //not an enum class because we want to be able to easily cast back and forth from unsigned
      /* TPool::Map */
      kExecFunc = 0,    ///< Execute function without arguments
      kExecFuncWithArg, ///< Execute function with the argument contained in the message
      kFuncResult,      ///< The message contains the result of a function execution
      /* TPool::MapReduce */
      kIdling,          ///< We are ready for the next task
      kSendResult,      ///< Ask for a kFuncResult/kProcResult
      /* TPool::Process */
      kProcFile,        ///< Tell a TPoolProcessor which tree to process. The object sent is a TreeInfo
      kProcRange,       ///< Tell a TPoolProcessor which tree and entries range to process. The object sent is a TreeRangeInfo
      kProcTree,        ///< Tell a TPoolProcessor to process the tree that was passed to it at construction time
      kProcResult,      ///< The message contains the result of the processing of a TTree
      kProcEnded,       ///< Tell the client we are done processing (i.e. we have reached the target number of entries to process)
      kProcError,       ///< Tell the client there was an error while processing
   };

}

//////////////////////////////////////////////////////////////////////////
///
/// This namespace contains pre-defined functions to be used in
/// conjuction with TPool::Map and TPool::MapReduce.
///
//////////////////////////////////////////////////////////////////////////
namespace PoolUtils {
  //////////////////////////////////////////////////////////////////////////
  /// Merge collection of TObjects.
  /// This functor looks for an implementation of the Merge method
  /// (e.g. TH1F::Merge) and calls it on the objects contained in objs.
  /// If Merge is not found, a null pointer is returned.
   template <class T>
   class ReduceObjects{
     public:
     T operator()(const std::vector<T> &objs){
      static_assert(std::is_constructible<TObject *, T>::value,
                    "The argument should be a vector of pointers to TObject or derived classes");
      if(objs.size() == 0)
         return nullptr;

      if(objs.size() == 1)
         return objs[0];

      //get first object from objs
      auto obj = objs[0];
      //get merge function
      ROOT::MergeFunc_t merge = obj->IsA()->GetMerge();
      if(!merge) {
         Error("PoolUtils::ReduceObjects", "could not find merge method for the TObject\n. Aborting operation.");
         return nullptr;
      }

      //put the rest of the objs in a list
      TList mergelist;
      unsigned NObjs = objs.size();
      for(unsigned i=1; i<NObjs; ++i) //skip first object
         mergelist.Add(objs[i]);

      //call merge
{'fraction_non_alphanumeric': 0.221939117607617, 'fraction_numerical': 0.005095883062893925, 'mean_word_length': 1.6104305215260764, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1659982', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1744, 'n_words': 684}