Belle II Software  release-08-01-10
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 
12 using namespace std;
13 using namespace Belle2;
14 
15 //-----------------------------------------------------------------
16 // Register the Module
17 //-----------------------------------------------------------------
18 REG_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 
44 DummyDataSourceModule::~DummyDataSourceModule()
45 {
46 
47 }
48 
49 
50 void DummyDataSourceModule::initialize()
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 
83 void DummyDataSourceModule::event()
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  nwords_1st = 1;
120  if (nwords_1st > 10000 || nwords_1st <= 0) {
121  printf("ERRORORRRR nword1st %d\n", nwords_1st);
122  fflush(stdout);
123  }
124  buf1 = new int[ nwords_1st];
125 
126  for (int i = 0; i < nwords_1st; i++) {
127  if (i == 0) {
128  buf1[ i ] = 0x12345678;
129  } else {
130  buf1[ i ] = (i + 1) * buf1[ i - 1 ];
131  }
132  }
133 
134  // nwords_2nd = (n_basf2evt + 1) % 10;
135  // nwords_2nd = (n_basf2evt + 1) % 300 + 200;
136  nwords_2nd = 1;
137  if (nwords_2nd > 10000 || nwords_2nd <= 0) {
138  printf("ERRORORRRR nword2nd %d\n", nwords_2nd);
139  fflush(stdout);
140  }
141 
142  buf2 = new int[ nwords_2nd];
143  for (int i = 0; i < nwords_2nd; i++) {
144  if (i == 0) {
145  buf2[ i ] = 0x34567890;
146  } else {
147  buf2[ i ] = (i + 1) * buf2[ i - 1 ];
148  }
149  }
150 
151  // nwords_3rd = 3 * (n_basf2evt + 2) % 10;
152  // nwords_3rd = 3 * (n_basf2evt + 2) % 200 + 100;
153  nwords_3rd = 1;
154  if (nwords_3rd > 10000 || nwords_3rd <= 0) {
155  printf("ERRORORRRR nword3rd %d\n", nwords_3rd);
156  fflush(stdout);
157  }
158 
159  buf3 = new int[ nwords_3rd];
160  for (int i = 0; i < nwords_3rd; i++) {
161  if (i == 0) {
162  buf3[ i ] = 0x56789012;
163  } else {
164  buf3[ i ] = (i + 1) * buf3[ i - 1 ];
165  }
166  }
167 
168  // nwords_4th = 4 * (n_basf2evt + 3) % 10;
169  // nwords_4th = 4 * (n_basf2evt + 3) % 20 + 300;
170  nwords_4th = 1;
171  if (nwords_4th > 10000 || nwords_4th <= 0) {
172  printf("ERRORORRRR nwor_4th %d\n", nwords_4th);
173  fflush(stdout);
174  }
175 
176  buf4 = new int[ nwords_4th];
177  for (int i = 0; i < nwords_4th; i++) {
178  if (i == 0) {
179  buf4[ i ] = 0x78901234;
180  } else {
181  buf4[ i ] = (i + 1) * buf4[ i - 1 ];
182  }
183  }
184 
185 #ifdef USE_RAWDATABLOCK
186  raw_copper->PackDetectorBuf4DummyData(buf1, nwords_1st,
187  buf2, nwords_2nd,
188  buf3, nwords_3rd,
189  buf4, nwords_4th,
190  rawcprpacker_info);
191 #else
192  raw_copper->PackDetectorBuf(buf1, nwords_1st,
193  buf2, nwords_2nd,
194  buf3, nwords_3rd,
195  buf4, nwords_4th,
196  rawcprpacker_info);
197 
198 #endif
199 
200 #ifdef USE_RAWDATABLOCK
201  RawDataBlock* raw_datablk = raw_datablkarray.appendNew();
202  raw_datablk->SetBuffer(raw_copper->GetWholeBuffer(), raw_copper->TotalBufNwords(),
203  false, 1, 1);
204 #endif
205 
206  delete [] buf1;
207  delete [] buf2;
208  delete [] buf3;
209  delete [] buf4;
210 
211  //
212  // Update EventMetaData : Not affect on the output
213  //
214  m_eventMetaDataPtr.create();
215  m_eventMetaDataPtr->setExperiment(rawcprpacker_info.exp_num);
216  m_eventMetaDataPtr->setRun(rawcprpacker_info.run_subrun_num);
217  m_eventMetaDataPtr->setEvent(n_basf2evt);
218 
219 
220  //
221  // Monitor
222  //
223  if (max_nevt >= 0) {
224  if ((int)n_basf2evt >= max_nevt && max_nevt > 0) {
225  printf("[DEBUG] RunStop was detected. ( Setting: Max event # %d ) Processed Event %d \n",
226  max_nevt, n_basf2evt);
227  fflush(stdout);
228  m_eventMetaDataPtr->setEndOfData();
229  }
230  }
231 
232  if (n_basf2evt % 10000 == 0) {
233  double cur_time = getTimeSec();
234  double interval = cur_time - m_prev_time;
235  double total_time = cur_time - m_start_time;
236  if (n_basf2evt == 0) {
237  interval = 1;
238  }
239  printf("[INFO] Event %12d Rate %6.2lf[kHz] Recvd Flow %6.2lf[MB/s] RunTime %8.2lf[s] interval %8.4lf[s]\n",
240  n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC,
241  (n_basf2evt - m_prev_nevt)*NUM_EVT_PER_BASF2LOOP_PC / interval / 1.e3,
242  (m_totbytes - m_prev_totbytes) / interval / 1.e6,
243  total_time,
244  interval);
245  fflush(stdout);
246  m_prev_time = cur_time;
247  m_prev_totbytes = m_totbytes;
248  m_prev_nevt = n_basf2evt;
249 
250 
251  }
252 
253  n_basf2evt++;
254  RunInfoBuffer& status(DeSerializerModule::getStatus());
255  if (status.isAvailable()) {
256  status.addInputNBytes(1);
257  status.setInputCount(n_basf2evt);
258  }
259  return;
260 }
A class definition of an input module for Sequential ROOT I/O.
Base class for Modules.
Definition: Module.h:72
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 TotalBufNwords()
Get total length of m_buffer.
Definition: RawDataBlock.h:39
virtual int * GetWholeBuffer()
get pointer to buffer(m_buffer)
Definition: RawDataBlock.h:60
#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.