BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
BmnProfilometerSource.cxx
Go to the documentation of this file.
1
#include "
BmnProfilometerSource.h
"
2
3
BmnProfilometerSource::BmnProfilometerSource
(vector<string> addr, vector<string> boardIds)
4
:
fFirstEvent
(
kTRUE
)
5
,
keepWorking
(
kTRUE
)
6
,
isReceiving
(
kTRUE
)
7
,
fRunId
(0)
8
,
fPeriodId
(8)
9
,
fVerbosity
(0)
10
,
iEventNumber
(0)
11
,
isSpillStart
(true)
12
,
fArr
(nullptr)
13
,
fArrTemp
(nullptr)
14
,
fAddrs
(move(addr))
15
,
fBoardIds
(move(boardIds))
16
{}
17
18
BmnProfilometerSource::~BmnProfilometerSource
()
19
{
20
for
(
auto
& it :
fBoardsMap
)
21
delete
it.second;
22
}
23
24
Bool_t
BmnProfilometerSource::Init
()
25
{
26
printf(
"BmnProfilometerSource::Init()\n"
);
27
_ctx
= zmq_ctx_new();
28
// _rawSocket = zmq_socket(_ctx, ZMQ_SUB);
29
for
(
string
& addr :
fAddrs
) {
30
void
* raw_socket = zmq_socket(
_ctx
, ZMQ_SUB);
31
fRawSockets
.push_back(raw_socket);
32
if
(zmq_connect(raw_socket, addr.c_str()) != 0) {
33
// DBGERR("zmq connect")
34
fprintf(stderr,
"Error connecting to ZMQ socket: %s\n"
, strerror(errno));
35
return
kFALSE
;
36
}
else
{
37
printf(
"connected to %s\n"
, addr.c_str());
38
if
(zmq_setsockopt(raw_socket, ZMQ_SUBSCRIBE, NULL, 0) == -1) {
39
// DBGERR("zmq subscribe")
40
fprintf(stderr,
"Error subscribing to ZMQ socket: %s\n"
, strerror(errno));
41
return
kFALSE
;
42
}
43
}
44
}
45
46
FairRootManager* ioman = FairRootManager::Instance();
47
fArr
=
new
TClonesArray
(
BmnADCDigit<uint16_t>::Class
());
48
fArrTemp
=
new
TClonesArray
(
fArr
->GetClass());
49
ioman->RegisterInputObject(
"ADC192ASIC"
,
fArr
);
50
fEventHead
=
new
BmnEventHeader
();
51
ioman->RegisterInputObject(
"BmnEventHeader."
,
fEventHead
);
52
TPRegexp
re(
"\\w+(\\d+)"
);
53
for
(
string
&
id
:
fBoardIds
) {
54
ProfBoard
* b =
new
ProfBoard
();
55
TString
str(
id
);
56
re.
Substitute
(str,
"$1"
);
57
b->board_id = str.Atoi();
58
fBoardsMap
.insert(make_pair(
id
, b));
59
}
60
return
kTRUE
;
61
}
62
63
void
BmnProfilometerSource::Close
()
64
{
65
for
(
void
* rs :
fRawSockets
)
66
zmq_close(rs);
67
zmq_ctx_destroy(
_ctx
);
68
_ctx
= NULL;
69
}
70
71
Int_t
BmnProfilometerSource::ReadEvent
(UInt_t
i
)
72
{
73
fArr
->Delete();
74
if
(
fArrTemp
->GetEntriesFast() == 0) {
75
if
(
fVerbosity
)
76
printf(
"Empty\n"
);
77
ReceiveSpill
();
78
isSpillStart
=
true
;
79
iEventNumber
= 0;
80
}
81
// printf("entries before %d\n", fArrTemp->GetEntriesFast());
82
fArr
->AbsorbObjects(
fArrTemp
, 0, 0);
83
++
iEventNumber
;
84
fEventHead
->SetEventId(
iEventNumber
);
85
fEventHead
->SetSpillStart(
isSpillStart
);
86
if
(
isSpillStart
)
87
isSpillStart
=
false
;
88
// printf("entries after %d\n", fArrTemp->GetEntriesFast());
89
return
0;
90
}
91
92
void
BmnProfilometerSource::FillEventHeader
(
FairEventHeader
* feh)
93
{
94
return
;
95
}
96
97
BmnStatus
BmnProfilometerSource::ProcessBuffer
(uint32_t* word,
size_t
len,
ProfBoard
* board)
98
{
99
uint32_t holdb_temp = 0;
100
uint32_t holdb = 0;
101
// string str(reinterpret_cast<char*> (word), 6);
102
// printf("str %s\n", str.c_str());
103
for
(uint32_t
i
= 0;
i
< len;
i
++) {
104
uint32_t data = word[
i
];
105
// printf("data %08X i = %05u\n",data, i);
106
// Check is it data or a trigger:
107
if
(
BmnProfRawTools::data_or_trig
(data)) {
108
holdb =
BmnProfRawTools::holdb_cntr
(data);
// get holdb counter
109
if
(holdb_temp == holdb) {
110
// printf("data %08X\n", data);
111
// Divide ADC0 and ADC1 data
112
if
(!
BmnProfRawTools::adc_num
(data)) {
// 1st ADC
113
board->
adc1_word
.push_back(data);
114
}
else
if
(
BmnProfRawTools::adc_num
(data)) {
// 2nd ADC
115
board->
adc2_word
.push_back(data);
116
}
117
}
else
{
118
if
(board->
adc1_word
.size() ==
BmnProfRawTools::ChannelDigitCnt
())
119
new
((*fArrTemp)[
fArrTemp
->GetEntriesFast()])
120
BmnADCDigit<uint16_t>
(board->
board_id
, 0, std::move(board->
adc1_word
));
121
// if (board->adc2_word.size() == BmnProfRawTools::ChannelDigitCnt())
122
// new((*fArr)[fArr->GetEntriesFast()]) BmnADCDigit(board->board_id, 1,
123
// BmnProfRawTools::ChannelDigitCnt(), board->adc2_word);
124
// printf("adc1_word %lu\n", adc1_word.size());
125
// printf("adc1 %lu\n", adc1.size());
126
board->
adc1_word
.clear();
127
board->
adc2_word
.clear();
128
// Divide ADC0 and ADC1 data
129
if
(!
BmnProfRawTools::adc_num
(data)) {
// 1st ADC
130
board->
adc1_word
.push_back(data);
131
}
else
{
// 2nd ADC
132
board->
adc2_word
.push_back(data);
133
}
134
holdb_temp = holdb;
135
}
136
}
else
{
137
// if (BmnProfRawTools::trig_psd(data)) {
138
// trigger_pside.push_back(data);
139
// } else if (BmnProfRawTools::trig_nsd(data)) {
140
// trigger_nside.push_back(data);
141
// }
142
}
143
}
144
return
kBMNSUCCESS
;
145
}
146
147
BmnStatus
BmnProfilometerSource::ReceiveSpill
()
148
{
149
const
Int_t
MaxStrLen = 100;
150
bool
isIdFound =
kFALSE
;
151
bool
isHeaderFound =
kFALSE
;
152
bool
isTrailerFound =
kFALSE
;
153
string
BoardName;
154
ProfBoard
* Board =
nullptr
;
155
do
{
156
Int_t
recv_more = 0;
157
isIdFound =
kFALSE
;
158
do
{
159
// gSystem->ProcessEvents();
160
// fServer->ProcessRequests();
161
for
(
void
* rs :
fRawSockets
) {
162
zmq_msg_t msg;
163
zmq_msg_init(&msg);
164
Int_t
frame_size = zmq_msg_recv(&msg, rs, ZMQ_DONTWAIT);
// ZMQ_DONTWAIT
165
// printf("recv %d\n", frame_size);
166
if
(frame_size == -1) {
167
// printf("Receive error # %d #%s\n", errno, zmq_strerror(errno));
168
switch
(errno) {
169
case
EAGAIN:
170
// printf("EAGAIN\n");
171
usleep(50000);
172
break
;
173
case
EINTR:
174
if
(
fVerbosity
)
175
printf(
"EINTR\n"
);
176
isReceiving
=
kFALSE
;
177
keepWorking
=
kFALSE
;
178
if
(
fVerbosity
)
179
printf(
"Exit!\n"
);
180
break
;
181
case
EFAULT:
182
if
(
fVerbosity
)
183
printf(
"EFAULT\n"
);
184
zmq_close(rs);
185
isReceiving
=
kFALSE
;
186
keepWorking
=
kFALSE
;
187
break
;
188
default
:
189
break
;
190
}
191
}
else
{
192
if
(frame_size < MaxStrLen) {
193
string
str(
static_cast<
char
*
>
(zmq_msg_data(&msg)), zmq_msg_size(&msg));
194
// printf("str %s\n", str.c_str());
195
if
(isIdFound) {
196
if
(str ==
DataTrailer
) {
197
isTrailerFound =
kTRUE
;
198
if
(
fVerbosity
)
199
printf(
"trailer\n"
);
200
keepWorking
=
kFALSE
;
201
}
202
if
(str ==
DataHeader
) {
203
isHeaderFound =
kTRUE
;
204
if
(
fVerbosity
)
205
printf(
"header\n"
);
206
}
207
}
else
{
208
// if (str == TargetBoardId) {
209
BoardName = str;
210
auto
it =
fBoardsMap
.find(BoardName);
211
if
(it !=
fBoardsMap
.end())
212
Board = it->second;
213
isIdFound =
kTRUE
;
214
if
(
fVerbosity
)
215
printf(
"id %s\n"
, str.c_str());
216
// }
217
}
218
}
else
{
219
if
(isHeaderFound && Board) {
220
ProcessBuffer
(
static_cast<
uint32_t*
>
(zmq_msg_data(&msg)), zmq_msg_size(&msg) / 4, Board);
221
}
222
}
223
}
224
size_t
opt_size =
sizeof
(recv_more);
225
if
(zmq_getsockopt(rs, ZMQ_RCVMORE, &recv_more, &opt_size) == -1) {
226
printf(
"ZMQ socket options error #%s\n"
, zmq_strerror(errno));
227
return
kBMNERROR
;
228
}
229
// printf("ZMQ rcvmore = %d\n", recv_more);
230
zmq_msg_close(&msg);
231
}
232
}
while
(recv_more &&
isReceiving
&& (!isTrailerFound));
233
}
while
(
keepWorking
);
234
if
(
fVerbosity
)
235
printf(
"FullReceive\n"
);
236
if
(isTrailerFound) {
237
if
(
fVerbosity
)
238
printf(
"SPILLEND for %s\n"
, BoardName.c_str());
239
isHeaderFound =
kFALSE
;
240
isTrailerFound =
kFALSE
;
241
}
242
return
kBMNSUCCESS
;
243
}
i
int i
Definition
P4_F32vec4.h:22
Bool_t
bool Bool_t
Int_t
int Int_t
kFALSE
constexpr Bool_t kFALSE
kTRUE
constexpr Bool_t kTRUE
BmnStatus
BmnStatus
Define status code.
Definition
BmnEnums.h:93
kBMNERROR
@ kBMNERROR
Error.
Definition
BmnEnums.h:95
kBMNSUCCESS
@ kBMNSUCCESS
Success.
Definition
BmnEnums.h:94
BmnProfilometerSource.h
BmnADCDigit
Definition
BmnADCDigit.h:12
BmnEventHeader
Definition
BmnEventHeader.h:24
BmnProfRawTools::data_or_trig
static bool data_or_trig(const uint32_t &word)
Definition
BmnProfRawTools.cxx:16
BmnProfRawTools::ChannelDigitCnt
static constexpr const size_t ChannelDigitCnt()
Definition
BmnProfRawTools.h:20
BmnProfRawTools::holdb_cntr
static uint32_t holdb_cntr(const uint32_t &word)
Definition
BmnProfRawTools.cxx:21
BmnProfRawTools::adc_num
static bool adc_num(const bitset< 32 > &word)
Definition
BmnProfRawTools.cxx:41
BmnProfilometerSource::fEventHead
BmnEventHeader * fEventHead
Definition
BmnProfilometerSource.h:76
BmnProfilometerSource::fRawSockets
vector< void * > fRawSockets
Definition
BmnProfilometerSource.h:62
BmnProfilometerSource::ReadEvent
Int_t ReadEvent(UInt_t i=0)
Definition
BmnProfilometerSource.cxx:71
BmnProfilometerSource::fFirstEvent
Bool_t fFirstEvent
Definition
BmnProfilometerSource.h:64
BmnProfilometerSource::DataHeader
const string DataHeader
Definition
BmnProfilometerSource.h:55
BmnProfilometerSource::_ctx
void * _ctx
Definition
BmnProfilometerSource.h:60
BmnProfilometerSource::BmnProfilometerSource
BmnProfilometerSource(vector< string > addr={"tcp://159.93.49.126:5601", "tcp://159.93.49.126:5602"}, vector< string > boardIds={"board1", "board2"})
Definition
BmnProfilometerSource.cxx:3
BmnProfilometerSource::~BmnProfilometerSource
virtual ~BmnProfilometerSource()
Definition
BmnProfilometerSource.cxx:18
BmnProfilometerSource::fBoardIds
vector< string > fBoardIds
Definition
BmnProfilometerSource.h:80
BmnProfilometerSource::fRunId
Int_t fRunId
Definition
BmnProfilometerSource.h:69
BmnProfilometerSource::fPeriodId
Int_t fPeriodId
Definition
BmnProfilometerSource.h:70
BmnProfilometerSource::fArr
TClonesArray * fArr
Definition
BmnProfilometerSource.h:77
BmnProfilometerSource::isSpillStart
bool isSpillStart
Definition
BmnProfilometerSource.h:75
BmnProfilometerSource::FillEventHeader
void FillEventHeader(FairEventHeader *feh)
Definition
BmnProfilometerSource.cxx:92
BmnProfilometerSource::Init
Bool_t Init()
Definition
BmnProfilometerSource.cxx:24
BmnProfilometerSource::isReceiving
bool isReceiving
Definition
BmnProfilometerSource.h:67
BmnProfilometerSource::Close
void Close()
Definition
BmnProfilometerSource.cxx:63
BmnProfilometerSource::keepWorking
bool keepWorking
Definition
BmnProfilometerSource.h:66
BmnProfilometerSource::fVerbosity
Int_t fVerbosity
Definition
BmnProfilometerSource.h:72
BmnProfilometerSource::fBoardsMap
map< string, ProfBoard * > fBoardsMap
Definition
BmnProfilometerSource.h:82
BmnProfilometerSource::iEventNumber
Int_t iEventNumber
Definition
BmnProfilometerSource.h:74
BmnProfilometerSource::ReceiveSpill
BmnStatus ReceiveSpill()
Definition
BmnProfilometerSource.cxx:147
BmnProfilometerSource::DataTrailer
const string DataTrailer
Definition
BmnProfilometerSource.h:56
BmnProfilometerSource::fAddrs
vector< string > fAddrs
Definition
BmnProfilometerSource.h:79
BmnProfilometerSource::fArrTemp
TClonesArray * fArrTemp
Definition
BmnProfilometerSource.h:78
BmnProfilometerSource::ProcessBuffer
BmnStatus ProcessBuffer(uint32_t *word, size_t len, ProfBoard *board)
Definition
BmnProfilometerSource.cxx:97
FairEventHeader
TClonesArray
TObject::Class
static TClass * Class()
TPRegexp
TPRegexp::Substitute
Int_t Substitute(TString &s, const TString &replace, const TString &mods="", Int_t start=0, Int_t nMatchMax=10)
TString
ProfBoard
Definition
BmnProfilometerSource.h:31
ProfBoard::board_id
uint16_t board_id
Definition
BmnProfilometerSource.h:33
ProfBoard::adc2_word
vector< uint16_t > adc2_word
Definition
BmnProfilometerSource.h:36
ProfBoard::adc1_word
vector< uint16_t > adc1_word
Definition
BmnProfilometerSource.h:36
base
source
BmnProfilometerSource.cxx
Generated on
for BmnRoot by
1.17.0