stream  0.10.0
stream analysis framework
base/SubEvent.h
1 #ifndef BASE_SUBEVENT_H
2 #define BASE_SUBEVENT_H
3 
4 #include <algorithm>
5 #include <vector>
6 
7 namespace base {
8 
9 
14  class SubEvent {
15  public:
17  SubEvent() {}
18 
20  virtual ~SubEvent() {}
21 
23  virtual void Clear() {}
24 
26  virtual void Sort() {}
27 
29  virtual unsigned Multiplicity() const { return 0; }
30 
31  };
32 
35  template<class MsgClass>
36  class MessageExt {
37  protected:
38  MsgClass fMessage;
39 
40  double fGlobalTime;
41 
42  public:
43 
46  fMessage(),
47  fGlobalTime(0.)
48  {
49  }
50 
52  MessageExt(const MsgClass& _msg, double globaltm) :
53  fMessage(_msg),
54  fGlobalTime(globaltm)
55  {
56  }
57 
59  MessageExt(const MessageExt& src) :
60  fMessage(src.fMessage),
62  {
63  }
64 
67  {
68  fMessage = src.fMessage;
70  return *this;
71  }
72 
75 
77  bool operator<(const MessageExt &rhs) const
78  { return (fGlobalTime < rhs.fGlobalTime); }
79 
81  const MsgClass& msg() const { return fMessage; }
82 
84  double GetGlobalTime() const { return fGlobalTime; }
85  };
86 
87 
90  template<class MsgClass>
91  class SubEventEx : public base::SubEvent {
92  protected:
93  std::vector<MsgClass> fExtMessages;
94 
95  public:
96 
98  SubEventEx(unsigned capacity = 0) : base::SubEvent(), fExtMessages() { fExtMessages.reserve(capacity); }
99 
102 
104  void AddMsg(const MsgClass &_msg) { fExtMessages.emplace_back(_msg); }
105 
107  unsigned Size() const { return fExtMessages.size(); }
108 
110  unsigned Capacity() const { return fExtMessages.capacity(); }
111 
113  void SetCapacity(unsigned sz) { fExtMessages.reserve(sz); }
114 
116  MsgClass &msg(unsigned indx) { return fExtMessages[indx]; }
117 
119  std::vector<MsgClass>* vect_ptr() { return &fExtMessages; }
120 
122  virtual unsigned Multiplicity() const { return Size(); }
123 
125  virtual void Clear() { fExtMessages.clear(); }
126 
128  virtual void Sort()
129  {
130  std::sort(fExtMessages.begin(), fExtMessages.end());
131  }
132 
133  };
134 
135 }
136 
137 #endif
Extended message - any message plus global time stamp.
Definition: base/SubEvent.h:36
MessageExt & operator=(const MessageExt &src)
assign operator
Definition: base/SubEvent.h:66
const MsgClass & msg() const
message
Definition: base/SubEvent.h:81
MessageExt()
default constructor
Definition: base/SubEvent.h:45
double fGlobalTime
full time stamp without correction
Definition: base/SubEvent.h:40
MessageExt(const MsgClass &_msg, double globaltm)
constructor
Definition: base/SubEvent.h:52
MessageExt(const MessageExt &src)
copy constructor
Definition: base/SubEvent.h:59
double GetGlobalTime() const
global time stamp
Definition: base/SubEvent.h:84
~MessageExt()
destructor
Definition: base/SubEvent.h:74
bool operator<(const MessageExt &rhs) const
this is used for timesorting the messages in the filled vectors
Definition: base/SubEvent.h:77
MsgClass fMessage
original roc message
Definition: base/SubEvent.h:38
Subevent with vector of extended messages.
Definition: base/SubEvent.h:91
std::vector< MsgClass > * vect_ptr()
Returns pointer on vector with messages, used in the store.
Definition: base/SubEvent.h:119
virtual void Sort()
Do time sorting of messages.
Definition: base/SubEvent.h:128
unsigned Size() const
Returns number of messages.
Definition: base/SubEvent.h:107
~SubEventEx()
destructor
Definition: base/SubEvent.h:101
MsgClass & msg(unsigned indx)
Returns message with specified index.
Definition: base/SubEvent.h:116
virtual unsigned Multiplicity() const
Returns subevent multiplicity
Definition: base/SubEvent.h:122
void AddMsg(const MsgClass &_msg)
Add new message to sub-event.
Definition: base/SubEvent.h:104
std::vector< MsgClass > fExtMessages
vector of extended messages
Definition: base/SubEvent.h:93
SubEventEx(unsigned capacity=0)
constructor
Definition: base/SubEvent.h:98
virtual void Clear()
Clear subevent - remove all messages.
Definition: base/SubEvent.h:125
unsigned Capacity() const
Returns capacity of the message container.
Definition: base/SubEvent.h:110
void SetCapacity(unsigned sz)
Change capacity of the container.
Definition: base/SubEvent.h:113
SubEvent - base class for all event structures Need for: virtual destructor - to be able delete any i...
Definition: base/SubEvent.h:14
virtual unsigned Multiplicity() const
Method returns event multiplicity - that ever it means.
Definition: base/SubEvent.h:29
virtual ~SubEvent()
destructor
Definition: base/SubEvent.h:20
virtual void Clear()
clear sub event
Definition: base/SubEvent.h:23
SubEvent()
default constructor
Definition: base/SubEvent.h:17
virtual void Sort()
sort data in sub event
Definition: base/SubEvent.h:26