Belle II Software development
DummyDataSource.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <daq/rawdata/modules/DummyDataSource.h>
10#include <daq/rawdata/modules/DeSerializer.h>
11
12using namespace std;
13using namespace Belle2;
14
15//-----------------------------------------------------------------
16// Register the Module
17//-----------------------------------------------------------------
18REG_MODULE(DummyDataSource);
19
20//-----------------------------------------------------------------
21// Implementation
22//-----------------------------------------------------------------
23
25{
27 setDescription("an Example to pack data to a RawCOPPER object");
28
30 addParam("MaxEventNum", max_nevt, "Maximum event number to make", -1);
31
33 addParam("NodeID", m_nodeid, "Node ID", 0);
34
35 addParam("NodeName", m_nodename, "Node(subsystem) name", std::string(""));
36
37 addParam("UseShmFlag", m_shmflag, "Use shared memory to communicate with Runcontroller", 0);
38
39 B2INFO("DummyDataSource: Constructor done.");
40}
41
42
43
44DummyDataSourceModule::~DummyDataSourceModule()
45{
46
47}
48
49
51{
52 B2INFO("DummyDataSource: initialize() started.");
53
55 m_eventMetaDataPtr.registerInDataStore();
56
57#ifdef USE_RAWDATABLOCK
58 raw_datablkarray.registerInDataStore();
59#endif
60
61 rawcprarray.registerInDataStore();
62
63 // n_basf2evt = 0;
64 n_basf2evt = 0;
65 m_start_flag = 0;
66
67 if (m_shmflag > 0) {
68 if (m_nodename.size() == 0 || m_nodeid < 0) {
69 m_shmflag = 0;
70 } else {
71 printf("nodename = %s\n", m_nodename.c_str());
72 RunInfoBuffer& status(DeSerializerModule::getStatus());
73 status.open(m_nodename, m_nodeid);
74 }
75 }
76
77 B2INFO("DummyDataSource: initialize() done.");
78}
79
80
81
82
84{
85
86 // Make RawCOPPER array
87 if (m_start_flag == 0) {
88 m_start_flag = 1;
89 RunInfoBuffer& status(DeSerializerModule::getStatus());
90 if (status.isAvailable()) {
91 B2INFO("DeSerializerCOPPER: Waiting for Start...\n");
92 status.reportRunning();
93 }
94 }
95
96 //
97 // Fill event info (These values will be stored in RawHeader )
98 //
99 RawCOPPERPackerInfo rawcprpacker_info;
100 rawcprpacker_info.exp_num = 1;
101 rawcprpacker_info.run_subrun_num = 2; // run number : 14bits, subrun # : 8bits
102 rawcprpacker_info.eve_num = n_basf2evt;
103 rawcprpacker_info.node_id = m_nodeid;
104 rawcprpacker_info.tt_ctime = 0x7123456;
105 rawcprpacker_info.tt_utime = 0xF1234567;
106 rawcprpacker_info.b2l_ctime = 0x7654321;
107
108
109 //
110 // Prepare buffer to fill dummy data
111 //
112 RawCOPPER* raw_copper = rawcprarray.appendNew();
113
114 int* buf1, *buf2, *buf3, *buf4;
115 int nwords_1st = 0, nwords_2nd = 0, nwords_3rd = 0, nwords_4th = 0;
116
117 // nwords_1st = n_basf2evt % 10;
118 // nwords_1st = n_basf2evt % 100 + 1;
119 /*
120 if (nwords_1st > 10000 || nwords_1st <= 0) {
121 printf("ERRORORRRR nword1st %d\n", nwords_1st);
122 fflush(stdout);
123 }
124 */
125 buf1 = new int[ nwords_1st];
126
127 // cppcheck-suppress knownConditionTrueFalse ; the word counts come from module parameters
128 for (int i = 0; i < nwords_1st; i++) {
129 if (i == 0) {
130 buf1[ i ] = 0x12345678;
131 } else {
132 buf1[ i ] = (i + 1) * buf1[ i - 1 ];
133 }
134 }
135
136 // nwords_2nd = (n_basf2evt + 1) % 10;
137 // nwords_2nd = (n_basf2evt + 1) % 300 + 200;
138 /*
139 if (nwords_2nd > 10000 || nwords_2nd <= 0) {
140 printf("ERRORORRRR nword2nd %d\n", nwords_2nd);
141 fflush(stdout);
142 }
143 */
144
145 buf2 = new int[ nwords_2nd];
146 // cppcheck-suppress knownConditionTrueFalse ; the word counts come from module parameters
147 for (int i = 0; i < nwords_2nd; i++) {
148 if (i == 0) {
149 buf2[ i ] = 0x34567890;
150 } else {
151 buf2[ i ] = (i + 1) * buf2[ i - 1 ];
152 }
153 }
154
155 // nwords_3rd = 3 * (n_basf2evt + 2) % 10;
156 // nwords_3rd = 3 * (n_basf2evt + 2) % 200 + 100;
157 /*
158 if (nwords_3rd > 10000 || nwords_3rd <= 0) {
159 printf("ERRORORRRR nword3rd %d\n", nwords_3rd);
160 fflush(stdout);
161 }
162 */
163
164 buf3 = new int[ nwords_3rd];
165 // cppcheck-suppress knownConditionTrueFalse ; the word counts come from module parameters
166 for (int i = 0; i < nwords_3rd; i++) {
167 if (i == 0) {
168 buf3[ i ] = 0x56789012;
169 } else {
170 buf3[ i ] = (i + 1) * buf3[ i - 1 ];
171 }
172 }
173
174 // nwords_4th = 4 * (n_basf2evt + 3) % 10;
175 // nwords_4th = 4 * (n_basf2evt + 3) % 20 + 300;
176 /*
177 if (nwords_4th > 10000 || nwords_4th <= 0) {
178 printf("ERRORORRRR nwor_4th %d\n", nwords_4th);
179 fflush(stdout);
180 }
181 */
182
183 buf4 = new int[ nwords_4th];
184 // cppcheck-suppress knownConditionTrueFalse ; the word counts come from module parameters
185 for (int i = 0; i < nwords_4th; i++) {
186 if (i == 0) {
187 buf4[ i ] = 0x78901234;
188 } else {
189 buf4[ i ] = (i + 1) * buf4[ i - 1 ];
190 }
191 }
192
193#ifdef USE_RAWDATABLOCK
194 raw_copper->PackDetectorBuf4DummyData(buf1, nwords_1st,
195 buf2, nwords_2nd,
196 buf3, nwords_3rd,
197 buf4, nwords_4th,
198 rawcprpacker_info);
199#else
200 raw_copper->PackDetectorBuf(buf1, nwords_1st,
201 buf2, nwords_2nd,
202 buf3, nwords_3rd,
203 buf4, nwords_4th,
204 rawcprpacker_info);
205
206#endif
207
208#ifdef USE_RAWDATABLOCK
209 RawDataBlock* raw_datablk = raw_datablkarray.appendNew();
210 raw_datablk->SetBuffer(raw_copper->GetWholeBuffer(), raw_copper->TotalBufNwords(),
211 false, 1, 1);
212#endif
213
214 delete [] buf1;
215 delete [] buf2;
216 delete [] buf3;
217 delete [] buf4;
218
219 //
220 // Update EventMetaData : Not affect on the output
221 //
222 m_eventMetaDataPtr.create();
223 m_eventMetaDataPtr->setExperiment(rawcprpacker_info.exp_num);
224 m_eventMetaDataPtr->setRun(rawcprpacker_info.run_subrun_num);
226
227
228 //
229 // Monitor
230 //
231 if (max_nevt >= 0) {
232 if ((int)n_basf2evt >= max_nevt && max_nevt > 0) {
233 printf("[DEBUG] RunStop was detected. ( Setting: Max event # %d ) Processed Event %u \n",
235 fflush(stdout);
236 m_eventMetaDataPtr->setEndOfData();
237 }
238 }
239
240 if (n_basf2evt % 10000 == 0) {
241 double cur_time = getTimeSec();
242 double interval = cur_time - m_prev_time;
243 double total_time = cur_time - m_start_time;
244 if (n_basf2evt == 0) {
245 interval = 1;
246 }
247 printf("[INFO] Event %12u Rate %6.2lf[kHz] Recvd Flow %6.2lf[MB/s] RunTime %8.2lf[s] interval %8.4lf[s]\n",
248 n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC,
249 (n_basf2evt - m_prev_nevt)*NUM_EVT_PER_BASF2LOOP_PC / interval / 1.e3,
250 (m_totbytes - m_prev_totbytes) / interval / 1.e6,
251 total_time,
252 interval);
253 fflush(stdout);
254 m_prev_time = cur_time;
255 m_prev_totbytes = m_totbytes;
256 m_prev_nevt = n_basf2evt;
257
258
259 }
260
261 n_basf2evt++;
262 RunInfoBuffer& status(DeSerializerModule::getStatus());
263 if (status.isAvailable()) {
264 status.addInputNBytes(1);
265 status.setInputCount(n_basf2evt);
266 }
267 return;
268}
StoreArray< RawCOPPER > rawcprarray
RawCOPPER array.
DummyDataSourceModule()
Constructor / Destructor.
void initialize() override
Module functions to be called from main process.
unsigned int n_basf2evt
Number of events.
std::string m_nodename
Node name.
void event() override
Module functions to be called from event process.
StoreArray< RawDataBlock > raw_datablkarray
RawDataBlock array.
int m_shmflag
Use shared memory.
static double getTimeSec()
store time info.
StoreObjPtr< EventMetaData > m_eventMetaDataPtr
Event Meta Data.
int max_nevt
check data contents
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
Module()
Constructor.
Definition Module.cc:30
struct to contain header information used by RawCOPPERFormat::Packer()
unsigned int b2l_ctime
32bit unitx time at trigger timing distributed by FTSW. For details, see Nakao-san's belle2link user ...
unsigned int eve_num
Run # and subrun # ( 22bit )
unsigned int tt_ctime
Node ID (32bit)
unsigned int tt_utime
27bit clock ticks at trigger timing distributed by FTSW. For details, see Nakao-san's belle2link user...
unsigned int node_id
Event Number (32bit)
unsigned int run_subrun_num
Experiment number (10bit)
unsigned int exp_num
Experiment number (10bit)
The Raw COPPER class This class stores data received by COPPER via belle2linkt Data from all detector...
Definition RawCOPPER.h:52
void PackDetectorBuf(int *detector_buf_1st, int nwords_1st, int *detector_buf_2nd, int nwords_2nd, int *detector_buf_3rd, int nwords_3rd, int *detector_buf_4th, int nwords_4th, RawCOPPERPackerInfo rawcprpacker_info)
Packer for RawCOPPER class Pack data (format ver.
Definition RawCOPPER.cc:183
void PackDetectorBuf4DummyData(int *detector_buf_1st, int nwords_1st, int *detector_buf_2nd, int nwords_2nd, int *detector_buf_3rd, int nwords_3rd, int *detector_buf_4th, int nwords_4th, RawCOPPERPackerInfo rawcprpacker_info)
Pack dummy data (format ver. = -1 -> Select the latest format version)
Definition RawCOPPER.cc:251
The RawDataBlock class Base class for rawdata handling.
virtual void SetBuffer(int *bufin, int nwords, int delete_flag, int num_events, int num_nodes)
set buffer ( delete_flag : m_buffer is freed( = 0 )/ not freed( = 1 ) in Destructor )
virtual int * GetWholeBuffer()
get pointer to buffer(m_buffer)
virtual int TotalBufNwords()
Get total length of m_buffer.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:650
Abstract base class for different kinds of events.
STL namespace.