evio  6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EvioEvent.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_EVIOEVENT_H
12 #define EVIO_6_0_EVIOEVENT_H
13 
14 #include <cstring>
15 #include <sstream>
16 #include <memory>
17 
18 #include "ByteBuffer.h"
19 #include "DataType.h"
20 #include "BaseStructure.h"
21 #include "BaseStructureHeader.h"
22 #include "EvioBank.h"
23 #include "BankHeader.h"
24 #include "StructureType.h"
25 
26 
27 namespace evio {
28 
39  class EvioEvent : public EvioBank {
40 
41  private:
42 
44  EvioEvent() : EvioBank() {}
45 
50  explicit EvioEvent(std::shared_ptr<BankHeader> const & head) : EvioBank(head) {}
51 
52  public:
53 
59  static std::shared_ptr<EvioEvent> getInstance() {
60  std::shared_ptr<EvioEvent> pNode(new EvioEvent());
61  return pNode;
62  }
63 
69  static std::shared_ptr<EvioEvent> getInstance(std::shared_ptr<BankHeader> const & head) {
70  std::shared_ptr<EvioEvent> pNode(new EvioEvent(head));
71  return pNode;
72  }
73 
81  static std::shared_ptr<EvioEvent> getInstance(uint16_t tag, DataType const & typ, uint8_t num) {
82  std::shared_ptr<BankHeader> head(new BankHeader(tag, typ, num));
83  std::shared_ptr<EvioEvent> pNode(new EvioEvent(head));
84  return pNode;
85  }
86 
87  private:
88 
93  size_t eventNumber = 0;
94 
96  std::string dictionaryXML{""};
97 
98  protected:
99 
101  bool parsed = false;
102 
103  public:
104 
109  void setParsed(bool p) {parsed = p;}
110 
115  bool isParsed() const {return parsed;}
116 
122  bool hasDictionaryXML() const {return !dictionaryXML.empty();}
123 
128  std::string getDictionaryXML() const {return dictionaryXML;}
129 
134  void setDictionaryXML(std::string &xml) {dictionaryXML = xml;}
135 
140  std::string toString() const override {
141 
142  std::stringstream ss;
143 
144  // show 0x for hex
145  ss << std::showbase;
146 
148  DataType dtype = header->getDataType();
149 
150  std::string sb;
151  sb.reserve(100);
152 
153  ss << "<Event> has " << dtype.toString() << "s: tag=" << header->getTag();
154  ss << std::hex << "(" << header->getTag() << ")" << std::dec;
155 
156  if (stype == StructureType::STRUCT_BANK) {
157  ss << " num=" << (int)(header->getNumber()) << std::hex << "(" << (int)(header->getNumber()) << ")" << std::dec;
158  }
159 
160  if (rawBytes.empty()) {
161  ss << " dataLen=" << ((header->getLength() - (header->getHeaderLength() - 1))/4);
162  }
163  else {
164  ss << " dataLen=" << (rawBytes.size()/4);
165  }
166 
167  if (header->getPadding() != 0) {
168  ss << " pad=" << (int)(header->getPadding());
169  }
170 
171  int numChildren = children.size();
172 
173  if (numChildren > 0) {
174  ss << " children=" << numChildren;
175  }
176 
177  return ss.str();
178  }
179 
186  size_t getEventNumber() const {return eventNumber;}
187 
194  void setEventNumber(size_t evNum) {eventNumber = evNum;}
195 
196  };
197 }
198 
199 #endif //EVIO_6_0_EVIOEVENT_H
std::vector< std::shared_ptr< BaseStructure > > children
Array of children, may be null if this node has no children.
Definition: BaseStructure.h:410
EvioBank()
Constructor.
Definition: EvioBank.h:42
static const StructureType STRUCT_BANK
Bank.
Definition: StructureType.h:41
size_t getEventNumber() const
This returns a number [1..] indicating which event this was in the event file from which it was read...
Definition: EvioEvent.h:186
std::string toString() const
Return a string which is usually the same as the name of the enumerated value, except in the cases of...
Definition: DataType.h:193
StructureType getStructureType() const override
This implements the virtual method from BaseStructure.
Definition: EvioBank.h:92
static std::shared_ptr< EvioEvent > getInstance(uint16_t tag, DataType const &typ, uint8_t num)
Method to return a shared pointer to a constructed object of this class.
Definition: EvioEvent.h:81
bool isParsed() const
Has this object been parsed or not.
Definition: EvioEvent.h:115
This the header for an evio bank structure (EvioBank).
Definition: BankHeader.h:35
std::string toString() const override
Obtain a string representation of the structure.
Definition: EvioEvent.h:140
void setParsed(bool p)
Method to set if this event has been parsed or not.
Definition: EvioEvent.h:109
bool parsed
Has this been parsed yet or not?
Definition: EvioEvent.h:101
std::vector< uint8_t > rawBytes
The raw data of the structure.
Definition: BaseStructure.h:530
This holds a CODA Bank structure.
Definition: EvioBank.h:36
void setEventNumber(size_t evNum)
This sets a number [1..] indicating which event this was in the event file from which it was read...
Definition: EvioEvent.h:194
std::shared_ptr< BaseStructureHeader > header
Holds the header of the bank as a shared pointer.
Definition: BaseStructure.h:527
static std::shared_ptr< EvioEvent > getInstance(std::shared_ptr< BankHeader > const &head)
Method to return a shared pointer to a constructed object of this class.
Definition: EvioEvent.h:69
static std::shared_ptr< EvioEvent > getInstance()
Method to return a shared pointer to a constructed object of this class.
Definition: EvioEvent.h:59
Numerical values associated with evio data types.
Definition: DataType.h:32
An event is really just the outer, primary bank.
Definition: EvioEvent.h:39
bool hasDictionaryXML() const
Is there an XML dictionary associated with this event?
Definition: EvioEvent.h:122
Numerical values associated with evio structure types.
Definition: StructureType.h:34
std::string getDictionaryXML() const
Get the XML dictionary associated with this event if there is one.
Definition: EvioEvent.h:128
void setDictionaryXML(std::string &xml)
Set the XML dictionary associated with this event.
Definition: EvioEvent.h:134