ROOT  6.06/09
Reference Guide
PoolUtils.cxx
Go to the documentation of this file.
1 #include "PoolUtils.h"
2 #include "TClass.h"
3 #include "TList.h"
4 #include <iostream>
5 
6 //////////////////////////////////////////////////////////////////////////
7 /// Merge collection of TObjects.
8 /// This function looks for an implementation of the Merge method
9 /// (e.g. TH1F::Merge) and calls it on the objects contained in objs.
10 /// If Merge is not found, a null pointer is returned.
11 TObject* PoolUtils::ReduceObjects(const std::vector<TObject *>& objs)
12 {
13  if(objs.size() == 0)
14  return nullptr;
15 
16  if(objs.size() == 1)
17  return objs[0];
18 
19  //get first object from objs
20  TObject *obj = objs[0];
21  //get merge function
22  ROOT::MergeFunc_t merge = obj->IsA()->GetMerge();
23  if(!merge) {
24  std::cerr << "could not find merge method for TObject*\n. Aborting operation.";
25  return nullptr;
26  }
27 
28  //put the rest of the objs in a list
29  TList mergelist;
30  unsigned NObjs = objs.size();
31  for(unsigned i=1; i<NObjs; ++i) //skip first object
32  mergelist.Add(objs[i]);
33 
34  //call merge
35  merge(obj, &mergelist, nullptr);
36  mergelist.Delete();
37 
38  //return result
39  return obj;
40 }
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:404
TObject * ReduceObjects(const std::vector< TObject * > &objs)
Merge collection of TObjects.
Definition: PoolUtils.cxx:11
Long64_t(* MergeFunc_t)(void *, TCollection *, TFileMergeInfo *)
Definition: Rtypes.h:153
A doubly linked list.
Definition: TList.h:47
Mother of all ROOT objects.
Definition: TObject.h:58
virtual void Add(TObject *obj)
Definition: TList.h:81
TObject * obj