12#include "FairLogger.h"
39namespace fs = std::filesystem;
40using namespace std::chrono;
96 LOG(debug) <<
"RunId " << prop.
GetRunId() <<
" got from props";
99 LOG(debug) <<
"subname " << subName;
128 printf(
"\n!!!!!\ncannot open file %s\nConvertRawToRoot stopped\n!!!!!\n\n",
fRawFileName.Data());
133 printf(
"\nRAW FILE: ");
135 printf(
"\nRAW FILE LENGTH: ");
137 std::string fileType{};
153 bool convertMSC =
conf.get<
bool>(
"Decoder.ProcessMSC",
false);
176 LOGF(error,
"\n!!!!!\ncannot open file %s\nConvertRawToRoot are stopped\n!!!!!\n",
fRawFileName.Data());
181 printf(
"\nRAW FILE: ");
183 printf(
"\nRAW FILE LENGTH: ");
185 std::string fileType{};
201 LOGF(info,
"InitConverter without file");
204 LOGF(debug,
"fRawTree %p init", (
void*)
fRawTree);
205 LOGF(debug,
"fRawTree path %s",
fRawTree->GetDirectory()->GetPath());
208 int threadNumber = 0;
209 if (threadNumber == 0) {
210 if (std::thread::hardware_concurrency() <= 1)
213 threadNumber = std::thread::hardware_concurrency() - 1;
216 for (
int i = 0;
i < threadNumber;
i++)
219 bool convertMSC =
conf.get<
bool>(
"Decoder.ProcessMSC",
false);
235 LOGF(debug1,
"%s ", __func__);
330 const DeviceHeader* dh =
reinterpret_cast<const DeviceHeader*
>(d + idx);
334 string str(
reinterpret_cast<const char*
>(d + idx), str_len);
335 json j = json::parse(str);
338 for (json::iterator it = j.begin(); it != j.end(); ++it) {
340 string jkey(it.key());
342 if (!jkey.compare(
"status")) {
343 auto& j_runtime = it.value()[
"runTime"];
344 auto j_spill = j_runtime[
"spill"];
345 Int_t phase =
static_cast<Int_t>(j_spill[
"phase"]);
347 auto wr = j_runtime[
"time"][
"WR"];
362 LOGF(info,
"JSON status phase %d", phase);
369 std::tie(spill_it, inserted) =
fSpillMap.insert(
372 .start_ts = ss.start_ts,
373 .stop_ts = ss.start_ts}));
374 LOGF(debug,
"spill record inserted %d", inserted);
381 std::ofstream outfile(
Form(
"j_%s_%d_%9d_%09d_%02X_%08X_phase_%d_%s.json", jkey.c_str(),
fRunId, sec,
382 ns, dh->DeviceId, dh->Serial, phase,
fSubName.Data()),
383 std::ofstream::binary);
384 outfile << std::setw(4) << j << std::endl;
387 metadata->SpillStatusVec().push_back(move(ss));
389 LOGF(info,
"JSON config");
390 if (!jkey.compare(
"config")) {
391 string start_DT = it.value()[
"meta"][
"startDateTime"];
393 std::ofstream outfile(
Form(
"j_%s_%d_%s_%02X_%08X.json", jkey.c_str(),
fRunId, start_DT.data(),
394 dh->DeviceId, dh->Serial),
395 std::ofstream::binary);
396 outfile << std::setw(4) << j << std::endl;
402 LOGF(error,
"Parsing JSON config failed!");
404 LOGF(info,
"Unknown json key %s", jkey.data());
407 }
catch (std::exception& ex) {
408 LOGF(error,
"Exception for JSON block: %s", ex.what());
441 LOGF(info,
"Input is raw root file. Nothing to do!");
445 LOGF(error,
"Init converter failed!");
500 if ((pRawFiles !=
nullptr) && (pRawFiles->
GetEntries() == 0)) {
502 cout <<
"CRITICAL WARNING: there are overlaps in events for the new file metadata: " <<
fRawFileName
503 <<
" (" << period_id <<
":" << run_id <<
" " << start_event <<
"-" << end_event <<
")" << endl
504 <<
"PLEASE, SEND THE INFO TO THE SOFTWARE COORDINATOR" << endl;
511 if (strFileHash !=
"")
512 pFileHash =
new TString(strFileHash);
514 cout <<
"WARNING: a problem occurred while calculating checksum for the raw file: " <<
fRawFileName
524 cout <<
"Raw file information has been successfully added to the Condition Database for run "
525 << period_id <<
":" << run_id <<
" and event interval " << start_event <<
"-" << end_event << endl;
534 if (pRawFiles !=
nullptr) {
536 cout <<
"CRITICAL WARNING: there are more than one records for the file metadata: " <<
fRawFileName
538 <<
"PLEASE, SEND THE INFO TO THE SOFTWARE COORDINATOR" << endl;
542 cout <<
"CRITICAL WARNING: there are different start event for the file metadata: "
543 <<
fRawFileName <<
" (" << period_id <<
":" << run_id <<
" " << start_event <<
"-"
544 << end_event <<
")" << endl
545 <<
"PLEASE, SEND THE INFO TO THE SOFTWARE COORDINATOR" << endl;
546 else if (pExistingRawFile->
GetEndEvent() < end_event)
547 cout <<
"CRITICAL WARNING: the existing file metadata has 'end event' less than: "
548 <<
fRawFileName <<
" (" << period_id <<
":" << run_id <<
" " << start_event <<
"-"
549 << end_event <<
")" << endl
550 <<
"PLEASE, SEND THE INFO TO THE SOFTWARE COORDINATOR" << endl;
557 }
catch (std::exception& ex) {
558 printf(
"Exception of working with the Condition Database: %s\n", ex.what());
614 LOGF(error,
"WTF?? in the main event: fDat == %u",
fDat);
661 LOGF(error,
"WTF?? in the STAT: fDat == %u",
fDat);
663 LOGF(debug3,
"STAT ev length bytes %d",
fDat);
674 LOGF(info,
"RUN START");
677 LOGF(info,
"RUN STOP");
685 LOGF(info,
"FILE BEGIN");
688 LOGF(info,
"FILE END");
698 LOGF(debug,
"SYNC JSON len %u",
fDat);
704 LOGF(error,
"unrecognized sync %08X",
fDat);
752 const DeviceHeader* dh =
reinterpret_cast<const DeviceHeader*
>(d + idx);
753 LOGF(debug2,
"[%u / %u]", idx, len);
755 uint32_t serial = dh->Serial;
756 uint8_t
id = dh->DeviceId;
757 uint32_t payload = dh->GetNWords();
759 if (payload > 2000000) {
761 LOGF(warn,
"Event %d:\n serial = 0x%06X\n id = Ox%02X\n payload = %d",
fEventId, serial,
id, payload);
765 LOGF(debug4,
"STAT iev %7u idx %6u/%6u idev %02X serial 0x%08X payload %4u",
fEventId, idx, len,
id,
806 LOGF(warning,
"Malformed data from ADC64VE %08X in the event %u", serial,
fEventId);
814 LOGF(warning,
"Malformed data from ADC64WR %08X in the event %u", serial,
fEventId);
834 if (payload + idx > len) {
836 "Error in the event #%d: 0x%08X : %2X device payload length mismatch! pauload %5u idx/len: %5u/%5u \n",
837 fEventId, serial,
id, payload, idx, len);
878 LOGF(debug2,
"FVME serial %08X len %u", serial, len);
881 LOGF(debug,
"Stat FVME serial %08X efter iEv %u", serial,
fEventId);
886 for (uint32_t
i = 0;
i < len;
i++) {
904 modId = (d[
i] >> 16) & 0x7F;
905 slot = (d[
i] >> 23) & 0x1F;
912 if (!((d[
i] >> 16) & 0x1))
914 if (!((d[
i] >> 17) & 0x1))
916 if (!((d[
i] >> 18) & 0x1))
918 if (!((d[
i] >> 19) & 0x1))
959 uint32_t nSmpl = (len - 3) / nWords;
961 for (uint32_t iSmpl = 0; iSmpl < nSmpl; ++iSmpl) {
962 for (uint32_t iWord = 0; iWord < nWords; ++iWord) {
963 uint32_t word32 = d[3 + iWord + iSmpl * nWords];
964 for (
Int_t iCh = 0; iCh < 32; ++iCh) {
965 if (word32 &
BIT(iCh)) {
967 new (ar_hrb[
hrb->GetEntriesFast()])
BmnHRBDigit(serial, iCh + 32 * iWord, iSmpl, tH, tL);
978 uint32_t type = d[idx] >> 28;
990 if (type ==
kWORDAUX && !countersDone) {
999 countersDone =
kTRUE;
1002 type = d[idx] >> 28;
1011 uint32_t type = d[idx] >> 28;
1015 LOGF(warning,
"TDC (modID 0x%02X serial 0x%08X slot %d tdcID %d) error flags: 0x%04X", modId, serial,
1016 slot, ((d[idx] >> 24) & 0xF), (d[idx] & ((1 << 15) - 1)));
1017 if ((d[idx] &
BIT(12)) || (d[idx] &
BIT(13))) {
1018 LOGF(warning,
"TDC data loss in 0x%08X ", serial);
1024 uint32_t tdcId = (d[idx] >> 24) & 0xF;
1026 (modId ==
kTDC64V) ? (d[idx] & 0x7FFFF) : ((d[idx] & 0x7FFFF) << 2) | ((d[idx] & 0x180000) >> 19);
1027 uint32_t channel = (modId ==
kTDC64V) ? (d[idx] >> 19) & 0x1F : (d[idx] >> 21) & 0x7;
1030 new (ar_tdc[
tdc->GetEntriesFast()])
1033 LOGF(debug4,
"tdc %08X : %d channel %d", serial, slot, channel);
1036 type = d[idx] >> 28;
1043 uint32_t type = d[idx] >> 28;
1048 uint32_t channel = 0;
1050 vector<int16_t> valI;
1055 LOGF(warning,
"In event %8u: TDC (serial 0x%08X slot %d tdcID %d) error flags: 0x%04X",
fEventId,
1056 serial, slot, ((d[idx] >> 24) & ((1 << 4) - 1)), (d[idx] & ((1 << 15) - 1)));
1057 if ((d[idx] &
BIT(12)) || (d[idx] &
BIT(13))) {
1058 LOGF(warning,
"\tTQDC data loss in 0x%08X ", serial);
1063 uint32_t mode = (d[idx] >> 26) & 0x3;
1066 channel = (d[idx] >> 19) & 0x1F;
1067 uint32_t time = ((d[idx] & 0x7FFFF) << 2) | ((d[idx] >> 24) & 0x3);
1069 new ((*tqdc_tdc)[
tqdc_tdc->GetEntriesFast()])
1072 }
else if ((type == 4) && (mode != 0)) {
1073 channel = (d[idx] >> 19) & 0x1F;
1074 if (d[idx] &
BIT(16)) {
1075 adcTimestamp = d[idx] & 0xFFFF;
1078 trigTimestamp = d[idx] & 0xFFFF;
1081 tdcTimestamp = d[idx] & 0xFFF;
1089 if ((type == 5) && (mode == 2) ) {
1090 Short_t val = (d[idx] & ((1 << 14) - 1)) - (1 << (14 - 1));
1092 valI.push_back(val);
1094 new ((*tqdc_adc)[
tqdc_adc->GetEntriesFast()])
1095 BmnTQDCADCDigit(serial, channel, slot, std::move(valI), trigTimestamp, adcTimestamp);
1101 type = d[++idx] >> 28;
1112 vector<int16_t> valI;
1113 const uint8_t NBytesInSample = 2;
1115 while (iWord < len) {
1116 uint16_t adcTS = d[iWord] & (
BIT(16) - 1);
1117 uint16_t SigLen = d[iWord] >> 16;
1118 uint16_t NSamples = SigLen / NBytesInSample;
1121 if (iWord + NSampleWords + 1 > len) {
1122 LOGF(error,
"TQDC ADC wrong payload length! iWord %u SigLen %u len %u", iWord, SigLen, len);
1125 uint16_t iSampleWord = 0;
1126 while (iSampleWord++ < NSampleWords) {
1127 int16_t adcLo =
static_cast<int16_t
>(d[iWord + iSampleWord] & (
BIT(16) - 1));
1128 int16_t adcHi =
static_cast<int16_t
>(d[iWord + iSampleWord] >> 16);
1129 valI.push_back(adcLo);
1130 if (valI.size() < NSamples)
1131 valI.push_back(adcHi);
1135 iWord += iSampleWord;
1148 uint16_t tdcLine = 0;
1149 while (tdcLine < len) {
1150 uint32_t word = d[tdcLine];
1151 uint32_t bt = word >> 28;
1168 uint8_t channel = (word >> 21) & (
BIT(7) - 1);
1170 uint32_t time = word & (
BIT(21) - 1);
1178 LOGF(warning,
"TDC (serial 0x%08X tdcID %d) in event %u error flags: 0x%04X %s", serial,
1179 ((word >> 24) & ((1 << 4) - 1)),
fEventId, (word & ((1 << 15) - 1)),
1180 ((word &
BIT(12)) || (word &
BIT(13))) ?
"data lost" :
"");
1194 const MStreamTAI* ms0 =
reinterpret_cast<const MStreamTAI*
>(d + index);
1201 while (index < len) {
1202 const TqdcDataHeader* th =
reinterpret_cast<const TqdcDataHeader*
>(d + index);
1207 switch (th->DataType) {
1215 printf(
"Wrong TQDC data type %u !\n", th->DataType);
1229 const MStreamTAI* ms0 =
reinterpret_cast<const MStreamTAI*
>(d + index);
1235 while (index < len) {
1236 uint8_t dtype = d[index] >> 28;
1237 bool overflow = d[index] &
BIT(16);
1248 printf(
"Wrong VXS data type %u !\n", dtype);
1262 const MStreamTAI* ms0 =
reinterpret_cast<const MStreamTAI*
>(d + index);
1269 while (index < len) {
1270 uint8_t dtype = d[index] >> 28;
1271 bool overflow = d[index] &
BIT(16);
1285 printf(
"Wrong TTVXS data type %u !\n", dtype);
1297 return MapVSP(d, dev_hdr);
1301 LOGF(error,
"BmnRawSource::ProcessGenericDevice: Unknown device serial 0x%08X", dev_hdr->Serial);
1311 const uint16_t* words =
reinterpret_cast<const uint16_t*
>(d);
1312 size_t total_words = len /
sizeof(uint16_t);
1314 if (FairLogger::GetLogger()->IsLogNeeded(fair::Severity::debug4)) {
1315 for (
size_t i = 0;
i < total_words; ++
i)
1316 LOGF(debug4,
"0x%04x", words[
i]);
1320 std::vector<uint16_t> event_words;
1321 std::unique_ptr<BmnHgndRaw::FIFO_block> event;
1323 while (index < total_words) {
1324 auto* word = words + index;
1326 LOGF(error,
"BmnRawSource::FillTDC250HGND: Wrong header 0x%04X", *word);
1333 LOGF(debug4,
"Event type %d, 16bit words %d (index=%zu, total=%zu)", (uint32_t)event_type, event_length, index,
1336 if (index + event_length > total_words) {
1337 LOGF(error,
"BmnRawSource::FillTDC250HGND: Event block overruns buffer");
1341 event_words.assign(word, word + event_length);
1342 if (FairLogger::GetLogger()->IsLogNeeded(fair::Severity::debug4)) {
1343 for (
size_t i = 0;
i < event_words.size(); ++
i) {
1344 LOGF(debug4,
"0x%04x", event_words[
i]);
1349 event = std::make_unique<BmnHgndRaw::Event_type_1>(event_words);
1351 event = std::make_unique<BmnHgndRaw::Event_type_2>(event_words);
1352 if (!event->validate()) {
1353 LOGF(error,
"BmnRawSource::FillTDC250HGND: Event block validation failed");
1359 LOGF(error,
"BmnRawSource::FillTDC250HGND: Event cast to Event_type_2 failed");
1364 uint8_t tfall_100ps = ev2->TDC_falling_time;
1365 int64_t time_sec = ev2->timestamp >> 31;
1367 uint64_t time_nsec = ((ev2->timestamp & 0x7ffffff0) >> 4) * 32;
1368 uint16_t time_100ps =
1369 (ev2->timestamp & 0xf) * 32 + trise_100ps;
1370 uint16_t plen_100ps =
1371 (ev2->pulse_length + 1) * 32 + tfall_100ps - trise_100ps;
1373 LOGF(debug4,
"ch_num = 0x%02X", ev2->channel_number);
1374 LOGF(debug4,
"timestamp = 0x%016lX", ev2->timestamp);
1375 LOGF(debug4,
"time_sec = 0x%08X", time_sec);
1376 LOGF(debug4,
"time_nsec = 0x%08X", time_nsec);
1377 LOGF(debug4,
"trise_100ps = 0x%02X", trise_100ps);
1378 LOGF(debug4,
"tfall_100ps = 0x%02X", tfall_100ps);
1379 LOGF(debug4,
"time_100ps = 0x%04X", time_100ps);
1380 LOGF(debug4,
"plen_100ps = 0x%04X", plen_100ps);
1381 LOGF(debug4,
"global_ch = 0x%04X", ev2->channel_number_global);
1383 new ((*tdc_hgnd)[
tdc_hgnd->GetEntriesFast()])
1384 BmnAbstractTDCDigit(serial, ev2->channel_number_global, time_sec, time_nsec, time_100ps, plen_100ps);
1386 LOGF(error,
"BmnRawSource::FillTDC250HGND: Wrong event type");
1390 index += event_length;
1398 LOGF(debug,
"MapVSP");
1399 if (dev_hdr->GetNWords() < 3) {
1400 LOGF(warning,
"Empty VSP block");
1403 uint8_t iComp = (dev_hdr->Serial & 0xFF000000) >> 24;
1410 LOGF(debug,
"FillVSP");
1411 const uint8_t kuMaxComps = 10;
1412 uint16_t fvuCurrentTsMsbCycle[kuMaxComps] = {};
1413 uint64_t fvulCurrentTsMsb[kuMaxComps] = {};
1419 for (uint8_t iw01 = 0; iw01 < nComp; iw01++)
1420 (*stti).append_component(1);
1423 uint8_t iw01 = el.first;
1424 auto* mslice_descr = el.second;
1428 for (uint8_t uw02 = 0; uw02 < nComp; uw02++) {
1432 uint16_t fuCurrentEquipmentId =
static_cast<uint16_t
>(msd.
eq_id);
1433 uint16_t fusCurrentDpbIdx =
static_cast<uint32_t
>(fuCurrentEquipmentId & 0xFFFF);
1436 uint64_t tgn = msd.
idx;
1438 LOGF(warning,
"!!! Misplaced VSP event! tgn = %lu while EventId = %u !!!\n", tgn,
fEventId);
1439 uint32_t tgNev =
static_cast<uint32_t
>(tgn);
1448 uint32_t uNbMessages = 0;
1450 uint64_t uiTrgTimeFLES = 0;
1451 uint64_t uiHitTimeFLES = 0;
1454 static const uint32_t kuBytesPerMessage = 4;
1456 uNbMessages = (size - (size % kuBytesPerMessage)) / kuBytesPerMessage;
1459 const uint32_t* pInBuff =
reinterpret_cast<const uint32_t*
>((*stti).content(uw02, 0));
1462 uint64_t uiTrgTime_TsMsb = 0;
1463 uint64_t uiHitTime_TsMsb = 0;
1464 uint64_t uiTrgTime_Epoch = 0;
1466 uint16_t uiTsMsbMessageNumber = 0;
1467 uint16_t uiEpochMessageNumber = 0;
1469 uint16_t usHitMissedEvts = 0;
1470 if (uNbMessages == 0)
1474 for (uint32_t uIdx = 0; uIdx < uNbMessages; ++uIdx) {
1476 uint32_t ulData =
static_cast<uint32_t
>(pInBuff[uIdx]);
1484 uiEpochMessageNumber++;
1486 if (uiEpochMessageNumber == 1)
1489 printf(
"fles WARNING: more than one EPOCH message in event tgN = %lu, exactly: %u\n", tgn,
1490 uiEpochMessageNumber);
1494 uiTsMsbMessageNumber++;
1496 if (uVal < fvulCurrentTsMsb[uw02]) {
1497 printf(
"TsMsbCycle: event trigger# %u", tgNev);
1498 printf(
"\tDPB: %u, Old TsMsb= %lu, new TsMsb=%lu, Old MsbCy=%u\n", uw02, fvulCurrentTsMsb[uw02],
1499 uVal, fvuCurrentTsMsbCycle[uw02]);
1501 if ((fvulCurrentTsMsb[uw02] - uVal) > 10000000)
1502 fvuCurrentTsMsbCycle[uw02]++;
1505 fvulCurrentTsMsb[uw02] = uVal;
1506 uiHitTime_TsMsb = uVal << 10;
1508 * fvuCurrentTsMsbCycle[uw02];
1509 if (uiTsMsbMessageNumber == 1) {
1511 uiHitTime_TsMsb & 0xFFE0000000;
1517 uiHitTimeFLES = uiHitTime_TsMsb +
static_cast<uint64_t
>(usRawTs);
1524 dig->
AppendHit(uiHitTimeFLES, usElinkIdx, usChan, usRawAdc);
1533 uiTrgTimeFLES = uiTrgTime_TsMsb + uiTrgTime_Epoch;
1544 const uint32_t len = dev_hdr->GetNWords();
1545 const MSC16VE_EHeader* ms =
reinterpret_cast<const MSC16VE_EHeader*
>(d);
1548 if (ms->Hdr.Len > (len - 1)) {
1549 LOGF(error,
"MSC header payload length mismatch!");
1557 std::array<uint8_t, MSC_N_COUNTERS> cntrs = {};
1558 switch (ms->GetVersion()) {
1560 const uint8_t NumsInWord = 4;
1561 while (index < len) {
1562 uint8_t type = d[index] >> 28;
1566 uint32_t ext_cond = (d[index] >> 24) & (
BIT(4) - 1);
1567 uint32_t sliceNum = (d[index]) & (
BIT(24) - 1);
1568 auto sc_time_shift = ms->SliceInt * sliceNum * 1ns;
1570 LOGF(debug,
"MSC ext_cond %2u sliceNum %7u time %s", ext_cond, sliceNum,
1572 new ((*msc)[
msc->GetEntriesFast()])
1578 for (uint8_t
i = 0;
i < NumsInWord;
i++) {
1579 uint32_t cnt = (d[index] >> (
i * ms->NCntrBits)) & (
BIT(ms->NCntrBits) - 1);
1580 cntrs[type * NumsInWord +
i] = cnt;
1589 if (ms->Hdr.Len <= 1 + (
sizeof(MSC16VE_EHeader) -
sizeof(MStreamHeader)) /
kNBYTESINWORD)
1591 uint32_t n_slices = ms->Hdr.Len - 1 - (
sizeof(MSC16VE_EHeader) -
sizeof(MStreamHeader)) /
kNBYTESINWORD;
1592 uint32_t missing_hits = d[index++];
1594 LOGF(info,
"missing_hits %3u !!!", missing_hits);
1598 vector<uint8_t>& vals = dig->
GetValues();
1601 int32_t istart = index;
1602 while (index < len) {
1603 uint8_t cnt = d[index] & (
BIT(ms->NCntrBits) - 1);
1604 uint8_t ext_cond = (d[index] >> ms->NCntrBits) & (
BIT(ms->ExtCondCnt) - 1);
1605 uint32_t sliceNum = d[index] >> (ms->NCntrBits + ms->ExtCondCnt);
1606 auto sc_time_shift = ms->SliceInt * sliceNum * 1ns;
1607 SysPoint point_slice{point + sc_time_shift};
1608 int32_t iVal = index - istart;
1613 conds[iVal] = ext_cond;
1614 LOGF(debug,
"MSC ext_cond %2u cnt %2u sliceNum %7u time %s", ext_cond, cnt, sliceNum,
1620 LOGF(warning,
"MSC16 ver $u not implemented", ms->GetVersion());
1629 LOGF(info,
"Found virtual device 0x%08X block", dh->Serial);
1631 LOGF(info,
"Not T0 device");
1635 std::ofstream outfile(
Form(
"virt_device_run_%u_%08X_%02X_%s_t_%ld_%ld.txt",
fRunId, dh->Serial, dh->DeviceId,
1637 ios::out | ios::binary);
1639 outfile << std::hex << d[
i];
1644 LOGF(error,
"Raw T0 parse failed");
1657 const MStreamHeader* ms =
reinterpret_cast<const MStreamHeader*
>(d);
1661 auto* ms0 =
reinterpret_cast<const MStreamTAI*
>(d + index);
1669 LOGF(error,
"UT24VE-TRC Error! MSHeader payload length larger than from device header!");
1674 LOGF(debug,
"FillUT24VE_TRC etype %u WR %08X ts: %s", (uint32_t)
fCurEvType, serial,
1679 while (++index < len) {
1680 uint32_t sig_states = d[index];
1681 vec.push_back(sig_states);
1682 bitset<32> sig_states_bs(sig_states);
1683 LOGF(debug2,
"TRC states d[%3u] %s", index, sig_states_bs.to_string());
1695 LOGF(warn,
"Possibly wrong state of %08X", serial);
1703 uint32_t word = d[idx];
1704 uint32_t
id = word >> 28;
1707 uint32_t d0 = d[idx + 0];
1708 uint32_t d1 = d[idx + 1];
1709 uint32_t d2 = d[idx + 2];
1710 uint32_t d3 = d[idx + 3];
1711 if ((d0 >> 28) != 2 || (d1 >> 28) != 2 || (d2 >> 28) != 2 || (d3 >> 28) != 2)
1713 int64_t ts_t0_s = -1;
1714 int64_t ts_t0_ns = -1;
1715 int64_t GlobalEvent = -1;
1716 ts_t0_ns = (d0 & 0x0FFFFFFF) | ((d1 & 0x3) << 28);
1717 ts_t0_s = ((d1 >> 4) & 0xFFFFFF) | ((d2 & 0xFFFF) << 24);
1718 GlobalEvent = ((d3 & 0x0FFFFFFF) << 12) | ((d2 >> 16) & 0xFFF);
1725 LOGF(debug2,
"ts :\t %10lli %9lli TMWR 0x%08X", ts_t0_s, ts_t0_ns, serial);
1728 uint32_t d0 = d[idx + 0];
1729 uint32_t d1 = d[idx + 1];
1730 if (((d0 >> 28) != 4) || ((d1 >> 28) != 5))
1756 printf(
"unrecognized TMWR id %u\n",
id);
1766 uint32_t type = d[idx] >> 28;
1769 std::array<uint32_t, MSC_N_COUNTERS>& cntrArrCur = dig->
GetValue();
1778 }
else if (type == 5) {
1779 uint32_t cnt = d[idx] & (
BIT(28) - 1);
1782 cntrArrCur[iCnt++] = cnt;
1785 type = (d[++idx] >> 28) & (
BIT(5) - 1);
1832 TFile* fRootFileIn =
new TFile(name,
"READ");
1833 if (fRootFileIn->
IsOpen()) {
1837 LOGF(info,
"fRunId %u from raw root run header",
fRunId);
1846 fRunId = tempHdr->GetRunId();
1847 LOGF(info,
"fRunId %u from raw root BmnEventHeader",
fRunId);
1853 fRootFileIn->
Close();
1862 FILE* file = fopen(name.
Data(),
"rb");
1863 if (file ==
nullptr) {
1864 LOGF(error,
"File %s is not open!!!", name.
Data());
1869 while (fread(&word,
kWORDSIZE, 1, file)) {
1871 printf(
"After checking %d words in input file run number not found!\n", cntr);
1872 printf(
"Let's get run number from file name\n");
1876 if (fread(&word,
kWORDSIZE, 1, file) != 1)
1895 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1972, 1, 1, 0, 0, 9), 10));
1896 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1972, 7, 1, 0, 0, 10), 11));
1897 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1973, 1, 1, 0, 0, 11), 12));
1898 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1974, 1, 1, 0, 0, 12), 13));
1899 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1975, 1, 1, 0, 0, 13), 14));
1900 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1976, 1, 1, 0, 0, 14), 15));
1901 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1977, 1, 1, 0, 0, 15), 16));
1902 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1978, 1, 1, 0, 0, 16), 17));
1903 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1979, 1, 1, 0, 0, 17), 18));
1904 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1980, 1, 1, 0, 0, 18), 19));
1905 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1981, 7, 1, 0, 0, 19), 20));
1906 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1982, 7, 1, 0, 0, 20), 21));
1907 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1983, 7, 1, 0, 0, 21), 22));
1908 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1985, 7, 1, 0, 0, 22), 23));
1909 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1988, 1, 1, 0, 0, 23), 24));
1910 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1990, 1, 1, 0, 0, 24), 25));
1911 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1991, 1, 1, 0, 0, 25), 26));
1912 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1992, 7, 1, 0, 0, 26), 27));
1913 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1993, 7, 1, 0, 0, 27), 28));
1914 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1994, 7, 1, 0, 0, 28), 29));
1915 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1996, 1, 1, 0, 0, 29), 30));
1916 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1997, 7, 1, 0, 0, 30), 31));
1917 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1999, 1, 1, 0, 0, 31), 32));
1918 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(2006, 1, 1, 0, 0, 32), 33));
1919 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(2009, 1, 1, 0, 0, 33), 34));
1920 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(2012, 7, 1, 0, 0, 34), 35));
1921 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(2015, 7, 1, 0, 0, 35), 36));
1922 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(2017, 1, 1, 0, 0, 36), 37));
1929 if (t <
leaps.begin()->first) {
1930 LOGF(warning,
"Wrong time! %s", t.
AsString());
1934 LOGF(warning,
"Warning! Leap seconds table expired!");
1936 auto it =
leaps.lower_bound(t);
1937 if ((it ==
leaps.end()))
1939 else if (it->first > t)
BmnIFileReader * BmnCompressionCreateNewSuitableReaderForAFile(const std::filesystem::path &aFilePath, const BmnFileType aPreferredTypeForThisAlgorithm=BmnFileType::Unknown)
std::filesystem::path BmnCompressionRemoveArchiveExtension(std::filesystem::path aFilePath)
BmnStatus
Define status code.
@ kBMNPAYLOAD
spill event.
@ kBMNPEDESTAL
pedestal event.
@ kBMNEMPTY
No event (wrong sync word or metadata payload).
std::chrono::time_point< SysClock > SysPoint
void memset(T *dest, T i, size_t num)
Copy to memory block [@dest, @dest+@num] num number of times the value of i of type @T with size @typ...
const uint32_t kMSTREAM_TYPE_TRIG
const uint32_t kADC64VE_XGE
const uint32_t SYNC_RUN_START
const uint32_t SYNC_EVENT
const uint32_t RECORD_RUN_NUMBER
const uint32_t kEVENTTYPESLOT
const uint32_t kVSP_SERIALS
const uint32_t kMODTRAILER
const uint32_t TDC_TRAILING
const uint32_t kMSTREAM_TYPE_TDC
const uint32_t TMWR_REL_TS
const uint32_t kVIRTUAL_DEVICE
const uint32_t kTQDC16VS_E
const uint32_t kEVTRAILER
const uint32_t TMWR_REL_TS_TB
const uint32_t TMWR_EOS_CNT
const uint32_t kUT24VE_TRC
const uint32_t kMSTREAM_TYPE_STAT
const uint32_t kTDC64VHLE
const uint32_t TDC_EV_HEADER
const uint32_t TDC_EV_TRAILER
const uint32_t TDC_LEADING
const uint32_t MSC_N_COUNTERS
const uint32_t SYNC_RUN_STOP
const uint32_t kMSTREAM_TYPE_ADC
const uint32_t kNBYTESINWORD
const uint32_t kGENERIC_DEVICE
const uint32_t kHGND_SERIALS
const uint32_t kT0_BIN_BLOCK_BYTES
const uint32_t SYNC_FILE_BEGIN
const uint32_t SERIAL_TO_CFG
const uint32_t TMWR_PULSE
const uint32_t SYNC_FILE_END
const uint32_t SYNC_EVENT_OLD
const uint32_t kTDC64VHLE_E
const uint32_t kT0_BIN_BLOCK_WORDS
const uint8_t MSC_TIME_SLICE_INFO
const uint32_t kMSC16VE_E
const uint32_t kMODHEADER
const uint32_t TMWR_EOS_CNT_MATCHED
Defines the fles::StorableTimeslice class.
char * Form(const char *fmt,...)
uint32_t GetRunId() const
static std::string TimePoint2String(SysPoint p)
static SysPoint TimeStamp2TP(TTimeStamp p)
static TTimeStamp TimePoint2TS(SysPoint p)
std::array< IntType, MSC_N_COUNTERS > & GetValue()
Raw MSC block with zero suppression and for one specific channel.
std::vector< IntType > & GetValues()
std::vector< TTimeStamp > & GetTimes()
std::vector< uint8_t > & GetExtCond()
BmnStatus FillTDC(const uint32_t *d, uint32_t serial, uint32_t slot, uint32_t modId, uint32_t &idx)
BmnStatus FillBlockADC(const uint32_t *d, uint32_t serial, uint8_t channel, uint16_t &len, TClonesArray *ar)
const TTimeStamp TimeZero
BmnStatus ConvertRawToRoot()
BmnStatus FillU40VE(const uint32_t *d, uint32_t slot, uint32_t &idx, BmnTrigInfo &spillInfo)
Int_t GetUTCShift(TTimeStamp t)
BmnStatus FillTQDC(const uint32_t *d, uint32_t serial, uint32_t slot, uint32_t modId, uint32_t &idx)
map< TTimeStamp, Int_t > leaps
unique_ptr< BmnMetadataRaw > metadata
BmnStatus ProcessEvent(const uint32_t *data, uint32_t len)
BmnSpillHeader * spillHeader
BmnStatus FillFVME2TMWR(const uint32_t *d, uint32_t serial, uint32_t &idx, uint32_t &len)
BmnStatus FillTDC250HGND(const uint32_t *d, uint32_t serial, uint32_t len)
Parse custom HGND TDC data block.
string fDecoderConfigFileName
virtual void Reset() override
BmnStatus ConvertStatEvent(const uint32_t *buf, uint32_t &len)
BmnStatus ConvertRawToRootIterate(const uint32_t *buf, uint32_t len)
void FinalizeStat()
Finishes the spill during raw conversion.
void RegisterSpillBranches()
BmnRawSource(vector< TString > files, uint32_t period=8)
BmnIFileReader * fFileReader
BmnStatus ProcessGenericDevice(const uint32_t *d, const DeviceHeader *dev_hdr)
Bool_t fExportExternalSpillStat
BmnStatus FillMSC(const uint32_t *d, uint32_t serial, uint32_t slot, uint32_t &idx)
Old MSC format (periodId < 8, one record for spill).
BmnStatus Process_FVME(const uint32_t *data, uint32_t len, uint32_t serial, BmnTrigInfo &spillInfo)
virtual ~BmnRawSource() override
void ClearRawSpillArrays()
BmnStatus InitConverter()
void QuickProcessEvent(const uint32_t *d, uint32_t len)
BmnStatus ConvertRawToRootIterateFileRead()
BmnThreadManager< BmnConverterThread > * fThreads
BmnStatus FillTDC72VXS(const uint32_t *d, uint32_t serial, uint32_t &len, uint32_t modid)
https://afi.jinr.ru/TDC72VXS_DataFormat
BmnStatus FillUT24VE_TRC(const uint32_t *d, uint32_t &serial, uint32_t &len)
Parse UT24VE-TRC MStream data block https://afi.jinr.ru/DataFormatUT24VE-TRC.
BmnEventHeader * eventHeaderDAQ
BmnStatus ParseJsonTLV(const uint32_t *buf, uint32_t &len)
BmnStatus FillBlockTDC(const uint32_t *d, uint32_t serial, uint16_t &len, TClonesArray *ar, uint32_t modid)
BmnStatus MapVSP(const uint32_t *d, const DeviceHeader *dev_hdr)
Parse VSP data block.
virtual void Close() override
BmnStatus FillVSP(TClonesArray *ar)
Int_t GetRunIdFromFile(TString name)
BmnStatus FillTTVXS(const uint32_t *d, uint32_t serial, uint32_t &len)
https://afi.jinr.ru/TTVXS_DataFormat
BmnStatus FillMSC16VE_E(const uint32_t *d, const DeviceHeader *dev_hdr)
Parse MSC16VE-E MStream data block https://afi.jinr.ru/DataFormatMSC_ETH https://afi....
void BranchRegFun(TString name, BrType **ar, TTree *tree=nullptr)
virtual bool Init() override
BmnSyncDigit * FillWR(uint32_t iSerial, uint64_t iEvent, int64_t t_sec, int64_t t_ns)
int64_t fCurentPositionRawFile
BmnStatus FillVirtualDevice(const uint32_t *d, const DeviceHeader *dh)
std::map< uint8_t, const uint32_t * > time_slice_map
virtual Int_t ReadEvent(uint32_t i=0) override
BmnStatus FillTQDC_E(const uint32_t *d, uint32_t serial, uint32_t &len)
Parse TQDC16VS-E MStream data block https://afi.jinr.ru/DataFormatTQDC16VSE.
BmnStatus Process_HRB(const uint32_t *data, uint32_t len, uint32_t serial)
map< SysPoint, BmnSpillInfo > fSpillMap
unique_ptr< DigiRunHeader > runHeader
BmnStatus ConvertRawToRootIterateFile(uint32_t limit=WAIT_LIMIT)
Long64_t GetTime_sec() const
Long64_t GetTime_ns() const
T0 module spill settings and counts.
void SetTimeSinceLastEvNs(Double_t dur)
Write time since the last written event.
Class BmnTrigInfo Trigger counters of the current spill from U40VE card.
void SetTrigBefo(UInt_t _v)
void SetTrigAccepted(UInt_t _v)
void SetTrigAfter(UInt_t _v)
void SetTrigAll(UInt_t _v)
void SetTrigRjct(UInt_t _v)
void SetTrigCand(UInt_t _v)
void SetTrigAvail(UInt_t _v)
void AppendHit(uint64_t HitTime, uint16_t ElinkIdx, uint16_t Chan, uint16_t Adc)
void SetTHitMissedEvts(uint16_t val)
void SetTTrigTime(uint64_t val)
T * Get(const char *namecycle)
virtual Bool_t IsOpen() const
void Close(Option_t *option="") override
Int_t GetEntriesFast() const
Int_t GetEntries() const override
TObject * At(Int_t idx) const override
Bool_t MatchB(const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10)
Int_t Substitute(TString &s, const TString &replace, const TString &mods="", Int_t start=0, Int_t nMatchMax=10)
void Start(Bool_t reset=kTRUE)
const char * Data() const
const char * AsString(const Option_t *option="") const
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
virtual Long64_t GetEntriesFast() const
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
/home/soul/bmnroot/database/uni_db1/UniRawFile.h Class for the table: raw_file
static int CheckRawFileExists(int file_id)
check raw file exists in the database: 1- true, 0 - false, <0 - database operation error
static UniRawFile * CreateRawFile(int period_number, int run_number, int start_event, int end_event, TDatime start_datetime, TDatime end_datetime, TString file_path, int event_count, int64_t file_size, TString *file_hash)
add new raw file to the database
int GetEndEvent()
get end event of the current raw file
static TObjArray * GetRawFiles(int period_number, int run_number)
get array of raw files (UniRawFile*) corresponding to the period:run number ordered by start_event as...
static TString CalculateFileHash(TString file_path)
calculate and return (in hex string format) cheŃksum for a given file use Adler32 algorithm if zlib l...
int GetStartEvent()
get start event of the current raw file
The StorableTimeslice class contains the data of a single timeslice.
uint32_t GetTsMsbValBinning() const
For TS MSB data: Returns the TS MSB 29 bit field).
uint16_t GetHitAdc() const
For Hit data: Returns ADC value (5 bit field).
uint16_t GetLinkIndexHitBinning() const
For Hit data: Returns (global) index of the eLink on which the message was received (6 bit field) => ...
uint16_t GetHitTimeBinning() const
For Hit data: Returns timestamp (9 bit field + 1b extra on b30) => Quick and dirty hack for binning F...
uint32_t GetEpochVal() const
For Epoch data: Returns the Epoch (29 bit field).
uint16_t GetHitChannel() const
For Hit data: Returns StsXYTER channel number (7 bit field).
MessType GetMessType() const
Returns the message type, see enum MessType.
bool IsHitMissedEvts() const
For Hit data: Returns Missed event flag (1 bit field).
bool is_word_event_header(uint16_t word)
uint16_t get_block_size(EventPacketVersion packet_version=ERR)
EventPacketVersion get_event_packet_version(uint16_t word)
static constexpr uint64_t kulTsCycleNbBinsBinning
Class SpillStatus raw spill status from JSON block.
Microslice descriptor struct.
uint64_t idx
Microslice index / start time.
uint32_t size
Content size (bytes).
uint16_t eq_id
Equipment identifier.