evio  6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseStructure.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_BASESTRUCTURE_H
12 #define EVIO_6_0_BASESTRUCTURE_H
13 
14 
15 #include <vector>
16 #include <cstring>
17 #include <cstdint>
18 #include <sstream>
19 #include <string>
20 #include <iomanip>
21 #include <limits>
22 #include <memory>
23 #include <type_traits>
24 #include <iterator>
25 #include <stack>
26 #include <vector>
27 #include <queue>
28 #include <utility>
29 #include <stdexcept>
30 
31 
32 #include "ByteOrder.h"
33 #include "ByteBuffer.h"
34 #include "DataType.h"
35 #include "StructureType.h"
36 #include "EvioException.h"
37 #include "BaseStructureHeader.h"
38 #include "CompositeData.h"
39 #include "Util.h"
40 #include "IEvioListener.h"
41 #include "IEvioFilter.h"
42 
43 
44 
45 
46 namespace evio {
47 
48 
50 
51  template<typename R>
52  class nodeIterator {
53 
54  // iterator of vector contained shared pointers to node's children
55  typedef typename std::vector<R>::iterator KidIter;
56 
57  protected:
58 
59  // Stack of pair containing 2 iterators, each iterating over vector
60  // of node's children (shared pts).
61  // In each pair, first is current iterator, second is end iterator.
62  std::stack<std::pair<KidIter, KidIter>> stack;
63 
64  // Where we are now in the tree
66 
67  // Is this the end iterator?
68  bool isEnd;
69 
70  public:
71 
72  // Copy shared pointer arg
73  explicit nodeIterator(R &node, bool isEnd) : currentNode(node), isEnd(isEnd) {
74  // store current-element and end of vector in pair
75  if (!node->children.empty()) {
76  std::pair<KidIter, KidIter> p(node->children.begin(), node->children.end());
77  stack.push(p);
78  }
79  }
80 
81  R operator*() const { return currentNode; }
82 
83  bool operator==(const nodeIterator &other) const {
84  // Identify end iterator
85  if (isEnd && other.isEnd) {
86  return true;
87  }
88  return this == &other;
89  }
90 
91  bool operator!=(const nodeIterator &other) const {
92  // Identify end iterator
93  if (isEnd && other.isEnd) {
94  return false;
95  }
96  return this != &other;
97  }
98 
99  bool isEndIter() {return isEnd;}
100 
101  // post increment gets ignored arg of 0 to distinguish from pre, A++
103 
104  if (isEnd) return *this;
105 
106  // copy this iterator here
107  nodeIterator niter = *this;
108 
109  // If gone thru the whole tree ...
110  if (stack.empty()) {
111  isEnd = true;
112  return niter;
113  }
114 
115  // Look at top vector of stack
116  auto &topPair = stack.top();
117  // iterator of vector @ current position
118  auto &curIter = topPair.first;
119  // end iterator of vector
120  auto &endIter = topPair.second;
121  // current element of vector
122  auto &node = *curIter;
123 
124  // If this vector has no more nodes ...
125  if (curIter - (endIter - 1) == 0) {
126  stack.pop();
127  }
128 
129  // Prepare to look at the next node in the vector (next call)
130  ++curIter;
131 
132  // If it has children, put pair of iterators on stack
133  if (!node->children.empty()) {
134  // Look at node's children
135  std::pair<KidIter, KidIter> p(node->children.begin(), node->children.end());
136  stack.push(p);
137  }
138 
139  currentNode = node;
140  // return copy of this iterator before changes
141  return niter;
142  }
143 
144 
145  // pre increment, ++A
147 
148  if (isEnd) return *this;
149 
150  // If gone thru the whole tree ...
151  if (stack.empty()) {
152  isEnd = true;
153  return *this;
154  }
155 
156  // Look at top vector of stack
157  auto &topPair = stack.top();
158  // iterator of vector @ current position
159  auto &curIter = topPair.first;
160  // end iterator of vector
161  auto &endIter = topPair.second;
162  // current element of vector
163  auto &node = *curIter;
164 
165  // If this vector has no more nodes ...
166  if (curIter - (endIter - 1) == 0) {
167  stack.pop();
168  }
169 
170  // Prepare to look at the next node in the vector (next call)
171  ++curIter;
172 
173  // If it has children, put pair of iterators on stack
174  if (!node->children.empty()) {
175  // Look at node's children
176  std::pair<KidIter, KidIter> p(node->children.begin(), node->children.end());
177  stack.push(p);
178  }
179 
180  currentNode = node;
181  return *this;
182  }
183  };
184 
185 
187 
188  template<typename R>
190 
191  protected:
192 
193  // iterator of vector contained shared pointers to node's children
194  typedef typename std::vector<R>::iterator KidIter;
195 
196  // Stack of iterators of vector of shared pointers.
197  // Each vector contains the children of a node,
198  // thus each iterator gives all a node's kids.
199 
200  // Stack of iterators over node's children.
201  // In each pair, first is current iterator, second is end
202  std::queue<std::pair<KidIter, KidIter>> que;
203 
204  // Where we are now in the tree
206 
207  // Is this the end iterator?
208  bool isEnd;
209 
210  public:
211 
212  // Copy shared pointer arg
213  nodeBreadthIterator(R & node, bool isEnd) : currentNode(node), isEnd(isEnd) {
214  // store current-element and end of vector in pair
215  if (!node->children.empty()) {
216  std::pair<KidIter, KidIter> p(node->children.begin(), node->children.end());
217  que.push(p);
218  }
219  }
220 
221  R operator*() const { return currentNode; }
222 
223  bool operator==(const nodeBreadthIterator &other) const {
224  if (isEnd && other.isEnd) {
225  return true;
226  }
227  return this == &other;
228  }
229 
230  bool operator!=(const nodeBreadthIterator &other) const {
231  if (isEnd && other.isEnd) {
232  return false;
233  }
234  return this != &other;
235  }
236 
237  bool isEndIter() {return isEnd;}
238 
239  // TODO: How does one handle going too far???
240 
241  // post increment gets ignored arg of 0 to distinguish from pre, A++
243 
244  if (isEnd) {
245  return *this;
246  }
247 
248  // copy this iterator here
249  nodeBreadthIterator niter = *this;
250 
251  // If gone thru the whole tree ...
252  if (que.empty()) {
253  isEnd = true;
254  return *this;
255  }
256 
257  // Look at top vector of Q
258  auto &topPair = que.front();
259  // iterator of vector @ current position
260  auto &curIter = topPair.first;
261  // end iterator of vector
262  auto &endIter = topPair.second;
263  // current element of vector
264  auto &node = *curIter;
265 
266  // If this vector has no more nodes ...
267  if (curIter - (endIter - 1) == 0) {
268  que.pop();
269  }
270 
271  // Prepare to look at the next node in the vector (next call)
272  ++curIter;
273 
274  // If it has children, put pair of iterators on stack
275  if (!node->children.empty()) {
276  // Look at node's children
277  std::pair<KidIter, KidIter> p(node->children.begin(), node->children.end());
278  que.push(p);
279  }
280 
281  currentNode = node;
282  // return copy of this iterator before changes
283  return niter;
284  }
285 
286 
287  // pre increment, ++A
289 
290  if (isEnd) {
291  return *this;
292  }
293 
294  // If gone thru the whole tree ...
295  if (que.empty()) {
296  isEnd = true;
297  return *this;
298  }
299 
300  // Look at top vector of Q
301  auto &topPair = que.front();
302  // iterator of vector @ current position
303  auto &curIter = topPair.first;
304  // end iterator of vector
305  auto &endIter = topPair.second;
306  // current element of vector
307  auto &node = *curIter;
308 
309  // If this vector has no more nodes ...
310  if (curIter - (endIter - 1) == 0) {
311  que.pop();
312  }
313 
314  // Prepare to look at the next node in the vector (next call)
315  ++curIter;
316 
317  // If it has children, put pair of iterators on stack
318  if (!node->children.empty()) {
319  // Look at node's children
320  std::pair<KidIter, KidIter> p(node->children.begin(), node->children.end());
321  que.push(p);
322  }
323 
324  currentNode = node;
325  return *this;
326  }
327  };
328 
329 
330 
347  class BaseStructure : public std::enable_shared_from_this<BaseStructure> {
348 
349  friend class EventParser;
350  friend class EvioReader;
351  friend class EvioReaderV4;
352  friend class EventBuilder;
353  friend class StructureTransformer;
354 
355  //---------------------------------------------
356  //---------- Tree structure members ----------
357  //---------------------------------------------
358 
359  public:
360 
361  // For defining our own iterator
362  typedef size_t size_type;
363  typedef std::ptrdiff_t difference_type;
364  typedef std::input_iterator_tag iterator_category;
365 
366  typedef std::shared_ptr<BaseStructure> value_type;
367  typedef std::shared_ptr<BaseStructure> reference;
368  typedef std::shared_ptr<BaseStructure> pointer;
369 
372 
373  friend class nodeIterator<std::shared_ptr<BaseStructure>>;
374  friend class nodeBreadthIterator<std::shared_ptr<BaseStructure>>;
375 
376  // Can't figure out how to implement a const iterator, so I give up.
377  //typedef nodeIterator_const<std::shared_ptr<const BaseStructure>> const_iterator;
378  //typedef nodeBreadthIterator_const<std::shared_ptr<BaseStructure>> breadth_iterator_const;
379  //friend class nodeIterator_const<std::shared_ptr<BaseStructure>>;
380  //friend class nodeBreadthIterator_const<std::shared_ptr<const BaseStructure>>;
381 
386  iterator begin() { auto arg = getThis(); return iterator(arg, false); }
391  iterator end() { auto arg = getThis(); return iterator(arg, true); }
392 
397  breadth_iterator bbegin() { auto arg = getThis(); return breadth_iterator(arg, false); }
402  breadth_iterator bend() { auto arg = getThis(); return breadth_iterator(arg, true); }
403 
404  protected:
405 
407  std::shared_ptr<BaseStructure> parent = nullptr;
408 
410  std::vector<std::shared_ptr<BaseStructure>> children;
411 
413  bool allowsChildren = true;
414 
415  public:
416 
417  std::shared_ptr<BaseStructure> getThis() {return shared_from_this();}
418  std::shared_ptr<const BaseStructure> getThisConst() const {return shared_from_this();}
419 
420  protected:
421 
422  void setParent(const std::shared_ptr<BaseStructure> &newParent);
423 
424  public:
425 
426  void insert(const std::shared_ptr<BaseStructure> newChild, size_t childIndex);
427  void remove(size_t childIndex);
428 
429  std::shared_ptr<BaseStructure> getParent() const;
430  std::vector<std::shared_ptr<BaseStructure>> getChildren() const;
431  std::shared_ptr<BaseStructure> getChildAt(size_t index) const;
432 
433  size_t getChildCount() const;
434  ssize_t getIndex(const std::shared_ptr<BaseStructure> aChild);
435  std::vector<std::shared_ptr<BaseStructure>>::iterator childrenBegin();
436  std::vector<std::shared_ptr<BaseStructure>>::iterator childrenEnd();
437 
438  void setAllowsChildren(bool allows);
439  bool getAllowsChildren() const;
440 
441  //
442  // Derived methods
443  //
444 
445  void removeFromParent();
446  void remove(const std::shared_ptr<BaseStructure> aChild);
447  void removeAllChildren();
448  void add(std::shared_ptr<BaseStructure> newChild);
449 
450  //
451  // Tree Queries
452  //
453 
454  bool isNodeAncestor(const std::shared_ptr<BaseStructure> anotherNode) const;
455  bool isNodeDescendant(std::shared_ptr<BaseStructure> anotherNode);
456  std::shared_ptr<BaseStructure> getSharedAncestor(std::shared_ptr<BaseStructure> aNode);
457  bool isNodeRelated(std::shared_ptr<BaseStructure> aNode);
458  uint32_t getDepth();
459  uint32_t getLevel() const;
460  std::vector<std::shared_ptr<BaseStructure>> getPath();
461 
462  protected:
463 
464  std::vector<std::shared_ptr<BaseStructure>> getPathToRoot(const std::shared_ptr<BaseStructure> & aNode, int depth) const;
465 
466  public:
467 
468  std::shared_ptr<BaseStructure> getRoot();
469  bool isRoot() const;
470  std::shared_ptr<BaseStructure> getNextNode();
471  std::shared_ptr<BaseStructure> getPreviousNode();
472 
473  //
474  // Child Queries
475  //
476 
477  bool isNodeChild(const std::shared_ptr<BaseStructure> aNode) const;
478  std::shared_ptr<BaseStructure> getFirstChild() const;
479  std::shared_ptr<BaseStructure> getLastChild() const;
480  std::shared_ptr<BaseStructure> getChildAfter(const std::shared_ptr<BaseStructure> aChild);
481  std::shared_ptr<BaseStructure> getChildBefore(const std::shared_ptr<BaseStructure> aChild);
482 
483  //
484  // Sibling Queries
485  //
486 
487  bool isNodeSibling(const std::shared_ptr<BaseStructure> anotherNode) const;
488  size_t getSiblingCount() const;
489  std::shared_ptr<BaseStructure> getNextSibling();
490  std::shared_ptr<BaseStructure> getPreviousSibling();
491 
492  //
493  // Leaf Queries
494  //
495 
496  bool isLeaf() const;
497  std::shared_ptr<BaseStructure> getFirstLeaf();
498  std::shared_ptr<BaseStructure> getLastLeaf();
499  std::shared_ptr<BaseStructure> getNextLeaf();
500  std::shared_ptr<BaseStructure> getPreviousLeaf();
501  ssize_t getLeafCount();
502 
503  //
504  // Tree Traversal and Searching
505  //
506 
507  void visitAllStructures(std::shared_ptr<IEvioListener> listener);
508  void visitAllStructures(std::shared_ptr<IEvioListener> listener,
509  std::shared_ptr<IEvioFilter> filter);
510  void getMatchingStructures(std::shared_ptr<IEvioFilter> filter,
511  std::vector<std::shared_ptr<BaseStructure>> & vec);
512  private:
513  void visitAllDescendants(std::shared_ptr<BaseStructure> structure,
514  std::shared_ptr<IEvioListener> listener,
515  std::shared_ptr<IEvioFilter> filter);
516 
517 
518 
519  //---------------------------------------------
520  //-------- CODA evio structure members -------
521  //---------------------------------------------
522 
523 
524  protected:
525 
527  std::shared_ptr<BaseStructureHeader> header;
528 
530  std::vector<uint8_t> rawBytes;
531 
533  std::vector<int16_t> shortData;
534 
536  std::vector<uint16_t> ushortData;
537 
539  std::vector<int32_t> intData;
540 
542  std::vector<uint32_t> uintData;
543 
545  std::vector<int64_t> longData;
546 
548  std::vector<uint64_t> ulongData;
549 
551  std::vector<double> doubleData;
552 
554  std::vector<float> floatData;
555 
557  std::vector<std::shared_ptr<CompositeData>> compositeData;
558 
567  std::vector<signed char> charData;
568 
570  std::vector<unsigned char> ucharData;
571 
572  //------------------- STRING STUFF -------------------
573 
575  std::vector<std::string > stringList;
576 
581  int stringEnd = 0;
582 
587  bool badStringFormat = false;
588 
589  //----------------------------------------------------
590 
598  size_t numberDataItems = 0;
599 
602 
604  bool lengthsUpToDate = false;
605 
606  private:
607 
609  static const uint8_t padValues[3];
610 
612  static const uint32_t padCount[4];
613 
614  protected:
615 
616  bool getLengthsUpToDate() const;
618  uint32_t dataLength();
619  void stringsToRawBytes();
620 
621  private:
622 
623  void clearData();
624  void copyData(BaseStructure const & other);
625  void copyData(std::shared_ptr<BaseStructure> const & other);
626 
627  protected:
628 
629  BaseStructure();
630  explicit BaseStructure(std::shared_ptr<BaseStructureHeader> head);
631 
632  // TODO: are these really necesary???
633  BaseStructure(const BaseStructure & srcBuf);
634  BaseStructure(BaseStructure && srcBuf) noexcept;
635  BaseStructure & operator=(BaseStructure && other) noexcept;
636  BaseStructure & operator=(const BaseStructure & other);
637 
638  public:
639 
640  void transform(std::shared_ptr<BaseStructure> const & structure);
641 
643 
645 
646  void setByteOrder(ByteOrder const & order);
647 
648  bool needSwap() const;
649 
650  virtual std::string toString() const;
651  std::string treeToString(std::string const & indent) const;
652 
653  std::shared_ptr<BaseStructureHeader> getHeader() const;
654 
655  size_t write(ByteBuffer & dest);
656  size_t write(uint8_t *dest, ByteOrder const & order);
657 
658  size_t writeQuick(uint8_t *dest);
659  size_t writeQuick(ByteBuffer & dest);
660 
661  uint32_t getNumberDataItems();
662 
663  uint32_t setAllHeaderLengths();
664  bool isContainer() const;
665  uint32_t getTotalBytes() const;
666 
667  std::vector<uint8_t> &getRawBytes();
668 
669  protected:
670 
671  void setRawBytes(uint8_t *bytes, uint32_t len);
672  void setRawBytes(std::vector<uint8_t> &bytes);
673 
674  public:
675  std::vector<int16_t> &getShortData();
676  std::vector<uint16_t> &getUShortData();
677 
678  std::vector<int32_t> &getIntData();
679  std::vector<uint32_t> &getUIntData();
680 
681  std::vector<int64_t> &getLongData();
682  std::vector<uint64_t> &getULongData();
683 
684  std::vector<float> &getFloatData();
685  std::vector<double> &getDoubleData();
686 
687  std::vector<signed char> & getCharData();
688  std::vector<unsigned char> & getUCharData();
689 
690  std::vector<std::shared_ptr<CompositeData>> & getCompositeData();
691 
692  std::vector<std::string> & getStringData();
693  uint32_t unpackRawBytesToStrings();
694 
695  static uint32_t stringToRawSize(const std::string & str);
696  static uint32_t stringsToRawSize(std::vector<std::string> const & strings);
697 
698  static void stringsToRawBytes(std::vector<std::string> & strings,
699  std::vector<uint8_t> & bytes);
700 
701  static void unpackRawBytesToStrings(std::vector<uint8_t> & bytes, size_t offset,
702  std::vector<std::string> & strData);
703  static void unpackRawBytesToStrings(std::vector<uint8_t> & bytes,
704  size_t offset, size_t maxLength,
705  std::vector<std::string> & strData);
706  static void unpackRawBytesToStrings(uint8_t *bytes, size_t length,
707  std::vector<std::string> & strData);
708  static void unpackRawBytesToStrings(ByteBuffer & buffer,
709  size_t pos, size_t length,
710  std::vector<std::string> & strData);
711 
712  void updateIntData();
713  void updateUIntData();
714  void updateShortData();
715  void updateUShortData();
716  void updateLongData();
717  void updateULongData();
718  void updateCharData();
719  void updateUCharData();
720  void updateFloatData();
721  void updateDoubleData();
722  void updateStringData();
723  void updateCompositeData();
724 
725  private:
726 
727  static void stringBuilderToStrings(std::string const & strData, bool onlyGoodChars,
728  std::vector<std::string> & strings);
729 
730 
731  };
732 
733 
734 }
735 
736 
737 #endif //EVIO_6_0_BASESTRUCTURE_H
std::vector< std::shared_ptr< BaseStructure > >::iterator childrenEnd()
Creates and returns a forward-order end iterator of this node&#39;s children.
Definition: BaseStructure.cpp:535
size_t writeQuick(uint8_t *dest)
Write myself out as evio format data in the data&#39;s current byte order given by getByteOrder() at the ...
Definition: BaseStructure.cpp:2723
std::vector< signed char > & getCharData()
Gets the raw data as an signed char vector, if the contents type as indicated by the header is approp...
Definition: BaseStructure.cpp:1971
std::shared_ptr< BaseStructure > getChildAt(size_t index) const
Returns the child at the specified index in this node&#39;s child vector.
Definition: BaseStructure.cpp:465
This class is copied from one of the same name in the Java programming language.
Definition: ByteBuffer.h:42
R operator*() const
Definition: BaseStructure.h:81
bool allowsChildren
True if the node is able to have children.
Definition: BaseStructure.h:413
std::vector< float > floatData
Used if raw data should be interpreted as floats.
Definition: BaseStructure.h:554
uint32_t getDepth()
Returns the depth of the tree rooted at this node – the longest distance from this node to a leaf...
Definition: BaseStructure.cpp:780
std::queue< std::pair< KidIter, KidIter > > que
Definition: BaseStructure.h:202
uint32_t unpackRawBytesToStrings()
Extract string data from rawBytes array.
Definition: BaseStructure.cpp:2419
bool isEndIter()
Definition: BaseStructure.h:237
std::shared_ptr< BaseStructure > getNextSibling()
Returns the next sibling of this node in the parent&#39;s children vector.
Definition: BaseStructure.cpp:1169
std::vector< double > doubleData
Used if raw data should be interpreted as doubles.
Definition: BaseStructure.h:551
nodeBreadthIterator< std::shared_ptr< BaseStructure > > breadth_iterator
Definition: BaseStructure.h:371
void setParent(const std::shared_ptr< BaseStructure > &newParent)
Sets this node&#39;s parent to newParent but does not change the parent&#39;s child array.
Definition: BaseStructure.cpp:370
std::vector< std::shared_ptr< BaseStructure > > children
Array of children, may be null if this node has no children.
Definition: BaseStructure.h:410
ssize_t getLeafCount()
Returns the total number of leaves that are descendants of this node.
Definition: BaseStructure.cpp:1359
std::shared_ptr< BaseStructure > getThis()
Definition: BaseStructure.h:417
std::shared_ptr< BaseStructure > getRoot()
Returns the root of the tree that contains this node.
Definition: BaseStructure.cpp:870
std::vector< uint32_t > uintData
Used if raw data should be interpreted as unsigned ints.
Definition: BaseStructure.h:542
Definition: BaseStructure.h:52
std::vector< int64_t > longData
Used if raw data should be interpreted as longs.
Definition: BaseStructure.h:545
virtual StructureType getStructureType() const
Definition: BaseStructure.h:642
This is the base class for all evio structures: Banks, Segments, and TagSegments. ...
Definition: BaseStructure.h:347
std::shared_ptr< BaseStructure > getPreviousNode()
Returns the node that precedes this node in a preorder traversal of this node&#39;s tree (return left nod...
Definition: BaseStructure.cpp:946
void updateLongData()
If data in this structure was changed by modifying the vector returned from getLongData(), then this method needs to be called in order to make this object internally consistent.
Definition: BaseStructure.cpp:3092
bool isEnd
Definition: BaseStructure.h:208
std::vector< std::string > stringList
Used if raw data should be interpreted as a string.
Definition: BaseStructure.h:575
R operator*() const
Definition: BaseStructure.h:221
R currentNode
Definition: BaseStructure.h:205
void updateULongData()
If data in this structure was changed by modifying the vector returned from getULongData(), then this method needs to be called in order to make this object internally consistent.
Definition: BaseStructure.cpp:3129
bool isEnd
Definition: BaseStructure.h:68
void transform(std::shared_ptr< BaseStructure > const &structure)
This method does a partial copy and is designed to help convert between banks, segments,and tagsegments in the StructureTransformer class (hence the name &quot;transform&quot;).
Definition: BaseStructure.cpp:165
void setAllowsChildren(bool allows)
Determines whether or not this node is allowed to have children.
Definition: BaseStructure.cpp:547
uint32_t getTotalBytes() const
Get the length of this structure in bytes, including the header.
Definition: BaseStructure.cpp:1668
void removeFromParent()
Removes the subtree rooted at this node from the tree, giving this node a null parent.
Definition: BaseStructure.cpp:575
std::vector< R >::iterator KidIter
Definition: BaseStructure.h:194
std::string treeToString(std::string const &indent) const
Recursive method to obtain a string representation of the entire tree structure rooted at this struct...
Definition: BaseStructure.cpp:1579
void setLengthsUpToDate(bool lengthsUpToDate)
Set whether the lengths of all header fields for this structure and all it descendants are up to date...
Definition: BaseStructure.cpp:2625
std::vector< unsigned char > ucharData
Used if raw data should be interpreted as unsigned chars.
Definition: BaseStructure.h:570
std::shared_ptr< BaseStructure > getFirstChild() const
Returns this node&#39;s first child.
Definition: BaseStructure.cpp:1007
Numerical values associated with endian byte order.
Definition: ByteOrder.h:53
void getMatchingStructures(std::shared_ptr< IEvioFilter > filter, std::vector< std::shared_ptr< BaseStructure >> &vec)
Visit all the descendant structures, and collect those that pass a filter.
Definition: BaseStructure.cpp:1452
std::vector< uint16_t > ushortData
Used if raw data should be interpreted as unsigned shorts.
Definition: BaseStructure.h:536
std::vector< float > & getFloatData()
Gets the raw data as a float vector if the content type as indicated by the header is appropriate...
Definition: BaseStructure.cpp:1889
void updateUIntData()
If data in this structure was changed by modifying the vector returned from getUIntData(), then this method needs to be called in order to make this object internally consistent.
Definition: BaseStructure.cpp:2953
std::vector< std::shared_ptr< BaseStructure > > getPath()
Returns the path from the root, to get to this node.
Definition: BaseStructure.cpp:822
void visitAllStructures(std::shared_ptr< IEvioListener > listener)
Visit all the structures in this structure (including the structure itself – which is considered its ...
Definition: BaseStructure.cpp:1392
void setByteOrder(ByteOrder const &order)
Set the byte order of this data.
Definition: BaseStructure.cpp:1518
std::vector< uint64_t > & getULongData()
Gets the raw data as an uint64_t vector if the content type as indicated by the header is appropriate...
Definition: BaseStructure.cpp:1859
void updateCompositeData()
If data in this structure was changed by modifying the vector returned from getCompositeData(), then this method needs to be called in order to make this object internally consistent.
Definition: BaseStructure.cpp:3333
void updateUShortData()
If data in this structure was changed by modifying the vector returned from getUShortData(), then this method needs to be called in order to make this object internally consistent.
Definition: BaseStructure.cpp:3042
bool getAllowsChildren() const
Returns true if this node is allowed to have children.
Definition: BaseStructure.cpp:562
std::vector< std::shared_ptr< BaseStructure > > getPathToRoot(const std::shared_ptr< BaseStructure > &aNode, int depth) const
Builds the parents of node up to and including the root node, where the original node is the last ele...
Definition: BaseStructure.cpp:839
size_t getSiblingCount() const
Returns the number of siblings of this node.
Definition: BaseStructure.cpp:1145
bool operator!=(const nodeIterator &other) const
Definition: BaseStructure.h:91
iterator end()
Get the end depth-first iterator.
Definition: BaseStructure.h:391
std::shared_ptr< BaseStructure > getLastChild() const
Returns this node&#39;s last child.
Definition: BaseStructure.cpp:1023
bool isNodeSibling(const std::shared_ptr< BaseStructure > anotherNode) const
Returns true if anotherNode is a sibling of (has the same parent as) this node.
Definition: BaseStructure.cpp:1115
std::shared_ptr< BaseStructure > value_type
Definition: BaseStructure.h:366
This class is used for creating and manipulating events.
Definition: EventBuilder.h:43
bool isNodeDescendant(std::shared_ptr< BaseStructure > anotherNode)
Returns true if anotherNode is a descendant of this node – if it is this node, one of this node&#39;s chi...
Definition: BaseStructure.cpp:676
std::shared_ptr< BaseStructureHeader > getHeader() const
Return the header for this structure.
Definition: BaseStructure.cpp:1602
size_t numberDataItems
The number of stored data items like number of banks, ints, floats, etc.
Definition: BaseStructure.h:598
void updateShortData()
If data in this structure was changed by modifying the vector returned from getShortData(), then this method needs to be called in order to make this object internally consistent.
Definition: BaseStructure.cpp:2989
std::shared_ptr< BaseStructure > getNextLeaf()
Returns the leaf after this node or null if this node is the last leaf in the tree.
Definition: BaseStructure.cpp:1298
std::shared_ptr< BaseStructure > parent
This node&#39;s parent, or null if this node has no parent.
Definition: BaseStructure.h:407
ByteOrder getByteOrder()
What is the byte order of this data?
Definition: BaseStructure.cpp:1510
static const StructureType STRUCT_UNKNOWN32
Unknown data type.
Definition: StructureType.h:38
void updateFloatData()
If data in this structure was changed by modifying the vector returned from getFloatData(), then this method needs to be called in order to make this object internally consistent.
Definition: BaseStructure.cpp:3238
static uint32_t stringsToRawSize(std::vector< std::string > const &strings)
This method returns the number of bytes in a raw evio format of the given string vector, not including header.
Definition: BaseStructure.cpp:2061
std::vector< std::shared_ptr< CompositeData > > & getCompositeData()
Gets the composite data as an vector of CompositeData objects, if the content type as indicated by th...
Definition: BaseStructure.cpp:1950
bool isNodeAncestor(const std::shared_ptr< BaseStructure > anotherNode) const
Returns true if anotherNode is an ancestor of this node – if it is this node, this node&#39;s parent...
Definition: BaseStructure.cpp:646
size_t getChildCount() const
Returns the number of children of this node.
Definition: BaseStructure.cpp:475
std::shared_ptr< BaseStructure > getChildBefore(const std::shared_ptr< BaseStructure > aChild)
Returns the child in this node&#39;s child vector that immediately precedes aChild, which must be a child...
Definition: BaseStructure.cpp:1080
std::shared_ptr< BaseStructure > reference
Definition: BaseStructure.h:367
std::vector< int16_t > shortData
Used if raw data should be interpreted as shorts.
Definition: BaseStructure.h:533
static uint32_t stringToRawSize(const std::string &str)
This method returns the number of bytes in a raw evio format of the given string vector, not including header.
Definition: BaseStructure.cpp:2091
virtual std::string toString() const
Obtain a string representation of the structure.
Definition: BaseStructure.cpp:1532
std::vector< uint8_t > & getRawBytes()
Get the raw data of the structure.
Definition: BaseStructure.cpp:1675
bool lengthsUpToDate
Keep track of whether header length data is up-to-date or not.
Definition: BaseStructure.h:604
R currentNode
Definition: BaseStructure.h:65
bool isLeaf() const
Returns true if this node has no children.
Definition: BaseStructure.cpp:1234
std::input_iterator_tag iterator_category
Definition: BaseStructure.h:364
breadth_iterator bend()
Get the end breadth-first iterator.
Definition: BaseStructure.h:402
std::shared_ptr< BaseStructure > getNextNode()
Returns the node that follows this node in a preorder traversal of this node&#39;s tree (return left node...
Definition: BaseStructure.cpp:903
std::vector< uint8_t > rawBytes
The raw data of the structure.
Definition: BaseStructure.h:530
uint32_t dataLength()
Compute the dataLength in 32-bit words.
Definition: BaseStructure.cpp:2559
std::shared_ptr< BaseStructureHeader > header
Holds the header of the bank as a shared pointer.
Definition: BaseStructure.h:527
void updateDoubleData()
If data in this structure was changed by modifying the vector returned from getDoubleData(), then this method needs to be called in order to make this object internally consistent.
Definition: BaseStructure.cpp:3275
This class contains methods to transform structures from one type to another, for example...
Definition: StructureTransformer.h:38
nodeBreadthIterator(R &node, bool isEnd)
Definition: BaseStructure.h:213
nodeBreadthIterator operator++()
Definition: BaseStructure.h:288
void setRawBytes(uint8_t *bytes, uint32_t len)
Set the data for the structure.
Definition: BaseStructure.cpp:1683
std::vector< int16_t > & getShortData()
Gets the raw data as an int16_t vector if the content type as indicated by the header is appropriate...
Definition: BaseStructure.cpp:1704
std::shared_ptr< BaseStructure > getLastLeaf()
Finds and returns the last leaf that is a descendant of this node – either this node or its last chil...
Definition: BaseStructure.cpp:1268
bool isRoot() const
Returns true if this node is the root of the tree.
Definition: BaseStructure.cpp:890
bool isNodeChild(const std::shared_ptr< BaseStructure > aNode) const
Returns true if aNode is a child of this node.
Definition: BaseStructure.cpp:980
iterator begin()
Get the beginning depth-first iterator.
Definition: BaseStructure.h:386
std::shared_ptr< const BaseStructure > getThisConst() const
Definition: BaseStructure.h:418
ByteOrder byteOrder
Endianness of the raw data if appropriate.
Definition: BaseStructure.h:601
size_t write(ByteBuffer &dest)
Write myself out into a byte buffer with fastest algorithm I could find.
Definition: BaseStructure.cpp:2887
std::vector< int64_t > & getLongData()
Gets the raw data as an int64_t vector if the content type as indicated by the header is appropriate...
Definition: BaseStructure.cpp:1829
nodeIterator(R &node, bool isEnd)
Definition: BaseStructure.h:73
std::shared_ptr< BaseStructure > getFirstLeaf()
Finds and returns the first leaf that is a descendant of this node – either this node or its first ch...
Definition: BaseStructure.cpp:1247
std::vector< std::shared_ptr< BaseStructure > >::iterator childrenBegin()
Creates and returns a forward-order begin iterator of this node&#39;s children.
Definition: BaseStructure.cpp:524
std::vector< std::shared_ptr< BaseStructure > > getChildren() const
Get the children of this structure.
Definition: BaseStructure.cpp:455
uint32_t getLevel() const
Returns the number of levels above this node – the distance from the root to this node...
Definition: BaseStructure.cpp:801
const nodeIterator & operator++()
Definition: BaseStructure.h:146
std::shared_ptr< BaseStructure > getPreviousLeaf()
Returns the leaf before this node or null if this node is the first leaf in the tree.
Definition: BaseStructure.cpp:1333
Definition: BaseStructure.h:189
Creates an object that controls the parsing of events.
Definition: EventParser.h:55
std::ptrdiff_t difference_type
Definition: BaseStructure.h:363
std::stack< std::pair< KidIter, KidIter > > stack
Definition: BaseStructure.h:62
std::vector< std::string > & getStringData()
Gets the raw data (ascii) as an vector of string objects, if the contents type as indicated by the he...
Definition: BaseStructure.cpp:2035
uint32_t getNumberDataItems()
Get the number of stored data items like number of banks, ints, floats, etc.
Definition: BaseStructure.cpp:1614
std::vector< uint16_t > & getUShortData()
Gets the raw data as an uint16_t vector if the content type as indicated by the header is appropriate...
Definition: BaseStructure.cpp:1739
void stringsToRawBytes()
This method transforms the internal vector of strings into internal rawBytes vector of evio format da...
Definition: BaseStructure.cpp:2167
bool getLengthsUpToDate() const
Get whether the lengths of all header fields for this structure and all it descendants are up to date...
Definition: BaseStructure.cpp:2615
uint32_t setAllHeaderLengths()
Compute and set length of all header fields for this structure and all its descendants.
Definition: BaseStructure.cpp:2644
bool operator!=(const nodeBreadthIterator &other) const
Definition: BaseStructure.h:230
size_t size_type
Definition: BaseStructure.h:362
nodeIterator< std::shared_ptr< BaseStructure > > iterator
Definition: BaseStructure.h:370
std::vector< uint32_t > & getUIntData()
Gets the raw data as an uint32_t vector if the content type as indicated by the header is appropriate...
Definition: BaseStructure.cpp:1799
std::shared_ptr< BaseStructure > getParent() const
Returns this node&#39;s parent or null if this node has no parent.
Definition: BaseStructure.cpp:448
std::vector< uint64_t > ulongData
Used if raw data should be interpreted as unsigned longs.
Definition: BaseStructure.h:548
bool isNodeRelated(std::shared_ptr< BaseStructure > aNode)
Returns true if and only if aNode is in the same tree as this node.
Definition: BaseStructure.cpp:764
ssize_t getIndex(const std::shared_ptr< BaseStructure > aChild)
Returns the index of the specified child in this node&#39;s child vector.
Definition: BaseStructure.cpp:491
bool operator==(const nodeIterator &other) const
Definition: BaseStructure.h:83
bool needSwap() const
Is a byte swap required (i.e.
Definition: BaseStructure.cpp:1525
const nodeIterator operator++(int)
Definition: BaseStructure.h:102
Numerical values associated with evio structure types.
Definition: StructureType.h:34
void add(std::shared_ptr< BaseStructure > newChild)
Removes newChild from its parent and makes it a child of this node by adding it to the end of this no...
Definition: BaseStructure.cpp:620
std::shared_ptr< BaseStructure > getChildAfter(const std::shared_ptr< BaseStructure > aChild)
Returns the child in this node&#39;s child vector that immediately follows aChild, which must be a child ...
Definition: BaseStructure.cpp:1047
std::shared_ptr< BaseStructure > getPreviousSibling()
Returns the previous sibling of this node in the parent&#39;s children vector.
Definition: BaseStructure.cpp:1199
bool isContainer() const
Checks whether this structure is a container, i.e.
Definition: BaseStructure.cpp:2545
void updateStringData()
If data in this structure was changed by modifying the vector returned from getStringData(), then this method needs to be called in order to make this object internally consistent.
Definition: BaseStructure.cpp:3312
BaseStructure()
Constructor.
Definition: BaseStructure.cpp:28
breadth_iterator bbegin()
Get the beginning breadth-first iterator.
Definition: BaseStructure.h:397
bool operator==(const nodeBreadthIterator &other) const
Definition: BaseStructure.h:223
std::shared_ptr< BaseStructure > pointer
Definition: BaseStructure.h:368
std::shared_ptr< BaseStructure > getSharedAncestor(std::shared_ptr< BaseStructure > aNode)
Returns the nearest common ancestor to this node and aNode.
Definition: BaseStructure.cpp:698
std::vector< int32_t > intData
Used if raw data should be interpreted as ints.
Definition: BaseStructure.h:539
int stringEnd
Keep track of end of the last string added to stringData (including null but not padding).
Definition: BaseStructure.h:581
bool badStringFormat
True if char data has non-ascii or non-printable characters, or has too little data to be in proper f...
Definition: BaseStructure.h:587
nodeBreadthIterator operator++(int)
Definition: BaseStructure.h:242
std::vector< double > & getDoubleData()
Gets the raw data as a double vector if the content type as indicated by the header is appropriate...
Definition: BaseStructure.cpp:1919
void removeAllChildren()
Removes all of this node&#39;s children, setting their parents to null.
Definition: BaseStructure.cpp:603
void updateIntData()
If data in this structure was changed by modifying the vector returned from getIntData(), then this method needs to be called in order to make this object internally consistent.
Definition: BaseStructure.cpp:2912
bool isEndIter()
Definition: BaseStructure.h:99
std::vector< int32_t > & getIntData()
Gets the raw data as an int32_t vector if the content type as indicated by the header is appropriate...
Definition: BaseStructure.cpp:1769
void updateUCharData()
If data in this structure was changed by modifying the vector returned from getUCharData(), then this method needs to be called in order to make this object internally consistent.
Definition: BaseStructure.cpp:3202
void insert(const std::shared_ptr< BaseStructure > newChild, size_t childIndex)
Removes newChild from its present parent (if it has a parent), sets the child&#39;s parent to this node...
Definition: BaseStructure.cpp:388
void updateCharData()
If data in this structure was changed by modifying the vector returned from getCharData(), then this method needs to be called in order to make this object internally consistent.
Definition: BaseStructure.cpp:3165
std::vector< signed char > charData
Used if raw data should be interpreted as signed chars.
Definition: BaseStructure.h:567
static const ByteOrder ENDIAN_LOCAL
Local host&#39;s byte order.
Definition: ByteOrder.h:61
std::vector< std::shared_ptr< CompositeData > > compositeData
Used if raw data should be interpreted as composite type.
Definition: BaseStructure.h:557
This is a class of interest to the user.
Definition: EvioReaderV4.h:58
This is a class of interest to the user.
Definition: EvioReader.h:52
std::vector< unsigned char > & getUCharData()
Gets the raw data as an unsigned char vector, if the contents type as indicated by the header is appr...
Definition: BaseStructure.cpp:1995