evio  6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EventParser.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_EVENTPARSER_H
12 #define EVIO_6_0_EVENTPARSER_H
13 
14 
15 #include <cstring>
16 #include <memory>
17 #include <vector>
18 #include <cstring>
19 #include <iostream>
20 #include <mutex>
21 
22 
23 #include "ByteOrder.h"
24 #include "BaseStructure.h"
25 #include "BankHeader.h"
26 #include "SegmentHeader.h"
27 #include "TagSegmentHeader.h"
28 #include "IEvioFilter.h"
29 #include "IEvioListener.h"
30 
31 #include "EvioEvent.h"
32 #include "EvioSegment.h"
33 #include "EvioTagSegment.h"
34 
35 
36 namespace evio {
37 
38 
55  class EventParser {
56 
57  private:
58 
59  std::vector<std::shared_ptr<IEvioListener>> evioListenerList;
60  std::shared_ptr<IEvioFilter> evioFilter;
61 
62  void parseStructure(std::shared_ptr<EvioEvent> evioEvent, std::shared_ptr<BaseStructure> structure);
63 
64  protected:
65 
66  bool notificationActive = true;
68  std::recursive_mutex mtx;
69 
70  public:
71 
72  static void eventParse(std::shared_ptr<EvioEvent> & evioEvent);
73 
74  void parseEvent(std::shared_ptr<EvioEvent> & evioEvent);
75  void parseEvent(std::shared_ptr<EvioEvent> & evioEvent, bool synced);
76 
77  private:
78 
79  static void parseStruct(std::shared_ptr<BaseStructure> structure);
80 
81 // Moved to EventHeaderParser to avoid circular references to BaseStructure:
82 // static std::shared_ptr<BankHeader> createBankHeader(uint8_t * bytes, ByteOrder const & byteOrder);
83 // static std::shared_ptr<SegmentHeader> createSegmentHeader(uint8_t * bytes, ByteOrder const & byteOrder);
84 // static std::shared_ptr<TagSegmentHeader> createTagSegmentHeader(uint8_t * bytes, ByteOrder const & byteOrder);
85 
86  protected:
87 
88  void notifyEvioListeners(std::shared_ptr<EvioEvent> & event,
89  std::shared_ptr<BaseStructure> & structure);
90  void notifyStart(std::shared_ptr<EvioEvent> & event);
91  void notifyStop(std::shared_ptr<EvioEvent> & event);
92 
93  public:
94 
95  void removeEvioListener(std::shared_ptr<IEvioListener> listener);
96  void addEvioListener(std::shared_ptr<IEvioListener> listener);
97 
98  bool isNotificationActive() const;
100  void setEvioFilter(std::shared_ptr<IEvioFilter> evioFilter);
101 
102  public:
103 
104  // Scanning structures that have already been parsed
105 
106  static void vistAllStructures(std::shared_ptr<BaseStructure> const & structure,
107  std::shared_ptr<IEvioListener> const & listener);
108  static void vistAllStructures(std::shared_ptr<BaseStructure> const & structure,
109  std::shared_ptr<IEvioListener> const & listener,
110  std::shared_ptr<IEvioFilter> const & filter);
111  static void getMatchingStructures(std::shared_ptr<BaseStructure> const & structure,
112  std::shared_ptr<IEvioFilter> const & filter,
113  std::vector<std::shared_ptr<BaseStructure>> & structs);
114  private:
115 
116  static void visitAllDescendants(std::shared_ptr<BaseStructure> const & topLevelStruct,
117  std::shared_ptr<BaseStructure> const & structure,
118  std::shared_ptr<IEvioListener> const & listener,
119  std::shared_ptr<IEvioFilter> const & filter);
120 
121 
122  };
123 
124 
125 }
126 
127 #endif //EVIO_6_0_EVENTPARSER_H
static void getMatchingStructures(std::shared_ptr< BaseStructure > const &structure, std::shared_ptr< IEvioFilter > const &filter, std::vector< std::shared_ptr< BaseStructure >> &structs)
Visit all the descendant structures, and collect those that pass a filter.
Definition: EventParser.cpp:531
void notifyStop(std::shared_ptr< EvioEvent > &event)
Notify listeners we are done to parsing a new event.
Definition: EventParser.cpp:367
static void vistAllStructures(std::shared_ptr< BaseStructure > const &structure, std::shared_ptr< IEvioListener > const &listener)
Visit all the structures in the given structure (including the structure itself – which is considered...
Definition: EventParser.cpp:464
void notifyEvioListeners(std::shared_ptr< EvioEvent > &event, std::shared_ptr< BaseStructure > &structure)
This is when a structure is encountered while parsing an event.
Definition: EventParser.cpp:315
void setEvioFilter(std::shared_ptr< IEvioFilter > evioFilter)
Set the global filter used for filtering structures.
Definition: EventParser.cpp:445
bool isNotificationActive() const
Get the flag determining whether notification of listeners is active.
Definition: EventParser.cpp:425
void addEvioListener(std::shared_ptr< IEvioListener > listener)
Add an Evio listener.
Definition: EventParser.cpp:410
void setNotificationActive(bool notificationActive)
Set the flag determining whether notification of listeners is active.
Definition: EventParser.cpp:435
std::recursive_mutex mtx
Mutex for thread safety.
Definition: EventParser.h:68
Creates an object that controls the parsing of events.
Definition: EventParser.h:55
void parseEvent(std::shared_ptr< EvioEvent > &evioEvent)
This is the workhorse method for parsing the event.
Definition: EventParser.cpp:134
void notifyStart(std::shared_ptr< EvioEvent > &event)
Notify listeners we are starting to parse a new event.
Definition: EventParser.cpp:345
void removeEvioListener(std::shared_ptr< IEvioListener > listener)
Remove an Evio listener.
Definition: EventParser.cpp:389
static void eventParse(std::shared_ptr< EvioEvent > &evioEvent)
Method for parsing the event which will drill down and uncover all structures.
Definition: EventParser.cpp:21
bool notificationActive
Definition: EventParser.h:66