.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_online_example.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_online_example.py: Reading Online Data =================== The following example shows how to access hits in a ROOT file which is coming from the detector and written by the `JDataWriter` application. Such a file is usually called "KM3NET_00000001_00000002.root", where the first number is the detector ID and the second the run number. .. GENERATED FROM PYTHON SOURCE LINES 11-15 .. code-block:: Python import km3io as ki from km3net_testdata import data_path .. GENERATED FROM PYTHON SOURCE LINES 16-20 Accessing the event tree ------------------------ Just pass a filename to the reader class and get access to the event tree with: .. GENERATED FROM PYTHON SOURCE LINES 20-24 .. code-block:: Python f = ki.OnlineReader(data_path("online/km3net_online.root")) .. GENERATED FROM PYTHON SOURCE LINES 25-29 Note that only some meta information is read into memory. Printing it will simply tell you how many events it has found. Again, nothing else is read yet: .. GENERATED FROM PYTHON SOURCE LINES 29-32 .. code-block:: Python print(f.events) .. rst-class:: sphx-glr-script-out .. code-block:: none Number of events: 3 .. GENERATED FROM PYTHON SOURCE LINES 33-34 Now let's look at the hits data: .. GENERATED FROM PYTHON SOURCE LINES 34-37 .. code-block:: Python print(f.events[0].snapshot_hits.tot) .. rst-class:: sphx-glr-script-out .. code-block:: none [26 19 25 22 28 29 24 30 14 26 29 24 24 24 36 25 21 21 28 14 25 30 24 22 16 23 29 29 37 31 26 27 12 25 22 22 22 27 23 13 35 30 23 27 23 29 28 17 23 27 20 24 32 34 36 16 28 76 7 17 28 25 26 28 26 24 27 26 19 28 29 18 23 29 27 22 27 12 9 27 22 24 28 12 20 28 24 25 12 20 23 6 10 29 28 27] .. GENERATED FROM PYTHON SOURCE LINES 38-39 the resulting arrays are numpy arrays. .. GENERATED FROM PYTHON SOURCE LINES 41-51 Reading SummarySlices --------------------- The following example shows how to access summary slices, in particular the DOM IDs of the slice with the index 0. The current implementation of the summaryslice I/O uses a chunked reading for better performance, which means that when you iterate through the `.slices`, you'll get chunks of summaryslices in each iteration instead of a single one. In the example below, we simulate a single iteration by using the `break` keyword and then use the data which has been "pulled out" of the ROOT file. .. GENERATED FROM PYTHON SOURCE LINES 51-56 .. code-block:: Python for chunk in f.summaryslices: break .. GENERATED FROM PYTHON SOURCE LINES 57-60 `chunk` now contains the first set of summaryslices so `chunk.slice[0]` refers to the first summaryslice in the ROOT file. To access e.g. the DOM IDs, use the `.dom_id` attribute .. GENERATED FROM PYTHON SOURCE LINES 60-65 .. code-block:: Python dom_ids = chunk.slices[0].dom_id print(dom_ids) .. rst-class:: sphx-glr-script-out .. code-block:: none [806451572, 806455814, 806465101, 806483369, ... 809526097, 809544058, 809544061] .. GENERATED FROM PYTHON SOURCE LINES 66-68 The .type attribute (or in general, completion) is useful to find out more about the field structure: .. GENERATED FROM PYTHON SOURCE LINES 68-71 .. code-block:: Python print(chunk.slices.type) .. rst-class:: sphx-glr-script-out .. code-block:: none 3 * var * {"dom_id": int32, "dq_status": uint32, "hrv": uint32, "fifo": uint32, "status3": uint32, "status4": uint32, "ch0": uint8, "ch1": uint8, "ch2": uint8, "ch3": uint8, "ch4": uint8, "ch5": uint8, "ch6": uint8, "ch7": uint8, "ch8": uint8, "ch9": uint8, "ch10": uint8, "ch11": uint8, "ch12": uint8, "ch13": uint8, "ch14": uint8, "ch15": uint8, "ch16": uint8, "ch17": uint8, "ch18": uint8, "ch19": uint8, "ch20": uint8, "ch21": uint8, "ch22": uint8, "ch23": uint8, "ch24": uint8, "ch25": uint8, "ch26": uint8, "ch27": uint8, "ch28": uint8, "ch29": uint8, "ch30": uint8} .. GENERATED FROM PYTHON SOURCE LINES 72-74 Similar to the summaryslice data, the headers can be accessed the same way To read the frame index of all summaryslices in the obtained chunk: .. GENERATED FROM PYTHON SOURCE LINES 74-77 .. code-block:: Python print(chunk.headers.frame_index) .. rst-class:: sphx-glr-script-out .. code-block:: none [126, 127, 128] .. GENERATED FROM PYTHON SOURCE LINES 78-79 To be continued... .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.925 seconds) **Estimated memory usage:** 9 MB .. _sphx_glr_download_auto_examples_plot_online_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_online_example.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_online_example.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_