DABC (Data Acquisition Backbone Core)  2.9.9
SorterModule.h
Go to the documentation of this file.
1 // $Id: SorterModule.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 HADAQ_SorterModule
17 #define HADAQ_SorterModule
18 
19 #ifndef DABC_ModuleAsync
20 #include "dabc/ModuleAsync.h"
21 #endif
22 
23 #ifndef DABC_Pointer
24 #include "dabc/Pointer.h"
25 #endif
26 
27 #include <vector>
28 
29 namespace hadaq {
30 
31 
39 
40  public:
41  struct SubsRec {
42  void* subevnt;
43  uint32_t trig;
44  uint32_t buf;
45  uint32_t sz;
46  };
47 
48  struct SubsComp {
50  SubsComp(SorterModule* _m) : m(_m) {}
51  // use in std::sort for sorting elements of std::vector<SubsRec>
52  bool operator() (const SubsRec& l,const SubsRec& r) { return m->Diff(l.trig, r.trig) > 0; }
53  };
54 
55 
56  int fFlushCnt;
57  int fBufCnt;
58  int fLastRet;
59  uint32_t fTriggersRange;
60  uint32_t fLastTrigger;
61  unsigned fNextBufIndx;
62  unsigned fReadyBufIndx;
63  std::vector<SubsRec> fSubs;
66 
67  void DecremntInputIndex(unsigned cnt=1);
68 
69  bool RemoveUsedSubevents(unsigned num);
70 
71  bool retransmit();
72 
73  virtual int ExecuteCommand(dabc::Command cmd);
74 
75  public:
76  SorterModule(const std::string &name, dabc::Command cmd = nullptr);
77 
78  virtual bool ProcessBuffer(unsigned) { return retransmit(); }
79 
80  virtual bool ProcessRecv(unsigned) { return retransmit(); }
81 
82  virtual bool ProcessSend(unsigned) { return retransmit(); }
83 
84  virtual void ProcessTimerEvent(unsigned);
85 
86  int Diff(uint32_t trig1, uint32_t trig2)
87  {
88  int res = (int) (trig2) - trig1;
89  if (res > ((int) fTriggersRange)/2) return res - fTriggersRange;
90  if (res < ((int) fTriggersRange)/-2) return res + fTriggersRange;
91  return res;
92  }
93 
94 
95  };
96 
97 }
98 
99 
100 #endif
Reference on memory from memory pool.
Definition: Buffer.h:135
Represents command with its arguments.
Definition: Command.h:99
Base class for user-derived code, implementing event-processing.
Definition: ModuleAsync.h:32
Manipulator with dabc::Buffer class.
Definition: Pointer.h:34
Sorts HADAQ subevents according to trigger number.
Definition: SorterModule.h:38
dabc::Buffer fOutBuf
output buffer
Definition: SorterModule.h:64
int Diff(uint32_t trig1, uint32_t trig2)
Definition: SorterModule.h:86
unsigned fNextBufIndx
next buffer which could be processed
Definition: SorterModule.h:61
dabc::Pointer fOutPtr
place for new data
Definition: SorterModule.h:65
virtual int ExecuteCommand(dabc::Command cmd)
Main method where commands are executed.
virtual bool ProcessBuffer(unsigned)
Method called by framework when at least one buffer available in pool handle.
Definition: SorterModule.h:78
SorterModule(const std::string &name, dabc::Command cmd=nullptr)
void DecremntInputIndex(unsigned cnt=1)
virtual bool ProcessRecv(unsigned)
Method called by framework when at least one buffer available in input port.
Definition: SorterModule.h:80
unsigned fReadyBufIndx
input buffer index which could be send directly
Definition: SorterModule.h:62
int fBufCnt
total number of buffers
Definition: SorterModule.h:57
uint32_t fLastTrigger
last trigger copied into output
Definition: SorterModule.h:60
virtual bool ProcessSend(unsigned)
Method called by framework when at least one buffer can be send to output port.
Definition: SorterModule.h:82
uint32_t fTriggersRange
valid range for the triggers, normally 0x1000000
Definition: SorterModule.h:59
virtual void ProcessTimerEvent(unsigned)
Method called by framework when timer event is produced.
std::vector< SubsRec > fSubs
vector with subevents data in the buffers
Definition: SorterModule.h:63
bool RemoveUsedSubevents(unsigned num)
Support for HADAQ - HADES DAQ
Definition: api.h:27
bool operator()(const SubsRec &l, const SubsRec &r)
Definition: SorterModule.h:52
SubsComp(SorterModule *_m)
Definition: SorterModule.h:50
uint32_t buf
buffer indx
Definition: SorterModule.h:44
uint32_t sz
padded size
Definition: SorterModule.h:45
void * subevnt
direct pointer on subevent
Definition: SorterModule.h:42
uint32_t trig
trigger number
Definition: SorterModule.h:43