DABC (Data Acquisition Backbone Core)  2.9.9
CombinerModule.h
Go to the documentation of this file.
1 // $Id: CombinerModule.h 4479 2020-04-15 14:30:52Z 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_CombinerModule
17 #define MBS_CombinerModule
18 
19 #ifndef DABC_ModuleAsync
20 #include "dabc/ModuleAsync.h"
21 #endif
22 
23 #ifndef MBS_Iterator
24 #include "mbs/Iterator.h"
25 #endif
26 
27 namespace mbs {
28 
32  protected:
33 
36  struct InputCfg {
40  bool real_mbs;
41 
44 
47 
51 
55 
59 
61  uint32_t evntsrc_fullid;
62 
64  uint32_t evntsrc_shift;
65 
67  bool selected;
68 
70  bool valid;
71 
73  double last_valid_tm;
74 
76  real_mbs(true),
77  curr_evnt_num(0),
78  curr_evnt_special(false),
79  real_evnt_num(true),
80  no_evnt_num(false),
81  optional_input(false),
82  evntsrc_fullid(0),
83  evntsrc_shift(0),
84  selected(false),
85  valid(false),
86  last_valid_tm(0){}
87 
88  InputCfg(const InputCfg& src) :
89  real_mbs(src.real_mbs),
97  selected(src.selected),
98  valid(src.valid),
100 
101  void Reset()
102  {
103  real_mbs = true;
104  curr_evnt_num = 0;
105  curr_evnt_special = false;
106  real_evnt_num = true;
107  no_evnt_num = false;
108  optional_input = false;
109  evntsrc_fullid = 0;
110  evntsrc_shift = 0;
111  selected = false;
112  valid = false;
113  last_valid_tm = 0.;
114  }
115  };
116 
117  std::vector<ReadIterator> fInp;
118  std::vector<InputCfg> fCfg;
121 
122  /* switch between partial combining of smallest event ids (false)
123  * and building of complete events only (true)*/
125 
126  /*switch on checking duplicate subevent ids in merged events -> indicate setup error*/
128 
133 
134  /* defines maximum difference allowed between event id in merged data streams.
135  * if id difference is larger, combiner may stop with error message*/
137 
144 
148 
150  double fExcludeTime;
151 
152  std::string fEventRateName;
153  std::string fDataRateName;
154  std::string fInfoName;
155  std::string fFileStateName;
156 
157  bool BuildEvent();
158  bool FlushBuffer();
159 
160  virtual void BeforeModuleStart();
161 
162  virtual void AfterModuleStop();
163 
164  bool ShiftToNextEvent(unsigned ninp);
165 
167  bool ShiftToNextBuffer(unsigned ninp);
168 
169  mbs::EventNumType CurrEventId(unsigned int ninp) const { return fCfg[ninp].curr_evnt_num; }
170 
171  void SetInfo(const std::string &info, bool forceinfo = false);
172 
173  bool IsOptionalInput(unsigned ninp) { return ninp<fCfg.size() ? (fCfg[ninp].optional_input || fCfg[ninp].no_evnt_num) : true; }
174 
175 
177  void ChangeFileState(bool on);
178 
179  public:
180 
181  CombinerModule(const std::string &name, dabc::Command cmd = nullptr);
182  virtual ~CombinerModule();
183 
184  virtual void ModuleCleanup();
185 
186  virtual bool ProcessRecv(unsigned port) { return BuildEvent(); }
187  virtual bool ProcessSend(unsigned port) { return BuildEvent(); }
188 
189  virtual void ProcessTimerEvent(unsigned timer);
190 
191  unsigned NumObligatoryInputs() const { return fNumObligatoryInputs; }
192 
193  /* returns maximum possible eventnumber for overflow checking*/
194  virtual unsigned int GetOverflowEventNumber() const;
195 
196  virtual int ExecuteCommand(dabc::Command cmd);
197  };
198 }
199 
200 
201 #endif
Represents command with its arguments.
Definition: Command.h:99
Base class for user-derived code, implementing event-processing.
Definition: ModuleAsync.h:32
Combiner of several MBS inputs - event building.
void SetInfo(const std::string &info, bool forceinfo=false)
virtual unsigned int GetOverflowEventNumber() const
bool ShiftToNextEvent(unsigned ninp)
virtual int ExecuteCommand(dabc::Command cmd)
Main method where commands are executed.
CombinerModule(const std::string &name, dabc::Command cmd=nullptr)
virtual void AfterModuleStop()
mbs::EventNumType CurrEventId(unsigned int ninp) const
WriteIterator fOut
mbs::EventNumType fEventIdMask
used to exclude higher bits from event id Can be used when some subsystems does not provide all 32 bi...
virtual void ProcessTimerEvent(unsigned timer)
Method called by framework when timer event is produced.
std::string fEventRateName
void ChangeFileState(bool on)
change file on/off state in application
virtual bool ProcessRecv(unsigned port)
Method called by framework when at least one buffer available in input port.
virtual bool ProcessSend(unsigned port)
Method called by framework when at least one buffer can be send to output port.
double fExcludeTime
Time to exclude optional input when no data comming.
mbs::EventNumType fEventIdTolerance
std::string fFileStateName
std::vector< ReadIterator > fInp
std::vector< InputCfg > fCfg
unsigned NumObligatoryInputs() const
int fSpecialTriggerLimit
Down limit for trigger number, which is recognized as special event This event is forwarded through c...
bool IsOptionalInput(unsigned ninp)
virtual void ModuleCleanup()
Method, which can be reimplemented by user and should cleanup all references on buffers and other obj...
bool ShiftToNextBuffer(unsigned ninp)
Method should be used to skip current buffer from the queue.
unsigned fNumObligatoryInputs
Indicates how many inputs should provide data that event is accepted as full Can be less than number ...
std::string fDataRateName
virtual void BeforeModuleStart()
Write iterator for MBS events/subevents.
Definition: Iterator.h:97
Support for MBS - standard GSI DAQ.
Definition: api.h:36
uint32_t EventNumType
Definition: MbsTypeDefs.h:94
Individual configuration and run parameters of each input.
bool curr_evnt_special
if it is start/stop daq event, treat it in special way
mbs::EventNumType curr_evnt_num
keeps current event number
uint32_t evntsrc_fullid
Full id of subevent, where actual event id should be searched.
bool valid
indicates if input has valid data
bool real_evnt_num
Indicates if event number is in event header or moved in data body Than event number will be searched...
InputCfg(const InputCfg &src)
bool selected
indicates if input was selected for event building
bool optional_input
Indicates that data from input optional and can be missing BUT one must ensure that next data is arri...
bool no_evnt_num
Indicates if event number in header is missing (unvalid value) In this case current data from the inp...
bool real_mbs
indicates if input is real mbs - means event produced by MBS Such input is used to set event number i...
double last_valid_tm
time when last valid event was produced, can be used to remove optional input completely
uint32_t evntsrc_shift
Shift in subevent raw data to access event id.