DABC (Data Acquisition Backbone Core)  2.9.9
Iterator.h
Go to the documentation of this file.
1 // $Id: Iterator.h 3862 2018-05-11 10:06:18Z linev $
2 
3 /************************************************************
4  * The Data Acquisition Backbone Core (DABC) *
5  ************************************************************
6  * Copyright (C) 2009 - *
7  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
8  * Planckstr. 1, 64291 Darmstadt, Germany *
9  * Contact: http://dabc.gsi.de *
10  ************************************************************
11  * This software can be used under the GPL license *
12  * agreements as stated in LICENSE.txt file *
13  * which is part of the distribution. *
14  ************************************************************/
15 
16 #ifndef MBS_Iterator
17 #define MBS_Iterator
18 
19 #ifndef MBS_MbsTypeDefs
20 #include "mbs/MbsTypeDefs.h"
21 #endif
22 
23 #ifndef DABC_Buffer
24 #include "dabc/Buffer.h"
25 #endif
26 
27 #ifndef DABC_Pointer
28 #include "dabc/Pointer.h"
29 #endif
30 
31 #ifndef DABC_eventsapi
32 #include "dabc/eventsapi.h"
33 #endif
34 
35 
36 namespace mbs {
37 
40  class ReadIterator {
41  protected:
46 
47  public:
48  ReadIterator();
49 
50  ReadIterator(const dabc::Buffer& buf);
51 
52  ReadIterator(const ReadIterator& src);
53 
54  ReadIterator& operator=(const ReadIterator& src);
55 
57 
60  bool Reset(const dabc::Buffer& buf);
61 
63  bool Reset() { Close(); return true; }
64 
65  void Close();
66 
67  bool IsData() const { return !fEvPtr.null(); }
68 
70  bool IsLastEvent() const;
71 
72  bool NextEvent();
73  bool NextSubEvent();
74 
75  EventHeader* evnt() const { return (EventHeader*) fEvPtr(); }
76  // return actual event size, will not exceed buffers limit
77  unsigned GetEventSize() const;
79 
82 
85 
86  SubeventHeader* subevnt() const { return (SubeventHeader*) fSubPtr(); }
87  void* rawdata() const { return fRawPtr(); }
88  unsigned rawdatasize() const { return fRawPtr.fullsize(); }
89 
90  static unsigned NumEvents(const dabc::Buffer& buf);
91  };
92 
93  // ___________________________________________________________________________
94 
97  class WriteIterator {
98  protected:
104 
105  public:
106  WriteIterator();
108  ~WriteIterator();
109 
110  bool Reset(dabc::Buffer& buf);
111 
112  bool IsBuffer() const { return !fBuffer.null(); }
113  bool IsEmpty() const { return fFullSize == 0; }
114 
116  bool IsAnyEvent() const { return fFullSize != 0; }
117 
119  bool IsAnyIncompleteData() const { return !fSubPtr.null(); }
120 
122  bool IsAnyData() const { return IsAnyEvent() || IsAnyIncompleteData(); }
123 
124  bool IsPlaceForEvent(uint32_t subeventsize, bool add_subev_header = false);
125  bool NewEvent(EventNumType event_number = 0, uint32_t subeventsize = 0);
127  bool IsEventStarted() const { return !fSubPtr.null(); }
128 
129  bool NewSubevent(uint32_t minrawsize = 0, uint8_t crate = 0, uint16_t procid = 0, uint8_t control = 0);
130  bool NewSubevent2(uint32_t fullid);
131 
132  bool IsPlaceForRawData(unsigned len) const;
133  bool AddRawData(const void* src, unsigned len);
134 
135  bool FinishSubEvent(uint32_t rawdatasz = 0);
136  bool AddSubevent(const dabc::Pointer& source);
137  bool AddSubevent(SubeventHeader* sub);
138 
139  bool FinishEvent();
140 
143  void DiscardEvent();
144 
149  bool CopyEventFrom(const dabc::Pointer& ptr, bool finish = true);
150 
152 
155 
156  EventHeader* evnt() const { return (EventHeader*) fEvPtr(); }
157  SubeventHeader* subevnt() const { return (SubeventHeader*) fSubPtr(); }
158  void* rawdata() const { return subevnt() ? subevnt()->RawData() : 0; }
159  uint32_t maxrawdatasize() const { return fSubPtr.null() ? 0 : fSubPtr.fullsize() - sizeof(SubeventHeader); }
160  };
161 
162  // ________________________________________________________________________________
163 
165  protected:
167 
168  public:
169  EventsIterator(const std::string &name) : dabc::EventsIterator(name), fIter() {}
170  virtual ~EventsIterator() {}
171 
172  virtual bool Assign(const dabc::Buffer& buf) { return fIter.Reset(buf); }
173  virtual void Close() { return fIter.Close(); }
174 
175  virtual bool NextEvent() { return fIter.NextEvent(); };
176  virtual void* Event() { return fIter.evnt(); }
178  };
179 
180 }
181 
182 #endif
Reference on memory from memory pool.
Definition: Buffer.h:135
Iterator over events in dabc::Buffer class.
Definition: eventsapi.h:44
Manipulator with dabc::Buffer class.
Definition: Pointer.h:34
bool null() const
Definition: Pointer.h:147
BufferSize_t fullsize() const
Definition: Pointer.h:149
bool null() const
Returns true if reference contains nullptr.
Definition: Reference.h:151
virtual void * Event()
Definition: Iterator.h:176
ReadIterator fIter
Definition: Iterator.h:166
virtual void Close()
Definition: Iterator.h:173
virtual bool NextEvent()
Definition: Iterator.h:175
virtual ~EventsIterator()
Definition: Iterator.h:170
virtual bool Assign(const dabc::Buffer &buf)
Definition: Iterator.h:172
EventsIterator(const std::string &name)
Definition: Iterator.h:169
virtual dabc::BufferSize_t EventSize()
Definition: Iterator.h:177
Read iterator for MBS events/subevents.
Definition: Iterator.h:40
unsigned GetEventSize() const
Definition: Iterator.cxx:122
bool IsData() const
Definition: Iterator.h:67
bool Reset()
Reset iterator - forget pointer on buffer.
Definition: Iterator.h:63
dabc::Pointer fEvPtr
Definition: Iterator.h:43
unsigned rawdatasize() const
Definition: Iterator.h:88
dabc::Pointer fRawPtr
Definition: Iterator.h:45
dabc::Pointer GetSubeventsPointer()
Returns pointer, which assign only on subevents.
Definition: Iterator.cxx:137
void * rawdata() const
Definition: Iterator.h:87
static unsigned NumEvents(const dabc::Buffer &buf)
Definition: Iterator.cxx:187
bool AssignEventPointer(dabc::Pointer &ptr)
Definition: Iterator.cxx:146
EventHeader * evnt() const
Definition: Iterator.h:75
SubeventHeader * subevnt() const
Definition: Iterator.h:86
ReadIterator & operator=(const ReadIterator &src)
Definition: Iterator.cxx:45
bool IsLastEvent() const
Returns true if it is last event in the buffer.
Definition: Iterator.cxx:80
dabc::Pointer GetEventPointer()
Returns pointer, which assign on complete event, including header.
Definition: Iterator.cxx:130
bool Reset(const dabc::Buffer &buf)
Initialize iterator on the beginning of the buffer, buffer instance should exists until end of iterat...
Definition: Iterator.cxx:55
dabc::Pointer fSubPtr
Definition: Iterator.h:44
Write iterator for MBS events/subevents.
Definition: Iterator.h:97
bool Reset(dabc::Buffer &buf)
Definition: Iterator.cxx:219
bool AddSubevent(const dabc::Pointer &source)
Definition: Iterator.cxx:409
bool FinishSubEvent(uint32_t rawdatasz=0)
Definition: Iterator.cxx:378
bool AddRawData(const void *src, unsigned len)
Definition: Iterator.cxx:371
dabc::Buffer CloseAndTransfer(dabc::Buffer &newbuf)
Method could be used to close current buffer and transfer all uncompleted parts to new buffer.
Definition: Iterator.cxx:256
SubeventHeader * subevnt() const
Definition: Iterator.h:157
bool IsAnyData() const
Return true if anything was written to the buffer.
Definition: Iterator.h:122
dabc::BufferSize_t fFullSize
size of accumulated events
Definition: Iterator.h:103
dabc::Pointer fSubData
pointer to place raw data of current subevent
Definition: Iterator.h:102
dabc::Pointer fSubPtr
place for subevents
Definition: Iterator.h:101
bool NewSubevent(uint32_t minrawsize=0, uint8_t crate=0, uint16_t procid=0, uint8_t control=0)
Definition: Iterator.cxx:329
bool IsAnyEvent() const
Return true if any complete event was written to the buffer.
Definition: Iterator.h:116
bool IsBuffer() const
Definition: Iterator.h:112
void DiscardEvent()
Ignore all data, which were add with last NewEvent call.
Definition: Iterator.cxx:449
bool IsPlaceForRawData(unsigned len) const
Definition: Iterator.cxx:365
void * rawdata() const
Definition: Iterator.h:158
bool NewSubevent2(uint32_t fullid)
Definition: Iterator.cxx:347
bool IsAnyIncompleteData() const
Return true if any incomplete data were provided to the iterator.
Definition: Iterator.h:119
uint32_t maxrawdatasize() const
Definition: Iterator.h:159
bool CopyEventFrom(const dabc::Pointer &ptr, bool finish=true)
Method to copy full event from the other place.
Definition: Iterator.cxx:456
dabc::Pointer fEvPtr
place for current event
Definition: Iterator.h:100
bool NewEvent(EventNumType event_number=0, uint32_t subeventsize=0)
Definition: Iterator.cxx:304
bool IsEmpty() const
Definition: Iterator.h:113
dabc::Buffer Close()
Definition: Iterator.cxx:237
bool IsEventStarted() const
Return true if new event was started and was not yet closed.
Definition: Iterator.h:127
dabc::Buffer fBuffer
here we keep buffer - mean onwership is delivered to iterator
Definition: Iterator.h:99
EventHeader * evnt() const
Definition: Iterator.h:156
bool IsPlaceForEvent(uint32_t subeventsize, bool add_subev_header=false)
Definition: Iterator.cxx:298
unsigned fullid
Definition: hldprint.cxx:995
Event manipulation API.
Definition: api.h:23
uint32_t BufferSize_t
Definition: Buffer.h:32
Support for MBS - standard GSI DAQ.
Definition: api.h:36
uint32_t EventNumType
Definition: MbsTypeDefs.h:94
MBS subevent
Definition: MbsTypeDefs.h:40
void * RawData() const
Definition: MbsTypeDefs.h:75