DABC (Data Acquisition Backbone Core)  2.9.9
RecalibrateModule.cxx
Go to the documentation of this file.
1 // $Id: RecalibrateModule.cxx 4464 2020-04-15 12:14:20Z 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 "dabc/BinaryFile.h"
17 
19 
20 #include "hadaq/Iterator.h"
21 #include "mbs/Iterator.h"
22 #include "hadaq/HldProcessor.h"
23 #include "stream/DabcProcMgr.h"
24 
25 #include "dabc/Manager.h"
26 #include "dabc/Factory.h"
27 #include "dabc/Iterator.h"
28 #include "dabc/Buffer.h"
29 #include "dabc/Publisher.h"
30 
31 #include <cstdlib>
32 
33 #include "base/Buffer.h"
34 #include "base/StreamProc.h"
35 
36 // ==================================================================================
37 
39  dabc::ModuleAsync(name, cmd),
40  fNumSub(0),
41  fReplace(false),
42  fProcMgr(0),
43  fHLD(0)
44 {
45  fNumSub = Cfg("NumSub",cmd).AsInt(1);
46  fReplace = Cfg("Replace",cmd).AsBool(true);
47 
49 
50  fWorkerHierarchy.Create("Worker");
51  fProcMgr = new DabcProcMgr;
53 
54  fHLD = new hadaq::HldProcessor();
55 
56  CreatePar("DataRate").SetRatemeter(false, 3.).SetUnits("MB");
57 
58  for (int n=0;n<fNumSub;n++) {
59  std::string mname = dabc::format("Sub%d",n);
60 
61  dabc::CmdCreateModule cmd("stream::TdcCalibrationModule", mname);
62  cmd.SetPtr("ProcMgr", fProcMgr);
63  cmd.SetPtr("HLDProc", fHLD);
64  dabc::mgr.Execute(cmd);
65  }
66 
67  fProcMgr->UserPreLoop();
68 
69  Publish(fWorkerHierarchy, dabc::format("$CONTEXT$/%s", GetName()));
70 
71  base::ProcMgr::ClearInstancePointer();
72 }
73 
75 {
76  // do not delete proc manager
77 }
78 
80 {
82 }
83 
85 {
86  if (CanSendToAllOutputs() && CanRecv()) {
87 
88  if (!fReplace && !CanTakeBuffer()) return false;
89 
90  dabc::Buffer buf = Recv();
91  Par("DataRate").SetValue(buf.GetTotalSize()/1024./1024.);
92 
93  if (buf.GetTypeId() == hadaq::mbt_HadaqEvents) {
94 
95  if (fReplace) {
96  // this is easier to handle, but hit messages are replaced
97  hadaq::ReadIterator iter(buf);
98  while (iter.NextEvent())
99  fHLD->TransformEvent(iter.evnt(), iter.evntsize());
100  } else {
101 
102  dabc::Buffer resbuf = TakeBuffer();
103 
104  hadaq::ReadIterator iter(buf);
105  dabc::Pointer tgt(resbuf);
106 
107  //DOUT0("Buffer size %u Original size %u", buf.GetTotalSize(), tgt.distance_to(resbuf));
108 
109  while (iter.NextEvent()) {
110  unsigned len = fHLD->TransformEvent(iter.evnt(), iter.evntsize(), tgt(), tgt.rawsize());
111  if (len==0) { EOUT("Fail to transform HLD event"); break; }
112  if (tgt.shift(len)!=len) { EOUT("no enough space to shift to next event"); exit(5); break; }
113  }
114 
115  //DOUT0("Buffer size %u Result size %d", buf.GetTotalSize(), tgt.distance_to_ownbuf());
116 
117  resbuf.SetTotalSize(tgt.distance_to_ownbuf());
119  buf = resbuf;
120  }
121 
122  } else {
123  DOUT0("Buffer of unsupported type %d", buf.GetTypeId());
124  }
125 
126  SendToAllOutputs(buf);
127 
128  return true;
129  }
130 
131  return false;
132 }
133 
135 {
136  if (fProcMgr && fProcMgr->ExecuteHCommand(cmd)) return dabc::cmd_true;
137 
139 }
140 
142 {
143 }
144 
146 {
147 }
Reference on memory from memory pool.
Definition: Buffer.h:135
void SetTotalSize(BufferSize_t len)
Set total length of the buffer to specified value Size cannot be bigger than original size of the buf...
Definition: Buffer.cxx:99
unsigned GetTypeId() const
Definition: Buffer.h:152
BufferSize_t GetTotalSize() const
Return total size of all buffer segments.
Definition: Buffer.cxx:91
void SetTypeId(unsigned tid)
Definition: Buffer.h:151
Represents command with its arguments.
Definition: Command.h:99
void SetPtr(const std::string &name, void *p)
Set pointer argument for the command.
Definition: Command.cxx:151
void Create(const std::string &name, bool withmutex=false)
Create top-level object with specified name.
Definition: Hierarchy.cxx:934
virtual Parameter CreatePar(const std::string &name, const std::string &kind="")
Definition: Module.cxx:129
virtual void OnThreadAssigned()
Definition: Module.cxx:79
virtual int ExecuteCommand(Command cmd)
Main method where commands are executed.
Definition: Module.h:232
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
const char * GetName() const
Returns name of the object, thread safe
Definition: Object.h:295
Parameter & SetUnits(const std::string &unit)
Set units field of parameter.
Definition: Parameter.h:256
Parameter & SetRatemeter(bool synchron=false, double interval=1.0)
Converts parameter in ratemeter - all values will be summed up and divided on specified interval.
Definition: Parameter.cxx:365
Manipulator with dabc::Buffer class.
Definition: Pointer.h:34
BufferSize_t shift(BufferSize_t sz)
Definition: Pointer.h:153
int distance_to_ownbuf() const
Definition: Pointer.h:204
BufferSize_t rawsize() const
Definition: Pointer.h:148
bool AsBool(bool dflt=false) const
Definition: Record.cxx:477
int64_t AsInt(int64_t dflt=0) const
Definition: Record.cxx:501
bool Execute(Command cmd, double tmout=-1.)
Definition: Worker.cxx:1147
Hierarchy fWorkerHierarchy
place for publishing of worker parameters
Definition: Worker.h:168
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
virtual bool Publish(const Hierarchy &h, const std::string &path)
Definition: Worker.cxx:1075
Read iterator for HADAQ events/subevents.
Definition: Iterator.h:39
bool NextEvent()
Used for ready HLD events.
Definition: Iterator.cxx:127
unsigned evntsize() const
Definition: Iterator.h:82
hadaq::RawEvent * evnt() const
Definition: Iterator.h:81
void SetTop(dabc::Hierarchy &top, bool withcmds=false)
Definition: DabcProcMgr.cxx:43
virtual int ExecuteCommand(dabc::Command cmd)
Main method where commands are executed.
hadaq::HldProcessor * fHLD
RecalibrateModule(const std::string &name, dabc::Command cmd=nullptr)
#define DOUT0(args ...)
Definition: logging.h:156
#define EOUT(args ...)
Definition: logging.h:150
Event manipulation API.
Definition: api.h:23
const char * xmlWorkPool
Definition: Object.cxx:46
ManagerRef mgr
Definition: Manager.cxx:42
std::string format(const char *fmt,...)
Definition: string.cxx:49
@ cmd_true
Definition: Command.h:38
@ mbt_HadaqEvents
Definition: HadaqTypeDefs.h:24