Belle II Software development
DesSer.h
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#ifndef DESSER_H
10#define DESSER_H
11
12#include <string>
13#include <vector>
14
15#include <sys/time.h>
16
17#include <daq/slc/readout/RunInfoBuffer.h>
18#include <daq/rawdata/CprErrorMessage.h>
19#include <daq/rawdata/modules/DAQConsts.h>
20#include <rawdata/dataobjects/PreRawCOPPERFormat_v2.h> // Should be the latest version before ver.4(PCIe40)
21#include <rawdata/switch_basf2_standalone.h>
22
23#include <daq/dataobjects/SendHeader.h>
24#include <daq/dataobjects/SendTrailer.h>
25
26#define BUF_SIZE_WORD 4800
27
29// From Serializer.cc
31
32
33namespace Belle2 {
41 class DesSer {
42
43 // Public functions
44 public:
45
47 DesSer();
48
49 // DesSer();
50 virtual ~DesSer();
51
52 void initialize(bool close_listen = true);
53
55 virtual void DataAcquisition() = 0;
56
58 void printData(int* buf, int nwords);
59
62
65
68
71
74
76 std::string m_dump_fname;
77
79 FILE* m_fp_dump;
80
83
85 int* m_bufary[ NUM_PREALLOC_BUF ];
86 // int* m_bufary[NUM_EVT_PER_BASF2LOOP];
87
89 int* getPreAllocBuf();
90
92 int* getNewBuffer(int nwords, int* delete_flag);
93
94 // For monitoring
95 timeval m_t0;
96 double m_recvd_totbytes;
97 double m_recvd_prev_totbytes;
98 double m_sent_totbytes;
99 double m_sent_prev_totbytes;
100 int m_ncycle;
102 double cur_time;
103
104 double m_start_time;
105 double m_prev_time;
106 int prev_event;
107
109 double getTimeSec();
110
112 void recordTime(int event, double* array);
113
115 unsigned int calcSimpleChecksum(int* buf, int nwords);
116
118 unsigned int calcXORChecksum(int* buf, int nwords);
119
120
121 void clearNumUsedBuf()
122 {
123 m_num_usedbuf = 0;
124 return ;
125 }
126
128 void RateMonitor(unsigned int nevt);
129
130
133
135 std::string m_nodename;
136
139
142
144 unsigned int m_exprunsubrun_no;
145
148
151
154
157
160
162 void shmOpen(char* path_cfg, char* path_sta);
163
165 int* shmGet(int fd, int size_words);
166
169
172
174 //int* m_cfg_buf;
176 //int* m_cfg_sta;
177
179
182
185
187 // static RunInfoBuffer g_status;
188 // RunInfoBuffer g_status;
189
191 PreRawCOPPERFormat_v2 m_pre_rawcpr; // Should be the latest version before ver.4(PCIe40)
192
194 // From Serializer.cc
196
199
201 void beginRun();
202
203 void endRun();
204 void terminate();
205
206 // int sendByWriteV(RawDataBlock* rawdblk);
207 int sendByWriteV(RawDataBlockFormat* rawdblk);
208 // void Connect(const char* hostname, const int port);
209 void Accept(bool close_listen = true);
210
211 // void fillSendHeaderTrailer(SendHeader* hdr, SendTrailer* trl, RawDataBlock* rawdblk);
212 void fillSendHeaderTrailer(SendHeader* hdr, SendTrailer* trl, RawDataBlockFormat* rawdblk);
213
214 // Data members
215
217 int Send(int socket, char* buf, int size_bytes);
218
219
222
225
228
231
232 protected :
234 // StoreArray<RawDataBlock> raw_datablkarray;
235
238
240 // std::vector<EvtSocketRecv*> m_recv;
241
243 std::vector<std::string> m_hostname_from;
244
246 std::vector<int> m_port_from;
247
248 std::vector<int> m_socket_recv;
249
250 // StoreArray<RawFTSW> raw_ftswarray;
251
252 // StoreArray<RawCOPPER> rawcprarray;
253
254 // StoreArray<ReducedRawCOPPER> rawcprarray;
255
256 int event_diff;
257
258 unsigned int m_prev_copper_ctr;
259
260 unsigned int m_prev_evenum;
261
263 // From Serializer.cc
265
268
269 enum {
270 COPPER = 1,
271 ROPC = 2
272 };
273
275 std::string m_hostname_local;
276
279
281 // EvtSocketSend* m_sock;
282
284 std::string p_method;
285 int p_method_val;
286
287#ifdef NONSTOP
289 int* m_ptr;
290
292 int m_run_no;
293
295 int m_prev_run_no;
296
298 int checkRunPause();
299
301 int checkRunRecovery();
302
304 void openRunPauseNshm();
305
307 void resumeRun();
308
310 void pauseRun();
311
313 void waitResume();
314
316 void callCheckRunPause(const std::string& err_str);
317
319 int CheckConnection(int socket);
320#endif
321
323 RawHeader_v2 tmp_header; // Should be the latest version before ver.4(PCIe40)
324
325 };
326
328} // end namespace Belle2
329
330#endif // DESSERCOPPER_H
A class definition of an input module for Sequential ROOT I/O.
Definition: DesSer.h:41
unsigned int calcSimpleChecksum(int *buf, int nwords)
calculate checksum
void shmOpen(char *path_cfg, char *path_sta)
open shared memory
Definition: DesSer.cc:679
int m_port_to
Destination port.
Definition: DesSer.h:278
RunInfoBuffer m_status
Run info buffer.
Definition: DesSer.h:141
std::string m_hostname_local
Destination Host.
Definition: DesSer.h:275
void beginRun()
Module functions to be called from event process.
void initializeNode()
Module functions to be called from main process.
unsigned int m_prev_exprunsubrun_no
run no.
Definition: DesSer.h:147
unsigned int calcXORChecksum(int *buf, int nwords)
calculate checksum
Definition: DesSer.cc:495
std::string m_nodename
Node Name for SLC.
Definition: DesSer.h:135
int * getPreAllocBuf()
Getbuffer.
Definition: DesSer.cc:57
int * shmGet(int fd, int size_words)
Get shared memory.
int m_start_flag
start flag
Definition: DesSer.h:181
int m_shmfd_cfg
file descripter for shm
Definition: DesSer.h:168
RawHeader_v2 tmp_header
which format is used
Definition: DesSer.h:323
int * m_cfg_buf
buffer for shared memory
Definition: DesSer.h:221
int * m_buffer
buffer
Definition: DesSer.h:82
std::vector< int > m_port_from
port # to connect data sources
Definition: DesSer.h:246
int m_data_type
data type
Definition: DesSer.h:153
DesSer()
Constructor / Destructor.
Definition: DesSer.cc:30
int n_basf2evt
No. of sent events.
Definition: DesSer.h:70
void RateMonitor(unsigned int nevt)
monitor rate
int m_trunc_mask
trunc mask
Definition: DesSer.h:156
int m_socket_send
Reciever Socket.
Definition: DesSer.h:267
PreRawCOPPERFormat_v2 m_pre_rawcpr
report status to SLC
Definition: DesSer.h:191
int m_exp_no
exp no.
Definition: DesSer.h:150
CprErrorMessage print_err
wrapper for B2LOG system
Definition: DesSer.h:184
int m_shmfd_sta
file descripter for shm
Definition: DesSer.h:171
int m_run_pause
flag to show that run-controller pauses a run
Definition: DesSer.h:227
void printData(int *buf, int nwords)
dump error data
Definition: DesSer.cc:505
int m_run_error
flag to show that there is some errors with which DAQ cannot continue.
Definition: DesSer.h:230
int * getNewBuffer(int nwords, int *delete_flag)
Getbuffer.
Definition: DesSer.cc:77
double cur_time
for time monitoring
Definition: DesSer.h:102
std::string m_dump_fname
dump filename
Definition: DesSer.h:76
int m_shmflag
Use shared memory.
Definition: DesSer.h:159
int monitor_numeve
buffer for shared memory
Definition: DesSer.h:178
virtual void DataAcquisition()=0
Module functions to be called from event process.
int m_prev_nevt
No. of prev sent events.
Definition: DesSer.h:73
void recordTime(int event, double *array)
store time info.
Definition: DesSer.cc:486
int m_num_usedbuf
Definition: DesSer.h:132
int * m_cfg_sta
buffer for shared memory
Definition: DesSer.h:224
int m_num_connections
check data contents
Definition: DesSer.h:237
int m_compressionLevel
Compression Level.
Definition: DesSer.h:67
int * m_bufary[NUM_PREALLOC_BUF]
buffer
Definition: DesSer.h:85
unsigned int m_exprunsubrun_no
run no.
Definition: DesSer.h:144
std::string p_method
EvtSocket.
Definition: DesSer.h:284
double max_seconds
time to stop a run
Definition: DesSer.h:64
FILE * m_fp_dump
dump file descripter
Definition: DesSer.h:79
int m_nodeid
Node ID for SLC.
Definition: DesSer.h:138
int max_nevt
Definition: DesSer.h:61
int Send(int socket, char *buf, int size_bytes)
send buffer
Definition: DesSer.cc:328
double getTimeSec()
store time info.
Definition: DesSer.cc:478
std::vector< std::string > m_hostname_from
Reciever basf2 Socket.
Definition: DesSer.h:243
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
The RawDataBlockFormat class Format information for rawdata handling.
The Raw Header class ver.1 ( the latest version since May, 2014 ) This class defines the format of th...
Definition: RawHeader_v2.h:32
Abstract base class for different kinds of events.