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
6163f717
Commit
6163f717
authored
5 years ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
Header parameters without names are now bare
parent
b8136331
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!27
Refactor offline I/O
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
km3io/offline.py
+7
-1
7 additions, 1 deletion
km3io/offline.py
tests/test_offline.py
+40
-29
40 additions, 29 deletions
tests/test_offline.py
with
47 additions
and
30 deletions
km3io/offline.py
+
7
−
1
View file @
6163f717
...
...
@@ -233,14 +233,20 @@ class Header:
n_values
=
len
(
values
)
n_fields
=
len
(
fields
)
if
n_values
==
1
and
n_fields
==
0
:
self
.
_data
[
attribute
]
=
_to_num
(
values
[
0
])
continue
n_max
=
max
(
n_values
,
n_fields
)
values
+=
[
None
]
*
(
n_max
-
n_values
)
fields
+=
[
"
field_{}
"
.
format
(
i
)
for
i
in
range
(
n_fields
,
n_max
)]
Constructor
=
namedtuple
(
attribute
,
fields
)
if
not
values
:
continue
Constructor
=
namedtuple
(
attribute
,
fields
)
self
.
_data
[
attribute
]
=
Constructor
(
**
{
f
:
_to_num
(
v
)
for
(
f
,
v
)
in
zip
(
fields
,
values
)})
...
...
This diff is collapsed.
Click to expand it.
tests/test_offline.py
+
40
−
29
View file @
6163f717
...
...
@@ -22,12 +22,6 @@ class TestOfflineReader(unittest.TestCase):
class
TestHeader
(
unittest
.
TestCase
):
def
test_reading_header
(
self
):
# head is the supported format
head
=
OFFLINE_NUMUCC
.
header
self
.
assertAlmostEqual
(
head
.
DAQ
.
livetime
,
394
)
def
test_str_header
(
self
):
assert
"
MC Header
"
in
str
(
OFFLINE_NUMUCC
.
header
)
...
...
@@ -36,36 +30,16 @@ class TestHeader(unittest.TestCase):
with
self
.
assertWarns
(
UserWarning
):
OFFLINE_FILE
.
header
def
test_header
(
self
):
head
=
{
'
DAQ
'
:
'
394
'
,
'
PDF
'
:
'
4
'
,
'
can
'
:
'
0 1027 888.4
'
,
'
undefined
'
:
'
1 2 test 3.4
'
}
header
=
Header
(
head
)
assert
394
==
header
.
DAQ
.
livetime
assert
4
==
header
.
PDF
.
i1
assert
header
.
PDF
.
i2
is
None
assert
0
==
header
.
can
.
zmin
assert
1027
==
header
.
can
.
zmax
assert
888.4
==
header
.
can
.
r
assert
1
==
header
.
undefined
.
field_0
assert
2
==
header
.
undefined
.
field_1
assert
"
test
"
==
header
.
undefined
.
field_2
assert
3.4
==
header
.
undefined
.
field_3
def
test_missing_key_definitions
(
self
):
head
=
{
'
a
'
:
'
1 2 3
'
,
'
b
'
:
'
4
'
}
head
=
{
'
a
'
:
'
1 2 3
'
,
'
b
'
:
'
4
'
,
'
c
'
:
'
d
'
}
header
=
Header
(
head
)
assert
1
==
header
.
a
.
field_0
assert
2
==
header
.
a
.
field_1
assert
3
==
header
.
a
.
field_2
assert
4
==
header
.
b
.
field_0
assert
4
==
header
.
b
assert
'
d
'
==
header
.
c
def
test_missing_values
(
self
):
head
=
{
'
can
'
:
'
1
'
}
...
...
@@ -86,6 +60,43 @@ class TestHeader(unittest.TestCase):
assert
3
==
header
.
can
.
r
assert
4
==
header
.
can
.
field_3
def
test_header
(
self
):
head
=
{
'
DAQ
'
:
'
394
'
,
'
PDF
'
:
'
4
'
,
'
can
'
:
'
0 1027 888.4
'
,
'
undefined
'
:
'
1 2 test 3.4
'
}
header
=
Header
(
head
)
assert
394
==
header
.
DAQ
.
livetime
assert
4
==
header
.
PDF
.
i1
assert
header
.
PDF
.
i2
is
None
assert
0
==
header
.
can
.
zmin
assert
1027
==
header
.
can
.
zmax
assert
888.4
==
header
.
can
.
r
assert
1
==
header
.
undefined
.
field_0
assert
2
==
header
.
undefined
.
field_1
assert
"
test
"
==
header
.
undefined
.
field_2
assert
3.4
==
header
.
undefined
.
field_3
def
test_reading_header_from_sample_file
(
self
):
head
=
OFFLINE_NUMUCC
.
header
assert
394
==
head
.
DAQ
.
livetime
assert
4
==
head
.
PDF
.
i1
assert
58
==
head
.
PDF
.
i2
assert
0
==
head
.
coord_origin
.
x
assert
0
==
head
.
coord_origin
.
y
assert
0
==
head
.
coord_origin
.
z
assert
100
==
head
.
cut_nu
.
Emin
assert
100000000.0
==
head
.
cut_nu
.
Emax
assert
-
1
==
head
.
cut_nu
.
cosTmin
assert
1
==
head
.
cut_nu
.
cosTmax
assert
"
diffuse
"
==
head
.
sourcemode
assert
100000.0
==
head
.
ngen
class
TestOfflineEvents
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
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