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
18402375
Commit
18402375
authored
5 years ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
make yapf
parent
2079c037
No related branches found
No related tags found
1 merge request
!24
Refactor offline
Pipeline
#10067
passed with warnings
5 years ago
Stage: test
Stage: coverage
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
km3io/tools.py
+12
-9
12 additions, 9 deletions
km3io/tools.py
tests/test_tools.py
+1
-0
1 addition, 0 deletions
tests/test_tools.py
with
13 additions
and
9 deletions
km3io/tools.py
+
12
−
9
View file @
18402375
...
@@ -6,6 +6,7 @@ import uproot
...
@@ -6,6 +6,7 @@ import uproot
BASKET_CACHE_SIZE
=
110
*
1024
**
2
BASKET_CACHE_SIZE
=
110
*
1024
**
2
BASKET_CACHE
=
uproot
.
cache
.
ThreadSafeArrayCache
(
BASKET_CACHE_SIZE
)
BASKET_CACHE
=
uproot
.
cache
.
ThreadSafeArrayCache
(
BASKET_CACHE_SIZE
)
class
cached_property
:
class
cached_property
:
"""
A simple cache decorator for properties.
"""
"""
A simple cache decorator for properties.
"""
def
__init__
(
self
,
function
):
def
__init__
(
self
,
function
):
...
@@ -56,8 +57,8 @@ class Branch:
...
@@ -56,8 +57,8 @@ class Branch:
def
_initialise_keys
(
self
):
def
_initialise_keys
(
self
):
"""
Create the keymap and instance attributes for branch keys
"""
"""
Create the keymap and instance attributes for branch keys
"""
# TODO: this could be a cached property
# TODO: this could be a cached property
keys
=
set
(
k
.
decode
(
'
utf-8
'
)
for
k
in
self
.
_branch
.
keys
())
-
set
(
keys
=
set
(
k
.
decode
(
'
utf-8
'
)
self
.
_mapper
.
exclude
)
for
k
in
self
.
_branch
.
keys
())
-
set
(
self
.
_mapper
.
exclude
)
self
.
_keymap
=
{
self
.
_keymap
=
{
**
{
self
.
_mapper
.
attrparser
(
k
):
k
**
{
self
.
_mapper
.
attrparser
(
k
):
k
for
k
in
keys
},
for
k
in
keys
},
...
@@ -132,6 +133,7 @@ class Branch:
...
@@ -132,6 +133,7 @@ class Branch:
self
.
_mapper
.
name
,
length
,
self
.
_mapper
.
name
,
length
,
'
s
'
if
length
>
1
else
''
)
'
s
'
if
length
>
1
else
''
)
class
Usr
:
class
Usr
:
"""
Helper class to access AAObject `usr` stuff
"""
"""
Helper class to access AAObject `usr` stuff
"""
def
__init__
(
self
,
mapper
,
branch
,
index
=
None
):
def
__init__
(
self
,
mapper
,
branch
,
index
=
None
):
...
@@ -165,7 +167,8 @@ class Usr:
...
@@ -165,7 +167,8 @@ class Usr:
# to massively increase the performance. This needs triple check if
# to massively increase the performance. This needs triple check if
# it's always the case.
# it's always the case.
self
.
_usr_names
=
[
self
.
_usr_names
=
[
n
.
decode
(
"
utf-8
"
)
for
n
in
self
.
_branch
[
self
.
_usr_key
+
'
_names
'
].
lazyarray
(
n
.
decode
(
"
utf-8
"
)
for
n
in
self
.
_branch
[
self
.
_usr_key
+
'
_names
'
].
lazyarray
(
basketcache
=
BASKET_CACHE
)[
0
]
basketcache
=
BASKET_CACHE
)[
0
]
]
]
self
.
_usr_idx_lookup
=
{
self
.
_usr_idx_lookup
=
{
...
@@ -207,12 +210,12 @@ class Usr:
...
@@ -207,12 +210,12 @@ class Usr:
def
__getitem_nested__
(
self
,
item
):
def
__getitem_nested__
(
self
,
item
):
data
=
self
.
_branch
[
self
.
_usr_key
+
'
_names
'
].
lazyarray
(
data
=
self
.
_branch
[
self
.
_usr_key
+
'
_names
'
].
lazyarray
(
# TODO this will be fixed soon in uproot,
# TODO this will be fixed soon in uproot,
# see https://github.com/scikit-hep/uproot/issues/465
# see https://github.com/scikit-hep/uproot/issues/465
uproot
.
asgenobj
(
uproot
.
asgenobj
(
uproot
.
SimpleArray
(
uproot
.
STLVector
(
uproot
.
STLString
())),
uproot
.
SimpleArray
(
uproot
.
STLVector
(
uproot
.
STLString
())),
self
.
_branch
[
self
.
_usr_key
+
'
_names
'
].
_context
,
6
),
self
.
_branch
[
self
.
_usr_key
+
'
_names
'
].
_context
,
6
),
basketcache
=
BASKET_CACHE
)
basketcache
=
BASKET_CACHE
)
if
self
.
_index
is
None
:
if
self
.
_index
is
None
:
return
data
return
data
else
:
else
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_tools.py
+
1
−
0
View file @
18402375
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
import
unittest
import
unittest
from
km3io.tools
import
_to_num
,
cached_property
from
km3io.tools
import
_to_num
,
cached_property
class
TestToNum
(
unittest
.
TestCase
):
class
TestToNum
(
unittest
.
TestCase
):
def
test_to_num
(
self
):
def
test_to_num
(
self
):
self
.
assertEqual
(
10
,
_to_num
(
"
10
"
))
self
.
assertEqual
(
10
,
_to_num
(
"
10
"
))
...
...
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