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