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
f52c0111
Commit
f52c0111
authored
5 years ago
by
Tamas Gal
Browse files
Options
Downloads
Plain Diff
Merge branch 'add-header' into 'master'
Add header readout for offline files. Closes
#13
Closes
#13
See merge request
!10
parents
188f00d1
63b48645
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!10
Add header readout for offline files. Closes #13
Pipeline
#8015
passed with warnings
5 years ago
Stage: test
Stage: coverage
Stage: doc
Stage: deploy
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.rst
+49
-2
49 additions, 2 deletions
README.rst
km3io/offline.py
+16
-0
16 additions, 0 deletions
km3io/offline.py
requirements.txt
+1
-1
1 addition, 1 deletion
requirements.txt
tests/test_offline.py
+11
-0
11 additions, 0 deletions
tests/test_offline.py
with
77 additions
and
3 deletions
README.rst
+
49
−
2
View file @
f52c0111
...
...
@@ -140,12 +140,59 @@ First, let's read our file:
.. code-block:: python3
>>> import km3io as ki
>>> file = '
datav6.0test.jchain.aanet.00005971
.root'
>>> file = '
my_file
.root'
>>> r = ki.OfflineReader(file)
<km3io.
aa
ne
t
.OfflineReader at 0x7f24cc2bd550>
<km3io.
offli
ne.OfflineReader at 0x7f24cc2bd550>
and that's it! Note that `file` can be either an str of your file path, or a path-like object.
To read the file header:
.. code-block:: python3
>>> r.header
DAQ 394
PDF 4 58
XSecFile
can 0 1027 888.4
can_user 0.00 1027.00 888.40
coord_origin 0 0 0
cut_in 0 0 0 0
cut_nu 100 1e+08 -1 1
cut_primary 0 0 0 0
cut_seamuon 0 0 0 0
decay doesnt happen
detector NOT
drawing Volume
end_event
genhencut 2000 0
genvol 0 1027 888.4 2.649e+09 100000
kcut 2
livetime 0 0
model 1 2 0 1 12
muon_desc_file
ngen 0.1000E+06
norma 0 0
nuflux 0 3 0 0.500E+00 0.000E+00 0.100E+01 0.300E+01
physics GENHEN 7.2-220514 181116 1138
seed GENHEN 3 305765867 0 0
simul JSirene 11012 11/17/18 07
sourcemode diffuse
spectrum -1.4
start_run 1
target isoscalar
usedetfile false
xlat_user 0.63297
xparam OFF
zed_user 0.00 3450.00
**Note:** not all file header types are supported, so don't be surprised when you get the following warning
.. code-block:: python3
/home/zineb/km3net/km3net/km3io/km3io/offline.py:341: UserWarning: Your file header has an unsupported format
warnings.warn("Your file header has an unsupported format")
To explore all the available branches in our offline file:
.. code-block:: python3
...
...
This diff is collapsed.
Click to expand it.
km3io/offline.py
+
16
−
0
View file @
f52c0111
import
uproot
import
warnings
# 110 MB based on the size of the largest basket found so far in km3net
BASKET_CACHE_SIZE
=
110
*
1024
**
2
...
...
@@ -319,6 +320,7 @@ class OfflineReader:
self
.
_mc_hits
=
None
self
.
_mc_tracks
=
None
self
.
_keys
=
None
self
.
_header
=
None
def
__getitem__
(
self
,
item
):
return
OfflineReader
(
file_path
=
self
.
_file_path
,
data
=
self
.
_data
[
item
])
...
...
@@ -326,6 +328,20 @@ class OfflineReader:
def
__len__
(
self
):
return
len
(
self
.
_data
)
@property
def
header
(
self
):
if
self
.
_header
is
None
:
fobj
=
uproot
.
open
(
self
.
_file_path
)
if
b
'
Head;1
'
in
fobj
.
keys
():
self
.
_header
=
{}
for
n
,
x
in
fobj
[
'
Head
'
].
_map_3c_string_2c_string_3e_
.
items
():
print
(
"
{:15s} {}
"
.
format
(
n
.
decode
(
"
utf-8
"
),
x
.
decode
(
"
utf-8
"
)))
self
.
_header
[
n
.
decode
(
"
utf-8
"
)]
=
x
.
decode
(
"
utf-8
"
)
if
b
'
Header;1
'
in
fobj
.
keys
():
warnings
.
warn
(
"
Your file header has an unsupported format
"
)
return
self
.
_header
@property
def
keys
(
self
):
"""
wrapper for all keys in an offline file.
...
...
This diff is collapsed.
Click to expand it.
requirements.txt
+
1
−
1
View file @
f52c0111
docopt
numba
uproot
>=3.1
0
.1
2
uproot
>=3.1
1
.1
setuptools_scm
This diff is collapsed.
Click to expand it.
tests/test_offline.py
+
11
−
0
View file @
f52c0111
...
...
@@ -132,6 +132,17 @@ class TestOfflineReader(unittest.TestCase):
# check that there are 10 events
self
.
assertEqual
(
Nevents
,
self
.
Nevents
)
def
test_reading_header
(
self
):
# head is the supported format
head
=
OfflineReader
(
OFFLINE_NUMUCC
).
header
self
.
assertEqual
(
float
(
head
[
'
DAQ
'
]),
394
)
self
.
assertEqual
(
float
(
head
[
'
kcut
'
]),
2
)
# test the warning for unsupported fheader format
self
.
assertWarns
(
UserWarning
,
self
.
r
.
header
,
"
Your file header has an unsupported format
"
)
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