evio  6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EvioNode.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_EVIONODE_H
12 #define EVIO_6_0_EVIONODE_H
13 
14 
15 #include <cstdint>
16 #include <sstream>
17 #include <memory>
18 #include <vector>
19 #include <algorithm>
20 
21 
22 #include "ByteOrder.h"
23 #include "ByteBuffer.h"
24 #include "DataType.h"
25 #include "RecordNode.h"
26 #include "EvioException.h"
27 
28 
29 namespace evio {
30 
31 
41  class EvioNode : public std::enable_shared_from_this<EvioNode> {
42 
43  friend class Util;
44  friend class EventHeaderParser;
45  friend class EvioCompactReaderV4;
46  friend class EvioCompactReaderV6;
47 
48  private:
49 
51  uint32_t len = 0;
53  uint16_t tag = 0;
55  uint8_t num = 0;
57  uint32_t pad = 0;
59  size_t pos = 0;
61  uint32_t type = 0;
62 
64  uint32_t dataLen = 0;
66  size_t dataPos = 0;
68  uint32_t dataType = 0;
69 
72  size_t recordPos = 0;
73 
75  std::vector<uint32_t> data;
76 
78  bool izEvent = false;
79 
82  bool obsolete = false;
83 
85  std::shared_ptr<ByteBuffer> buffer = nullptr;
86 
88  std::vector<std::shared_ptr<EvioNode>> childNodes;
89 
91  RecordNode recordNode;
92 
93  //-------------------------------
94  // For event-level node
95  //-------------------------------
96 
101  uint32_t place = 0;
102 
107  bool scanned = false;
108 
120  std::vector<std::shared_ptr<EvioNode>> allNodes;
121 
122  //-------------------------------
123  // For sub event-level node
124  //-------------------------------
125 
127  std::shared_ptr<EvioNode> eventNode = nullptr;
128 
130  std::shared_ptr<EvioNode> parentNode = nullptr;
131 
132  public:
133 
134  //-------------------------------
135  // For testing/debugging
136  //-------------------------------
137 
139  uint32_t id;
140 
142  static uint32_t staticId;
143 
144 
145  private:
146 
147  void copyParentForScan(std::shared_ptr<EvioNode> & parent);
148  void addChild(std::shared_ptr<EvioNode> & node);
149  void addToAllNodes(std::shared_ptr<EvioNode> & node);
150  void removeFromAllNodes(std::shared_ptr<EvioNode> & node);
151  void removeChild(std::shared_ptr<EvioNode> & node);
152  RecordNode & getRecordNode(); // public?
153  void copy(const EvioNode & src);
154 
155  protected:
156 
157  explicit EvioNode(std::shared_ptr<EvioNode> & firstNode, int dummy);
158  std::shared_ptr<EvioNode> getThis() {return shared_from_this();}
159 
160  public:
161 
162  EvioNode();
163  EvioNode(const EvioNode & firstNode);
164  explicit EvioNode(const std::shared_ptr<EvioNode> & src);
165  EvioNode(EvioNode && src) noexcept;
166  EvioNode(size_t pos, uint32_t place, std::shared_ptr<ByteBuffer> & buffer, RecordNode & blockNode);
167  EvioNode(size_t pos, uint32_t place, size_t recordPos, std::shared_ptr<ByteBuffer> & buffer);
168  EvioNode(uint16_t tag, uint8_t num, size_t pos, size_t dataPos,
169  DataType const & type, DataType const & dataType,
170  std::shared_ptr<ByteBuffer> buffer);
171 
172  ~EvioNode() = default;
173 
174  static void scanStructure(std::shared_ptr<EvioNode> & node);
175 
176  static std::shared_ptr<EvioNode> & extractNode(std::shared_ptr<EvioNode> & bankNode, size_t position);
177  static std::shared_ptr<EvioNode> extractEventNode(std::shared_ptr<ByteBuffer> & buffer,
178  RecordNode & recNode,
179  size_t position, uint32_t place);
180  static std::shared_ptr<EvioNode> extractEventNode(std::shared_ptr<ByteBuffer> & buffer,
181  size_t recPosition,
182  size_t position, uint32_t place);
183 
184  EvioNode & operator=(const EvioNode& other);
185  bool operator==(const EvioNode& src) const;
186 
187  EvioNode & shift(int deltaPos);
188  std::string toString();
189 
190  void clearLists();
191  void clear();
192  void clearObjects();
193  void clearIntArray();
194 
195  void setBuffer(std::shared_ptr<ByteBuffer> & buf);
196  void setData(size_t position, uint32_t plc, std::shared_ptr<ByteBuffer> & buf, RecordNode & recNode);
197  void setData(size_t position, uint32_t plc, size_t recPos, std::shared_ptr<ByteBuffer> & buf);
198 
199  // TODO: set many of these methods to CONST
200 
201  bool isObsolete() const;
202  void setObsolete(bool ob);
203  std::vector<std::shared_ptr<EvioNode>> & getAllNodes();
204  std::vector<std::shared_ptr<EvioNode>> & getChildNodes();
205  void getAllDescendants(std::vector<std::shared_ptr<EvioNode>> & descendants);
206  std::shared_ptr<EvioNode> getChildAt(uint32_t index);
207  uint32_t getChildCount() const;
208 
209  std::shared_ptr<ByteBuffer> getBuffer();
210 
211  uint32_t getLength() const;
212  uint32_t getTotalBytes() const;
213  uint16_t getTag() const;
214  uint8_t getNum() const;
215  uint32_t getPad() const;
216  size_t getPosition() const;
217  uint32_t getType() const;
218  DataType getTypeObj() const;
219  uint32_t getDataLength() const;
220  size_t getDataPosition() const;
221  uint32_t getDataType() const;
222  DataType getDataTypeObj() const;
223  size_t getRecordPosition() const;
224  uint32_t getPlace() const;
225 
226  std::shared_ptr<EvioNode> getParentNode();
227  uint32_t getEventNumber() const;
228  bool isEvent() const;
229  bool getScanned() const;
230 
231  void updateLengths(uint32_t deltaLen);
232  void updateTag(uint16_t newTag);
233  void updateNum(uint8_t newNum);
234 
235  ByteBuffer & getByteData(ByteBuffer & dest, bool copy);
236  std::shared_ptr<ByteBuffer> & getByteData(std::shared_ptr<ByteBuffer> & dest, bool copy);
237  std::shared_ptr<ByteBuffer> getByteData(bool copy);
238 
239  std::vector<uint32_t> & getIntData();
240  void getIntData(std::vector<uint32_t> & intData);
241  void getLongData(std::vector<uint64_t> & longData);
242  void getShortData(std::vector<uint16_t> & shortData);
243  ByteBuffer & getStructureBuffer(ByteBuffer & dest, bool copy);
244  std::shared_ptr<ByteBuffer> & getStructureBuffer(std::shared_ptr<ByteBuffer> & dest, bool copy);
245  };
246 
247 }
248 
249 #endif //EVIO_6_0_EVIONODE_H
This class is copied from one of the same name in the Java programming language.
Definition: ByteBuffer.h:42
void getShortData(std::vector< uint16_t > &shortData)
Get the data associated with this node as an 16-bit integer vector.
Definition: EvioNode.cpp:1216
static uint32_t staticId
Static id for testing.
Definition: EvioNode.h:142
ByteBuffer & getStructureBuffer(ByteBuffer &dest, bool copy)
Get this node&#39;s entire evio structure in ByteBuffer form.
Definition: EvioNode.cpp:1237
static std::shared_ptr< EvioNode > & extractNode(std::shared_ptr< EvioNode > &bankNode, size_t position)
This method populates an EvioNode object that will represent an evio bank from that same node contain...
Definition: EvioNode.cpp:453
void getAllDescendants(std::vector< std::shared_ptr< EvioNode >> &descendants)
Get the list of all descendant nodes that this node contains - not only the immediate children...
Definition: EvioNode.cpp:815
bool getScanned() const
Has this object been scanned (i.e.
Definition: EvioNode.cpp:983
void clear()
Clear all data in this object.
Definition: EvioNode.cpp:297
std::shared_ptr< EvioNode > getThis()
Definition: EvioNode.h:158
Class containing static methods of general purpose.
Definition: Util.h:41
bool isEvent() const
Does this object represent an event?
Definition: EvioNode.cpp:974
size_t getDataPosition() const
Get the file/buffer byte position of this evio structure&#39;s data.
Definition: EvioNode.cpp:924
std::vector< uint32_t > & getIntData()
Get the data associated with this node as an 32-bit integer vector.
Definition: EvioNode.cpp:1165
The createXXX methods exist is in the EventParser class in the original Java, but must be moved in C+...
Definition: EventHeaderParser.h:40
ByteBuffer & getByteData(ByteBuffer &dest, bool copy)
Get the data associated with this node in ByteBuffer form.
Definition: EvioNode.cpp:1091
This class is used to store relevant info about an evio record (or block) along with its position in ...
Definition: RecordNode.h:30
std::shared_ptr< EvioNode > getChildAt(uint32_t index)
Get the child node at the given index (starts at 0).
Definition: EvioNode.cpp:833
uint32_t getDataType() const
Get the evio type of the data this evio structure contains.
Definition: EvioNode.cpp:932
This class is used to read an evio format version 4 formatted file or buffer and extract specific evi...
Definition: EvioCompactReaderV4.h:54
uint32_t getTotalBytes() const
Get the length of this evio structure including entire header in bytes.
Definition: EvioNode.cpp:870
static void scanStructure(std::shared_ptr< EvioNode > &node)
This method recursively stores, in the given list, all the information about an evio structure&#39;s chil...
Definition: EvioNode.cpp:504
uint32_t getPad() const
Get the padding of this evio structure.
Definition: EvioNode.cpp:890
DataType getTypeObj() const
Get the evio type of this evio structure as an object.
Definition: EvioNode.cpp:910
EvioNode & shift(int deltaPos)
Shift the positions (pos, dataPos, and recordPos) of this node and its children by a fixed amount...
Definition: EvioNode.cpp:226
DataType getDataTypeObj() const
Get the evio type of the data this evio structure contains as an object.
Definition: EvioNode.cpp:938
void setBuffer(std::shared_ptr< ByteBuffer > &buf)
Set the buffer.
Definition: EvioNode.cpp:330
void clearLists()
Clear childNodes.
Definition: EvioNode.cpp:282
void setObsolete(bool ob)
Set whether this node &amp; descendants are now obsolete because the data they represent in the buffer ha...
Definition: EvioNode.cpp:769
size_t getPosition() const
Get the file/buffer byte position of this evio structure.
Definition: EvioNode.cpp:896
void updateLengths(uint32_t deltaLen)
Update the length of this node in the buffer and all its parent nodes as well.
Definition: EvioNode.cpp:991
This class is used to store relevant info about an evio container (bank, segment, or tag segment)...
Definition: EvioNode.h:41
void getLongData(std::vector< uint64_t > &longData)
Get the data associated with this node as an 64-bit integer vector.
Definition: EvioNode.cpp:1200
std::shared_ptr< EvioNode > getParentNode()
Get this node&#39;s parent node.
Definition: EvioNode.cpp:958
void clearIntArray()
Only clear the data vector.
Definition: EvioNode.cpp:318
uint32_t getChildCount() const
Get the number all children that this node contains.
Definition: EvioNode.cpp:847
bool isObsolete() const
Has the data this node represents in the buffer been removed?
Definition: EvioNode.cpp:759
Numerical values associated with evio data types.
Definition: DataType.h:32
size_t getRecordPosition() const
Get the file/buffer byte position of the record containing this node.
Definition: EvioNode.cpp:945
uint32_t getType() const
Get the evio type of this evio structure, not what it contains.
Definition: EvioNode.cpp:904
void updateTag(uint16_t newTag)
Update, in the buffer, the tag of the structure header this object represents.
Definition: EvioNode.cpp:1024
uint8_t getNum() const
Get the num of this evio structure.
Definition: EvioNode.cpp:883
uint32_t getPlace() const
Get the place of containing event in file/buffer.
Definition: EvioNode.cpp:952
void updateNum(uint8_t newNum)
Update, in the buffer, the num of the bank header this object represents.
Definition: EvioNode.cpp:1063
uint32_t id
Local id for testing.
Definition: EvioNode.h:139
EvioNode()
Constructor when fancy features not needed.
Definition: EvioNode.cpp:22
std::string toString()
Get a string representation of this object.
Definition: EvioNode.cpp:243
void setData(size_t position, uint32_t plc, std::shared_ptr< ByteBuffer > &buf, RecordNode &recNode)
Once this node is cleared, it may be reused and then re-initialized with this method.
Definition: EvioNode.cpp:342
static std::shared_ptr< EvioNode > extractEventNode(std::shared_ptr< ByteBuffer > &buffer, RecordNode &recNode, size_t position, uint32_t place)
This method extracts an EvioNode object representing an evio event (top level evio bank) from a given...
Definition: EvioNode.cpp:394
std::vector< std::shared_ptr< EvioNode > > & getAllNodes()
Get the vector of all nodes that this node contains, always including itself.
Definition: EvioNode.cpp:786
This class is used to read an evio format version 6 formatted file or buffer.
Definition: EvioCompactReaderV6.h:52
uint32_t getDataLength() const
Get the length of this evio structure&#39;s data only (no header words) in 32-bit words.
Definition: EvioNode.cpp:918
std::vector< std::shared_ptr< EvioNode > > & getChildNodes()
Get the vector of all child nodes that this node contains.
Definition: EvioNode.cpp:804
uint32_t getEventNumber() const
If this object represents an event (top-level, evio bank), then returns its number (place in file or ...
Definition: EvioNode.cpp:966
uint32_t getLength() const
Get the length of this evio structure (not including length word itself) in 32-bit words...
Definition: EvioNode.cpp:863
std::shared_ptr< ByteBuffer > getBuffer()
Get the object containing the buffer that this node is associated with.
Definition: EvioNode.cpp:854
void clearObjects()
Empty all lists and remove all other objects from this object.
Definition: EvioNode.cpp:305
uint16_t getTag() const
Get the tag of this evio structure.
Definition: EvioNode.cpp:876