Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Gaudi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gaudi
Gaudi
Commits
32a017ab
Commit
32a017ab
authored
3 years ago
by
Marco Clemencic
Browse files
Options
Downloads
Patches
Plain Diff
Refactor to move TDirectory management inside saveRootHistoInternal
parent
63917b20
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1234
Correctly group histograms in ROOT files
Pipeline
#2861864
passed
3 years ago
Stage: pre-build-checks
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
GaudiCommonSvc/src/HistogramPersistencySvc/RootHistogramSink.cpp
+34
-25
34 additions, 25 deletions
...mmonSvc/src/HistogramPersistencySvc/RootHistogramSink.cpp
with
34 additions
and
25 deletions
GaudiCommonSvc/src/HistogramPersistencySvc/RootHistogramSink.cpp
+
34
−
25
View file @
32a017ab
...
...
@@ -44,7 +44,8 @@ namespace {
}
template
<
typename
Traits
,
std
::
size_t
...
index
>
void
saveRootHistoInternal
(
const
std
::
string
&
name
,
nlohmann
::
json
&
j
,
std
::
index_sequence
<
index
...
>
)
{
void
saveRootHistoInternal
(
TFile
&
file
,
std
::
string
dir
,
std
::
string
name
,
const
nlohmann
::
json
&
j
,
std
::
index_sequence
<
index
...
>
)
{
// extract data from json
auto
jsonAxis
=
j
.
at
(
"axis"
);
auto
axis
=
std
::
array
{
toAxis
(
jsonAxis
[
index
]
)...};
...
...
@@ -55,6 +56,31 @@ namespace {
// compute total number of bins, multiplying bins per axis
auto
totNBins
=
(
(
axis
[
index
].
nBins
+
2
)
*
...
);
assert
(
weights
.
size
()
==
totNBins
);
// take into account the case where name contains '/'s (e.g. "Group/Name") by
// moving the prefix into dir
if
(
auto
pos
=
name
.
rfind
(
'/'
);
pos
!=
std
::
string
::
npos
)
{
dir
+=
'/'
+
name
.
substr
(
0
,
pos
);
name
=
name
.
substr
(
pos
+
1
);
}
// remember the current directory
auto
previousDir
=
gDirectory
;
// find or create the directory for the histogram
auto
currentDir
=
file
.
GetDirectory
(
""
);
for
(
const
auto
&
dir_level
:
dir
|
ranges
::
view
::
split_when
(
[](
auto
c
)
{
return
c
==
'/'
||
c
==
'.'
;
}
)
|
ranges
::
view
::
transform
(
[](
auto
&&
rng
)
{
return
rng
|
ranges
::
to
<
std
::
string
>
;
}
)
)
{
auto
nextDir
=
currentDir
->
GetDirectory
(
dir_level
.
c_str
()
);
if
(
!
nextDir
)
nextDir
=
currentDir
->
mkdir
(
dir_level
.
c_str
()
);
if
(
!
nextDir
)
throw
GaudiException
(
"Could not create directory "
+
dir
,
"Histogram::Sink::Root"
,
StatusCode
::
FAILURE
);
currentDir
=
nextDir
;
}
// switch to the directory
currentDir
->
cd
();
// Create Root histogram calling constructors with the args tuple
auto
histo
=
std
::
make_from_tuple
<
typename
Traits
::
Histo
>
(
std
::
tuple_cat
(
std
::
tuple
{
name
.
c_str
(),
title
.
c_str
()},
...
...
@@ -63,6 +89,9 @@ namespace {
for
(
unsigned
int
i
=
0
;
i
<
totNBins
;
i
++
)
Traits
::
fill
(
histo
,
i
,
weights
[
i
]
);
// write to file
histo
.
Write
();
// switch back to the previous directory
previousDir
->
cd
();
}
template
<
bool
isProfile
,
typename
RootHisto
>
...
...
@@ -95,8 +124,9 @@ namespace {
};
template
<
unsigned
int
N
,
bool
isProfile
,
typename
ROOTHisto
>
void
saveRootHisto
(
const
std
::
string
&
name
,
nlohmann
::
json
&
j
)
{
saveRootHistoInternal
<
Traits
<
isProfile
,
ROOTHisto
>>
(
name
,
j
,
std
::
make_index_sequence
<
N
>
()
);
void
saveRootHisto
(
TFile
&
file
,
std
::
string
dir
,
std
::
string
name
,
nlohmann
::
json
&
j
)
{
saveRootHistoInternal
<
Traits
<
isProfile
,
ROOTHisto
>>
(
file
,
std
::
move
(
dir
),
std
::
move
(
name
),
j
,
std
::
make_index_sequence
<
N
>
()
);
}
using
namespace
std
::
string_literals
;
...
...
@@ -144,28 +174,7 @@ namespace Gaudi::Histograming::Sink {
if
(
saver
==
registry
.
end
()
)
throw
GaudiException
(
"Unknown type : "
+
type
+
" dim : "
+
std
::
to_string
(
dim
),
"Histogram::Sink::Root"
,
StatusCode
::
FAILURE
);
// convert (owner + name) to (dir, name) splitting the name on "/" if needed
std
::
string
dir
=
ent
.
component
;
std
::
string
name
=
ent
.
name
;
if
(
auto
pos
=
name
.
rfind
(
'/'
);
pos
!=
std
::
string
::
npos
)
{
dir
+=
'/'
+
name
.
substr
(
0
,
pos
);
name
=
name
.
substr
(
pos
+
1
);
}
// find or create the directory for the histogram
auto
currentDir
=
histoFile
.
GetDirectory
(
""
);
for
(
const
auto
&
dir_level
:
dir
|
ranges
::
view
::
split_when
(
[](
auto
c
)
{
return
c
==
'/'
||
c
==
'.'
;
}
)
|
ranges
::
view
::
transform
(
[](
auto
&&
rng
)
{
return
rng
|
ranges
::
to
<
std
::
string
>
;
}
)
)
{
auto
nextDir
=
currentDir
->
GetDirectory
(
dir_level
.
c_str
()
);
if
(
!
nextDir
)
nextDir
=
currentDir
->
mkdir
(
dir_level
.
c_str
()
);
if
(
!
nextDir
)
throw
GaudiException
(
"Could not create directory "
+
dir
,
"Histogram::Sink::Root"
,
StatusCode
::
FAILURE
);
currentDir
=
nextDir
;
}
// switch to the directory and save the histogram
currentDir
->
cd
();
(
*
saver
->
second
)(
name
,
j
);
histoFile
.
cd
();
(
*
saver
->
second
)(
histoFile
,
ent
.
component
,
ent
.
name
,
j
);
}
);
return
ok
;
}
...
...
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