evio  6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RecordOutput.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_RECORDOUTPUT_H
12 #define EVIO_6_0_RECORDOUTPUT_H
13 
14 
15 #include <cstdlib>
16 #include <cstdint>
17 #include <cstdio>
18 #include <vector>
19 #include <memory>
20 
21 
22 #include "ByteBuffer.h"
23 #include "ByteOrder.h"
24 #include "EvioBank.h"
25 #include "EvioNode.h"
26 #include "RecordHeader.h"
27 #include "FileHeader.h"
28 #include "Compressor.h"
29 #include "EvioException.h"
30 
31 
32 namespace evio {
33 
34 
105  class RecordOutput {
106 
107  public:
108 
110  static constexpr int ONE_MEG = 1024*1024;
111 
113  uint32_t MAX_EVENT_COUNT = 1000000;
114 
124  uint32_t MAX_BUFFER_SIZE = 8*ONE_MEG;
125 
134 
138  uint32_t userBufferSize = 0;
139 
141  uint32_t eventCount = 0;
142 
145  uint32_t indexSize = 0;
146 
148  uint32_t eventSize = 0;
149 
152  size_t startingPosition = 0;
153 
155  std::shared_ptr<ByteBuffer> recordIndex;
156 
158  std::shared_ptr<ByteBuffer> recordEvents;
159 
161  std::shared_ptr<ByteBuffer> recordData;
162 
165  std::shared_ptr<ByteBuffer> recordBinary;
166 
168  std::shared_ptr<RecordHeader> header;
169 
172 
174  bool userProvidedBuffer = false;
175 
176 
177  public:
178 
179 
180  RecordOutput();
181 
182  explicit RecordOutput(const ByteOrder & order,
183  uint32_t maxEventCount = 1000000,
184  uint32_t maxBufferSize = 8*ONE_MEG,
187 
188  RecordOutput(std::shared_ptr<ByteBuffer> & buffer, uint32_t maxEventCount,
189  Compressor::CompressionType compressionType, HeaderType hType);
190 
191  RecordOutput(const RecordOutput & srcRec);
192  RecordOutput(RecordOutput && srcBuf) noexcept;
193 
194  RecordOutput & operator=(RecordOutput&& other) noexcept;
195  RecordOutput & operator=(const RecordOutput& other);
196 
197  ~RecordOutput() = default;
198 
199 
200  private:
201 
202 
203  void allocate();
204  bool allowedIntoRecord(uint32_t length);
205  void copy(const RecordOutput & rec);
206 
207 
208  public:
209 
210 
211  void setBuffer(std::shared_ptr<ByteBuffer> & buf);
212  void transferDataForReading(const RecordOutput & rec);
213 
214  uint32_t getUserBufferSize() const;
215  uint32_t getUncompressedSize() const;
216  uint32_t getInternalBufferCapacity() const;
217  uint32_t getMaxEventCount() const;
218  uint32_t getEventCount() const;
219 
220  std::shared_ptr<RecordHeader> & getHeader();
221  const ByteOrder & getByteOrder() const;
222  const std::shared_ptr<ByteBuffer> getBinaryBuffer() const;
223  const Compressor::CompressionType getCompressionType() const;
224  const HeaderType getHeaderType() const;
225 
226  bool hasUserProvidedBuffer() const;
227  bool roomForEvent(uint32_t length) const;
228  bool oneTooMany() const;
229 
230  bool addEvent(const uint8_t * event, uint32_t eventLen, uint32_t extraDataLen = 0);
231 
232  bool addEvent(const std::vector<uint8_t> & event);
233  bool addEvent(const std::vector<uint8_t> & event, size_t offset, uint32_t eventLen, uint32_t extraDataLen = 0);
234 
235  bool addEvent(const ByteBuffer & event, uint32_t extraDataLen = 0);
236  bool addEvent(const std::shared_ptr<ByteBuffer> & event, uint32_t extraDataLen = 0);
237 
238  bool addEvent(EvioNode & node, uint32_t extraDataLen = 0);
239  bool addEvent(std::shared_ptr<EvioNode> & node, uint32_t extraDataLen = 0);
240 
241  bool addEvent(EvioBank & event, uint32_t extraDataLen);
242  bool addEvent(std::shared_ptr<EvioBank> & event, uint32_t extraDataLen = 0);
243 
244  void reset();
245 
246  void setStartingBufferPosition(size_t pos);
247 
248  void build();
249  void build(std::shared_ptr<ByteBuffer> userHeader);
250  void build(const ByteBuffer & userHeader);
251 
252  };
253 
254 }
255 
256 
257 #endif //EVIO_6_0_RECORDOUTPUT_H
This class is copied from one of the same name in the Java programming language.
Definition: ByteBuffer.h:42
uint32_t getMaxEventCount() const
Get the maximum number of events allowed in this record.
Definition: RecordOutput.cpp:330
static constexpr int ONE_MEG
Maximum number of events per record.
Definition: RecordOutput.h:110
const Compressor::CompressionType getCompressionType() const
Get the compression type of the contained record.
Definition: RecordOutput.cpp:387
std::shared_ptr< RecordHeader > header
Header of this Record.
Definition: RecordOutput.h:168
bool roomForEvent(uint32_t length) const
Is there room in this record&#39;s memory for an additional event of the given length in bytes (length NO...
Definition: RecordOutput.cpp:439
const ByteOrder & getByteOrder() const
Get the byte order of the record to be built.
Definition: RecordOutput.cpp:414
uint32_t getInternalBufferCapacity() const
Get the capacity of the internal buffer in bytes.
Definition: RecordOutput.cpp:357
bool addEvent(const uint8_t *event, uint32_t eventLen, uint32_t extraDataLen=0)
Adds an event&#39;s ByteBuffer into the record.
Definition: RecordOutput.cpp:482
Singleton class used to provide data compression and decompression in a variety of formats...
Definition: Compressor.h:41
CompressionType
Enum of supported data compression types.
Definition: Compressor.h:65
Numerical values associated with endian byte order.
Definition: ByteOrder.h:53
uint32_t RECORD_BUFFER_SIZE
Size of buffer holding built record in bytes.
Definition: RecordOutput.h:133
size_t startingPosition
The starting position of a user-given buffer.
Definition: RecordOutput.h:152
void transferDataForReading(const RecordOutput &rec)
Copy the contents of the arg into this object and get data buffer ready for reading.
Definition: RecordOutput.cpp:244
static const HeaderType EVIO_RECORD
Header for a general evio record.
Definition: HeaderType.h:36
uint32_t userBufferSize
The number of initially available bytes to be written into in the user-given buffer, that go from position to limit.
Definition: RecordOutput.h:138
const std::shared_ptr< ByteBuffer > getBinaryBuffer() const
Get the internal ByteBuffer used to construct binary representation of this record.
Definition: RecordOutput.cpp:378
const HeaderType getHeaderType() const
Get the header type of the contained record.
Definition: RecordOutput.cpp:398
bool hasUserProvidedBuffer() const
Was the internal buffer provided by the user?
Definition: RecordOutput.cpp:407
std::shared_ptr< ByteBuffer > recordIndex
This buffer stores event lengths (in bytes) ONLY.
Definition: RecordOutput.h:155
Definition: Compressor.h:66
std::shared_ptr< ByteBuffer > recordBinary
Buffer in which to put constructed (&amp; compressed) binary record.
Definition: RecordOutput.h:165
RecordOutput()
Default, no-arg constructor.
Definition: RecordOutput.cpp:18
Class which handles the creation and use of Evio &amp; HIPO Records.
Definition: RecordOutput.h:105
uint32_t indexSize
Number of valid bytes in recordIndex buffer.
Definition: RecordOutput.h:145
ByteOrder byteOrder
Byte order of record byte arrays to build.
Definition: RecordOutput.h:171
bool oneTooMany() const
Does adding one more event exceed the event count limit?
Definition: RecordOutput.cpp:449
std::shared_ptr< ByteBuffer > recordEvents
This buffer stores event data ONLY.
Definition: RecordOutput.h:158
This class is used to store relevant info about an evio container (bank, segment, or tag segment)...
Definition: EvioNode.h:41
This holds a CODA Bank structure.
Definition: EvioBank.h:36
void setBuffer(std::shared_ptr< ByteBuffer > &buf)
Reset internal buffers and set the buffer in which to build this record.
Definition: RecordOutput.cpp:211
uint32_t MAX_BUFFER_SIZE
Size of some internal buffers in bytes.
Definition: RecordOutput.h:124
std::shared_ptr< ByteBuffer > recordData
This buffer stores data that will be compressed.
Definition: RecordOutput.h:161
uint32_t getUncompressedSize() const
Get the current uncompressed size of the record in bytes.
Definition: RecordOutput.cpp:346
void build()
Builds the record.
Definition: RecordOutput.cpp:841
uint32_t MAX_EVENT_COUNT
Maximum number of events per record.
Definition: RecordOutput.h:113
Definition: RecordHeader.h:182
uint32_t eventCount
Number of events written to this Record.
Definition: RecordOutput.h:141
void setStartingBufferPosition(size_t pos)
Set the starting position of the user-given buffer being written into.
Definition: RecordOutput.cpp:829
void reset()
Reset internal buffers.
Definition: RecordOutput.cpp:804
uint32_t getEventCount() const
Get the number of events written so far into the buffer.
Definition: RecordOutput.cpp:371
uint32_t eventSize
Number of valid bytes in recordEvents buffer.
Definition: RecordOutput.h:148
bool userProvidedBuffer
Is recordBinary a user provided buffer?
Definition: RecordOutput.h:174
uint32_t getUserBufferSize() const
Get the number of initially available bytes to be written into in the user-given buffer, that goes from position to limit.
Definition: RecordOutput.cpp:338
static const ByteOrder ENDIAN_LOCAL
Local host&#39;s byte order.
Definition: ByteOrder.h:61
std::shared_ptr< RecordHeader > & getHeader()
Get the general header of this record.
Definition: RecordOutput.cpp:364
Numerical values associated with types of a file or record header.
Definition: HeaderType.h:32