evio  6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RecordInput.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_RECORDINPUT_H
12 #define EVIO_6_0_RECORDINPUT_H
13 
14 
15 #include <iostream>
16 #include <fstream>
17 #include <memory>
18 
19 
20 #include "ByteOrder.h"
21 #include "ByteBuffer.h"
22 #include "RecordHeader.h"
23 #include "Compressor.h"
24 #include "EvioException.h"
25 
26 
27 namespace evio {
28 
29 
103  class RecordInput {
104 
105  private:
106 
108  static const uint32_t DEFAULT_BUF_SIZE = 8 * 1024 * 1024;
109 
111  uint32_t nEntries = 0;
112 
115  uint32_t userHeaderOffset = 0;
116 
119  uint32_t eventsOffset = 0;
120 
123  uint32_t uncompressedEventsLength = 0;
124 
127 
129  std::shared_ptr<RecordHeader> header;
130 
133  std::shared_ptr<ByteBuffer> dataBuffer;
134 
136  ByteBuffer recordBuffer;
137 
139  ByteBuffer headerBuffer;
140 
141 
142  private:
143 
144  void allocate(size_t size);
145  void setByteOrder(const ByteOrder & order);
146  void showIndex() const;
147 
148  public:
149 
150  RecordInput();
151  explicit RecordInput(const ByteOrder & order);
152  RecordInput(const RecordInput & recordIn);
153  RecordInput(RecordInput && srcRec) noexcept;
154 
155  ~RecordInput() = default;
156 
157  RecordInput & operator=(RecordInput&& other) noexcept;
158  RecordInput & operator=(const RecordInput& other);
159 
160  std::shared_ptr<RecordHeader> getHeader();
161  const ByteOrder & getByteOrder();
162  std::shared_ptr<ByteBuffer> getUncompressedDataBuffer();
163 
164  bool hasIndex() const;
165  bool hasUserHeader() const;
166 
167  std::shared_ptr<ByteBuffer> getEvent(std::shared_ptr<ByteBuffer> & buffer, uint32_t index, size_t bufOffset = 0);
168  ByteBuffer & getEvent(ByteBuffer & buffer, uint32_t index, size_t bufOffset = 0);
169  std::shared_ptr<uint8_t> getUserHeader();
170  std::shared_ptr<ByteBuffer> getUserHeader(std::shared_ptr<ByteBuffer> & buffer, size_t bufOffset = 0);
171  ByteBuffer & getUserHeader(ByteBuffer & buffer, size_t bufOffset = 0);
172 
173  std::shared_ptr<uint8_t> getEvent(uint32_t index, uint32_t * len);
174  uint32_t getEventLength(uint32_t index) const;
175  uint32_t getEntries() const;
176 
177  std::shared_ptr<RecordInput> getUserHeaderAsRecord(ByteBuffer & buffer,
178  size_t bufOffset);
179 
180  void readRecord(std::ifstream & file, size_t position);
181  void readRecord(ByteBuffer & buffer, size_t offset);
182 
183  static uint32_t uncompressRecord(std::shared_ptr<ByteBuffer> & srcBuf, size_t srcOff,
184  std::shared_ptr<ByteBuffer> & dstBuf,
185  RecordHeader & hdr);
186  static uint32_t uncompressRecord(ByteBuffer & srcBuf, size_t srcOff,
187  ByteBuffer & dstBuf,
188  RecordHeader & header);
189  };
190 
191 }
192 #endif //EVIO_6_0_RECORDINPUT_H
This class is copied from one of the same name in the Java programming language.
Definition: ByteBuffer.h:42
~RecordInput()=default
RecordInput()
Default constructor.
Definition: RecordInput.cpp:22
bool hasUserHeader() const
Does this record contain a user header?
Definition: RecordInput.cpp:178
Numerical values associated with endian byte order.
Definition: ByteOrder.h:53
static uint32_t uncompressRecord(std::shared_ptr< ByteBuffer > &srcBuf, size_t srcOff, std::shared_ptr< ByteBuffer > &dstBuf, RecordHeader &hdr)
Uncompress the data of a record from the source buffer at the given offset into the destination buffe...
Definition: RecordInput.cpp:616
std::shared_ptr< uint8_t > getUserHeader()
Get the user header contained in this record and return it in an allocated array. ...
Definition: RecordInput.cpp:309
void readRecord(std::ifstream &file, size_t position)
Reads record from the file at given position.
Definition: RecordInput.cpp:419
std::shared_ptr< RecordInput > getUserHeaderAsRecord(ByteBuffer &buffer, size_t bufOffset)
Get any existing user header and write it into the given byte buffer.
Definition: RecordInput.cpp:387
Class which reads data to create an Evio or HIPO Record.
Definition: RecordInput.h:103
uint32_t getEntries() const
Returns number of the events packed in the record.
Definition: RecordInput.cpp:749
std::shared_ptr< RecordHeader > getHeader()
Get the header of this record.
Definition: RecordInput.cpp:133
RecordInput & operator=(RecordInput &&other) noexcept
Move assignment operator.
Definition: RecordInput.cpp:86
const ByteOrder & getByteOrder()
Get the byte order of the internal buffers.
Definition: RecordInput.cpp:140
bool hasIndex() const
Does this record contain an event index?
Definition: RecordInput.cpp:171
uint32_t getEventLength(uint32_t index) const
Returns the length of the event with given index.
Definition: RecordInput.cpp:224
Definition: RecordHeader.h:182
std::shared_ptr< ByteBuffer > getEvent(std::shared_ptr< ByteBuffer > &buffer, uint32_t index, size_t bufOffset=0)
Get the event at the given index and write it into the given byte buffer.
Definition: RecordInput.cpp:254
static const ByteOrder ENDIAN_LOCAL
Local host&#39;s byte order.
Definition: ByteOrder.h:61
std::shared_ptr< ByteBuffer > getUncompressedDataBuffer()
Get the buffer with all uncompressed data in it.
Definition: RecordInput.cpp:161