Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Root
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
为了安全,强烈建议开启2FA双因子认证:User Settings -> Account -> Enable two-factor authentication!!!
Show more breadcrumbs
cxwx
Root
Commits
94031e04
Commit
94031e04
authored
6 years ago
by
Enrico Guiraud
Browse files
Options
Downloads
Patches
Plain Diff
[TREEPROCMT] Add gtest with many input files
parent
17f4edce
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tree/treeplayer/test/CMakeLists.txt
+1
-0
1 addition, 0 deletions
tree/treeplayer/test/CMakeLists.txt
tree/treeplayer/test/treeprocmt/treeprocessormt_manyfiles.cxx
+73
-0
73 additions, 0 deletions
.../treeplayer/test/treeprocmt/treeprocessormt_manyfiles.cxx
with
74 additions
and
0 deletions
tree/treeplayer/test/CMakeLists.txt
+
1
−
0
View file @
94031e04
...
...
@@ -2,3 +2,4 @@ ROOT_ADD_UNITTEST_DIR(TreePlayer)
add_custom_command
(
TARGET treetreeplayertestUnit POST_BUILD
COMMAND
${
CMAKE_COMMAND
}
-E copy
${
CMAKE_CURRENT_SOURCE_DIR
}
/data.h data.h
)
ROOT_ADD_GTEST
(
treeprocessormt_manyfiles treeprocmt/treeprocessormt_manyfiles.cxx LIBRARIES TreePlayer
)
This diff is collapsed.
Click to expand it.
tree/treeplayer/test/treeprocmt/treeprocessormt_manyfiles.cxx
0 → 100644
+
73
−
0
View file @
94031e04
#include
<atomic>
#include
<chrono>
#include
<random>
#include
<string>
#include
<thread>
#include
<TFile.h>
#include
<TTree.h>
#include
<TSystem.h>
#include
<TTreeReader.h>
#include
<TTreeReaderValue.h>
#include
<ROOT/TTreeProcessorMT.hxx>
#include
"gtest/gtest.h"
void
WriteFiles
(
const
std
::
string
&
treename
,
const
std
::
vector
<
std
::
string
>
&
filenames
)
{
int
v
=
0
;
for
(
const
auto
&
f
:
filenames
)
{
TFile
file
(
f
.
c_str
(),
"recreate"
);
TTree
t
(
treename
.
c_str
(),
treename
.
c_str
());
t
.
Branch
(
"v"
,
&
v
);
for
(
auto
i
=
0
;
i
<
10
;
++
i
)
{
++
v
;
t
.
Fill
();
}
t
.
Write
();
}
}
void
DeleteFiles
(
const
std
::
vector
<
std
::
string
>
&
filenames
)
{
for
(
const
auto
&
f
:
filenames
)
gSystem
->
Unlink
(
f
.
c_str
());
}
TEST
(
TreeProcessorMT
,
ManyFiles
)
{
const
auto
nFiles
=
100u
;
const
std
::
string
treename
=
"t"
;
std
::
vector
<
std
::
string
>
filenames
;
for
(
auto
i
=
0u
;
i
<
nFiles
;
++
i
)
filenames
.
emplace_back
(
"treeprocmt_"
+
std
::
to_string
(
i
)
+
".root"
);
WriteFiles
(
treename
,
filenames
);
std
::
atomic_int
sum
(
0
);
std
::
atomic_int
count
(
0
);
auto
sumValues
=
[
&
sum
,
&
count
](
TTreeReader
&
r
)
{
TTreeReaderValue
<
int
>
v
(
r
,
"v"
);
std
::
random_device
seed
;
std
::
default_random_engine
eng
(
seed
());
std
::
uniform_int_distribution
<>
rand
(
1
,
100
);
while
(
r
.
Next
())
{
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
nanoseconds
(
rand
(
eng
)));
sum
+=
*
v
;
++
count
;
}
};
// TTreeProcMT requires a vector<string_view>
std
::
vector
<
std
::
string_view
>
fnames
;
for
(
const
auto
&
f
:
filenames
)
fnames
.
emplace_back
(
f
);
ROOT
::
TTreeProcessorMT
proc
(
fnames
,
treename
);
proc
.
Process
(
sumValues
);
EXPECT_EQ
(
count
.
load
(),
int
(
nFiles
*
10
));
// 10 entries per file
EXPECT_EQ
(
sum
.
load
(),
500500
);
// sum 1..nFiles*10
DeleteFiles
(
filenames
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment