DABC (Data Acquisition Backbone Core)  2.9.9
MonitorSlowControl.cxx
Go to the documentation of this file.
1 // $Id: MonitorSlowControl.cxx 4482 2020-04-15 14:47: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 #include "mbs/MonitorSlowControl.h"
17 
18 #include <cstdlib>
19 #include <cmath>
20 
21 mbs::MonitorSlowControl::MonitorSlowControl(const std::string &name, const std::string &prefix, dabc::Command cmd) :
22  dabc::ModuleAsync(name, cmd),
23  fRec(),
24  fDoRec(false),
25  fSubeventId(8),
26  fEventNumber(0),
27  fLastSendTime(),
28  fIter(),
29  fFlushTime(10)
30 {
32  fDoRec = NumOutputs() > 0;
33 
34  double period = Cfg(prefix + "Period", cmd).AsDouble(1);
35  fSubeventId = Cfg(prefix + "SubeventId", cmd).AsUInt(fSubeventId);
37 
38  if (fDoRec)
39  CreateTimer("update", (period>0.01) ? period : 0.01);
40 }
41 
43 {
44 }
45 
47 {
48  if (fDoRec && (TimerName(timer) == "update"))
49  SendDataToOutputs();
50 }
51 
53 {
54  return time(NULL);
55 }
56 
57 
59 {
60  unsigned nextsize = GetRecRawSize();
61 
62  if (fIter.IsAnyEvent() && !fIter.IsPlaceForEvent(nextsize, true)) {
63 
64  // if output is blocked, do not produce data
65  if (!CanSendToAllOutputs()) return;
66 
67  dabc::Buffer buf = fIter.Close();
68  SendToAllOutputs(buf);
69 
70  fLastSendTime.GetNow();
71  }
72 
73  if (!fIter.IsBuffer()) {
74  dabc::Buffer buf = TakeBuffer();
75  // if no buffer can be taken, skip data
76  if (buf.null()) { EOUT("Cannot take buffer for FESA data"); return; }
77  fIter.Reset(buf);
78  }
79 
80  if (!fIter.IsPlaceForEvent(nextsize, true)) {
81  EOUT("EZCA event %u too large for current buffer size", nextsize);
82  return;
83  }
84 
85  unsigned evid = GetNextEventNumber();
86 
87  fRec.SetEventId(evid);
88  fRec.SetEventTime(GetNextEventTime());
89 
90  fIter.NewEvent(evid);
91  fIter.NewSubevent2(fSubeventId);
92 
93  unsigned size = WriteRecRawData(fIter.rawdata(), fIter.maxrawdatasize());
94 
95  if (size==0) {
96  EOUT("Fail to write data into MBS subevent");
97  }
98 
99  fIter.FinishSubEvent(size);
100  fIter.FinishEvent();
101 
102  if (fLastSendTime.Expired(fFlushTime) && CanSendToAllOutputs()) {
103  dabc::Buffer buf = fIter.Close();
104  SendToAllOutputs(buf);
105  fLastSendTime.GetNow();
106  }
107 }
Reference on memory from memory pool.
Definition: Buffer.h:135
Represents command with its arguments.
Definition: Command.h:99
unsigned NumOutputs() const
Definition: Module.h:141
unsigned CreateTimer(const std::string &name, double period_sec=-1., bool synchron=false)
Definition: Module.cxx:109
void EnsurePorts(unsigned numinp=0, unsigned numout=0, const std::string &poolname="")
Method ensure that at least specified number of input and output ports will be created.
Definition: Module.cxx:66
uint64_t AsUInt(uint64_t dflt=0) const
Definition: Record.cxx:525
double AsDouble(double dflt=0.) const
Definition: Record.cxx:549
bool null() const
Returns true if reference contains nullptr.
Definition: Reference.h:151
RecordField Cfg(const std::string &name, Command cmd=nullptr) const
Returns configuration field of specified name Configuration value of specified name searched in follo...
Definition: Worker.cxx:521
unsigned fSubeventId
full id number for subevent
virtual unsigned GetNextEventTime()
MonitorSlowControl(const std::string &name, const std::string &prefix, dabc::Command cmd=nullptr)
bool fDoRec
when true, record should be filled
double fFlushTime
time to flush event
virtual void ProcessTimerEvent(unsigned timer)
Method called by framework when timer event is produced.
#define EOUT(args ...)
Definition: logging.h:150
Event manipulation API.
Definition: api.h:23
const char * xmlWorkPool
Definition: Object.cxx:46
const char * xmlFlushTimeout
Definition: Object.cxx:61