DABC (Data Acquisition Backbone Core)  2.9.9
Iterator.h
Go to the documentation of this file.
1 // $Id: Iterator.h 4569 2020-07-31 12:38:50Z 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 HADAQ_Iterator
17 #define HADAQ_Iterator
18 
19 #ifndef HADAQ_HadaqTypeDefs
20 #include "hadaq/HadaqTypeDefs.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 namespace hadaq {
36 
39  class ReadIterator {
40  protected:
45  unsigned fBufType;
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 NextHadTu();
71 
73  bool NextEvent();
74 
76  bool NextSubeventsBlock();
77 
79  bool NextSubEvent();
80 
81  hadaq::RawEvent* evnt() const { return (hadaq::RawEvent*) fEvPtr(); }
82  unsigned evntsize() const { return evnt() ? evnt()->GetPaddedSize() : 0; }
83 
85  unsigned remained_size() const { return fEvPtr.fullsize(); }
86 
87  hadaq::HadTu* hadtu() const { return (hadaq::HadTu*) fEvPtr(); }
88 
91  void* rawdata() const { return fRawPtr(); }
92  uint32_t rawdatasize() const { return fRawPtr.fullsize(); }
93 
95  unsigned rawdata_maxsize() const;
96 
97  static unsigned NumEvents(const dabc::Buffer& buf);
98  };
99 
100  // _____________________________________________________________________
101 
105  public:
106  WriteIterator();
107  WriteIterator(const dabc::Buffer& buf);
108  ~WriteIterator();
109 
110  bool Reset(const dabc::Buffer& buf);
111 
112  bool IsBuffer() const { return !fBuffer.null(); }
113  bool IsEmpty() const { return fFullSize == 0; }
114  bool IsPlaceForEvent(uint32_t subeventsize);
115  bool NewEvent(uint32_t evtSeqNr = 0, uint32_t runNr = 0, uint32_t minsubeventsize = 0);
116  bool NewSubevent(uint32_t minrawsize = 0, uint32_t trigger = 0);
117  bool FinishSubEvent(uint32_t rawdatasz);
118 
119  bool AddSubevent(const dabc::Pointer &source);
120  bool AddSubevent(const void *ptr, unsigned len);
122  {
123  return AddSubevent(sub, sub->GetPaddedSize());
124  }
126  {
128  }
129  bool FinishEvent();
130 
132 
133  hadaq::RawEvent* evnt() const { return (hadaq::RawEvent*) fEvPtr(); }
135  void* rawdata() const { return subevnt() ? subevnt()->RawData() : 0; }
136  uint32_t maxrawdatasize() const { return fSubPtr.null() ? 0 : fSubPtr.fullsize() - sizeof(hadaq::RawSubevent); }
137 
138  protected:
139  dabc::Buffer fBuffer; // here we keep buffer - mean ownership is delivered to iterator
143  };
144 
145  // _______________________________________________________________________________________________
146 
148  protected:
150 
151  public:
152  EventsIterator(const std::string &name) : dabc::EventsIterator(name), fIter() {}
153  virtual ~EventsIterator() {}
154 
155  virtual bool Assign(const dabc::Buffer& buf) { return fIter.Reset(buf); }
156  virtual void Close() { return fIter.Close(); }
157 
158  virtual bool NextEvent() { return fIter.NextEvent(); };
159  virtual void* Event() { return fIter.evnt(); }
160  virtual dabc::BufferSize_t EventSize() { return fIter.evntsize(); }
161  };
162 
163  // _______________________________________________________________________________________________
164 
166  protected:
168 
169  public:
170  EventsProducer(const std::string &name) : dabc::EventsProducer(name), fIter() {}
171  virtual ~EventsProducer() {}
172 
173  virtual bool Assign(const dabc::Buffer& buf) { return fIter.Reset(buf); }
174  virtual void Close() { fIter.Close(); }
175 
176  virtual bool GenerateEvent(uint64_t evid, uint64_t subid, uint64_t raw_size)
177  {
178  if (!fIter.IsPlaceForEvent(raw_size)) return false;
179  if (!fIter.NewEvent(evid)) return false;
180  if (!fIter.NewSubevent(raw_size)) return false;
181 
182  if (!fIter.FinishSubEvent(raw_size)) return false;
183  fIter.FinishEvent();
184  return true;
185  }
186  };
187 
188 
189 }
190 
191 #endif
Reference on memory from memory pool.
Definition: Buffer.h:135
Iterator over events in dabc::Buffer class.
Definition: eventsapi.h:44
Producer of the events.
Definition: eventsapi.h:73
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 Close()
Definition: Iterator.h:156
ReadIterator fIter
Definition: Iterator.h:149
virtual ~EventsIterator()
Definition: Iterator.h:153
EventsIterator(const std::string &name)
Definition: Iterator.h:152
virtual bool NextEvent()
Definition: Iterator.h:158
virtual dabc::BufferSize_t EventSize()
Definition: Iterator.h:160
virtual bool Assign(const dabc::Buffer &buf)
Definition: Iterator.h:155
virtual void * Event()
Definition: Iterator.h:159
virtual void Close()
Definition: Iterator.h:174
virtual bool GenerateEvent(uint64_t evid, uint64_t subid, uint64_t raw_size)
Definition: Iterator.h:176
WriteIterator fIter
Definition: Iterator.h:167
virtual bool Assign(const dabc::Buffer &buf)
Definition: Iterator.h:173
EventsProducer(const std::string &name)
Definition: Iterator.h:170
virtual ~EventsProducer()
Definition: Iterator.h:171
Read iterator for HADAQ events/subevents.
Definition: Iterator.h:39
bool IsData() const
Definition: Iterator.h:67
static unsigned NumEvents(const dabc::Buffer &buf)
Definition: Iterator.cxx:259
bool Reset()
Reset iterator - forget pointer on buffer.
Definition: Iterator.h:63
uint32_t rawdatasize() const
Definition: Iterator.h:92
bool NextEvent()
Used for ready HLD events.
Definition: Iterator.cxx:127
hadaq::RawSubevent * subevnt() const
Definition: Iterator.h:90
unsigned rawdata_maxsize() const
Try to define maximal length for the raw data.
Definition: Iterator.cxx:252
unsigned remained_size() const
Returns size used by current event plus rest.
Definition: Iterator.h:85
bool AssignEventPointer(dabc::Pointer &ptr)
Definition: Iterator.cxx:188
unsigned evntsize() const
Definition: Iterator.h:82
hadaq::HadTu * hadtu() const
Definition: Iterator.h:87
bool NextSubEvent()
Used for sub-events iteration inside current block.
Definition: Iterator.cxx:199
hadaq::RawEvent * evnt() const
Definition: Iterator.h:81
bool NextHadTu()
Used for raw data from TRBs.
Definition: Iterator.cxx:88
void * rawdata() const
Definition: Iterator.h:91
bool NextSubeventsBlock()
Depending from buffer type calls NextHadTu() or NextEvent()
Definition: Iterator.cxx:166
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:59
unsigned fBufType
Definition: Iterator.h:45
dabc::Pointer fEvPtr
Definition: Iterator.h:42
dabc::Pointer fRawPtr
Definition: Iterator.h:44
dabc::Pointer fSubPtr
Definition: Iterator.h:43
ReadIterator & operator=(const ReadIterator &src)
Definition: Iterator.cxx:48
Write iterator for HADAQ events/subevents.
Definition: Iterator.h:104
hadaq::RawEvent * evnt() const
Definition: Iterator.h:133
bool IsBuffer() const
Definition: Iterator.h:112
void * rawdata() const
Definition: Iterator.h:135
bool NewEvent(uint32_t evtSeqNr=0, uint32_t runNr=0, uint32_t minsubeventsize=0)
Definition: Iterator.cxx:333
bool IsPlaceForEvent(uint32_t subeventsize)
Definition: Iterator.cxx:322
bool FinishSubEvent(uint32_t rawdatasz)
Definition: Iterator.cxx:367
dabc::BufferSize_t fFullSize
Definition: Iterator.h:142
bool AddAllSubevents(hadaq::RawEvent *evnt)
Definition: Iterator.h:125
dabc::Pointer fEvPtr
Definition: Iterator.h:140
uint32_t maxrawdatasize() const
Definition: Iterator.h:136
dabc::Buffer Close()
Definition: Iterator.cxx:309
bool IsEmpty() const
Definition: Iterator.h:113
bool NewSubevent(uint32_t minrawsize=0, uint32_t trigger=0)
Definition: Iterator.cxx:353
bool AddSubevent(const dabc::Pointer &source)
Definition: Iterator.cxx:380
bool AddSubevent(hadaq::RawSubevent *sub)
Definition: Iterator.h:121
hadaq::RawSubevent * subevnt() const
Definition: Iterator.h:134
bool Reset(const dabc::Buffer &buf)
Definition: Iterator.cxx:291
dabc::Pointer fSubPtr
Definition: Iterator.h:141
dabc::Buffer fBuffer
Definition: Iterator.h:139
Event manipulation API.
Definition: api.h:23
uint32_t BufferSize_t
Definition: Buffer.h:32
Support for HADAQ - HADES DAQ
Definition: api.h:27
HADES transport unit header.
Definition: defines.h:138
uint32_t GetPaddedSize() const
Definition: defines.h:184
Hadaq event structure.
Definition: defines.h:443
RawSubevent * FirstSubevent()
Definition: defines.cxx:53
uint32_t AllSubeventsSize()
Definition: defines.cxx:60
Hadaq subevent structure.
Definition: defines.h:262
void * RawData() const
Return pointer where raw data should starts.
Definition: defines.h:344