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 for (int i = 0; i < nwords_1st; i++) {
128 if (i == 0) {
129 buf1[ i ] = 0x12345678;
130 } else {
131 buf1[ i ] = (i + 1) * buf1[ i - 1 ];
132 }
133 }
134
135 // nwords_2nd = (n_basf2evt + 1) % 10;
136 // nwords_2nd = (n_basf2evt + 1) % 300 + 200;
137 /*
138 if (nwords_2nd > 10000 || nwords_2nd <= 0) {
139 printf("ERRORORRRR nword2nd %d\n", nwords_2nd);
140 fflush(stdout);
141 }
142 */
143
144 buf2 = new int[ nwords_2nd];
145 for (int i = 0; i < nwords_2nd; i++) {
146 if (i == 0) {
147 buf2[ i ] = 0x34567890;
148 } else {
149 buf2[ i ] = (i + 1) * buf2[ i - 1 ];
150 }
151 }
152
153 // nwords_3rd = 3 * (n_basf2evt + 2) % 10;
154 // nwords_3rd = 3 * (n_basf2evt + 2) % 200 + 100;
155 /*
156 if (nwords_3rd > 10000 || nwords_3rd <= 0) {
157 printf("ERRORORRRR nword3rd %d\n", nwords_3rd);
158 fflush(stdout);
159 }
160 */
161
162 buf3 = new int[ nwords_3rd];
163 for (int i = 0; i < nwords_3rd; i++) {
164 if (i == 0) {
165 buf3[ i ] = 0x56789012;
166 } else {
167 buf3[ i ] = (i + 1) * buf3[ i - 1 ];
168 }
169 }
170
171 // nwords_4th = 4 * (n_basf2evt + 3) % 10;
172 // nwords_4th = 4 * (n_basf2evt + 3) % 20 + 300;
173 /*
174 if (nwords_4th > 10000 || nwords_4th <= 0) {
175 printf("ERRORORRRR nwor_4th %d\n", nwords_4th);
176 fflush(stdout);
177 }
178 */
179
180 buf4 = new int[ nwords_4th];
181 for (int i = 0; i < nwords_4th; i++) {
182 if (i == 0) {
183 buf4[ i ] = 0x78901234;
184 } else {
185 buf4[ i ] = (i + 1) * buf4[ i - 1 ];
186 }
187 }
188
189#ifdef USE_RAWDATABLOCK
190 raw_copper->PackDetectorBuf4DummyData(buf1, nwords_1st,
191 buf2, nwords_2nd,
192 buf3, nwords_3rd,
193 buf4, nwords_4th,
194 rawcprpacker_info);
195#else
196 raw_copper->PackDetectorBuf(buf1, nwords_1st,
197 buf2, nwords_2nd,
198 buf3, nwords_3rd,
199 buf4, nwords_4th,
200 rawcprpacker_info);
201
202#endif
203
204#ifdef USE_RAWDATABLOCK
205 RawDataBlock* raw_datablk = raw_datablkarray.appendNew();
206 raw_datablk->SetBuffer(raw_copper->GetWholeBuffer(), raw_copper->TotalBufNwords(),
207 false, 1, 1);
208#endif
209
210 delete [] buf1;
211 delete [] buf2;
212 delete [] buf3;
213 delete [] buf4;
214
215 //
216 // Update EventMetaData : Not affect on the output
217 //
218 m_eventMetaDataPtr.create();
219 m_eventMetaDataPtr->setExperiment(rawcprpacker_info.exp_num);
220 m_eventMetaDataPtr->setRun(rawcprpacker_info.run_subrun_num);
222
223
224 //
225 // Monitor
226 //
227 if (max_nevt >= 0) {
228 if ((int)n_basf2evt >= max_nevt && max_nevt > 0) {
229 printf("[DEBUG] RunStop was detected. ( Setting: Max event # %d ) Processed Event %d \n",
231 fflush(stdout);
232 m_eventMetaDataPtr->setEndOfData();
233 }
234 }
235
236 if (n_basf2evt % 10000 == 0) {
237 double cur_time = getTimeSec();
238 double interval = cur_time - m_prev_time;
239 double total_time = cur_time - m_start_time;
240 if (n_basf2evt == 0) {
241 interval = 1;
242 }
243 printf("[INFO] Event %12d Rate %6.2lf[kHz] Recvd Flow %6.2lf[MB/s] RunTime %8.2lf[s] interval %8.4lf[s]\n",
244 n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC,
245 (n_basf2evt - m_prev_nevt)*NUM_EVT_PER_BASF2LOOP_PC / interval / 1.e3,
246 (m_totbytes - m_prev_totbytes) / interval / 1.e6,
247 total_time,
248 interval);
249 fflush(stdout);
250 m_prev_time = cur_time;
251 m_prev_totbytes = m_totbytes;
252 m_prev_nevt = n_basf2evt;
253
254
255 }
256
257 n_basf2evt++;
258 RunInfoBuffer& status(DeSerializerModule::getStatus());
259 if (status.isAvailable()) {
260 status.addInputNBytes(1);
261 status.setInputCount(n_basf2evt);
262 }
263 return;
264}
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.
StoreObjPtr< EventMetaData > m_eventMetaDataPtr
Event Meta Data.
int max_nevt
check data contents
double getTimeSec()
store time info.
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
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.
Definition: RawDataBlock.h:27
virtual void SetBuffer(int *bufin, int nwords, int delete_flag, int num_events, int num_nodes)
set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )
Definition: RawDataBlock.cc:35
virtual int * GetWholeBuffer()
get pointer to buffer(m_buffer)
Definition: RawDataBlock.h:60
virtual int TotalBufNwords()
Get total length of m_buffer.
Definition: RawDataBlock.h:39
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.