12#include "FairLogger.h"
14#include "BmnADCDigit.h"
15#include "BmnAbstractTDCDigit.h"
16#include "BmnCompressionGlobalFunctions.h"
18#include "BmnFileProp.h"
19#include "BmnGemStripDigit.h"
20#include "BmnHRBDigit.h"
21#include "BmnHgndRaw.h"
22#include "BmnIFileReader.h"
23#include "BmnMSCDigit.h"
24#include "BmnMSCZSDigit.h"
25#include "BmnSyncDigit.h"
26#include "BmnTDCDigit.h"
27#include "BmnTQDCADCDigit.h"
28#include "BmnVspRawDigit.h"
30#include "UniDetectorParameter.h"
31#include "UniRawFile.h"
34#include "StorableTimeslice.h"
35#include "StsXyterMessage.h"
39namespace fs = std::filesystem;
40using namespace std::chrono;
96 LOG(debug) <<
"RunId " << prop.
GetRunId() <<
" got from props";
99 LOG(debug) <<
"subname " << subName;
129 printf(
"\n!!!!!\ncannot open file %s\nConvertRawToRoot stopped\n!!!!!\n\n",
fRawFileName.Data());
134 printf(
"\nRAW FILE: ");
136 printf(
"\nRAW FILE LENGTH: ");
138 std::string fileType{};
154 bool convertMSC =
conf.get<
bool>(
"Decoder.ProcessMSC",
false);
178 LOGF(error,
"\n!!!!!\ncannot open file %s\nConvertRawToRoot are stopped\n!!!!!\n",
fRawFileName.Data());
183 printf(
"\nRAW FILE: ");
185 printf(
"\nRAW FILE LENGTH: ");
187 std::string fileType{};
203 LOGF(info,
"InitConverter without file");
206 LOGF(debug,
"fRawTree %p init", (
void*)
fRawTree);
207 LOGF(debug,
"fRawTree path %s",
fRawTree->GetDirectory()->GetPath());
210 int threadNumber = 0;
211 if (threadNumber == 0) {
212 if (std::thread::hardware_concurrency() <= 1)
215 threadNumber = std::thread::hardware_concurrency() - 1;
218 for (
int i = 0;
i < threadNumber;
i++)
221 bool convertMSC =
conf.get<
bool>(
"Decoder.ProcessMSC",
false);
237 LOGF(debug1,
"%s ", __func__);
332 const DeviceHeader* dh =
reinterpret_cast<const DeviceHeader*
>(d + idx);
336 string str(
reinterpret_cast<const char*
>(d + idx), str_len);
337 json j = json::parse(str);
340 for (json::iterator it = j.begin(); it != j.end(); ++it) {
342 string jkey(it.key());
344 if (!jkey.compare(
"status")) {
345 auto& j_runtime = it.value()[
"runTime"];
346 auto j_spill = j_runtime[
"spill"];
347 Int_t phase =
static_cast<Int_t>(j_spill[
"phase"]);
349 auto wr = j_runtime[
"time"][
"WR"];
364 LOGF(info,
"JSON status phase %d", phase);
371 std::tie(spill_it, inserted) =
fSpillMap.insert(
374 .start_ts = ss.start_ts,
375 .stop_ts = ss.start_ts}));
376 LOGF(debug,
"spill record inserted %d", inserted);
383 std::ofstream outfile(
Form(
"j_%s_%d_%9d_%09d_%02X_%08X_phase_%d_%s.json", jkey.c_str(),
fRunId, sec,
384 ns, dh->DeviceId, dh->Serial, phase,
fSubName.Data()),
385 std::ofstream::binary);
386 outfile << std::setw(4) << j << std::endl;
389 metadata->SpillStatusVec().push_back(move(ss));
391 LOGF(info,
"JSON config");
392 if (!jkey.compare(
"config")) {
393 string start_DT = it.value()[
"meta"][
"startDateTime"];
395 std::ofstream outfile(
Form(
"j_%s_%d_%s_%02X_%08X.json", jkey.c_str(),
fRunId, start_DT.data(),
396 dh->DeviceId, dh->Serial),
397 std::ofstream::binary);
398 outfile << std::setw(4) << j << std::endl;
404 LOGF(error,
"Parsing JSON config failed!");
406 LOGF(info,
"Unknown json key %s", jkey.data());
409 }
catch (std::exception& ex) {
410 LOGF(error,
"Exception for JSON block: %s", ex.what());
443 LOGF(info,
"Input is raw root file. Nothing to do!");
447 LOGF(error,
"Init converter failed!");
502 if ((pRawFiles !=
nullptr) && (pRawFiles->
GetEntries() == 0)) {
504 cout <<
"CRITICAL WARNING: there are overlaps in events for the new file metadata: " <<
fRawFileName
505 <<
" (" << period_id <<
":" << run_id <<
" " << start_event <<
"-" << end_event <<
")" << endl
506 <<
"PLEASE, SEND THE INFO TO THE SOFTWARE COORDINATOR" << endl;
513 if (strFileHash !=
"")
514 pFileHash =
new TString(strFileHash);
516 cout <<
"WARNING: a problem occurred while calculating checksum for the raw file: " <<
fRawFileName
526 cout <<
"Raw file information has been successfully added to the Condition Database for run "
527 << period_id <<
":" << run_id <<
" and event interval " << start_event <<
"-" << end_event << endl;
536 if (pRawFiles !=
nullptr) {
538 cout <<
"CRITICAL WARNING: there are more than one records for the file metadata: " <<
fRawFileName
540 <<
"PLEASE, SEND THE INFO TO THE SOFTWARE COORDINATOR" << endl;
544 cout <<
"CRITICAL WARNING: there are different start event for the file metadata: "
545 <<
fRawFileName <<
" (" << period_id <<
":" << run_id <<
" " << start_event <<
"-"
546 << end_event <<
")" << endl
547 <<
"PLEASE, SEND THE INFO TO THE SOFTWARE COORDINATOR" << endl;
548 else if (pExistingRawFile->
GetEndEvent() < end_event)
549 cout <<
"CRITICAL WARNING: the existing file metadata has 'end event' less than: "
550 <<
fRawFileName <<
" (" << period_id <<
":" << run_id <<
" " << start_event <<
"-"
551 << end_event <<
")" << endl
552 <<
"PLEASE, SEND THE INFO TO THE SOFTWARE COORDINATOR" << endl;
559 }
catch (std::exception& ex) {
560 printf(
"Exception of working with the Condition Database: %s\n", ex.what());
616 LOGF(error,
"WTF?? in the main event: fDat == %u",
fDat);
663 LOGF(error,
"WTF?? in the STAT: fDat == %u",
fDat);
665 LOGF(debug3,
"STAT ev length bytes %d",
fDat);
676 LOGF(info,
"RUN START");
679 LOGF(info,
"RUN STOP");
687 LOGF(info,
"FILE BEGIN");
690 LOGF(info,
"FILE END");
700 LOGF(debug,
"SYNC JSON len %u",
fDat);
706 LOGF(error,
"unrecognized sync %08X",
fDat);
754 const DeviceHeader* dh =
reinterpret_cast<const DeviceHeader*
>(d + idx);
755 LOGF(debug2,
"[%u / %u]", idx, len);
757 uint32_t serial = dh->Serial;
758 uint8_t
id = dh->DeviceId;
759 uint32_t payload = dh->GetNWords();
761 if (payload > 2000000) {
763 LOGF(warn,
"Event %d:\n serial = 0x%06X\n id = Ox%02X\n payload = %d",
fEventId, serial,
id, payload);
767 LOGF(debug4,
"STAT iev %7u idx %6u/%6u idev %02X serial 0x%08X payload %4u",
fEventId, idx, len,
id,
808 LOGF(warning,
"Malformed data from ADC64VE %08X in the event %u", serial,
fEventId);
816 LOGF(warning,
"Malformed data from ADC64WR %08X in the event %u", serial,
fEventId);
836 if (payload + idx > len) {
838 "Error in the event #%d: 0x%08X : %2X device payload length mismatch! pauload %5u idx/len: %5u/%5u \n",
839 fEventId, serial,
id, payload, idx, len);
880 LOGF(debug2,
"FVME serial %08X len %u", serial, len);
883 LOGF(debug,
"Stat FVME serial %08X efter iEv %u", serial,
fEventId);
888 for (uint32_t
i = 0;
i < len;
i++) {
906 modId = (d[
i] >> 16) & 0x7F;
907 slot = (d[
i] >> 23) & 0x1F;
914 if (!((d[
i] >> 16) & 0x1))
916 if (!((d[
i] >> 17) & 0x1))
918 if (!((d[
i] >> 18) & 0x1))
920 if (!((d[
i] >> 19) & 0x1))
961 uint32_t nSmpl = (len - 3) / nWords;
963 for (uint32_t iSmpl = 0; iSmpl < nSmpl; ++iSmpl) {
964 for (uint32_t iWord = 0; iWord < nWords; ++iWord) {
965 uint32_t word32 = d[3 + iWord + iSmpl * nWords];
966 for (
Int_t iCh = 0; iCh < 32; ++iCh) {
967 if (word32 &
BIT(iCh)) {
969 new (ar_hrb[
hrb->GetEntriesFast()])
BmnHRBDigit(serial, iCh + 32 * iWord, iSmpl, tH, tL);
980 uint32_t type = d[idx] >> 28;
992 if (type ==
kWORDAUX && !countersDone) {
1001 countersDone =
kTRUE;
1004 type = d[idx] >> 28;
1013 uint32_t type = d[idx] >> 28;
1017 LOGF(warning,
"TDC (modID 0x%02X serial 0x%08X slot %d tdcID %d) error flags: 0x%04X", modId, serial,
1018 slot, ((d[idx] >> 24) & 0xF), (d[idx] & ((1 << 15) - 1)));
1019 if ((d[idx] &
BIT(12)) || (d[idx] &
BIT(13))) {
1020 LOGF(warning,
"TDC data loss in 0x%08X ", serial);
1026 uint32_t tdcId = (d[idx] >> 24) & 0xF;
1028 (modId ==
kTDC64V) ? (d[idx] & 0x7FFFF) : ((d[idx] & 0x7FFFF) << 2) | ((d[idx] & 0x180000) >> 19);
1029 uint32_t channel = (modId ==
kTDC64V) ? (d[idx] >> 19) & 0x1F : (d[idx] >> 21) & 0x7;
1032 new (ar_tdc[
tdc->GetEntriesFast()])
1035 LOGF(debug4,
"tdc %08X : %d channel %d", serial, slot, channel);
1038 type = d[idx] >> 28;
1045 uint32_t type = d[idx] >> 28;
1050 uint32_t channel = 0;
1052 vector<int16_t> valI;
1057 LOGF(warning,
"In event %8u: TDC (serial 0x%08X slot %d tdcID %d) error flags: 0x%04X",
fEventId,
1058 serial, slot, ((d[idx] >> 24) & ((1 << 4) - 1)), (d[idx] & ((1 << 15) - 1)));
1059 if ((d[idx] &
BIT(12)) || (d[idx] &
BIT(13))) {
1060 LOGF(warning,
"\tTQDC data loss in 0x%08X ", serial);
1065 uint32_t mode = (d[idx] >> 26) & 0x3;
1068 channel = (d[idx] >> 19) & 0x1F;
1069 uint32_t time = ((d[idx] & 0x7FFFF) << 2) | ((d[idx] >> 24) & 0x3);
1071 new ((*tqdc_tdc)[
tqdc_tdc->GetEntriesFast()])
1074 }
else if ((type == 4) && (mode != 0)) {
1075 channel = (d[idx] >> 19) & 0x1F;
1076 if (d[idx] &
BIT(16)) {
1077 adcTimestamp = d[idx] & 0xFFFF;
1080 trigTimestamp = d[idx] & 0xFFFF;
1083 tdcTimestamp = d[idx] & 0xFFF;
1091 if ((type == 5) && (mode == 2) ) {
1092 Short_t val = (d[idx] & ((1 << 14) - 1)) - (1 << (14 - 1));
1094 valI.push_back(val);
1096 new ((*tqdc_adc)[
tqdc_adc->GetEntriesFast()])
1097 BmnTQDCADCDigit(serial, channel, slot, std::move(valI), trigTimestamp, adcTimestamp);
1103 type = d[++idx] >> 28;
1114 vector<int16_t> valI;
1115 const uint8_t NBytesInSample = 2;
1117 while (iWord < len) {
1118 uint16_t adcTS = d[iWord] & (
BIT(16) - 1);
1119 uint16_t SigLen = d[iWord] >> 16;
1120 uint16_t NSamples = SigLen / NBytesInSample;
1123 if (iWord + NSampleWords + 1 > len) {
1124 LOGF(error,
"TQDC ADC wrong payload length! iWord %u SigLen %u len %u", iWord, SigLen, len);
1127 uint16_t iSampleWord = 0;
1128 while (iSampleWord++ < NSampleWords) {
1129 int16_t adcLo =
static_cast<int16_t
>(d[iWord + iSampleWord] & (
BIT(16) - 1));
1130 int16_t adcHi =
static_cast<int16_t
>(d[iWord + iSampleWord] >> 16);
1131 valI.push_back(adcLo);
1132 if (valI.size() < NSamples)
1133 valI.push_back(adcHi);
1137 iWord += iSampleWord;
1150 uint16_t tdcLine = 0;
1151 while (tdcLine < len) {
1152 uint32_t word = d[tdcLine];
1153 uint32_t bt = word >> 28;
1170 uint8_t channel = (word >> 21) & (
BIT(7) - 1);
1172 uint32_t time = word & (
BIT(21) - 1);
1180 LOGF(warning,
"TDC (serial 0x%08X tdcID %d) in event %u error flags: 0x%04X %s", serial,
1181 ((word >> 24) & ((1 << 4) - 1)),
fEventId, (word & ((1 << 15) - 1)),
1182 ((word &
BIT(12)) || (word &
BIT(13))) ?
"data lost" :
"");
1196 const MStreamTAI* ms0 =
reinterpret_cast<const MStreamTAI*
>(d + index);
1203 while (index < len) {
1204 const TqdcDataHeader* th =
reinterpret_cast<const TqdcDataHeader*
>(d + index);
1209 switch (th->DataType) {
1217 printf(
"Wrong TQDC data type %u !\n", th->DataType);
1231 const MStreamTAI* ms0 =
reinterpret_cast<const MStreamTAI*
>(d + index);
1237 while (index < len) {
1238 uint8_t dtype = d[index] >> 28;
1239 bool overflow = d[index] &
BIT(16);
1250 printf(
"Wrong VXS data type %u !\n", dtype);
1264 const MStreamTAI* ms0 =
reinterpret_cast<const MStreamTAI*
>(d + index);
1271 while (index < len) {
1272 uint8_t dtype = d[index] >> 28;
1273 bool overflow = d[index] &
BIT(16);
1287 printf(
"Wrong TTVXS data type %u !\n", dtype);
1299 return MapVSP(d, dev_hdr);
1303 LOGF(error,
"BmnRawSource::ProcessGenericDevice: Unknown device serial 0x%08X", dev_hdr->Serial);
1313 const uint16_t* words =
reinterpret_cast<const uint16_t*
>(d);
1314 size_t total_words = len /
sizeof(uint16_t);
1316 if (FairLogger::GetLogger()->IsLogNeeded(fair::Severity::debug4)) {
1317 for (
size_t i = 0;
i < total_words; ++
i)
1318 LOGF(debug4,
"0x%04x", words[
i]);
1322 std::vector<uint16_t> event_words;
1323 std::unique_ptr<BmnHgndRaw::FIFO_block> event;
1325 while (index < total_words) {
1326 auto* word = words + index;
1328 LOGF(error,
"BmnRawSource::FillTDC250HGND: Wrong header 0x%04X", *word);
1335 LOGF(debug4,
"Event type %d, 16bit words %d (index=%zu, total=%zu)", (uint32_t)event_type, event_length, index,
1338 if (index + event_length > total_words) {
1339 LOGF(error,
"BmnRawSource::FillTDC250HGND: Event block overruns buffer");
1343 event_words.assign(word, word + event_length);
1344 if (FairLogger::GetLogger()->IsLogNeeded(fair::Severity::debug4)) {
1345 for (
size_t i = 0;
i < event_words.size(); ++
i) {
1346 LOGF(debug4,
"0x%04x", event_words[
i]);
1350 if (event_type == BmnHgndRaw::Block::EventPacketVersion::V1) {
1351 event = std::make_unique<BmnHgndRaw::Event_type_1>(event_words);
1352 }
else if (event_type == BmnHgndRaw::Block::EventPacketVersion::V2) {
1353 event = std::make_unique<BmnHgndRaw::Event_type_2>(event_words);
1354 if (!event->validate()) {
1355 LOGF(error,
"BmnRawSource::FillTDC250HGND: Event block validation failed");
1361 LOGF(error,
"BmnRawSource::FillTDC250HGND: Event cast to Event_type_2 failed");
1366 uint8_t tfall_100ps = ev2->TDC_falling_time;
1367 int64_t time_sec = ev2->timestamp >> 31;
1369 uint64_t time_nsec = ((ev2->timestamp & 0x7ffffff0) >> 4) * 32;
1370 uint16_t time_100ps =
1371 (ev2->timestamp & 0xf) * 32 + trise_100ps;
1372 uint16_t plen_100ps =
1373 (ev2->pulse_length + 1) * 32 + tfall_100ps - trise_100ps;
1375 LOGF(debug4,
"ch_num = 0x%02X", ev2->channel_number);
1376 LOGF(debug4,
"timestamp = 0x%016lX", ev2->timestamp);
1377 LOGF(debug4,
"time_sec = 0x%08X", time_sec);
1378 LOGF(debug4,
"time_nsec = 0x%08X", time_nsec);
1379 LOGF(debug4,
"trise_100ps = 0x%02X", trise_100ps);
1380 LOGF(debug4,
"tfall_100ps = 0x%02X", tfall_100ps);
1381 LOGF(debug4,
"time_100ps = 0x%04X", time_100ps);
1382 LOGF(debug4,
"plen_100ps = 0x%04X", plen_100ps);
1383 LOGF(debug4,
"global_ch = 0x%04X", ev2->channel_number_global);
1385 new ((*tdc_hgnd)[
tdc_hgnd->GetEntriesFast()])
1386 BmnAbstractTDCDigit(serial, ev2->channel_number_global, time_sec, time_nsec, time_100ps, plen_100ps);
1388 LOGF(error,
"BmnRawSource::FillTDC250HGND: Wrong event type");
1392 index += event_length;
1400 LOGF(debug,
"MapVSP");
1401 if (dev_hdr->GetNWords() < 3) {
1402 LOGF(warning,
"Empty VSP block");
1405 uint8_t iComp = (dev_hdr->Serial & 0xFF000000) >> 24;
1412 LOGF(debug,
"FillVSP");
1413 const uint8_t kuMaxComps = 10;
1414 uint16_t fvuCurrentTsMsbCycle[kuMaxComps] = {};
1415 uint64_t fvulCurrentTsMsb[kuMaxComps] = {};
1421 for (uint8_t iw01 = 0; iw01 < nComp; iw01++)
1422 (*stti).append_component(1);
1425 uint8_t iw01 = el.first;
1426 auto* mslice_descr = el.second;
1430 for (uint8_t uw02 = 0; uw02 < nComp; uw02++) {
1434 uint16_t fuCurrentEquipmentId =
static_cast<uint16_t
>(msd.
eq_id);
1435 uint16_t fusCurrentDpbIdx =
static_cast<uint32_t
>(fuCurrentEquipmentId & 0xFFFF);
1438 uint64_t tgn = msd.
idx;
1440 LOGF(warning,
"!!! Misplaced VSP event! tgn = %lu while EventId = %u !!!\n", tgn,
fEventId);
1441 uint32_t tgNev =
static_cast<uint32_t
>(tgn);
1450 uint32_t uNbMessages = 0;
1452 uint64_t uiTrgTimeFLES = 0;
1453 uint64_t uiHitTimeFLES = 0;
1456 static const uint32_t kuBytesPerMessage = 4;
1458 uNbMessages = (size - (size % kuBytesPerMessage)) / kuBytesPerMessage;
1461 const uint32_t* pInBuff =
reinterpret_cast<const uint32_t*
>((*stti).content(uw02, 0));
1464 uint64_t uiTrgTime_TsMsb = 0;
1465 uint64_t uiHitTime_TsMsb = 0;
1466 uint64_t uiTrgTime_Epoch = 0;
1468 uint16_t uiTsMsbMessageNumber = 0;
1469 uint16_t uiEpochMessageNumber = 0;
1471 uint16_t usHitMissedEvts = 0;
1472 if (uNbMessages == 0)
1476 for (uint32_t uIdx = 0; uIdx < uNbMessages; ++uIdx) {
1478 uint32_t ulData =
static_cast<uint32_t
>(pInBuff[uIdx]);
1486 uiEpochMessageNumber++;
1488 if (uiEpochMessageNumber == 1)
1491 printf(
"fles WARNING: more than one EPOCH message in event tgN = %lu, exactly: %u\n", tgn,
1492 uiEpochMessageNumber);
1496 uiTsMsbMessageNumber++;
1498 if (uVal < fvulCurrentTsMsb[uw02]) {
1499 printf(
"TsMsbCycle: event trigger# %u", tgNev);
1500 printf(
"\tDPB: %u, Old TsMsb= %lu, new TsMsb=%lu, Old MsbCy=%u\n", uw02, fvulCurrentTsMsb[uw02],
1501 uVal, fvuCurrentTsMsbCycle[uw02]);
1503 if ((fvulCurrentTsMsb[uw02] - uVal) > 10000000)
1504 fvuCurrentTsMsbCycle[uw02]++;
1507 fvulCurrentTsMsb[uw02] = uVal;
1508 uiHitTime_TsMsb = uVal << 10;
1510 * fvuCurrentTsMsbCycle[uw02];
1511 if (uiTsMsbMessageNumber == 1) {
1513 uiHitTime_TsMsb & 0xFFE0000000;
1519 uiHitTimeFLES = uiHitTime_TsMsb +
static_cast<uint64_t
>(usRawTs);
1526 dig->
AppendHit(uiHitTimeFLES, usElinkIdx, usChan, usRawAdc);
1535 uiTrgTimeFLES = uiTrgTime_TsMsb + uiTrgTime_Epoch;
1546 const uint32_t len = dev_hdr->GetNWords();
1547 const MSC16VE_EHeader* ms =
reinterpret_cast<const MSC16VE_EHeader*
>(d);
1550 if (ms->Hdr.Len > (len - 1)) {
1551 LOGF(error,
"MSC header payload length mismatch!");
1559 std::array<uint8_t, MSC_N_COUNTERS> cntrs = {};
1560 switch (ms->GetVersion()) {
1562 const uint8_t NumsInWord = 4;
1563 while (index < len) {
1564 uint8_t type = d[index] >> 28;
1568 uint32_t ext_cond = (d[index] >> 24) & (
BIT(4) - 1);
1569 uint32_t sliceNum = (d[index]) & (
BIT(24) - 1);
1570 auto sc_time_shift = ms->SliceInt * sliceNum * 1ns;
1572 LOGF(debug,
"MSC ext_cond %2u sliceNum %7u time %s", ext_cond, sliceNum,
1574 new ((*msc)[
msc->GetEntriesFast()])
1580 for (uint8_t
i = 0;
i < NumsInWord;
i++) {
1581 uint32_t cnt = (d[index] >> (
i * ms->NCntrBits)) & (
BIT(ms->NCntrBits) - 1);
1582 cntrs[type * NumsInWord +
i] = cnt;
1591 if (ms->Hdr.Len <= 1 + (
sizeof(MSC16VE_EHeader) -
sizeof(MStreamHeader)) /
kNBYTESINWORD)
1593 uint32_t n_slices = ms->Hdr.Len - 1 - (
sizeof(MSC16VE_EHeader) -
sizeof(MStreamHeader)) /
kNBYTESINWORD;
1594 uint32_t missing_hits = d[index++];
1596 LOGF(info,
"missing_hits %3u !!!", missing_hits);
1600 vector<uint8_t>& vals = dig->
GetValues();
1603 int32_t istart = index;
1604 while (index < len) {
1605 uint8_t cnt = d[index] & (
BIT(ms->NCntrBits) - 1);
1606 uint8_t ext_cond = (d[index] >> ms->NCntrBits) & (
BIT(ms->ExtCondCnt) - 1);
1607 uint32_t sliceNum = d[index] >> (ms->NCntrBits + ms->ExtCondCnt);
1608 auto sc_time_shift = ms->SliceInt * sliceNum * 1ns;
1609 SysPoint point_slice{point + sc_time_shift};
1610 int32_t iVal = index - istart;
1615 conds[iVal] = ext_cond;
1616 LOGF(debug,
"MSC ext_cond %2u cnt %2u sliceNum %7u time %s", ext_cond, cnt, sliceNum,
1622 LOGF(warning,
"MSC16 ver $u not implemented", ms->GetVersion());
1631 LOGF(info,
"Found virtual device 0x%08X block", dh->Serial);
1633 LOGF(info,
"Not T0 device");
1637 std::ofstream outfile(
Form(
"virt_device_run_%u_%08X_%02X_%s_t_%ld_%ld.txt",
fRunId, dh->Serial, dh->DeviceId,
1639 ios::out | ios::binary);
1641 outfile << std::hex << d[
i];
1655 const MStreamHeader* ms =
reinterpret_cast<const MStreamHeader*
>(d);
1659 auto* ms0 =
reinterpret_cast<const MStreamTAI*
>(d + index);
1667 LOGF(error,
"UT24VE-TRC Error! MSHeader payload length larger than from device header!");
1672 LOGF(debug,
"FillUT24VE_TRC etype %u WR %08X ts: %s", (uint32_t)
fCurEvType, serial,
1677 while (++index < len) {
1678 uint32_t sig_states = d[index];
1679 vec.push_back(sig_states);
1680 bitset<32> sig_states_bs(sig_states);
1681 LOGF(debug2,
"TRC states d[%3u] %s", index, sig_states_bs.to_string());
1693 LOGF(warn,
"Possibly wrong state of %08X", serial);
1701 uint32_t word = d[idx];
1702 uint32_t
id = word >> 28;
1705 uint32_t d0 = d[idx + 0];
1706 uint32_t d1 = d[idx + 1];
1707 uint32_t d2 = d[idx + 2];
1708 uint32_t d3 = d[idx + 3];
1709 if ((d0 >> 28) != 2 || (d1 >> 28) != 2 || (d2 >> 28) != 2 || (d3 >> 28) != 2)
1711 int64_t ts_t0_s = -1;
1712 int64_t ts_t0_ns = -1;
1713 int64_t GlobalEvent = -1;
1714 ts_t0_ns = (d0 & 0x0FFFFFFF) | ((d1 & 0x3) << 28);
1715 ts_t0_s = ((d1 >> 4) & 0xFFFFFF) | ((d2 & 0xFFFF) << 24);
1716 GlobalEvent = ((d3 & 0x0FFFFFFF) << 12) | ((d2 >> 16) & 0xFFF);
1723 LOGF(debug2,
"ts :\t %10lli %9lli TMWR 0x%08X", ts_t0_s, ts_t0_ns, serial);
1726 uint32_t d0 = d[idx + 0];
1727 uint32_t d1 = d[idx + 1];
1728 if (((d0 >> 28) != 4) || ((d1 >> 28) != 5))
1754 printf(
"unrecognized TMWR id %u\n",
id);
1764 uint32_t type = d[idx] >> 28;
1767 std::array<uint32_t, MSC_N_COUNTERS>& cntrArrCur = dig->
GetValue();
1776 }
else if (type == 5) {
1777 uint32_t cnt = d[idx] & (
BIT(28) - 1);
1780 cntrArrCur[iCnt++] = cnt;
1783 type = (d[++idx] >> 28) & (
BIT(5) - 1);
1830 TFile* fRootFileIn =
new TFile(name,
"READ");
1831 if (fRootFileIn->
IsOpen()) {
1835 LOGF(info,
"fRunId %u from raw root run header",
fRunId);
1844 fRunId = tempHdr->GetRunId();
1845 LOGF(info,
"fRunId %u from raw root BmnEventHeader",
fRunId);
1851 fRootFileIn->
Close();
1860 FILE* file = fopen(name.
Data(),
"rb");
1861 if (file ==
nullptr) {
1862 LOGF(error,
"File %s is not open!!!", name.
Data());
1867 while (fread(&word,
kWORDSIZE, 1, file)) {
1869 printf(
"After checking %d words in input file run number not found!\n", cntr);
1870 printf(
"Let's get run number from file name\n");
1874 if (fread(&word,
kWORDSIZE, 1, file) != 1)
1893 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1972, 1, 1, 0, 0, 9), 10));
1894 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1972, 7, 1, 0, 0, 10), 11));
1895 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1973, 1, 1, 0, 0, 11), 12));
1896 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1974, 1, 1, 0, 0, 12), 13));
1897 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1975, 1, 1, 0, 0, 13), 14));
1898 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1976, 1, 1, 0, 0, 14), 15));
1899 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1977, 1, 1, 0, 0, 15), 16));
1900 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1978, 1, 1, 0, 0, 16), 17));
1901 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1979, 1, 1, 0, 0, 17), 18));
1902 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1980, 1, 1, 0, 0, 18), 19));
1903 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1981, 7, 1, 0, 0, 19), 20));
1904 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1982, 7, 1, 0, 0, 20), 21));
1905 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1983, 7, 1, 0, 0, 21), 22));
1906 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1985, 7, 1, 0, 0, 22), 23));
1907 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1988, 1, 1, 0, 0, 23), 24));
1908 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1990, 1, 1, 0, 0, 24), 25));
1909 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1991, 1, 1, 0, 0, 25), 26));
1910 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1992, 7, 1, 0, 0, 26), 27));
1911 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1993, 7, 1, 0, 0, 27), 28));
1912 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1994, 7, 1, 0, 0, 28), 29));
1913 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1996, 1, 1, 0, 0, 29), 30));
1914 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1997, 7, 1, 0, 0, 30), 31));
1915 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(1999, 1, 1, 0, 0, 31), 32));
1916 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(2006, 1, 1, 0, 0, 32), 33));
1917 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(2009, 1, 1, 0, 0, 33), 34));
1918 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(2012, 7, 1, 0, 0, 34), 35));
1919 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(2015, 7, 1, 0, 0, 35), 36));
1920 leaps.insert(pair<TTimeStamp, Int_t>(
TTimeStamp(2017, 1, 1, 0, 0, 36), 37));
1927 if (t <
leaps.begin()->first) {
1928 LOGF(warning,
"Wrong time! %s", t.
AsString());
1932 LOGF(warning,
"Warning! Leap seconds table expired!");
1934 auto it =
leaps.lower_bound(t);
1935 if ((it ==
leaps.end()))
1937 else if (it->first > t)
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...
char * Form(const char *fmt,...)
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
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
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)
map< SysPoint, BmnSpillInfo > fSpillMap
const TTimeStamp TimeZero
BmnStatus ConvertRawToRoot()
BmnIFileReader * fFileReader
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)
BmnStatus ProcessEvent(const uint32_t *data, uint32_t len)
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)
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)
std::map< uint8_t, const uint32_t * > time_slice_map
unique_ptr< DigiRunHeader > runHeader
virtual ~BmnRawSource() override
void ClearRawSpillArrays()
BmnThreadManager< BmnConverterThread > * fThreads
BmnEventHeader * eventHeaderDAQ
BmnSpillHeader * spillHeader
map< TTimeStamp, Int_t > leaps
BmnStatus InitConverter()
void QuickProcessEvent(const uint32_t *d, uint32_t len)
BmnStatus ConvertRawToRootIterateFileRead()
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.
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
unique_ptr< BmnMetadataRaw > metadata
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)
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)
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).
BmnIFileReader * BmnCompressionCreateNewSuitableReaderForAFile(const std::filesystem::path &aFilePath, const BmnFileType aPreferredTypeForThisAlgorithm=BmnFileType::Unknown)
std::filesystem::path BmnCompressionRemoveArchiveExtension(std::filesystem::path aFilePath)
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.