evio  6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EvioReader.h
Go to the documentation of this file.
1 //
2 // Copyright 2020, Jefferson Science Associates, LLC.
3 // Subject to the terms in the LICENSE file found in the top-level directory.
4 //
5 // EPSCI Group
6 // Thomas Jefferson National Accelerator Facility
7 // 12000, Jefferson Ave, Newport News, VA 23606
8 // (757)-269-7100
9 
10 
11 #ifndef EVIO_6_0_EVIOREADER_H
12 #define EVIO_6_0_EVIOREADER_H
13 
14 
15 #include <memory>
16 #include <fstream>
17 
18 
19 #include "ByteOrder.h"
20 #include "ByteBuffer.h"
21 #include "IEvioReader.h"
22 #include "EvioReaderV4.h"
23 #include "EvioReaderV6.h"
24 #include "IBlockHeader.h"
25 #include "BlockHeaderV2.h"
26 #include "BlockHeaderV4.h"
27 #include "RecordHeader.h"
28 
29 namespace evio {
30 
31 
52  class EvioReader : public IEvioReader {
53 
54  private:
55 
57  uint32_t evioVersion = 4;
58 
61 
63  std::shared_ptr<ByteBuffer> byteBuffer;
64 
66  size_t initialPosition = 0;
67 
69  std::shared_ptr<IEvioReader> reader;
70 
71  public:
72 
73  // File constructor
74  explicit EvioReader(std::string const & path, bool checkRecNumSeq = false, bool synced = false);
75 
76  // Buffer constructor
77  explicit EvioReader(std::shared_ptr<ByteBuffer> & bb, bool checkRecNumSeq = false, bool synced = false);
78 
79  //------------------------------------------
80 
81  void setBuffer(std::shared_ptr<ByteBuffer> & buf) override;
82  bool isClosed () override;
83  bool checkBlockNumberSequence() override;
84  ByteOrder & getByteOrder() override;
85  uint32_t getEvioVersion() override;
86  std::string getPath() override;
87  std::shared_ptr<EventParser> & getParser() override;
88  void setParser(std::shared_ptr<EventParser> & evParser) override;
89 
90  std::string getDictionaryXML() override;
91  bool hasDictionaryXML() override;
92  std::shared_ptr<EvioEvent> getFirstEvent() override;
93  bool hasFirstEvent() override;
94 
95  size_t getNumEventsRemaining() override;
96  std::shared_ptr<ByteBuffer> getByteBuffer() override;
97  size_t fileSize() override;
98  std::shared_ptr<IBlockHeader> getFirstBlockHeader() override;
99 
100 
101  std::shared_ptr<EvioEvent> getEvent(size_t index) override;
102  std::shared_ptr<EvioEvent> parseEvent(size_t index) override;
103  std::shared_ptr<EvioEvent> nextEvent() override;
104  std::shared_ptr<EvioEvent> parseNextEvent() override;
105  void parseEvent(std::shared_ptr<EvioEvent> evioEvent) override;
106 
107 
108  static std::shared_ptr<EvioEvent> getEvent(uint8_t * src, size_t len, ByteOrder const & order);
109  static std::shared_ptr<EvioEvent> parseEvent(uint8_t * src, size_t len, ByteOrder const & order) ;
110 
111 
112  uint32_t getEventArray(size_t evNumber, std::vector<uint8_t> & vec) override;
113  uint32_t getEventBuffer(size_t evNumber, ByteBuffer & buf) override;
114 
115  void rewind() override;
116  ssize_t position() override;
117  void close() override;
118 
119  std::shared_ptr<IBlockHeader> getCurrentBlockHeader() override;
120  std::shared_ptr<EvioEvent> gotoEventNumber(size_t evNumber) override;
121  size_t getEventCount() override;
122  size_t getBlockCount() override;
123  };
124 
125 }
126 
127 
128 #endif //EVIO_6_0_EVIOREADER_H
ssize_t position() override
This is equivalent to obtaining the current position in the file.What it actually does is return the ...
Definition: EvioReader.cpp:269
This class is copied from one of the same name in the Java programming language.
Definition: ByteBuffer.h:42
std::shared_ptr< EvioEvent > nextEvent() override
Get the next event in the file/buffer.As useful as this sounds, most applications will probably call ...
Definition: EvioReader.cpp:175
size_t fileSize() override
Get the size of the file being read, in bytes.the file size in bytes
Definition: EvioReader.cpp:161
std::shared_ptr< EvioEvent > parseNextEvent() override
This is a workhorse method.It retrieves the next event from the file/buffer, and then parses it SAX-l...
Definition: EvioReader.cpp:179
std::shared_ptr< EvioEvent > gotoEventNumber(size_t evNumber) override
Go to a specific event in the file.The events are numbered 1..N. This number is transient–it is not p...
Definition: EvioReader.cpp:278
void close() override
This is closes the file, but for buffers it only sets the position to 0.
Definition: EvioReader.cpp:272
void setBuffer(std::shared_ptr< ByteBuffer > &buf) override
This method can be used to avoid creating additional EvioReader objects by reusing this one with anot...
Definition: EvioReader.cpp:119
std::string getDictionaryXML() override
Get the XML format dictionary if there is one.XML format dictionary, else null.
Definition: EvioReader.cpp:143
Numerical values associated with endian byte order.
Definition: ByteOrder.h:53
std::shared_ptr< EventParser > & getParser() override
Get the file/buffer parser.file/buffer parser.
Definition: EvioReader.cpp:137
size_t getNumEventsRemaining() override
Get the number of events remaining in the file.Useful only if doing a sequential read.number of events remaining in the file if failed reading from file
Definition: EvioReader.cpp:155
void setParser(std::shared_ptr< EventParser > &evParser) override
Set the file/buffer parser.file/buffer parser.
Definition: EvioReader.cpp:140
size_t getBlockCount() override
This is the number of blocks/records in the file/buffer including the empty block, record or trailer at the end.if object closed. the number of records in the file/buffer (estimate for version 3 files).
Definition: EvioReader.cpp:286
This pure, virtual class is meant to encapsulate the operation of reading both 2 differently formatte...
Definition: IEvioReader.h:39
std::shared_ptr< IBlockHeader > getFirstBlockHeader() override
This returns the FIRST block (record) header.the first block (record) header.
Definition: EvioReader.cpp:164
ByteOrder & getByteOrder() override
Get the byte order of the file/buffer being read.byte order of the file/buffer being read...
Definition: EvioReader.cpp:128
bool checkBlockNumberSequence() override
Is this reader checking the block number sequence and throwing an exception if it&#39;s not sequential an...
Definition: EvioReader.cpp:125
uint32_t getEventBuffer(size_t evNumber, ByteBuffer &buf) override
Get an evio bank or event in ByteBuffer form.number of event of interest buffer to contain bank&#39;s/eve...
Definition: EvioReader.cpp:261
bool hasDictionaryXML() override
Does this evio file have an associated XML dictionary?true if this evio file has an associated XML di...
Definition: EvioReader.cpp:146
std::shared_ptr< EvioEvent > getEvent(size_t index) override
Get the event in the file/buffer at a given index (starting at 1).As useful as this sounds...
Definition: EvioReader.cpp:167
std::shared_ptr< IBlockHeader > getCurrentBlockHeader() override
This returns the current (active) block (physical record) header.Since most users have no interest in...
Definition: EvioReader.cpp:275
std::shared_ptr< ByteBuffer > getByteBuffer() override
Get the byte buffer being read.Not useful when reading files. the byte buffer being read (in certain ...
Definition: EvioReader.cpp:158
EvioReader(std::string const &path, bool checkRecNumSeq=false, bool synced=false)
Constructor for reading an event file.
Definition: EvioReader.cpp:38
void rewind() override
The equivalent of rewinding the file.What it actually does is set the position of the file/buffer bac...
Definition: EvioReader.cpp:266
uint32_t getEventArray(size_t evNumber, std::vector< uint8_t > &vec) override
Get an evio bank or event in vector-of-bytes form.number of event of interest (starting at 1)...
Definition: EvioReader.cpp:256
std::shared_ptr< EvioEvent > parseEvent(size_t index) override
This is a workhorse method.It retrieves the desired event from the file/buffer, and then parses it SA...
Definition: EvioReader.cpp:171
size_t getEventCount() override
This is the number of events in the file/buffer.Any dictionary or first event are not included in the...
Definition: EvioReader.cpp:283
uint32_t getEvioVersion() override
Get the evio version number.evio version number.
Definition: EvioReader.cpp:131
bool hasFirstEvent() override
Does this evio file have an associated first event? It&#39;s also called the Beginning-Of-Run event...
Definition: EvioReader.cpp:152
bool isClosed() override
Has close() been called (without reopening by calling setBuffer(std::shared_ptr&lt;ByteBuffer&gt; &amp;))...
Definition: EvioReader.cpp:122
std::shared_ptr< EvioEvent > getFirstEvent() override
Get the &quot;first&quot; event if there is one.It&#39;s also called the Beginning-Of-Run event. This event is defined once but included in each of the related split files written out. the first event is it existed, else null.
Definition: EvioReader.cpp:149
std::string getPath() override
Get the path to the file.path to the file
Definition: EvioReader.cpp:134
static const ByteOrder ENDIAN_LOCAL
Local host&#39;s byte order.
Definition: ByteOrder.h:61
This is a class of interest to the user.
Definition: EvioReader.h:52