BmnRoot
Loading...
Searching...
No Matches
BmnOnlineDecoder.cxx
Go to the documentation of this file.
1/*
2 * File: BmnOnlineDecoder.cxx
3 * Author: ilnur
4 *
5 * Created on January 11, 2017, 11:08 AM
6 */
7
8#include "BmnOnlineDecoder.h"
9
10#include <dirent.h>
11#include <regex>
12#include <signal.h>
13#include <sys/inotify.h>
14#include <thread>
15#include <zmq.h>
16// BmnRoot
17#include <BmnConverterTools.h>
18#include <BmnFileProp.h>
19#include <BmnGemStripDigit.h>
20#include <BmnTof1Digit.h>
21#include <BmnTrigDigit.h>
22#include <BmnVSPDigit.h>
23#include <RawTypes.h>
24
25namespace
26{
27int ReceivedSignal = 0;
28
29void signal_handler(int sig)
30{
31 ReceivedSignal = sig;
32 // fKeepWorking = false;
33 printf("Received signal %d Exiting\n", sig);
34}
35} // namespace
36
38 : _ctx(nullptr)
39 , fBmnSetup(kBMNSETUP)
40 , rawDataDecoder(nullptr)
41 , fRunID(UNKNOWN_RUNID)
42 , fKeepWorking(false)
43 , _do_process_stat_ev(false)
44 , _do_process_norm_ev(true)
45 , _digi_socket(RAW_DECODER_SOCKET_PORT)
46{}
47
49{
50 signal(SIGINT, SIG_DFL);
51 if (rawDataDecoder) {
52 rawDataDecoder->GetDecoder()->Finalize();
53 delete rawDataDecoder;
54 rawDataDecoder = nullptr;
55 }
56 if (_ctx) {
57 zmq_ctx_destroy(_ctx);
58 _ctx = NULL;
59 }
60}
61
62BmnStatus BmnOnlineDecoder::InitDecoder(string fRawFileName)
63{
64 return InitDecoder(TString(fRawFileName.data()));
65}
66
67BmnStatus BmnOnlineDecoder::InitDecoder(TString fRawFileName)
68{
69 DBG("started")
70 rawDataDecoder = new BmnRawDataDecoder(fRawFileName);
71 // rawDataDecoder->SetApplyThreshold();
72 Int_t runID = rawDataDecoder->GetRunId();
73 if (runID < 1) {
74 runID = rawDataDecoder->GetRunIdFromFile(_curFile);
75 // regex re(".*mpd_run_.*_(\\d+).data");
76 // string idstr = regex_replace(fRawFileName.Data(), re, "$1");
77 // runID = atoi(idstr.c_str());
78 if (runID < 0) {
79 printf("!!! Error Could not detect runID\n");
80 return kBMNERROR;
81 }
82 }
83 InitDecoder(runID);
84
85 DBG("fin")
86 return kBMNSUCCESS;
87}
88
89BmnStatus BmnOnlineDecoder::InitDecoder(uint32_t runID)
90{
91 LOGF(info, "InitDecoder runID = %d", runID);
92 if (!rawDataDecoder)
93 rawDataDecoder = new BmnRawDataDecoder();
94 rawDataDecoder->SetRunId(runID);
95 rawDataDecoder->SetPeriodId(fPeriodID);
96 rawDataDecoder->SetDetectorSetup(fDetectorSetup);
97 rawDataDecoder->SetBmnSetup(fBmnSetup);
98 rawDataDecoder->SetVerbose(1);
99 rawDataDecoder->CreateConverter();
100 rawDataDecoder->CreateDecoder();
101 rawDataDecoder->SetForwardMode();
102 BmnDecoder* decoder = rawDataDecoder->GetDecoder();
103 TString PeriodSetupExt = Form("%d%s.txt", fPeriodID, ((fBmnSetup == kBMNSETUP) ? "" : "_SRC"));
104 decoder->SetTrigPlaceMapping(TString("Trig_PlaceMap_Run") + PeriodSetupExt);
105 decoder->SetTrigChannelMapping(TString("Trig_map_Run") + PeriodSetupExt);
106 decoder->SetSiliconMapping(TString("SILICON_map_run") + PeriodSetupExt);
107 decoder->SetSiBTMapping(TString("SiBT_map_period") + PeriodSetupExt);
108 decoder->SetGemMapping(TString("GEM_map_run") + PeriodSetupExt);
109 decoder->SetCSCMapping(TString("CSC_map_period")
110 + Form("%d%s%s.txt", fPeriodID, ((fBmnSetup == kBMNSETUP) ? "" : "_SRC"),
111 (((decoder->GetRunId() < 7013) && (fPeriodID == 8)) ? "_before_run_7013" : "")));
112 decoder->SetVspMapping(TString("VSP_map_period") + PeriodSetupExt);
113 decoder->SetMSCMapping(TString("MSC_map_Run") + PeriodSetupExt);
114 // in case comment out the line decoder->SetTof400Mapping("...")
115 // the maps of TOF400 will be read from DB (only for JINR network)
116 decoder->SetTOF700ReferenceRun(7012);
117 decoder->SetTof700Geom(TString("TOF700_geometry_run") + PeriodSetupExt);
118 decoder->SetTof400Mapping(TString("TOF400_PlaceMap_RUN") + PeriodSetupExt,
119 TString("TOF400_StripMap_RUN") + PeriodSetupExt);
120 decoder->SetTof701Mapping(TString("TOF701_PlaceMap_RUN") + PeriodSetupExt,
121 TString("TOF701_StripMap_RUN") + PeriodSetupExt);
122 if (decoder->GetRunId() >= 4278 && decoder->GetPeriodId() == 7)
123 decoder->SetTof700Mapping(TString("TOF700_map_period_") + Form("%d_from_run_4278.txt", fPeriodID));
124 else
125 decoder->SetTof700Mapping(TString("TOF700_map_period_") + Form("%d.txt", fPeriodID));
126 decoder->SetScWallMapping(TString("SCWALL_map_period") + PeriodSetupExt);
127 decoder->SetScWallCalibration(TString("SCWALL_calibration_period") + PeriodSetupExt);
128 decoder->SetFHCalMapping(TString("FHCAL_map_period") + PeriodSetupExt);
129 decoder->SetFHCalCalibration(TString("FHCAL_calibration_period") + PeriodSetupExt);
130 decoder->SetHodoMapping(Form("HODO_map_period%d%s.json", fPeriodID, ((fBmnSetup == kBMNSETUP) ? "" : "_SRC")));
131 decoder->SetHodoCalibration(
132 Form("HODO_Q_calibration_period%d%s.json", fPeriodID, ((fBmnSetup == kBMNSETUP) ? "" : "_SRC")));
133 decoder->SetNdetMapping(TString("NDET_map_period") + PeriodSetupExt);
134 if ((decoder->GetRunId() >= 7506 && decoder->GetRunId() <= 7534)
135 || (decoder->GetRunId() >= 8203 && decoder->GetRunId() <= 8258))
136 decoder->SetNdetCalibration(TString("NDET_calibration_period")
137 + Form("%d_run_7506_7534_or_8203_8258.txt", fPeriodID));
138 else
139 decoder->SetNdetCalibration(TString("NDET_calibration_period") + PeriodSetupExt);
140 decoder->SetUseCalibFile(true);
141 if (_curFile.Length() > 0)
142 rawDataDecoder->InitConverter(_curDir + _curFile);
143 else
144 rawDataDecoder->InitConverter();
145 rawDataDecoder->ConnectForward();
146 BmnStatus iniStatus = rawDataDecoder->InitDecoder();
147 return iniStatus;
148}
149
150BmnStatus BmnOnlineDecoder::ConnectDataSocket()
151{
152 _socket_data = zmq_socket(_ctx, ZMQ_STREAM);
153 Char_t endpoint_addr[MAX_ADDR_LEN];
154 snprintf(endpoint_addr, MAX_ADDR_LEN, "tcp://%s", fDAQAddr.Data());
155 if (zmq_connect(_socket_data, endpoint_addr) != 0) {
156 DBGERR("zmq connect")
157 return kBMNERROR;
158 } else {
159 printf("Listening to %s\n", endpoint_addr);
160 }
161 // UInt_t rcvBufLen = MAX_BUF_LEN;
162 // Int_t rcvBuf = 0;
163 // size_t vl = sizeof(rcvBuf);
164 // if (zmq_setsockopt(_socket_data, ZMQ_RCVBUF, &rcvBufLen, sizeof(rcvBufLen)) == -1)
165 // DBGERR("zmq_setsockopt of ZMQ_RCVBUF")
166 // if (zmq_getsockopt(_socket_data, ZMQ_RCVBUF, &rcvBuf, &vl) == -1)
167 // DBGERR("zmq_getsockopt of ZMQ_RCVBUF")
168 // printf("data rcvbuf = %d\n", rcvBuf);
169 return kBMNSUCCESS;
170}
171
172BmnStatus BmnOnlineDecoder::ConnectDigiSocket()
173{
174 _decoSocket = zmq_socket(_ctx, ZMQ_PUB);
175 // _socket_mcast = zmq_socket(_ctx, ZMQ_XSUB);
176 // UInt_t sndBufLen = 8 * 1024 * 1024;
177 // if (zmq_setsockopt(_decoSocket, ZMQ_SNDBUF, &rcvBuf, sizeof(rcvBuf)) == -1)
178 // DBGERR("zmq_setsockopt of ZMQ_SNDBUF")
179 // rcvBuf = 0;
180 // if (zmq_getsockopt(_decoSocket, ZMQ_SNDBUF, &rcvBuf, &vl) == -1)
181 // DBGERR("zmq_getsockopt of ZMQ_RCVBUF")
182 // printf("digi sndbuf = %d\n", rcvBuf);
183
184 int32_t hwm = 5;
185 if (zmq_setsockopt(_decoSocket, ZMQ_SNDHWM, &hwm, sizeof(hwm)) == -1)
186 fprintf(stderr, "Error in zmq_setsockopt of ZMQ_SNDHWM: %s\n", strerror(errno));
187 size_t vl = sizeof(hwm);
188 if (zmq_getsockopt(_decoSocket, ZMQ_SNDHWM, &hwm, &vl) == -1)
189 fprintf(stderr, "Error getting ZMQ socket ZMQ_SNDHWM size: %s\n", strerror(errno));
190 printf("ZMQ_SND HWM %d\n", hwm);
191
192 TString localDecoStr = Form("tcp://*:%d", _digi_socket);
193 if (zmq_bind(_decoSocket, localDecoStr.Data()) != 0) {
194 DBGERR("zmq bind")
195 return kBMNERROR;
196 }
197 return kBMNSUCCESS;
198}
199
201{
202 DBG("started")
203 _ctx = zmq_ctx_new();
204 if (ConnectDataSocket() != kBMNSUCCESS)
205 return kBMNERROR;
206 if (ConnectDigiSocket() != kBMNSUCCESS)
207 return kBMNERROR;
208 return kBMNSUCCESS;
209}
210
212{
213 DBG("started")
214 // zmq_close(_socket_mcast);
215 zmq_close(_socket_data);
216 zmq_close(_decoSocket);
217 zmq_ctx_destroy(_ctx);
218 _ctx = NULL;
219 DBG("exit")
220 return kBMNFINISH;
221}
222
223BmnStatus BmnOnlineDecoder::Decode(TString dirname, TString startFile, Bool_t runCurrent)
224{
225 DBG("started")
226 _ctx = zmq_ctx_new();
227 _decoSocket = zmq_socket(_ctx, ZMQ_PUB);
228 Int_t rcvBuf = 0;
229 size_t vl = sizeof(rcvBuf);
230 if (zmq_getsockopt(_decoSocket, ZMQ_RCVBUF, &rcvBuf, &vl) == -1)
231 DBGERR("zmq_getsockopt of ZMQ_RCVBUF")
232 printf("rcvbuf = %d\n", rcvBuf);
233 // rcvBuf = 8192; //MAX_BUF_LEN;
234 // if (zmq_setsockopt(_decoSocket, ZMQ_RCVBUF, &rcvBuf, sizeof (rcvBuf)) == -1)
235 // DBGERR("zmq_setsockopt of ZMQ_RCVBUF")
236 // if (zmq_setsockopt(_decoSocket, ZMQ_SNDBUF, &rcvBuf, sizeof (rcvBuf)) == -1)
237 // DBGERR("zmq_setsockopt of ZMQ_SNDBUF")
238 // rcvBuf = 0;
239 // if (zmq_getsockopt(_decoSocket, ZMQ_RCVBUF, &rcvBuf, &vl) == -1)
240 // DBGERR("zmq_getsockopt of ZMQ_RCVBUF")
241 // printf("rcvbuf = %d\n", rcvBuf);
242 TString localDecoStr = Form("tcp://*:%d", RAW_DECODER_SOCKET_PORT);
243 if (zmq_bind(_decoSocket, localDecoStr.Data()) != 0) {
244 DBGERR("zmq bind")
245 return kBMNERROR;
246 }
247 _curFile = startFile;
248 _curDir = dirname;
249
250 if (!runCurrent) {
251 _curFile = "";
252 _curFile = WatchNext(_curDir, _curFile, RUN_FILE_CHECK_PERIOD);
253 _curFile = WatchNext(_curDir, _curFile, RUN_FILE_CHECK_PERIOD);
254 } else if (_curFile.Length() == 0) {
255 _curFile = WatchNext(_curDir, _curFile, RUN_FILE_CHECK_PERIOD);
256 }
257
258 while (kTRUE) {
259 if (InitDecoder(_curDir + _curFile) == kBMNERROR)
260 continue;
261 ProcessFileRun(_curDir + _curFile);
262 rawDataDecoder->GetDecoder()->Finalize();
263 delete rawDataDecoder;
264 rawDataDecoder = NULL;
265 // break; // @TODO Remove
266 _curFile = WatchNext(_curDir, _curFile, RUN_FILE_CHECK_PERIOD);
267 }
268 zmq_close(_decoSocket);
269 zmq_ctx_destroy(_ctx);
270 _ctx = NULL;
271 return kBMNSUCCESS;
272}
273
275{
276 DBG("started")
277 if (OpenStream() == kBMNERROR) {
278 LOGF(error, "Connection failed! Exit!");
279 return;
280 }
281 // UInt_t *buf = (UInt_t*) malloc(MAX_BUF_LEN);
282 Char_t conID[MAX_ADDR_LEN] = {0};
283 Int_t conID_size = 0;
284 UInt_t msg_len = 0;
285 Int_t frame_size = 0;
286 // Int_t iEv = 0;
287 // Int_t lastEv = -1;
288 fEvents = 0;
289 BmnStatus convertResult = kBMNSUCCESS;
290 Int_t sendRes = 0;
291 TBufferFile t(TBuffer::kWrite);
292 // UInt_t syncCounter = 0;
293 bool isListening = true;
294 fKeepWorking = true;
295 FILE* fp(nullptr);
296 // fp = fopen("sample.data", "w");
297 signal(SIGINT, signal_handler);
298 // signal(SIGTERM, signal_handler);
299
300 while ((!ReceivedSignal) && isListening /* && (msg_len > MAX_BUF_LEN)*/) {
301
302 conID_size = zmq_recv(_socket_data, &conID, sizeof(conID), ZMQ_DONTWAIT);
303 // printf("ID Recv %u\n", conID_size);
304 if (conID_size == -1) {
305 // printf("ID Receive error #%d : %s\n", errno, zmq_strerror(errno));
306 switch (errno) {
307 case EAGAIN:
308 usleep(MSG_TIMEOUT);
309 // else
310 // printf("no sleep\n");
311 break;
312 case EINTR:
313 printf("Interrupted!\n");
314 isListening = kFALSE;
315 printf("Exit cycle!\n");
316 continue;
317 break;
318 default:
319 printf("ID Receive error #%d : %s\n", errno, zmq_strerror(errno));
320 break;
321 }
322 } else {
323 LOGF(debug, "ID size = %d\n Id:%x\n", conID_size, conID);
324 }
325 // }
326 if (conID_size < 0)
327 continue;
328 zmq_msg_t msg;
329 zmq_msg_init(&msg);
330 Int_t recv_more = 0;
331 UInt_t* word;
332 bool isReceiving = true;
333 do {
334 frame_size = zmq_msg_recv(&msg, _socket_data, ZMQ_DONTWAIT); // ZMQ_DONTWAIT
335 // printf("recv %u\n", frame_size);
336 // frame_size = zmq_recv(_socket_data, buf, MAX_BUF_LEN, 0);
337 if (frame_size == -1) {
338 printf("Receive error # %d #%s\n", errno, zmq_strerror(errno));
339 switch (errno) {
340 case EAGAIN:
341 if ((msg_len < MPD_EVENT_HEAD_WORDS_OLD))
342 usleep(MSG_TIMEOUT);
343 break;
344 case EINTR:
345 printf("EINTR\n");
346 isReceiving = kFALSE;
347 isListening = kFALSE;
348 printf("Exit!\n");
349 break;
350 case EFAULT:
351 printf("EFAULT\n");
352 zmq_close(_socket_data);
353 ConnectDataSocket();
354 isReceiving = kFALSE;
355 break;
356 default:
357 break;
358 }
359 } else {
360 if (frame_size) {
361 if (msg_len + frame_size > MAX_BUF_LEN) {
362 printf("buf overflow! msg len %u frame size %u\n", msg_len, frame_size);
363 printf("Something wrong! Exit!\n");
364 isReceiving = kFALSE;
365 isListening = kFALSE;
366 msg_len = 0;
367 // if (msg_len % kNBYTESINWORD) {
368 // printf("Something wrong! Resetting buffer!\n");
369 // msg_len = 0;
370 // } else {
371 // UInt_t dropped = msg_len + frame_size - MAX_BUF_LEN;
372 // msg_len -= dropped;
373 // printf("Frame_size %u\t Message length %d, dropped %d bytes\n",
374 // frame_size, msg_len, dropped); memmove(buf, &buf[frame_size],
375 // msg_len);
376 // }
377 }
378 memcpy(buf + msg_len, zmq_msg_data(&msg), frame_size);
379 msg_len += frame_size;
380 // fwrite(zmq_msg_data(&msg), 1, zmq_msg_size(&msg), fp);
381 // printf("msg_len = %d\n", msg_len);
382 }
383 }
384 size_t opt_size = sizeof(recv_more);
385 if (zmq_getsockopt(_socket_data, ZMQ_RCVMORE, &recv_more, &opt_size) == -1) {
386 printf("ZMQ socket options error #%s\n", zmq_strerror(errno));
387 isReceiving = false;
388 }
389 // printf("ZMQ rcvmore = %d\n", recv_more);
390 zmq_msg_close(&msg);
391 } while ((!ReceivedSignal) && recv_more && isReceiving);
392
393 if (msg_len < MPD_EVENT_HEAD_WORDS_OLD * sizeof(UInt_t))
394 continue;
395 UInt_t iWord = 0;
396 Bool_t evExit = false;
397 UInt_t lenBytes = 0;
398 UInt_t lenWords = 0;
399 UInt_t runID = 0;
400 word = reinterpret_cast<UInt_t*>(buf);
401 while (isListening && (!ReceivedSignal) && (iWord < msg_len / kNBYTESINWORD) && (!evExit)
402 && (msg_len > MPD_EVENT_HEAD_WORDS_OLD))
403 {
404 UInt_t val = *(word + iWord);
405 switch (val) {
406 case SYNC_RUN_START:
407 printf("iWord = %u\n", iWord);
408 printf("start run\n");
409 lenWords = *(word + ++iWord) / sizeof(UInt_t);
410 printf("payLen = %u words\n", lenWords);
411 if (lenWords + iWord > MAX_BUF_LEN) {
412 printf("Wrong payload size!\n");
413 lenBytes = iWord * sizeof(UInt_t);
414 msg_len -= lenBytes;
415 printf(" %u will move by %u bytes. skip wrong header\n", msg_len, lenBytes);
416 memmove(&buf[0], &buf[lenBytes], msg_len);
417 iWord = 0;
418 break;
419 }
420 BmnConverterTools::ParseComplexTLV((word + ++iWord), lenWords, runID);
421 printf("runID = %u\n", runID);
422 if (fRunID != runID) {
423 AddRun2DB();
424 if (StartNewRun(runID))
425 break;
426 }
427 iWord += lenWords;
428 lenBytes = iWord * sizeof(UInt_t);
429 msg_len -= lenBytes;
430 memmove(&buf[0], &buf[lenBytes], msg_len);
431 iWord = 0;
432 // evExit = kTRUE;
433 break;
434 case SYNC_RUN_STOP:
435 printf("iWord = %u\n", iWord);
436 printf("stop run\n");
437 lenWords = *(word + ++iWord) / sizeof(UInt_t);
438 printf("payLen = %d words\n", lenWords);
439 if (lenWords + iWord > MAX_BUF_LEN) {
440 printf("Wrong payload size!\n");
441 lenBytes = iWord * sizeof(UInt_t);
442 msg_len -= lenBytes;
443 printf(" %u will move by %u bytes\n", msg_len, lenBytes);
444 memmove(&buf[0], &buf[lenBytes], msg_len);
445 iWord = 0;
446
447 break;
448 }
449 BmnConverterTools::ParseComplexTLV((word + ++iWord), lenWords, runID);
450 fRunID = runID;
451 AddRun2DB();
452 if (rawDataDecoder) {
453 rawDataDecoder->GetDecoder()->Finalize();
454 delete rawDataDecoder;
455 rawDataDecoder = NULL;
456 }
457 iWord += lenWords;
458 lenBytes = iWord * sizeof(UInt_t);
459 msg_len -= lenBytes;
460 // printf(" %u will move by %u bytes\n", msg_len, lenBytes);
461 memmove(&buf[0], &buf[lenBytes], msg_len);
462 iWord = 0;
463 // evExit = kTRUE;
464 break;
465 case SYNC_EVENT:
466 case SYNC_EVENT_OLD:
467 lenBytes = *(word + ++iWord);
468 lenWords = lenBytes / kNBYTESINWORD + (fPeriodID <= 7 ? 1 : 0);
469 if (msg_len / kNBYTESINWORD
470 >= lenWords + iWord + (fPeriodID > 7 ? MPD_EVENT_HEAD_WORDS : MPD_EVENT_HEAD_WORDS_OLD))
471 {
472 // printf(ANSI_COLOR_BLUE "SYNC_EVENT\n" ANSI_COLOR_RESET);
474 // printf("lenBytes == %u\n", lenBytes);
475 // printf("msg_len == %u\n", msg_len);
476 // printf("lenWords == %u\n", lenWords);
477 // // printf("captured enough\n");
478 if (!rawDataDecoder) {
479 printf("Init without run header!\n");
480 if (InitDecoder(fRunID) == kBMNERROR) {
481 printf("\n\tError in InitDecoder !!\n\n");
482 // evExit = kTRUE;
483 break;
484 }
485 }
486 if (_do_process_norm_ev) {
487 // rawDataDecoder->SetRunId(fRunID);
488 convertResult = rawDataDecoder->ConvertRawToRootIterate(word + ++iWord, lenWords);
489 // printf(" convertResult %d \n", convertResult);
490 if (convertResult == kBMNERROR) {
491 printf("convert failed\n");
492 // evExit = kTRUE;
493 lenBytes = (iWord - 1) * sizeof(UInt_t);
494 // lenBytes = iWord * sizeof (UInt_t);
495 msg_len -= lenBytes;
496 printf(" %u will move by %u bytes. after conv failed\n", msg_len, lenBytes);
497 memmove(&buf[0], &buf[lenBytes], msg_len);
498 iWord = 0;
499 break;
500 }
501 BmnStatus decostat = rawDataDecoder->DecodeDataToDigiIterate();
502 // printf(" decostat %d \n", decostat);
503 fEvents++;
504 if (decostat == kBMNSUCCESS) {
505 DigiArrays iterDigi = rawDataDecoder->GetDecoder()->GetDigiArraysObject();
506 BmnEventHeader* head = iterDigi.header;
507 if (head) {
508 if (fRunID != head->GetRunId()) {
509 if (StartNewRun(head->GetRunId()))
510 break;
511 }
512 if (head->GetEventType() == kBMNPAYLOAD) {
513 t.WriteObject(&iterDigi);
514 sendRes = zmq_send(_decoSocket, t.Buffer(), t.Length(), ZMQ_NOBLOCK);
515 // printf("sendRes %d\n", sendRes);
516 t.Reset();
517 if (sendRes == -1) {
518 printf("Send error # %d : %s\n", errno, zmq_strerror(errno));
519 }
520 }
521 }
522 }
523 }
524 iWord += lenWords;
525 lenBytes = iWord * sizeof(UInt_t);
526 // printf("msg_len %8u lenBytes %8u bytes. after deco\n", msg_len,
527 // lenBytes);
528 msg_len -= lenBytes;
529 // printf(" %8u will move by %8u bytes. after deco\n", msg_len,
530 // lenBytes);
531 memmove(&buf[0], &buf[lenBytes], msg_len);
532 iWord = 0;
533 } else {
534 // printf("Not enough data in the buffer!\n");
535 iWord = 0;
536 evExit = kTRUE;
537 }
538 break;
539 case SYNC_STAT: // just skip at this point
540 // printf(ANSI_COLOR_BLUE "STAT\n" ANSI_COLOR_RESET);
541 lenBytes = *(word + ++iWord);
542 lenBytes = lenBytes + (fPeriodID <= 7 ? kNBYTESINWORD : 0);
543 lenWords = lenBytes / kNBYTESINWORD;
544 if (msg_len >= lenBytes + iWord * kNBYTESINWORD + MPD_EVENT_HEAD_WORDS * kNBYTESINWORD) {
545 // // printf("iWord == %7u STAT\n", iWord);
546 // printf("lenBytes == %u\n", lenBytes);
547 // printf("msg_len == %u\n", msg_len);
548 // printf("lenWords == %u\n", lenWords);
549 // ++iWord; // if other is commented
550
551 if (_do_process_stat_ev) {
552 if (!rawDataDecoder) {
553 printf("Init without run header!\n");
554 if (InitDecoder(fRunID) == kBMNERROR) {
555 printf("\n\tError in InitDecoder !!\n\n");
556 // evExit = kTRUE;
557 break;
558 }
559 }
560 convertResult = rawDataDecoder->ConvertRawToRootIterate(word + ++iWord, lenWords);
561 // convertResult = rawDataDecoder->ConvertStatEvent(word +
562 // ++iWord, lenWords);
563 // printf("stat convertResult %d \n", convertResult);
564 rawDataDecoder->GetRawConverter()->SetRawEventStat();
565 if (convertResult == kBMNERROR) {
566 printf("stat convert failed\n");
567 // evExit = kTRUE;
568 lenBytes = iWord * sizeof(UInt_t);
569 msg_len -= lenBytes;
570 // printf(" %u will move by %u bytes. after conv failed\n",
571 // msg_len, lenBytes);
572 memmove(&buf[0], &buf[lenBytes], msg_len);
573 iWord = 0;
574 break;
575 }
576 BmnStatus decostat = rawDataDecoder->DecodeDataToDigiIterate();
577 // printf(" decostat %d \n", decostat);
578 fEvents++;
579 if (decostat == kBMNSUCCESS) {
580 DigiArrays iterDigi = rawDataDecoder->GetDecoder()->GetDigiArraysObject();
581 BmnEventHeader* head = iterDigi.header;
582 if (head) {
583 // printf("EventId == %u\n", head->GetEventId());
584 // if (head->GetEventType() == kBMNPAYLOAD) {
585 t.WriteObject(&iterDigi);
586 sendRes = zmq_send(_decoSocket, t.Buffer(), t.Length(), ZMQ_NOBLOCK);
587 // printf("sendRes %d\n", sendRes);
588 t.Reset();
589 if (sendRes == -1) {
590 printf("Send error # %d : %s\n", errno, zmq_strerror(errno));
591 }
592 // }
593 }
594 }
595 // iWord += lenWords;
596 lenBytes += (iWord - 1) * kNBYTESINWORD;
597 // lenBytes += iWord * kNBYTESINWORD;
598 // lenBytes = iWord * sizeof (UInt_t);
599 }
600 msg_len -= lenBytes;
601 // printf(" %u will move by %u bytes. after stat\n", msg_len, lenBytes);
602 memmove(&buf[0], &buf[lenBytes], msg_len);
603 iWord = 0;
604 } else {
605 // printf("Not enough data in the buffer!\n");
606 iWord = 0;
607 evExit = kTRUE;
608 }
609 break;
610 case SYNC_JSON:
611 // printf(ANSI_COLOR_BLUE "SYNC_JSON\n" ANSI_COLOR_RESET);
612 lenBytes = *(word + ++iWord);
613 // // lenWords = lenBytes / kNBYTESINWORD + (fPeriodID <= 7 ?
614 // 1 : 0);
615 if (msg_len >= lenBytes + iWord * kNBYTESINWORD) {
616 // printf("iWord == %7u JSON\n", iWord);
617 // printf("lenBytes == %u\n", lenBytes);
618 // printf("msg_len == %u\n", msg_len);
619 // ++iWord; // if other is commented
620 if (!rawDataDecoder) {
621 printf("Init without run header!\n");
622 if (InitDecoder(fRunID) == kBMNERROR) {
623 printf("\n\tError in InitDecoder !!\n\n");
624 // evExit = kTRUE;
625 break;
626 }
627 }
628 rawDataDecoder->GetRawConverter()->ParseJsonTLV(word + ++iWord, lenBytes);
629 // lenBytes += (iWord-1) * kNBYTESINWORD;
630 lenBytes += iWord * kNBYTESINWORD;
631 word = reinterpret_cast<UInt_t*>(buf + lenBytes);
632 msg_len -= lenBytes;
633 // printf(" %u will move by %u bytes\n", msg_len, lenBytes);
634 memmove(&buf[0], &buf[lenBytes], msg_len);
635 iWord = 0;
636 } else {
637 // printf("Not enough data in the buffer!\n");
638 iWord = 0;
639 evExit = kTRUE;
640 }
641 break;
642 default:
643 // printf("unrecognized sync %08X\n", *(word + iWord));
644 iWord++;
645 break;
646 }
647 }
648 if (iWord >= MAX_BUF_LEN) {
649 printf("Wrong data, resetting array!\n");
650 msg_len = 0;
651 }
652 }
653 CloseStream();
654
655 if (fp != NULL) {
656 fclose(fp);
657 printf("I: file closed\n\r");
658 }
659 DBG("exit")
660 signal(SIGINT, SIG_DFL);
661}
662
663BmnStatus BmnOnlineDecoder::StartNewRun(uint32_t runID)
664{
665 fRunID = runID;
666 LOGF(info, "fRunID %u\n", fRunID);
667 if (rawDataDecoder) {
668 rawDataDecoder->GetDecoder()->Finalize();
669 delete rawDataDecoder;
670 rawDataDecoder = NULL;
671 }
672 if (InitDecoder(runID) == kBMNERROR) {
673 printf("\n\tError in InitDecoder !!\n\n");
674 if (rawDataDecoder) {
675 delete rawDataDecoder;
676 rawDataDecoder = NULL;
677 }
678 return kBMNERROR;
679 }
680 return kBMNSUCCESS;
681}
682
683BmnStatus BmnOnlineDecoder::AddRun2DB()
684{
685 if (fRunID == UNKNOWN_RUNID)
686 return kBMNERROR; // do not store unknown run
687 if (!rawDataDecoder)
688 return kBMNSUCCESS;
689 TTimeStamp fRunStartTime = rawDataDecoder->GetRunStartTime();
690 TTimeStamp fRunEndTime = rawDataDecoder->GetRunEndTime();
691 TDatime fFileStartDate(Int_t(fRunStartTime.GetDate(kFALSE)), Int_t(fRunStartTime.GetTime(kFALSE)));
692 TDatime fFileEndDate(Int_t(fRunEndTime.GetDate(kFALSE)), Int_t(fRunEndTime.GetTime(kFALSE)));
693 Int_t event_count = rawDataDecoder->GetEventId();
694 printf("\tEvCnt %d\n", event_count);
695 printf("\tStartTime %s\n", fRunStartTime.AsString());
696 printf("\t EndTime %s\n", fRunEndTime.AsString());
697 UniRun* pRun = UniRun::GetRun(fPeriodID, fRunID);
698 if (!pRun) {
699 pRun = UniRun::CreateRun(fPeriodID, fRunID, 0, fFileStartDate, &fFileEndDate, nullptr, nullptr, nullptr,
700 nullptr, &event_count, nullptr, 1);
701 if (pRun)
702 cout << "New run has been successfully created in the Condition Database with number " << fPeriodID << ":"
703 << fRunID << endl;
704 else
705 return kBMNERROR;
706 } else {
707 printf("Run %8u is already found in the DB.\n", fRunID);
708 printf("\tStartTime %s\n", pRun->GetStartDatetime().AsString());
709 printf("\t EndTime %s\n", pRun->GetEndDatetime() ? pRun->GetEndDatetime()->AsString() : "");
710 printf("\t Events %d\n", pRun->GetEventCount() ? *pRun->GetEventCount() : -1);
711 // if ()
712 if ((pRun->GetEndDatetime()) || (event_count == 0))
713 return kBMNSUCCESS; // do nothing (probably our data is invalid)
714 pRun->SetStartDatetime(fFileStartDate);
715 printf("writing StartTime %s\n", fFileStartDate.AsString());
716
717 // if (!pRun->GetEndDatetime())
718 pRun->SetEndDatetime(&fFileEndDate);
719 printf("writing EndTime %s\n", fFileEndDate.AsString());
720 // if (!pRun->GetEventCount())
721 pRun->SetEventCount(&event_count);
722 printf("writing EvCnt %d\n", event_count);
723 }
724 delete pRun;
725 return kBMNSUCCESS;
726}
727
728void BmnOnlineDecoder::ProcessFileRun(TString rawFileName, UInt_t timeLimit)
729{
730 DBG("start")
731 // UInt_t iEv = 0;
732 // UInt_t lastEv = 0;
733 BmnStatus convertResult = kBMNSUCCESS;
734 Int_t sendRes = 0;
735 TBufferFile t(TBuffer::kWrite);
736 while (!ReceivedSignal) {
737 convertResult = rawDataDecoder->GetRawConverter()->ConvertRawToRootIterateFileRead();
738 if (convertResult == kBMNFINISH) {
739 printf("finish\n");
740 break;
741 }
742 if (convertResult == kBMNERROR) {
743 printf("Converting error\n");
744 break;
745 }
746 // lastEv = iEv;
747 // iEv = rawDataDecoder->GetEventId();
748 // if (iEv > lastEv) {
749 /*BmnStatus decodeResult = */ rawDataDecoder->DecodeDataToDigiIterate();
750 // printf("iev %u convert %d decode %d\n", iEv, convertResult, decodeResult);
751 fEvents++;
752 DigiArrays iterDigi = rawDataDecoder->GetDecoder()->GetDigiArraysObject();
753 if (iterDigi.header == NULL)
754 continue;
755 // BmnEventHeader* head = (BmnEventHeader*) iterDigi.header;
756 // if (head->GetEventType() != kBMNPAYLOAD)
757 // continue;
758 t.WriteObject(&iterDigi);
759 sendRes = zmq_send(_decoSocket, t.Buffer(), t.Length(), ZMQ_NOBLOCK);
760 t.Reset();
761 if (sendRes == -1) {
762 printf("Send error %d #%s\n", errno, zmq_strerror(errno));
763 }
764 // }
765 if (convertResult == kBMNTIMEOUT) {
766 printf("timeout\n");
767 break;
768 }
769 // break;
770 }
771}
772
773TString BmnOnlineDecoder::WatchNext(TString dirname, TString filename, Int_t cycleWait)
774{
775 DBG("started")
776 struct dirent** namelist;
777 regex re("\\w+\\.data");
778 Int_t n;
779 TString ret;
780 while (kTRUE) {
781 n = scandir(dirname.Data(), &namelist, 0, versionsort);
782 if (n < 0)
783 perror("scandir");
784 else {
785 for (Int_t i = 0; i < n; ++i) {
786 if (regex_match(namelist[i]->d_name, re))
787 ret = namelist[i]->d_name;
788 free(namelist[i]);
789 }
790 free(namelist);
791 }
792 if (strcmp(filename.Strip().Data(), ret.Strip().Data()) != 0)
793 return ret;
794 gSystem->ProcessEvents();
795 usleep(cycleWait);
796 }
797
798 return ret;
799}
800
801TString BmnOnlineDecoder::WatchNext(Int_t inotifDir, Int_t cycleWait)
802{
803 TString fileName = "";
804 Char_t evBuf[INOTIF_BUF_LEN];
805 while (kTRUE) {
806 Int_t len, i = 0;
807 len = read(inotifDir, evBuf, INOTIF_BUF_LEN);
808 if ((len == -1) && (errno != EAGAIN))
809 DBG("inotify read error!")
810 else {
811 while (i < len) {
812 struct inotify_event* event = (struct inotify_event*)&evBuf[i];
813 if (event->len) {
814 if ((event->mask & IN_CREATE) && !(event->mask & IN_ISDIR)) {
815 fileName = TString(event->name);
816 printf("File %s was created!\n", fileName.Data());
817 break;
818 }
819 }
820 i += sizeof(struct inotify_event) + event->len;
821 }
822 if (cycleWait > 0)
823 usleep(cycleWait);
824 else
825 break;
826 }
827 gSystem->ProcessEvents();
828 }
829 return fileName;
830}
831
833{
834 _curDir = dirname;
835 _ctx = zmq_ctx_new();
836 _decoSocket = zmq_socket(_ctx, ZMQ_PUB);
837 TString localDecoStr = Form("tcp://*:%d", RAW_DECODER_SOCKET_PORT);
838 if (zmq_bind(_decoSocket, localDecoStr.Data()) != 0) {
839 DBGERR("zmq bind")
840 return kBMNERROR;
841 }
842 struct dirent** namelist;
843 const regex re(".*_run_.*_(\\d+).*.data");
844
845 // vector<TString> fileNames;
846 vector<pair<BmnFileProp, string>> fileNames;
847 Int_t runCount = 0;
848 Int_t n;
849 n = scandir(_curDir, &namelist, 0, versionsort);
850 LOGF(info, "Found %d files for batch decoding", n);
851 if (n < 0) {
852 perror("scandir");
853 return kBMNERROR;
854 } else {
855 for (Int_t i = 0; i < n; ++i) {
856 if (ReceivedSignal)
857 break;
858 if (regex_match(namelist[i]->d_name, re)) {
859 BmnFileProp prop;
860 string file_name(namelist[i]->d_name);
861 if (BmnConverterTools::ParseRawFileName(file_name, prop) == kBMNERROR)
862 continue;
863 fileNames.emplace_back(make_pair(move(prop), move(file_name)));
864 }
865 }
866 std::sort(fileNames.begin(), fileNames.end(), [](auto& a, auto& b) {
867 if (a.first.GetRunId() < b.first.GetRunId())
868 return true;
869 else if (a.first.GetRunId() == b.first.GetRunId()) {
870 if (a.first.GetFileId() < b.first.GetFileId())
871 return true;
872 else if ((a.first.GetFileId() == b.first.GetFileId())
873 && (a.first.GetEventOrder() < b.first.GetEventOrder()))
874 return true;
875 }
876 return false;
877 });
878 for (auto& pf : fileNames) {
879 LOGF(info, "raw file: %s", pf.second.data());
880 _curFile = TString(pf.second.data());
881 int32_t runID = pf.first.GetRunId();
882 if ((runID > 7281) || (runID < 1)) {
883 if (runCount == 0) {
884 if (InitDecoder(_curDir + _curFile) == kBMNERROR)
885 continue;
886 } else {
887 if (rawDataDecoder) {
888 rawDataDecoder->GetDecoder()->Finalize();
889 delete rawDataDecoder;
890 rawDataDecoder = NULL;
891 }
892 if (InitDecoder(_curDir + _curFile) == kBMNERROR) {
893 printf("\n\tError in InitDecoder !!\n\n");
894 if (rawDataDecoder) {
895 delete rawDataDecoder;
896 rawDataDecoder = NULL;
897 }
898 // evExit = kTRUE;
899 continue;
900 }
901 }
902 ProcessFileRun(_curFile, 0);
903 runCount++;
904 } else {
905 continue;
906 }
907 }
908 free(namelist);
909 }
910 zmq_close(_decoSocket);
911 zmq_ctx_destroy(_ctx);
912 _ctx = NULL;
913 return kBMNSUCCESS;
914}
915
917{
918 uint32_t data_port = 21323;
919 signal(SIGINT, signal_handler);
920 _curDir = dirname;
921 struct dirent** namelist;
922 const regex re(".*_run_.*_(\\d+).*.data");
923
924 // vector<TString> fileNames;
925 vector<pair<BmnFileProp, string>> fileNames;
926 Int_t n;
927 n = scandir(_curDir, &namelist, 0, versionsort);
928 LOGF(info, "Found %d files for batch decoding", n);
929 if (n < 0) {
930 perror("scandir");
931 return kBMNERROR;
932 } else {
933 for (Int_t i = 0; i < n; ++i) {
934 if (ReceivedSignal)
935 break;
936 if (regex_match(namelist[i]->d_name, re)) {
937 BmnFileProp prop;
938 string file_name(namelist[i]->d_name);
939 if (BmnConverterTools::ParseRawFileName(file_name, prop) == kBMNERROR)
940 continue;
941 fileNames.emplace_back(make_pair(move(prop), move(file_name)));
942 }
943 }
944 std::sort(fileNames.begin(), fileNames.end(), [](auto& a, auto& b) {
945 if (a.first.GetRunId() < b.first.GetRunId())
946 return true;
947 else if (a.first.GetRunId() == b.first.GetRunId()) {
948 if (a.first.GetFileId() < b.first.GetFileId())
949 return true;
950 else if ((a.first.GetFileId() == b.first.GetFileId())
951 && (a.first.GetEventOrder() < b.first.GetEventOrder()))
952 return true;
953 }
954 return false;
955 });
956 for (auto& pf : fileNames) {
957 if (ReceivedSignal)
958 break;
959 if (pf.first.GetRunId() < 7281)
960 continue;
961 LOGF(info, "raw file: %s", pf.second.data());
962 _curFile = TString(pf.second.data());
963 int ret = system(Form("socat -u FILE:%s TCP4-LISTEN:%u,reuseaddr", (_curDir + _curFile).Data(), data_port));
964 if (ret)
965 LOGF(info, "Socat error code: %d", ret);
966 }
967 free(namelist);
968 }
969 zmq_close(_decoSocket);
970 zmq_ctx_destroy(_ctx);
971 _ctx = NULL;
972 signal(SIGINT, SIG_DFL);
973 return kBMNSUCCESS;
974}
975
976Int_t BmnOnlineDecoder::GetRunIdFromName(TString name)
977{
978 TPRegexp re(".*\\w+_\\w+_\\w+_(\\d+)[^/]*\\.data");
979 // TPRegexp re(".*mpd_run_.*_(\\d+).data");
980 TObjArray* subStr = re.MatchS(name.Data());
981 if (subStr->GetEntriesFast() > 1) {
982 TString str = ((TObjString*)subStr->At(1))->GetString();
983 Int_t runID = atoi(str.Data());
984 subStr->Delete();
985 delete subStr;
986 return runID;
987 } else {
988 delete subStr;
989 return -1;
990 }
991}
992
993void BmnOnlineDecoder::StripView(TString OrigFileName,
994 TString TestFileName,
995 uint32_t periodID,
996 uint32_t runID,
997 BmnSetup fSetup,
998 bool FillOccupancy)
999{
1000 gStyle->SetOptStat(0);
1001 // Int_t sumMods = 0;
1002 // Int_t maxLayers = 0;
1003 bool set_bin_content = !FillOccupancy;
1004
1005 TString fnames[STRIP_COMP_COLS] = {OrigFileName, TestFileName};
1006 TString treeNames[STRIP_COMP_COLS] = {"bmndata", "bmndata"};
1007 TString hdrNames[STRIP_COMP_COLS] = {"BmnEventHeader.", "BmnEventHeader."};
1008 TString runhdrNames[STRIP_COMP_COLS] = {"DigiRunHeader", "DigiRunHeader"};
1009 TString silNames[STRIP_COMP_COLS] = {"SILICON", "SILICON"};
1010 TString gemNames[STRIP_COMP_COLS] = {"GEM", "GEM"};
1011 TString cscNames[STRIP_COMP_COLS] = {"CSC", "CSC"};
1012 TString sibtNames[STRIP_COMP_COLS] = {"SiBT", "SiBT"};
1013 TString vspNames[STRIP_COMP_COLS] = {"VSP", "VSP"};
1014 TFile* files[STRIP_COMP_COLS] = {NULL};
1015 TTree* trees[STRIP_COMP_COLS] = {NULL};
1016 // TClonesArray * hits[STRIP_COMP_COLS] = {NULL};
1017 // TClonesArray * tracks[STRIP_COMP_COLS] = {NULL};
1018 DigiRunHeader* runHeaders[STRIP_COMP_COLS] = {NULL, NULL};
1019 BmnEventHeader* headers[STRIP_COMP_COLS] = {NULL, NULL};
1020 TClonesArray* silDigit[STRIP_COMP_COLS] = {NULL, NULL};
1021 TClonesArray* gemDigit[STRIP_COMP_COLS] = {NULL, NULL};
1022 TClonesArray* cscDigit[STRIP_COMP_COLS] = {NULL, NULL};
1023 TClonesArray* sibtDigit[STRIP_COMP_COLS] = {NULL, NULL};
1024 TClonesArray* vspDigit[STRIP_COMP_COLS] = {NULL, NULL};
1025 vector<vector<vector<TH1F*>>> histStrip[STRIP_COMP_COLS];
1026 vector<vector<vector<TH1F*>>> histStripGem[STRIP_COMP_COLS];
1027 vector<vector<vector<TH1F*>>> histStripCsc[STRIP_COMP_COLS];
1028 vector<vector<vector<TH1F*>>> histStripSiBT[STRIP_COMP_COLS];
1029 vector<vector<vector<TH1F*>>> histStripVSP[STRIP_COMP_COLS];
1030 TCanvas* canStrip = nullptr;
1031 TCanvas* canStripGem = nullptr;
1032 TCanvas* canStripCsc = nullptr;
1033 TCanvas* canStripSiBT = nullptr;
1034 TCanvas* canStripVSP = nullptr;
1035 vector<PadInfo*> canStripPads;
1036 vector<PadInfo*> canStripPadsGem;
1037 vector<PadInfo*> canStripPadsCsc;
1038 vector<PadInfo*> canStripPadsSiBT;
1039 vector<PadInfo*> canStripPadsVSP;
1040
1041 // ********************
1042 // init pads and canvases
1043 // ********************
1044 auto stationSetFSD(BmnSiliconStationSet::Create(periodID, fSetup));
1045 InitCanvas("Silicon", stationSetFSD, canStrip, canStripPads, histStrip);
1046 auto stationSetGEM(BmnGemStripStationSet::Create(periodID, fSetup));
1047 InitCanvas("GEM", stationSetGEM, canStripGem, canStripPadsGem, histStripGem);
1048 auto stationSetCSC(BmnCSCStationSet::Create(periodID, fSetup));
1049 InitCanvas("CSC", stationSetCSC, canStripCsc, canStripPadsCsc, histStripCsc);
1050 unique_ptr<BmnSiBTStationSet> stationSetSiBT(BmnSiBTStationSet::Create(periodID, fSetup));
1051 InitCanvas("SiBT", stationSetSiBT, canStripSiBT, canStripPadsSiBT, histStripSiBT);
1052 auto stationSetVSP(BmnVSPStationSet::Create(periodID, fSetup));
1053 InitCanvas("VSP", stationSetVSP, canStripVSP, canStripPadsVSP, histStripVSP);
1054
1055 // ********************
1056 // Trees processing
1057 // ********************
1058
1059 Int_t curEv = 0;
1060 // Int_t preEv = 0;
1061 Long64_t nEvs = LONG_MAX;
1062 for (Int_t i = 0; i < STRIP_COMP_COLS; i++) {
1063 if (fnames[i].Length() == 0)
1064 continue;
1065 files[i] = new TFile(fnames[i], "READ");
1066 if (files[i]->IsOpen())
1067 printf("file %s opened\n", fnames[i].Data());
1068 else {
1069 fprintf(stderr, "file %s open error\n", fnames[i].Data());
1070 return;
1071 }
1072 trees[i] = (TTree*)files[i]->Get(treeNames[i]);
1073 nEvs = Min(nEvs, trees[i]->GetEntries());
1074 cout << "#recorded entries = " << trees[i]->GetEntries() << endl;
1075 if (i > 0)
1076 runHeaders[i] = (DigiRunHeader*)files[i]->Get(runhdrNames[i].Data());
1077 // runHeaders[i]);
1078 trees[i]->SetBranchAddress(hdrNames[i], &headers[i]);
1079 trees[i]->SetBranchAddress(silNames[i], &silDigit[i]);
1080 trees[i]->SetBranchAddress(gemNames[i], &gemDigit[i]);
1081 trees[i]->SetBranchAddress(cscNames[i], &cscDigit[i]);
1082 trees[i]->SetBranchAddress(sibtNames[i], &sibtDigit[i]);
1083 trees[i]->SetBranchAddress(vspNames[i], &vspDigit[i]);
1084 }
1085 for (Int_t i = 0; i < STRIP_COMP_COLS; i++) {
1086 if (trees[i] == nullptr)
1087 continue;
1088 cout << "tree # " << i << endl;
1089 if (i > 0 && runHeaders[i]) {
1090 printf("START (event 1):\t%s\n", runHeaders[i]->GetRunStartTime().AsString());
1091 printf("FINISH (event %lld):\t%s\n", nEvs, runHeaders[i]->GetRunEndTime().AsString());
1092 }
1093 for (Int_t iEv = 0; iEv < nEvs; iEv++) {
1094 trees[i]->GetEntry(iEv);
1095 if (iEv % 10000 == 0)
1096 cout << "iEv = " << iEv << endl;
1097 BmnEventHeader* hdr = (BmnEventHeader*)headers[i];
1098 // preEv = curEv;
1099 curEv = hdr->GetEventId();
1100 // if (curEv - preEv > 1)
1101 // printf("Events between %d & %d missed\n", preEv, curEv);
1102 if (silDigit[i])
1103 FillHists<BmnSiliconDigit>(histStrip[i], silDigit[i], set_bin_content);
1104 if (gemDigit[i])
1105 FillHists<BmnGemStripDigit>(histStripGem[i], gemDigit[i], set_bin_content);
1106 if (cscDigit[i])
1107 FillHists<BmnCSCDigit>(histStripCsc[i], cscDigit[i], set_bin_content);
1108 if (sibtDigit[i])
1109 FillHists<BmnSiBTDigit>(histStripSiBT[i], sibtDigit[i], set_bin_content);
1110 if (vspDigit[i])
1111 FillHists<BmnVSPDigit>(histStripVSP[i], vspDigit[i], set_bin_content);
1112 }
1113 printf("Last event %d\n", curEv);
1114 }
1115 if (canStrip) {
1116 BmnHist::DrawRef(canStrip, &canStripPads);
1117 canStrip->SaveAs(Form("can-run-%d-sil.png", runID));
1118 }
1119 if (canStripGem) {
1120 BmnHist::DrawRef(canStripGem, &canStripPadsGem);
1121 canStripGem->SaveAs(Form("can-run-%d-gem.png", runID));
1122 }
1123 if (canStripCsc) {
1124 BmnHist::DrawRef(canStripCsc, &canStripPadsCsc);
1125 canStripCsc->SaveAs(Form("can-run-%d-csc.png", runID));
1126 }
1127 if (canStripSiBT) {
1128 BmnHist::DrawRef(canStripSiBT, &canStripPadsSiBT);
1129 canStripSiBT->SaveAs(Form("can-run-%d-sibt.png", runID));
1130 }
1131 if (canStripVSP) {
1132 BmnHist::DrawRef(canStripVSP, &canStripPadsVSP);
1133 canStripVSP->SaveAs(Form("can-run-%d-vsp.png", runID));
1134 }
1135}
#define ZMQ_STREAM
int i
Definition P4_F32vec4.h:22
BmnStatus
Definition BmnEnums.h:24
@ kBMNTIMEOUT
Definition BmnEnums.h:27
@ kBMNFINISH
Definition BmnEnums.h:28
@ kBMNERROR
Definition BmnEnums.h:26
@ kBMNSUCCESS
Definition BmnEnums.h:25
BmnSetup
Definition BmnEnums.h:89
@ kBMNSETUP
Definition BmnEnums.h:90
@ kBMNPAYLOAD
Definition BmnEnums.h:71
#define DBGERR(a)
Definition BmnMath.h:25
#define DBG(a)
Definition BmnMath.h:24
const uint32_t SYNC_RUN_START
Definition RawTypes.h:10
const uint32_t SYNC_EVENT
Definition RawTypes.h:5
const uint32_t SYNC_STAT
Definition RawTypes.h:7
const uint32_t SYNC_JSON
Definition RawTypes.h:9
const uint32_t SYNC_RUN_STOP
Definition RawTypes.h:11
const uint32_t kNBYTESINWORD
Definition RawTypes.h:19
const uint32_t SYNC_EVENT_OLD
Definition RawTypes.h:6
static unique_ptr< BmnCSCStationSet > Create(Int_t period, Int_t stp=0)
static BmnStatus ParseComplexTLV(UInt_t *buf, UInt_t &len, UInt_t &runId)
static BmnStatus ParseRawFileName(TString s, BmnFileProp &prop)
void SetVspMapping(TString map)
Definition BmnDecoder.h:176
void SetTOF700ReferenceRun(Int_t n)
Definition BmnDecoder.h:120
UInt_t GetPeriodId() const
Definition BmnDecoder.h:134
void SetTof700Geom(TString geom)
Definition BmnDecoder.h:192
void SetFHCalCalibration(TString cal)
Definition BmnDecoder.h:207
void SetFHCalMapping(TString map)
Definition BmnDecoder.h:205
void SetMSCMapping(TString map)
Definition BmnDecoder.h:225
void SetTof701Mapping(TString PlaceMap, TString StripMap)
Definition BmnDecoder.h:184
void SetUseCalibFile(bool v)
Definition BmnDecoder.h:243
void SetNdetCalibration(TString cal)
Definition BmnDecoder.h:215
void SetTrigPlaceMapping(TString map)
Definition BmnDecoder.h:160
UInt_t GetRunId() const
Definition BmnDecoder.h:132
void SetGemMapping(TString map)
Definition BmnDecoder.h:174
void SetHodoCalibration(TString cal)
Definition BmnDecoder.h:211
void SetTof700Mapping(TString map)
Definition BmnDecoder.h:190
void SetTrigChannelMapping(TString file)
Definition BmnDecoder.h:168
void SetScWallMapping(TString map)
Definition BmnDecoder.h:201
void SetCSCMapping(TString map)
Definition BmnDecoder.h:166
BmnStatus Finalize()
void SetSiliconMapping(TString map)
Definition BmnDecoder.h:162
void SetTof400Mapping(TString PlaceMap, TString StripMap)
Definition BmnDecoder.h:178
void SetScWallCalibration(TString cal)
Definition BmnDecoder.h:203
void SetHodoMapping(TString map)
Definition BmnDecoder.h:209
void SetNdetMapping(TString map)
Definition BmnDecoder.h:213
void SetSiBTMapping(TString map)
Definition BmnDecoder.h:164
DigiArrays GetDigiArraysObject()
Definition BmnDecoder.h:86
UInt_t GetEventId()
BmnEventType GetEventType()
static unique_ptr< BmnGemStripStationSet > Create(Int_t period, Int_t stp=0)
static void DrawRef(unique_ptr< TCanvas > &canGemStrip, vector< PadInfo * > *canGemStripPads)
Definition BmnHist.cxx:15
static void StripView(TString OrigFileName, TString TestFileName, uint32_t periodID=8, uint32_t runID=0, BmnSetup fSetup=kBMNSETUP, bool FillOccupancy=true)
BmnStatus BatchDirectoryToSocket(TString dirname)
BmnStatus Decode(TString dirname, TString startFile, Bool_t runCurrent)
BmnStatus BatchDirectory(TString dirname)
void SetDetectorSetup(std::map< DetectorId, bool > setup)
void SetPeriodId(UInt_t v)
BmnDecoder * GetDecoder() const
UInt_t GetEventId() const
void SetVerbose(Int_t v)
BmnStatus DecodeDataToDigiIterate()
void SetBmnSetup(BmnSetup v)
BmnStatus InitConverter(TString FileName)
void SetRunId(UInt_t v)
BmnStatus ConvertRawToRootIterate(UInt_t *buf, UInt_t len)
BmnRawSource * GetRawConverter() const
TTimeStamp GetRunStartTime() const
void SetForwardMode(bool v=true)
TTimeStamp GetRunEndTime() const
static Int_t GetRunIdFromFile(TString name)
void SetRawEventStat()
BmnStatus ParseJsonTLV(UInt_t *buf, UInt_t &len)
BmnStatus ConvertRawToRootIterateFileRead()
static unique_ptr< BmnSiBTStationSet > Create(Int_t period, Int_t stp=0)
static unique_ptr< BmnSiliconStationSet > Create(Int_t period, Int_t stp=0)
static unique_ptr< BmnVSPStationSet > Create(Int_t period, Int_t stp=0)
BmnEventHeader * header
Definition DigiArrays.h:146
static UniRun * GetRun(int period_number, int run_number)
get run from the database
Definition UniRun.cxx:177
int SetEndDatetime(TDatime *end_datetime)
set end datetime of the current run
Definition UniRun.cxx:543
TDatime * GetEndDatetime()
get end datetime of the current run
Definition UniRun.h:105
TDatime GetStartDatetime()
get start datetime of the current run
Definition UniRun.h:103
static UniRun * CreateRun(int period_number, int run_number, int run_type, TDatime start_datetime, TDatime *end_datetime, TString beam_particle, TString target_particle, double *energy, double *field_voltage, int *event_count, int *geometry_id, int run_quality)
add new run to the database
Definition UniRun.cxx:67
int * GetEventCount()
get event count of the current run
Definition UniRun.h:133
int SetEventCount(int *event_count)
set event count of the current run
Definition UniRun.cxx:732
int SetStartDatetime(TDatime start_datetime)
set start datetime of the current run
Definition UniRun.cxx:510
#define UNKNOWN_RUNID
Definition BmnDecoder.h:49
#define MAX_ADDR_LEN
#define MAX_BUF_LEN
#define MSG_TIMEOUT
#define RAW_DECODER_SOCKET_PORT
#define RUN_FILE_CHECK_PERIOD
#define STRIP_COMP_COLS
#define MPD_EVENT_HEAD_WORDS_OLD
#define MPD_EVENT_HEAD_WORDS
#define RAW_DECODER_SOCKET_PORT
#define INOTIF_BUF_LEN
name
Definition setup.py:7