evio  6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CompactEventBuilder.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_COMPACTEVENTBUILDER_H
12 #define EVIO_6_0_COMPACTEVENTBUILDER_H
13 
14 
15 #include <vector>
16 #include <memory>
17 #include <cstring>
18 
19 
20 #include "ByteOrder.h"
21 #include "ByteBuffer.h"
22 #include "DataType.h"
23 #include "EvioNode.h"
24 #include "EvioSwap.h"
25 #include "Util.h"
26 #include "FileHeader.h"
27 #include "RecordHeader.h"
28 
29 
30 namespace evio {
31 
48 
49  private:
50 
52  std::shared_ptr<ByteBuffer> buffer = nullptr;
53 
55  uint8_t * array = nullptr;
56 
58  size_t arrayOffset = 0;
59 
61  size_t position = 0;
62 
65 
67  bool createdBuffer = false;
68 
71  bool generateNodes = false;
72 
75  std::vector<std::shared_ptr<EvioNode>> nodes;
76 
78  static const uint32_t MAX_LEVELS = 50;
79 
81  static const uint32_t padCount[];
82 
83 
89  class StructureContent {
90  public:
91 
93  size_t pos = 0;
96  uint32_t dataLen = 0;
98  uint32_t padding = 0;
100  DataType type {DataType::BANK};
102  DataType dataType {DataType::UNKNOWN32};
103 
104  StructureContent() = default;
105 
106  void setData(size_t pos, DataType const & type, DataType const & dataType) {
107  this->pos = pos;
108  this->type = type;
109  this->dataType = dataType;
110  padding = dataLen = 0;
111  }
112  };
113 
114 
118  std::vector<std::shared_ptr<StructureContent>> stackArray;
119 
125  std::vector<uint32_t> totalLengths;
126 
128  std::shared_ptr<StructureContent> currentStructure = nullptr;
129 
132  int32_t currentLevel = -1;
133 
134 
135  public:
136 
137  CompactEventBuilder(size_t bufferSize, ByteOrder const & order, bool generateNodes = false);
138  explicit CompactEventBuilder(std::shared_ptr<ByteBuffer> buffer, bool generateNodes = false);
139 
140  void setBuffer(std::shared_ptr<ByteBuffer> buffer, bool generateNodes = false);
141 
142  private:
143 
144  void initBuffer(std::shared_ptr<ByteBuffer> buffer, bool generateNodes);
145 
146  public:
147 
148  std::shared_ptr<ByteBuffer> getBuffer();
149 
150  size_t getTotalBytes() const;
151 
152  std::shared_ptr<EvioNode> openSegment(uint16_t tag, DataType const & dataType);
153  std::shared_ptr<EvioNode> openTagSegment(int tag, DataType dataType);
154  std::shared_ptr<EvioNode> openBank(uint16_t tag, DataType const & dataType, uint8_t num);
155 
156  bool closeStructure();
157  void closeAll();
158 
159  void setTopLevelTag(short tag);
160 
161  private:
162 
163  void addToAllLengths(uint32_t len);
164 
165  void setCurrentHeaderLength(uint32_t len);
166  void setCurrentHeaderPadding(uint32_t padding);
167 
168  void writeHeader(std::shared_ptr<EvioNode> & node);
169  void writeNode(std::shared_ptr<EvioNode> & node, bool swapData);
170 
171  public:
172 
173  void addEvioNode(std::shared_ptr<EvioNode> node);
174 
175  void addByteData(uint8_t * data, uint32_t len);
176  void addIntData(uint32_t * data, uint32_t len);
177  void addShortData(uint16_t * data, uint32_t len);
178  void addLongData(uint64_t * data, uint32_t len);
179  void addFloatData(float * data, uint32_t len);
180  void addDoubleData(double * data, uint32_t len);
181  void addStringData(std::vector<std::string> & strings);
182  void addCompositeData(std::vector<std::shared_ptr<CompositeData>> & data);
183 
184  void toFile(std::string const & fileName);
185 
186  };
187 
188 
189 }
190 
191 
192 #endif //EVIO_6_0_COMPACTEVENTBUILDER_H
bool closeStructure()
This method ends the writing of the current evio structure and makes sure the length and padding fiel...
Definition: CompactEventBuilder.cpp:409
void addCompositeData(std::vector< std::shared_ptr< CompositeData >> &data)
Appends CompositeData objects to the structure.
Definition: CompactEventBuilder.cpp:1138
void setTopLevelTag(short tag)
In the emu software package, it&#39;s necessary to change the top level tag after the top level bank has ...
Definition: CompactEventBuilder.cpp:456
void addLongData(uint64_t *data, uint32_t len)
Appends long data to the structure.
Definition: CompactEventBuilder.cpp:934
Numerical values associated with endian byte order.
Definition: ByteOrder.h:53
void addEvioNode(std::shared_ptr< EvioNode > node)
Adds the evio structure represented by the EvioNode object into the buffer.
Definition: CompactEventBuilder.cpp:680
This class is used for creating events and their substructures while minimizing use of objects...
Definition: CompactEventBuilder.h:47
void addDoubleData(double *data, uint32_t len)
Appends double data to the structure.
Definition: CompactEventBuilder.cpp:1044
void addStringData(std::vector< std::string > &strings)
Appends string data to the structure.
Definition: CompactEventBuilder.cpp:1094
void addShortData(uint16_t *data, uint32_t len)
Appends short data to the structure.
Definition: CompactEventBuilder.cpp:855
void closeAll()
This method finishes the event writing by setting all the proper lengths &amp; padding and ends up at the...
Definition: CompactEventBuilder.cpp:445
std::shared_ptr< EvioNode > openTagSegment(int tag, DataType dataType)
This method adds an evio tagsegment structure to the buffer.
Definition: CompactEventBuilder.cpp:242
CompactEventBuilder(size_t bufferSize, ByteOrder const &order, bool generateNodes=false)
This is the constructor to use for building a new event (just the event in a buffer, not the full evio file format).
Definition: CompactEventBuilder.cpp:31
static const DataType BANK
Bank.
Definition: DataType.h:52
void toFile(std::string const &fileName)
This method writes a file in proper evio format with block header containing the single event constru...
Definition: CompactEventBuilder.cpp:1190
std::shared_ptr< EvioNode > openSegment(uint16_t tag, DataType const &dataType)
This method adds an evio segment structure to the buffer.
Definition: CompactEventBuilder.cpp:166
Numerical values associated with evio data types.
Definition: DataType.h:32
void addIntData(uint32_t *data, uint32_t len)
Appends int data to the structure.
Definition: CompactEventBuilder.cpp:799
std::shared_ptr< ByteBuffer > getBuffer()
Get the buffer being written into.
Definition: CompactEventBuilder.cpp:141
static const DataType UNKNOWN32
Unknown data type.
Definition: DataType.h:36
size_t getTotalBytes() const
Get the total number of bytes written into the buffer.
Definition: CompactEventBuilder.cpp:151
void addByteData(uint8_t *data, uint32_t len)
Appends byte data to the structure.
Definition: CompactEventBuilder.cpp:735
void setBuffer(std::shared_ptr< ByteBuffer > buffer, bool generateNodes=false)
Set the buffer to be written into.
Definition: CompactEventBuilder.cpp:94
void addFloatData(float *data, uint32_t len)
Appends float data to the structure.
Definition: CompactEventBuilder.cpp:993
std::shared_ptr< EvioNode > openBank(uint16_t tag, DataType const &dataType, uint8_t num)
This method adds an evio bank to the buffer.
Definition: CompactEventBuilder.cpp:324
static const ByteOrder ENDIAN_LOCAL
Local host&#39;s byte order.
Definition: ByteOrder.h:61