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