11 #include "gtest/gtest.h" 19 tree->Branch(
"n", &n,
"n/I");
21 for (
int i = 0; i < count; ++i) {
30 return stat(name, &buffer) == 0;
50 EXPECT_TRUE(
FileExists(
"tbuffermerger_create.root"));
63 auto mytree =
new TTree(
"mytree",
"mytree");
71 Fill(mytree, 0, nevents);
75 EXPECT_TRUE(
FileExists(
"tbuffermerger_sequential.root"));
87 std::vector<std::thread> threads;
88 for (
int i = 0; i < nthreads; ++i) {
89 threads.emplace_back([=, &merger]() {
91 auto mytree =
new TTree(
"mytree",
"mytree");
99 Fill(mytree, i * nevents, nevents);
104 for (
auto &&t : threads) t.join();
107 EXPECT_TRUE(
FileExists(
"tbuffermerger_parallel.root"));
114 ASSERT_TRUE(
FileExists(
"tbuffermerger_sequential.root"));
117 TFile f(
"tbuffermerger_sequential.root");
118 auto t = (TTree *)f.
Get(
"mytree");
121 int nentries = (int)t->GetEntries();
123 t->SetBranchAddress(
"n", &n);
125 for (
int i = 0; i <
nentries; ++i) {
133 ASSERT_TRUE(
FileExists(
"tbuffermerger_parallel.root"));
136 TFile f(
"tbuffermerger_parallel.root");
137 auto t = (TTree *)f.
Get(
"mytree");
140 int nentries = (int)t->GetEntries();
142 t->SetBranchAddress(
"n", &n);
144 for (
int i = 0; i <
nentries; ++i) {
154 EXPECT_EQ(523776, sum_s);
155 EXPECT_EQ(523776, sum_p);
static long int sum(long int i)
std::shared_ptr< ToContentType_t< T > > Get(const std::string &name)
Get the object for a key.
TBufferMerger is a class to facilitate writing data in parallel from multiple threads, while writing to a single output file.
static bool FileExists(const char *name)
void EnableThreadSafety()
Enables the global mutex to make ROOT thread safe/aware.
std::shared_ptr< TBufferMergerFile > GetFile()
Returns a TBufferMergerFile to which data can be written.
double f2(const double *x)
TEST(TBufferMerger, CreateAndDestroy)
static void Fill(TTree *tree, int init, int count)