Logo ROOT  
Reference Guide
TBranchIMTHelper.h
Go to the documentation of this file.
1 // @(#)root/tree:$Id$
2 // Author: Brian Bockelman, 2017
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_TBranchIMTHelper
13 #define ROOT_TBranchIMTHelper
14 
15 #include "RtypesCore.h"
16 
17 #ifdef R__USE_IMT
18 #include "ROOT/TTaskGroup.hxx"
19 #endif
20 
21 /** \class ROOT::Internal::TBranchIMTHelper
22  A helper class for managing IMT work during TTree:Fill operations.
23 */
24 
25 namespace ROOT {
26 namespace Internal {
27 
29 
30 #ifdef R__USE_IMT
32 #endif
33 
34 public:
35  template<typename FN> void Run(const FN &lambda) {
36 #ifdef R__USE_IMT
37  if (!fGroup) { fGroup.reset(new TaskGroup_t()); }
38  fGroup->Run( [=]() {
39  auto nbytes = lambda();
40  if (nbytes >= 0) {
41  fBytes += nbytes;
42  } else {
43  ++fNerrors;
44  }
45  });
46 #else
47  (void)lambda;
48 #endif
49  }
50 
51  void Wait() {
52 #ifdef R__USE_IMT
53  if (fGroup) fGroup->Wait();
54 #endif
55  }
56 
57  Long64_t GetNbytes() { return fBytes; }
59 
60 private:
61  std::atomic<Long64_t> fBytes{0}; ///< Total number of bytes written by this helper.
62  std::atomic<Int_t> fNerrors{0}; ///< Total error count of all tasks done by this helper.
63 #ifdef R__USE_IMT
64  std::unique_ptr<TaskGroup_t> fGroup;
65 #endif
66 };
67 
68 } // Internal
69 } // ROOT
70 
71 #endif
ROOT::Internal::TBranchIMTHelper::Run
void Run(const FN &lambda)
Definition: TBranchIMTHelper.h:35
ROOT::Internal::TBranchIMTHelper::GetNbytes
Long64_t GetNbytes()
Definition: TBranchIMTHelper.h:57
ROOT::Internal::TBranchIMTHelper::GetNerrors
Long64_t GetNerrors()
Definition: TBranchIMTHelper.h:58
ROOT::Internal::TBranchIMTHelper::fGroup
std::unique_ptr< TaskGroup_t > fGroup
Definition: TBranchIMTHelper.h:64
ROOT::Internal::TBranchIMTHelper::fNerrors
std::atomic< Int_t > fNerrors
Total error count of all tasks done by this helper.
Definition: TBranchIMTHelper.h:62
Long64_t
long long Long64_t
Definition: RtypesCore.h:80
ROOT::Experimental::TTaskGroup
A class to manage the asynchronous execution of work items.
Definition: TTaskGroup.hxx:21
ROOT::Internal::TBranchIMTHelper::fBytes
std::atomic< Long64_t > fBytes
Total number of bytes written by this helper.
Definition: TBranchIMTHelper.h:61
void
typedef void((*Func_t)())
ROOT::Internal::TBranchIMTHelper::TaskGroup_t
ROOT::Experimental::TTaskGroup TaskGroup_t
Definition: TBranchIMTHelper.h:31
RtypesCore.h
ROOT::Internal::TBranchIMTHelper
A helper class for managing IMT work during TTree:Fill operations.
Definition: TBranchIMTHelper.h:28
TTaskGroup.hxx
ROOT::Internal::TBranchIMTHelper::Wait
void Wait()
Definition: TBranchIMTHelper.h:51
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4