PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
SIOReader.h
Go to the documentation of this file.
1#ifndef PODIO_SIOREADER_H
2#define PODIO_SIOREADER_H
3
4#include <algorithm>
5#include <iostream>
6#include <map>
7#include <string>
8#include <vector>
9
10#include "podio/EventStore.h"
12#include "podio/IReader.h"
13#include "podio/SIOBlock.h"
14
15// -- sio headers
16#include <sio/api.h>
17#include <sio/buffer.h>
18#include <sio/definitions.h>
19#include <sio/exception.h>
20
21namespace podio {
22
23class CollectionBase;
24class CollectionIDTable;
25
26/**
27 This class has the function to read available data from disk
28 and to prepare collections and buffers.
29**/
30class SIOReader : public IReader {
31 friend EventStore;
32
33public:
34 SIOReader();
35 ~SIOReader() = default;
36
37 // make non-copyable
38 SIOReader(const SIOReader&) = delete;
39 SIOReader& operator=(const SIOReader&) = delete;
40
41 void openFile(const std::string& filename) override;
42 void closeFile() override;
43
44 /// Read all collections requested
45 void readEvent() override;
46
47 void goToEvent(unsigned iEvent) override;
48
49 /// Read CollectionIDTable from SIO file
50 std::shared_ptr<CollectionIDTable> getCollectionIDTable() override {
51 return m_table;
52 }
53
54 unsigned getEntries() const override {
55 return m_tocRecord.getNRecords("event_record");
56 }
57
58 /// Check if file is valid
59 bool isValid() const override;
60
62 return m_fileVersion;
63 }
64
65 void endOfEvent() override;
66
67private:
68 /// Implementation for collection reading
69 CollectionBase* readCollection(const std::string& name) override;
70
71 /// read event meta data for current event
72 GenericParameters* readEventMetaData() override;
73
74 /// read the collection meta data
75 std::map<int, GenericParameters>* readCollectionMetaData() override;
76
77 /// read the run meta data
78 std::map<int, GenericParameters>* readRunMetaData() override;
79
80 /// read the TOC record
81 bool readFileTOCRecord();
82
83 /// reconstruct the TOC record from the file contents
84 void reconstructFileTOCRecord();
85
86private:
87 void readCollectionIDTable();
88 void readMetaDataRecord(const std::shared_ptr<SIONumberedMetaDataBlock>& mdBlock);
89 void createBlocks();
90
91 typedef std::pair<CollectionBase*, std::string> Input;
92 std::vector<Input> m_inputs{};
93 std::shared_ptr<CollectionIDTable> m_table{nullptr}; // Co-owned by the EventStore
94 int m_eventNumber{0};
95 int m_lastEventRead{-1};
96 std::vector<std::string> m_typeNames{};
97 std::vector<short> m_subsetCollectionBits{};
98
99 std::shared_ptr<SIOEventMetaDataBlock> m_eventMetaData{};
100 std::shared_ptr<SIONumberedMetaDataBlock> m_runMetaData{};
101 std::shared_ptr<SIONumberedMetaDataBlock> m_collectionMetaData{};
102
103 sio::ifstream m_stream{};
104 sio::record_info m_rec_info{};
105 sio::buffer m_info_buffer{sio::max_record_info_len};
106 sio::buffer m_rec_buffer{sio::mbyte};
107 sio::buffer m_unc_buffer{sio::mbyte};
108 sio::block_list m_blocks{};
109
110 SIOFileTOCRecord m_tocRecord{};
111
112 podio::version::Version m_fileVersion{0};
113};
114
115} // namespace podio
116
117#endif
size_t getNRecords(const std::string &name) const
Definition: SIOBlock.cc:195
unsigned getEntries() const override
get the number of events available from this reader
Definition: SIOReader.h:54
SIOReader & operator=(const SIOReader &)=delete
podio::version::Version currentFileVersion() const override
Get the podio version with which the current file has been written.
Definition: SIOReader.h:61
void closeFile() override
Definition: SIOReader.cc:74
void readEvent() override
Read all collections requested.
Definition: SIOReader.cc:78
void openFile(const std::string &filename) override
Definition: SIOReader.cc:62
void endOfEvent() override
Prepare the reader to read the next event.
Definition: SIOReader.cc:107
SIOReader(const SIOReader &)=delete
bool isValid() const override
Check if file is valid.
Definition: SIOReader.cc:103
~SIOReader()=default
std::shared_ptr< CollectionIDTable > getCollectionIDTable() override
Read CollectionIDTable from SIO file.
Definition: SIOReader.h:50
void goToEvent(unsigned iEvent) override
Definition: SIOReader.cc:113
void readCollection()