Logo ROOT   6.12/07
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 "Rtypes.h"
16 
17 #ifdef R__USE_IMT
18 #include "ROOT/TTaskGroup.hxx"
19 #endif
20 
21 /// A helper class for managing IMT work during TTree:Fill operations.
22 ///
23 namespace ROOT {
24 namespace Internal {
25 
27 
28 #ifdef R__USE_IMT
30 #endif
31 
32 public:
33  template<typename FN> void Run(const FN &lambda) {
34 #ifdef R__USE_IMT
35  if (!fGroup) { fGroup.reset(new TaskGroup_t()); }
36  fGroup->Run( [=]() {
37  auto nbytes = lambda();
38  if (nbytes >= 0) {
39  fBytes += nbytes;
40  } else {
41  ++fNerrors;
42  }
43  });
44 #else
45  (void)lambda;
46 #endif
47  }
48 
49  void Wait() {
50 #ifdef R__USE_IMT
51  if (fGroup) fGroup->Wait();
52 #endif
53  }
54 
55  Long64_t GetNbytes() { return fBytes; }
57 
58 private:
59  std::atomic<Long64_t> fBytes{0}; // Total number of bytes written by this helper.
60  std::atomic<Int_t> fNerrors{0}; // Total error count of all tasks done by this helper.
61 #ifdef R__USE_IMT
62  std::unique_ptr<TaskGroup_t> fGroup;
63 #endif
64 };
65 
66 } // Internal
67 } // ROOT
68 
69 #endif
ROOT::Experimental::TTaskGroup TaskGroup_t
long long Long64_t
Definition: RtypesCore.h:69
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
std::atomic< Long64_t > fBytes
A class to manage the asynchronous execution of work items.
Definition: TTaskGroup.hxx:21
std::unique_ptr< TaskGroup_t > fGroup
typedef void((*Func_t)())