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 /// 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::Internal::TBranchIMTHelper::Run
void Run(const FN &lambda)
Definition: TBranchIMTHelper.h:33
ROOT::Internal::TBranchIMTHelper::GetNbytes
Long64_t GetNbytes()
Definition: TBranchIMTHelper.h:55
ROOT::Internal::TBranchIMTHelper::GetNerrors
Long64_t GetNerrors()
Definition: TBranchIMTHelper.h:56
ROOT::Internal::TBranchIMTHelper::fGroup
std::unique_ptr< TaskGroup_t > fGroup
Definition: TBranchIMTHelper.h:62
ROOT::Internal::TBranchIMTHelper::fNerrors
std::atomic< Int_t > fNerrors
Definition: TBranchIMTHelper.h:60
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
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
Definition: TBranchIMTHelper.h:59
void
typedef void((*Func_t)())
ROOT::Internal::TBranchIMTHelper::TaskGroup_t
ROOT::Experimental::TTaskGroup TaskGroup_t
Definition: TBranchIMTHelper.h:29
RtypesCore.h
ROOT::Internal::TBranchIMTHelper
Definition: TBranchIMTHelper.h:26
TTaskGroup.hxx
ROOT::Internal::TBranchIMTHelper::Wait
void Wait()
Definition: TBranchIMTHelper.h:49
ROOT
VSD Structures.
Definition: StringConv.hxx:21