Logo ROOT  
Reference Guide
PoolUtils.h
Go to the documentation of this file.
1/* @(#)root/multiproc:$Id$ */
2// Author: Enrico Guiraud July 2015
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_PoolUtils
13#define ROOT_PoolUtils
14
15#include "TError.h"
16#include "TList.h"
17#include "TObject.h"
18#include <vector>
19
20
21namespace ROOT {
22//////////////////////////////////////////////////////////////////////////
23///
24/// This namespace contains pre-defined functions to be used in
25/// conjuction with TExecutor::Map and TExecutor::MapReduce.
26///
27//////////////////////////////////////////////////////////////////////////
28 namespace ExecutorUtils {
29 //////////////////////////////////////////////////////////////////////////
30 /// Merge collection of TObjects.
31 /// This functor looks for an implementation of the Merge method
32 /// (e.g. TH1F::Merge) and calls it on the objects contained in objs.
33 /// If Merge is not found, a null pointer is returned.
34 template <class T>
36 public:
37 T operator()(const std::vector<T> &objs){
39 "The argument should be a vector of pointers to TObject or derived classes");
40 if(objs.size() == 0)
41 return nullptr;
42
43 if(objs.size() == 1)
44 return objs[0];
45
46 //get first object from objs
47 auto obj = objs[0];
48 //get merge function
49 ROOT::MergeFunc_t merge = obj->IsA()->GetMerge();
50 if(!merge) {
51 Error("PoolUtils::ReduceObjects", "could not find merge method for the TObject\n. Aborting operation.");
52 return nullptr;
53 }
54
55 //put the rest of the objs in a list
56 TList mergelist;
57 unsigned NObjs = objs.size();
58 for(unsigned i=1; i<NObjs; ++i) //skip first object
59 mergelist.Add(objs[i]);
60
61 //call merge
62 merge(obj, &mergelist, nullptr);
63 mergelist.Delete();
64
65 //return result
66 return obj;
67 }
68 };
69 }
70}
71
72// For backward compatibility
74
75namespace ROOT {
76 namespace Internal {
77 namespace ExecutorUtils {
78 // The caster casts a pointer to a TObject to a specialised type F and leaves
79 // unaltered the other cases.
80 template <class O, class F>
82 public:
83 static O CastIfNeeded(O &&obj)
84 {
85 return obj;
86 }
87 };
88 template <class F>
90 public:
92 {
93 return static_cast<F>(obj);
94 }
95 };
96 }
97 // For backward compatibility
98 namespace PoolUtils = ExecutorUtils;
99 }
100}
101
102
103#endif
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition: TError.cxx:187
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Merge collection of TObjects.
Definition: PoolUtils.h:35
T operator()(const std::vector< T > &objs)
Definition: PoolUtils.h:37
static std::enable_if< std::is_pointer< F >::value, F >::type CastIfNeeded(TObject *obj)
Definition: PoolUtils.h:91
A doubly linked list.
Definition: TList.h:38
void Add(TObject *obj) override
Definition: TList.h:81
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:470
Mother of all ROOT objects.
Definition: TObject.h:37
#define F(x, y, z)
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: PoolUtils.h:28
double T(double x)
Definition: ChebyshevPol.h:34
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
Long64_t(* MergeFunc_t)(void *, TCollection *, TFileMergeInfo *)
Definition: Rtypes.h:114