Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
km3io
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container 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
Show more breadcrumbs
km3py
km3io
Commits
c4c80cb3
Commit
c4c80cb3
authored
4 years ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
Refactor BranchMapper
parent
71867786
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
km3io/tools.py
+45
-3
45 additions, 3 deletions
km3io/tools.py
with
45 additions
and
3 deletions
km3io/tools.py
+
45
−
3
View file @
c4c80cb3
...
...
@@ -34,9 +34,50 @@ def _unfold_indices(obj, indices):
return
obj
BranchMapper
=
namedtuple
(
"
BranchMapper
"
,
[
'
name
'
,
'
key
'
,
'
extra
'
,
'
exclude
'
,
'
update
'
,
'
attrparser
'
,
'
flat
'
,
'
interpretations
'
])
class
BranchMapper
:
def
__init__
(
self
,
name
,
key
,
extra
=
None
,
exclude
=
None
,
update
=
None
,
attrparser
=
None
,
flat
=
True
,
interpretations
=
None
):
"""
Mapper helper for keys in a ROOT branch.
Parameters
----------
name: str
The name of the mapper helper which is displayed to the user
key: str
The key of the branch in the ROOT tree.
exclude: ``None``, ``list(str)``
Keys to exclude from parsing.
update: ``None``, ``dict(str: str)``
An update map for keys which are to be presented with a different
key to the user e.g. ``{
"
n_hits
"
:
"
hits
"
}`` will rename the ``hits``
key to ``n_hits``.
extra: ``None``, ``dict(str: str)``
An extra mapper for hidden object, primarily nested ones like
``t.fSec``, which can be revealed and mapped to e.g. ``t_sec``
via ``{
"
t_sec
"
,
"
t.fSec
"
}``.
attrparser: ``None``, ``function(str) -> str``
The function to be used to create attribute names. This is only
needed if unsupported characters are present, like ``.``, which
would prevent setting valid Python attribute names.
"""
self
.
name
=
name
self
.
key
=
key
self
.
extra
=
{}
if
extra
is
None
else
extra
self
.
exclude
=
[]
if
exclude
is
None
else
exclude
self
.
update
=
{}
if
update
is
None
else
update
self
.
attrparser
=
(
lambda
x
:
x
)
if
attrparser
is
None
else
attrparser
self
.
flat
=
flat
self
.
interpretations
=
{}
if
interpretations
is
None
else
interpretations
class
Branch
:
...
...
@@ -85,6 +126,7 @@ class Branch:
for
k
in
self
.
_mapper
.
update
.
values
():
del
self
.
_keymap
[
k
]
print
(
self
.
_keymap
)
for
key
in
self
.
_keymap
.
keys
():
setattr
(
self
,
key
,
None
)
...
...
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