11#include "FairLogger.h"
13#include "BmnADCDigit.h"
14#include "BmnAbstractTDCDigit.h"
16#include "BmnGemStripDigit.h"
17#include "BmnHRBDigit.h"
18#include "BmnHgndRaw.h"
19#include "BmnMSCDigit.h"
20#include "BmnMSCZSDigit.h"
21#include "BmnSyncDigit.h"
22#include "BmnTDCDigit.h"
23#include "BmnTQDCADCDigit.h"
24#include "BmnVspRawDigit.h"
26#include "UniDetectorParameter.h"
27#include "UniRawFile.h"
30#include <BmnFileProp.h>
32#include "StorableTimeslice.h"
33#include "StsXyterMessage.h"
37using namespace std::chrono;
42 , isForwardMode(false)
44 , isRawRootInputFile(false)
52 , fRunStartTime(TimeZero)
53 , fRunEndTime(TimeZero)
55 , fRawTreeSpills(nullptr)
56 , fRootFileName(outfile)
58 , fRawRunHdrName(
"RawRunHeader")
59 , fMetadataName(
"RawRunMetadata")
60 , fRootFileIn(nullptr)
61 , fRootFileOut(nullptr)
75 , eventHeaderDAQ(nullptr)
76 , spillHeader(nullptr)
83 , fExportJsonBlocks(false)
84 , fExportExternalSpillStat(false)
89 LOGF(debug1,
"BmnRawSource: input %s, output %s", fRawFileName.Data(), fRootFileName.Data());
91 if (fRawFileName !=
"") {
96 LOG(debug) <<
"subname " << subName;
97 LOG(info) <<
"RunId " << fRunId <<
" got from " << (isRawRootInputFile ?
"RawRoot" :
"RawData") <<
" file";
98 if (fRootFileName.Length()) {
101 fRootFileName = Form(
"bmn_run%d%s_raw.root", fRunId, subName.Data());
115 fRawFileIn = fopen(fRawFileName,
"rb");
116 if (fRawFileIn ==
nullptr) {
117 printf(
"\n!!!!!\ncannot open file %s\nConvertRawToRoot stopped\n!!!!!\n\n", fRawFileName.Data());
120 fseeko64(fRawFileIn, 0, SEEK_END);
121 fLengthRawFile = ftello64(fRawFileIn);
123 printf(
"\nRAW FILE: ");
125 printf(
"\nRAW FILE LENGTH: ");
127 isSpillStart = kTRUE;
140 bool convertMSC = conf.get<
bool>(
"Decoder.ProcessMSC",
false);
142 fRawTreeSpills =
new TTree(
"BMN_RAW_SPILLS",
"BMN_RAW_SPILLS");
149 RegisterSpillBranches();
157 fRawFileName = FileName;
158 fRawFileIn = fopen(fRawFileName,
"rb");
159 if (fRawFileIn ==
nullptr) {
160 LOGF(error,
"\n!!!!!\ncannot open file %s\nConvertRawToRoot are stopped\n!!!!!\n", fRawFileName.Data());
163 fseeko64(fRawFileIn, 0, SEEK_END);
164 fLengthRawFile = ftello64(fRawFileIn);
166 printf(
"\nRAW FILE: ");
168 printf(
"\nRAW FILE LENGTH: ");
172 fRootFileOut =
new TFile(fRootFileName,
"recreate");
174 if (!fRootFileOut->IsOpen()) {
183 LOGF(info,
"InitConverter without file");
184 fRawTree =
new TTree(
"BMN_RAW",
"BMN_RAW");
186 LOGF(debug,
"fRawTree %p init", (
void*)fRawTree);
187 LOGF(debug,
"fRawTree path %s", fRawTree->GetDirectory()->GetPath());
190 int threadNumber = 0;
191 if (threadNumber == 0) {
192 if (std::thread::hardware_concurrency() <= 1)
195 threadNumber = std::thread::hardware_concurrency() - 1;
198 for (
int i = 0;
i < threadNumber;
i++)
201 bool convertMSC = conf.get<
bool>(
"Decoder.ProcessMSC",
false);
203 fRawTreeSpills =
new TTree(
"BMN_RAW_SPILLS",
"BMN_RAW_SPILLS");
210 RegisterSpillBranches();
217 LOGF(debug1,
"%s ", __func__);
219 fRawTreeSpills->Write();
223 delete eventHeaderDAQ;
251void BmnRawSource::RegisterBranches()
254 BranchRegFun(
"BmnEventHeader.", &eventHeaderDAQ, fRawTree);
257 sync =
new TClonesArray(BmnSyncDigit::Class());
258 BranchRegFun(
"SYNC", &sync, fRawTree);
259 adc32 =
new TClonesArray(BmnADCDigit::Class());
260 BranchRegFun(
"ADC32", &adc32, fRawTree);
261 adc64 =
new TClonesArray(BmnADCDigit::Class());
262 BranchRegFun(
"ADC64", &adc64, fRawTree);
263 adc128 =
new TClonesArray(BmnADCDigit::Class());
264 BranchRegFun(
"ADC128", &adc128, fRawTree);
265 adc =
new TClonesArray(BmnADCDigit::Class());
266 BranchRegFun(
"ADC", &adc, fRawTree);
267 vsp =
new TClonesArray(BmnVspRawDigit::Class());
268 BranchRegFun(
"VSP_RAW", &vsp, fRawTree);
269 tdc =
new TClonesArray(BmnTDCDigit::Class());
270 BranchRegFun(
"TDC", &tdc, fRawTree);
271 tqdc_adc =
new TClonesArray(BmnTQDCADCDigit::Class());
272 BranchRegFun(
"TQDC_ADC", &tqdc_adc, fRawTree);
273 tqdc_tdc =
new TClonesArray(BmnTDCDigit::Class());
274 BranchRegFun(
"TQDC_TDC", &tqdc_tdc, fRawTree);
275 hrb =
new TClonesArray(BmnHRBDigit::Class());
276 BranchRegFun(
"HRB", &hrb, fRawTree);
277 tdc_hgnd =
new TClonesArray(BmnAbstractTDCDigit::Class());
278 BranchRegFun(
"TDC_HGND", &tdc_hgnd, fRawTree);
281void BmnRawSource::RegisterSpillBranches()
286 BranchRegFun(
"MSC", &msc, fRawTreeSpills);
288 BranchRegFun(
"T0Raw", &t0raw, fRawTreeSpills);
298 DeviceHeader* dh =
reinterpret_cast<DeviceHeader*
>(
d + idx);
302 string str(
reinterpret_cast<const char*
>(
d + idx), str_len);
308 string jkey(it.key());
310 if (!jkey.compare(
"status")) {
311 auto& j_runtime = it.value()[
"runTime"];
312 auto j_spill = j_runtime[
"spill"];
313 Int_t phase =
static_cast<Int_t
>(j_spill[
"phase"]);
315 auto wr = j_runtime[
"time"][
"WR"];
316 Int_t ns =
static_cast<Int_t
>(wr[
"ns"]);
317 Int_t sec =
static_cast<Int_t
>(wr[
"sec"]);
318 if (tai_utc_dif == 0)
319 tai_utc_dif = GetUTCShift(TTimeStamp(time_t(sec), ns));
330 LOGF(info,
"JSON status phase %d", phase);
334 auto spill_it = fSpillMap.find(ss.
start_ts);
335 if (spill_it == fSpillMap.end()) {
337 std::tie(spill_it, inserted) = fSpillMap.insert(
340 .start_ts = ss.start_ts,
341 .stop_ts = ss.start_ts}));
342 LOGF(debug,
"spill record inserted %d", inserted);
348 if (fExportJsonBlocks) {
349 std::ofstream outfile(Form(
"j_%s_%d_%9d_%09d_%02X_%08X_phase_%d_%s.json", jkey.c_str(), fRunId, sec,
350 ns, dh->DeviceId, dh->Serial, phase, fSubName.Data()),
351 std::ofstream::binary);
352 outfile << std::setw(4) << j << std::endl;
355 metadata->SpillStatusVec().push_back(move(ss));
357 LOGF(info,
"JSON config");
358 if (!jkey.compare(
"config")) {
359 string start_DT = it.value()[
"meta"][
"startDateTime"];
360 if (fExportJsonBlocks) {
361 std::ofstream outfile(Form(
"j_%s_%d_%s_%02X_%08X.json", jkey.c_str(), fRunId, start_DT.data(),
362 dh->DeviceId, dh->Serial),
363 std::ofstream::binary);
364 outfile << std::setw(4) << j << std::endl;
370 LOGF(error,
"Parsing JSON config failed!");
372 LOGF(info,
"Unknown json key %s", jkey.data());
375 }
catch (std::exception& ex) {
376 LOGF(error,
"Exception for JSON block: %s", ex.what());
384 eventHeaderDAQ->SetRunId(fRunId);
386 ProcessEvent(
d, len);
395 LOGF(debug1,
"\tspill! nSpillEvents %d", nSpillEvents);
396 isSpillStart = kTRUE;
408 if (isRawRootInputFile) {
409 LOGF(info,
"Input is raw root file. Nothing to do!");
413 LOGF(error,
"Init converter failed!");
417 if ((fStartEventId == 0) && (fEventId))
418 fStartEventId = fEventId;
421 for (
auto& it : fSpillMap) {
427 fRunEndTime = TTimeStamp(time_t(fTime_s), fTime_ns);
428 Int_t shift = GetUTCShift(fRunEndTime);
429 if ((shift != tai_utc_dif)) {
430 LOGF(info,
"START (event %u):\t%s", fStartEventId, fRunStartTime.AsString());
431 LOGF(info,
"FINISH (event %u):\t%s", fEventId, fRunEndTime.AsString());
432 LOG(info) <<
"Total Events:\t" << fNTotalEvents;
433 LOG(info) <<
"nSignal Events:\t" << fNSignalEvents;
443 fCurentPositionRawFile = ftello64(fRawFileIn);
444 LOG(info) <<
"Read " << fNTotalEvents <<
" events; " << fCurentPositionRawFile <<
" bytes ("
445 << fCurentPositionRawFile / 1024. / 1024. <<
" Mb)";
451 fRawTreeSpills->Write();
454 runHeader->SetSpillMap(move(fSpillMap));
455 fRootFileOut->WriteObject(runHeader.get(), fRawRunHdrName.Data());
456 fRootFileOut->WriteObject(metadata.get(), fMetadataName.Data());
457 fRootFileOut->Close();
472 delete eventHeaderDAQ;
476 int period_id = (int)fPeriodId, run_id = (
int)fRunId, start_event = (int)fStartEventId,
477 end_event = (
int)fEventId,
478 event_count = fNSignalEvents;
481 TString raw_filename = gSystem->BaseName(fRawFileName);
484 if ((pRawFiles !=
nullptr) && (pRawFiles->GetEntries() == 0)) {
486 cout <<
"CRITICAL WARNING: there are overlaps in events for the new file metadata: " << fRawFileName
487 <<
" (" << period_id <<
":" << run_id <<
" " << start_event <<
"-" << end_event <<
")" << endl
488 <<
"PLEASE, SEND THE INFO TO THE SOFTWARE COORDINATOR" << endl;
490 TDatime fFileStartDate(Int_t(fRunStartTime.GetDate(kFALSE)), Int_t(fRunStartTime.GetTime(kFALSE)));
491 TDatime fFileEndDate(Int_t(fRunEndTime.GetDate(kFALSE)), Int_t(fRunEndTime.GetTime(kFALSE)));
494 TString* pFileHash =
nullptr;
495 if (strFileHash !=
"")
496 pFileHash =
new TString(strFileHash);
498 cout <<
"WARNING: a problem occurred while calculating checksum for the raw file: " << fRawFileName
503 fRawFileName, event_count, fLengthRawFile, pFileHash);
508 cout <<
"Raw file information has been successfully added to the Condition Database for run "
509 << period_id <<
":" << run_id <<
" and event interval " << start_event <<
"-" << end_event << endl;
518 if (pRawFiles !=
nullptr) {
519 if (pRawFiles->GetEntries() > 1)
520 cout <<
"CRITICAL WARNING: there are more than one records for the file metadata: " << fRawFileName
522 <<
"PLEASE, SEND THE INFO TO THE SOFTWARE COORDINATOR" << endl;
526 cout <<
"CRITICAL WARNING: there are different start event for the file metadata: "
527 << fRawFileName <<
" (" << period_id <<
":" << run_id <<
" " << start_event <<
"-"
528 << end_event <<
")" << endl
529 <<
"PLEASE, SEND THE INFO TO THE SOFTWARE COORDINATOR" << endl;
530 else if (pExistingRawFile->
GetEndEvent() < end_event)
531 cout <<
"CRITICAL WARNING: the existing file metadata has 'end event' less than: "
532 << fRawFileName <<
" (" << period_id <<
":" << run_id <<
" " << start_event <<
"-"
533 << end_event <<
")" << endl
534 <<
"PLEASE, SEND THE INFO TO THE SOFTWARE COORDINATOR" << endl;
541 }
catch (std::exception& ex) {
542 printf(
"Exception of working with the Condition Database: %s\n", ex.what());
545 LOG(info) <<
"Real time " << workTime_real <<
" s, CPU time " << workTime_cpu <<
" s for Converter\n";
551 Long_t pos = ftello64(fRawFileIn);
554 while (fLengthRawFile < pos + len) {
559 fseeko64(fRawFileIn, 0, SEEK_END);
560 fLengthRawFile = ftello64(fRawFileIn);
561 fseeko64(fRawFileIn, pos - fLengthRawFile, SEEK_CUR);
572 return ProcessEvent(buf, len);
582 fCurentPositionRawFile = ftello64(fRawFileIn);
600 if (fMaxEvent > 0 && fNSignalEvents >= fMaxEvent)
602 if (fread(&fDat,
kWORDSIZE, 1, fRawFileIn) != 1)
604 fCurentPositionRawFile = ftello64(fRawFileIn);
605 if (fCurentPositionRawFile >= fLengthRawFile)
613 if (fread(&fDat,
kWORDSIZE, 1, fRawFileIn) != 1)
616 LOGF(error,
"WTF?? in the main event: fDat == %u", fDat);
621 if (fread(data,
kWORDSIZE, fDat, fRawFileIn) != fDat)
628 QuickProcessEvent(data, fDat);
630 ProcessEvent(data, fDat);
643 LOGF(debug1,
"isSpillStart %d", isSpillStart);
644 if (isSpillStart == kTRUE)
645 isSpillStart = kFALSE;
656 if (fread(&fDat,
kWORDSIZE, 1, fRawFileIn) != 1)
659 LOGF(error,
"WTF?? in the STAT: fDat == %u", fDat);
661 LOGF(debug3,
"STAT ev length bytes %d", fDat);
664 if (fread(data,
kWORDSIZE, fDat, fRawFileIn) != fDat)
669 LOGF(info,
"RUN START");
672 LOGF(info,
"RUN STOP");
673 if (fread(&fDat,
kWORDSIZE, 1, fRawFileIn) != 1)
675 if (fread(data, 1, fDat, fRawFileIn) != fDat)
680 LOGF(info,
"FILE BEGIN");
683 LOGF(info,
"FILE END");
684 if (fread(&fDat,
kWORDSIZE, 1, fRawFileIn) != 1)
686 if (fread(data, 1, fDat, fRawFileIn) != fDat)
691 if (fread(&fDat,
kWORDSIZE, 1, fRawFileIn) != 1)
693 LOGF(debug,
"SYNC JSON len %u", fDat);
694 if (fread(data, 1, fDat, fRawFileIn) != fDat)
699 LOGF(error,
"unrecognized sync %08X", fDat);
702 fPrevEvType = fCurEvType;
708void BmnRawSource::FinalizeStat()
711 if (fRawTreeSpills && ((msc->GetEntriesFast() > 0) || (t0raw->GetEntriesFast() > 0))) {
712 fRawTreeSpills->Fill();
718void BmnRawSource::QuickProcessEvent(UInt_t*
d, UInt_t len)
727BmnStatus BmnRawSource::ProcessEvent(UInt_t*
d, UInt_t len)
735 if ((fNTotalEvents % 5000 == 0) && (fCurEvType !=
kBMNSTAT) && (fEventId > 0))
736 LOG(info) <<
"Converted events:" << fNTotalEvents;
745 Bool_t recognized = kTRUE;
746 DeviceHeader* dh =
reinterpret_cast<DeviceHeader*
>(
d + idx);
747 LOGF(debug2,
"[%u / %u]", idx, len);
749 UInt_t serial = dh->Serial;
750 uint8_t
id = dh->DeviceId;
751 UInt_t payload = dh->GetNWords();
753 if (payload > 2000000) {
755 LOGF(warn,
"Event %d:\n serial = 0x%06X\n id = Ox%02X\n payload = %d", fEventId, serial,
id, payload);
759 LOGF(debug4,
"STAT iev %7u idx %6u/%6u idev %02X serial 0x%08X payload %4u", fEventId, idx, len,
id,
763 FillTQDC_E(&
d[idx], serial, payload);
767 FillTDC72VXS(&
d[idx], serial, payload,
id);
770 FillTTVXS(&
d[idx], serial, payload);
773 ProcessGenericDevice(&
d[idx], dh);
777 FillMSC16VE_E(&
d[idx], dh);
782 BmnStatus ret = BmnConverterTools::Process_ADC64<Short_t>(&
d[idx], payload, serial,
783 [&](Int_t n_samples) -> TClonesArray* {
800 LOGF(warning,
"Malformed data from ADC64VE %08X in the event %u", serial, fEventId);
804 BmnStatus ret = BmnConverterTools::Process_ADC64<UShort_t>(
805 &
d[idx], payload, serial, [&](Int_t n_samples) -> TClonesArray* {
return adc; });
807 LOGF(warning,
"Malformed data from ADC64WR %08X in the event %u", serial, fEventId);
811 Process_FVME(&
d[idx], payload, serial, trigInfo);
814 Process_HRB(&
d[idx], payload, serial);
817 FillUT24VE_TRC(&
d[idx], serial, payload);
820 FillVirtualDevice(&
d[idx], dh);
827 if (payload + idx > len) {
829 "Error in the event #%d: 0x%08X : %2X device payload length mismatch! pauload %5u idx/len: %5u/%5u \n",
830 fEventId, serial,
id, payload, idx, len);
839 if (time_slice_map.size())
841 if (fRunStartTime == TimeZero && fCurEvType ==
kBMNPAYLOAD) {
842 fRunStartTime = TTimeStamp(time_t(fTime_s), fTime_ns);
843 LOGF(info,
"Run start ts %s", fRunStartTime.AsString());
845 eventHeaderDAQ->SetRunId(fRunId);
848 eventHeaderDAQ->
SetEventTimeTS(TTimeStamp(time_t(fTime_s), fTime_ns));
849 eventHeaderDAQ->SetEventTime(TTimeStamp(time_t(fTime_s), fTime_ns).AsDouble());
858 rtime = timer.RealTime();
859 ctime = timer.CpuTime();
860 workTime_cpu += rtime;
861 workTime_real += ctime;
862 if (fRunStartTime == TimeZero)
863 fRunStartTime = TTimeStamp(time_t(fTime_s), fTime_ns);
871 LOGF(debug2,
"FVME serial %08X len %u", serial, len);
874 LOGF(debug,
"Stat FVME serial %08X efter iEv %u", serial, fEventId);
879 for (UInt_t
i = 0;
i < len;
i++) {
897 modId = (
d[
i] >> 16) & 0x7F;
898 slot = (
d[
i] >> 23) & 0x1F;
905 if (!((
d[
i] >> 16) & 0x1))
907 if (!((
d[
i] >> 17) & 0x1))
909 if (!((
d[
i] >> 18) & 0x1))
911 if (!((
d[
i] >> 19) & 0x1))
926 FillTDC(
d, serial, slot, modId,
i);
930 FillTQDC(
d, serial, slot, modId,
i);
933 FillMSC(
d, serial, slot,
i);
936 FillFVME2TMWR(
d, serial,
i, len);
939 FillU40VE(
d, slot,
i, trigInfo);
948BmnStatus BmnRawSource::Process_HRB(UInt_t*
d, UInt_t len, UInt_t serial)
954 UInt_t nSmpl = (len - 3) / nWords;
956 for (UInt_t iSmpl = 0; iSmpl < nSmpl; ++iSmpl) {
957 for (UInt_t iWord = 0; iWord < nWords; ++iWord) {
958 UInt_t word32 =
d[3 + iWord + iSmpl * nWords];
959 for (Int_t iCh = 0; iCh < 32; ++iCh) {
960 if (word32 & BIT(iCh)) {
961 TClonesArray& ar_hrb = *hrb;
962 new (ar_hrb[hrb->GetEntriesFast()])
BmnHRBDigit(serial, iCh + 32 * iWord, iSmpl, tH, tL);
973 UInt_t
type =
d[idx] >> 28;
975 Bool_t countersDone = kFALSE;
985 if (type ==
kWORDAUX && !countersDone) {
994 countersDone = kTRUE;
1004BmnStatus BmnRawSource::FillTDC(UInt_t*
d, UInt_t serial, UInt_t slot, UInt_t modId, UInt_t& idx)
1006 UInt_t
type =
d[idx] >> 28;
1009 if (fVerbose == 0) {
1010 LOGF(warning,
"TDC (modID 0x%02X serial 0x%08X slot %d tdcID %d) error flags: 0x%04X", modId, serial,
1011 slot, ((
d[idx] >> 24) & 0xF), (
d[idx] & ((1 << 15) - 1)));
1012 if ((
d[idx] & BIT(12)) || (
d[idx] & BIT(13))) {
1013 LOGF(warning,
"TDC data loss in 0x%08X ", serial);
1019 UInt_t tdcId = (
d[idx] >> 24) & 0xF;
1021 (modId ==
kTDC64V) ? (
d[idx] & 0x7FFFF) : ((
d[idx] & 0x7FFFF) << 2) | ((
d[idx] & 0x180000) >> 19);
1022 UInt_t channel = (modId ==
kTDC64V) ? (
d[idx] >> 19) & 0x1F : (
d[idx] >> 21) & 0x7;
1024 TClonesArray& ar_tdc = *tdc;
1025 new (ar_tdc[tdc->GetEntriesFast()])
1028 LOGF(debug4,
"tdc %08X : %d channel %d", serial, slot, channel);
1031 type =
d[idx] >> 28;
1036BmnStatus BmnRawSource::FillTQDC(UInt_t*
d, UInt_t serial, UInt_t slot, UInt_t modId, UInt_t& idx)
1038 UInt_t
type =
d[idx] >> 28;
1039 UShort_t trigTimestamp = 0;
1040 UShort_t adcTimestamp = 0;
1041 UShort_t tdcTimestamp = 0;
1045 Bool_t inADC = kFALSE;
1048 if (fVerbose == 0) {
1049 LOGF(warning,
"In event %8u: TDC (serial 0x%08X slot %d tdcID %d) error flags: 0x%04X", fEventId,
1050 serial, slot, ((
d[idx] >> 24) & ((1 << 4) - 1)), (
d[idx] & ((1 << 15) - 1)));
1051 if ((
d[idx] & BIT(12)) || (
d[idx] & BIT(13))) {
1052 LOGF(warning,
"\tTQDC data loss in 0x%08X ", serial);
1057 UInt_t mode = (
d[idx] >> 26) & 0x3;
1060 channel = (
d[idx] >> 19) & 0x1F;
1061 UInt_t time = ((
d[idx] & 0x7FFFF) << 2) | ((
d[idx] >> 24) & 0x3);
1063 new ((*tqdc_tdc)[tqdc_tdc->GetEntriesFast()])
1066 }
else if ((type == 4) && (mode != 0)) {
1067 channel = (
d[idx] >> 19) & 0x1F;
1068 if (
d[idx] & BIT(16)) {
1069 adcTimestamp =
d[idx] & 0xFFFF;
1072 trigTimestamp =
d[idx] & 0xFFFF;
1075 tdcTimestamp =
d[idx] & 0xFFF;
1084 Short_t
val = (
d[idx] & ((1 << 14) - 1)) - (1 << (14 - 1));
1085 valI[iSampl++] =
val;
1087 new ((*tqdc_adc)[tqdc_adc->GetEntriesFast()])
1088 BmnTQDCADCDigit(serial, channel, slot, iSampl, valI, trigTimestamp, adcTimestamp);
1095 type =
d[++idx] >> 28;
1100BmnStatus BmnRawSource::FillBlockADC(UInt_t*
d, UInt_t serial, uint8_t channel, uint16_t& len, TClonesArray* ar)
1103 const uint8_t NBytesInSample = 2;
1105 while (iWord < len) {
1106 uint16_t adcTS =
d[iWord] & (BIT(16) - 1);
1107 uint16_t SigLen =
d[iWord] >> 16;
1108 uint16_t NSamples = SigLen / NBytesInSample;
1111 if (iWord + NSampleWords + 1 > len) {
1112 printf(
"Error! TQDC ADC wrong payload length! iWord %u SigLen %u len %u\n", iWord, SigLen, len);
1115 uint16_t iSampleWord = 0;
1116 while (iSampleWord++ < NSampleWords) {
1117 int16_t adcLo =
static_cast<int16_t
>(
d[iWord + iSampleWord] & (BIT(16) - 1));
1118 int16_t adcHi =
static_cast<int16_t
>(
d[iWord + iSampleWord] >> 16);
1120 valI[iSampleWord * 2 - 2] = adcLo;
1121 valI[iSampleWord * 2 - 1] = adcHi;
1125 new ((*ar)[ar->GetEntriesFast()])
BmnTQDCADCDigit(serial, channel, 0, NSamples, valI, 0, adcTS);
1126 iWord += iSampleWord;
1131BmnStatus BmnRawSource::FillBlockTDC(UInt_t*
d, UInt_t serial, uint16_t& len, TClonesArray* ar, UInt_t modid = 0)
1135 uint16_t tdcLine = 0;
1136 while (tdcLine < len) {
1137 UInt_t word =
d[tdcLine];
1138 UInt_t bt = word >> 28;
1155 uint8_t channel = (word >> 21) & (BIT(7) - 1);
1157 UInt_t time = word & (BIT(21) - 1);
1165 LOGF(warning,
"TDC (serial 0x%08X tdcID %d) in event %u error flags: 0x%04X %s", serial,
1166 ((word >> 24) & ((1 << 4) - 1)), fEventId, (word & ((1 << 15) - 1)),
1167 ((word & BIT(12)) || (word & BIT(13))) ?
"data lost" :
"");
1175BmnStatus BmnRawSource::FillTQDC_E(UInt_t*
d, UInt_t serial, UInt_t& len)
1181 MStreamTAI* ms0 =
reinterpret_cast<MStreamTAI*
>(
d + index);
1183 FillWR(serial, fEventId, ms0->Sec, ms0->NSec);
1188 while (index < len) {
1189 TqdcDataHeader* th =
reinterpret_cast<TqdcDataHeader*
>(
d + index);
1194 switch (th->DataType) {
1196 FillBlockTDC(
d + index, serial, blockLen, tqdc_tdc);
1199 FillBlockADC(
d + index, serial, th->Chan, blockLen, tqdc_adc);
1202 printf(
"Wrong TQDC data type %u !\n", th->DataType);
1210BmnStatus BmnRawSource::FillTDC72VXS(UInt_t*
d, UInt_t serial, UInt_t& len, UInt_t modid = 0)
1216 MStreamTAI* ms0 =
reinterpret_cast<MStreamTAI*
>(
d + index);
1218 FillWR(serial, fEventId, ms0->Sec, ms0->NSec);
1222 while (index < len) {
1223 uint8_t dtype =
d[index] >> 28;
1224 bool overflow =
d[index] & BIT(16);
1225 uint16_t blockLen = (
d[index++] & (BIT(16) - 1)) /
kNBYTESINWORD;
1230 FillBlockTDC(
d + index, serial, blockLen, tdc, modid);
1235 printf(
"Wrong VXS data type %u !\n", dtype);
1243BmnStatus BmnRawSource::FillTTVXS(UInt_t*
d, UInt_t serial, UInt_t& len)
1249 MStreamTAI* ms0 =
reinterpret_cast<MStreamTAI*
>(
d + index);
1252 FillWR(serial, fEventId, ms0->Sec, ms0->NSec);
1256 while (index < len) {
1257 uint8_t dtype =
d[index] >> 28;
1258 bool overflow =
d[index] & BIT(16);
1259 uint16_t blockLen = (
d[index++] & (BIT(16) - 1)) /
kNBYTESINWORD;
1272 printf(
"Wrong TTVXS data type %u !\n", dtype);
1280BmnStatus BmnRawSource::ProcessGenericDevice(UInt_t*
d, DeviceHeader* dev_hdr)
1284 return MapVSP(
d, dev_hdr);
1286 return FillTDC250HGND(
d, dev_hdr->Serial, dev_hdr->Len);
1288 LOGF(error,
"BmnRawSource::ProcessGenericDevice: Unknown device serial 0x%08X", dev_hdr->Serial);
1293BmnStatus BmnRawSource::FillTDC250HGND(UInt_t*
d, UInt_t serial, UInt_t len)
1298 uint16_t* words =
reinterpret_cast<uint16_t*
>(
d);
1299 size_t total_words = len /
sizeof(uint16_t);
1301 if (FairLogger::GetLogger()->IsLogNeeded(fair::Severity::debug4)) {
1302 for (
size_t i = 0;
i < total_words; ++
i)
1303 LOGF(debug4,
"0x%04x", words[
i]);
1307 std::vector<uint16_t> event_words;
1308 std::unique_ptr<BmnHgndRaw::FIFO_block> event;
1310 while (index < total_words) {
1311 uint16_t* word = words + index;
1313 LOGF(error,
"BmnRawSource::FillTDC250HGND: Wrong header 0x%04X", *word);
1320 LOGF(debug4,
"Event type %d, 16bit words %d (index=%zu, total=%zu)", (uint32_t)event_type, event_length, index,
1323 if (index + event_length > total_words) {
1324 LOGF(error,
"BmnRawSource::FillTDC250HGND: Event block overruns buffer");
1328 event_words.assign(word, word + event_length);
1329 if (FairLogger::GetLogger()->IsLogNeeded(fair::Severity::debug4)) {
1330 for (
size_t i = 0;
i < event_words.size(); ++
i) {
1331 LOGF(debug4,
"0x%04x", event_words[
i]);
1335 if (event_type == BmnHgndRaw::Block::EventPacketVersion::V1) {
1336 event = std::make_unique<BmnHgndRaw::Event_type_1>(event_words);
1337 }
else if (event_type == BmnHgndRaw::Block::EventPacketVersion::V2) {
1338 event = std::make_unique<BmnHgndRaw::Event_type_2>(event_words);
1339 if (!event->validate()) {
1340 LOGF(error,
"BmnRawSource::FillTDC250HGND: Event block validation failed");
1346 LOGF(error,
"BmnRawSource::FillTDC250HGND: Event cast to Event_type_2 failed");
1350 uint8_t trise_100ps = ev2->TDC_rise_time;
1351 uint8_t tfall_100ps = ev2->TDC_falling_time;
1352 int64_t time_sec = ev2->timestamp >> 31;
1353 time_sec -= tai_utc_dif;
1354 uint64_t time_nsec = ((ev2->timestamp & 0x7ffffff0) >> 4) * 32;
1355 uint16_t time_100ps =
1356 (ev2->timestamp & 0xf) * 32 + trise_100ps;
1357 uint16_t plen_100ps =
1358 (ev2->pulse_length + 1) * 32 + tfall_100ps - trise_100ps;
1360 LOGF(debug4,
"ch_num = 0x%02X", ev2->channel_number);
1361 LOGF(debug4,
"timestamp = 0x%016lX", ev2->timestamp);
1362 LOGF(debug4,
"time_sec = 0x%08X", time_sec);
1363 LOGF(debug4,
"time_nsec = 0x%08X", time_nsec);
1364 LOGF(debug4,
"trise_100ps = 0x%02X", trise_100ps);
1365 LOGF(debug4,
"tfall_100ps = 0x%02X", tfall_100ps);
1366 LOGF(debug4,
"time_100ps = 0x%04X", time_100ps);
1367 LOGF(debug4,
"plen_100ps = 0x%04X", plen_100ps);
1368 LOGF(debug4,
"global_ch = 0x%04X", ev2->channel_number_global);
1370 new ((*tdc_hgnd)[tdc_hgnd->GetEntriesFast()])
1371 BmnAbstractTDCDigit(serial, ev2->channel_number_global, time_sec, time_nsec, time_100ps, plen_100ps);
1373 LOGF(error,
"BmnRawSource::FillTDC250HGND: Wrong event type");
1377 index += event_length;
1383BmnStatus BmnRawSource::MapVSP(UInt_t*
d, DeviceHeader* dev_hdr)
1385 LOGF(debug,
"MapVSP");
1386 if (dev_hdr->GetNWords() < 3) {
1387 LOGF(warning,
"Empty VSP block");
1390 uint8_t iComp = (dev_hdr->Serial & 0xFF000000) >> 24;
1391 time_slice_map[iComp] =
d;
1395BmnStatus BmnRawSource::FillVSP(TClonesArray* ar)
1397 LOGF(debug,
"FillVSP");
1398 const uint8_t kuMaxComps = 10;
1399 uint16_t fvuCurrentTsMsbCycle[kuMaxComps] = {};
1400 uint64_t fvulCurrentTsMsb[kuMaxComps] = {};
1402 uint8_t nComp = time_slice_map.size();
1406 for (uint8_t iw01 = 0; iw01 < nComp; iw01++)
1407 (*stti).append_component(1);
1409 for (
auto& el : time_slice_map) {
1410 uint8_t iw01 = el.first;
1411 auto* mslice_descr = el.second;
1415 for (uint8_t uw02 = 0; uw02 < nComp; uw02++) {
1419 uint16_t fuCurrentEquipmentId =
static_cast<uint16_t
>(msd.
eq_id);
1420 uint16_t fusCurrentDpbIdx =
static_cast<uint32_t
>(fuCurrentEquipmentId & 0xFFFF);
1423 uint64_t tgn = msd.
idx;
1424 if (tgn != fEventId)
1425 LOGF(warning,
"!!! Misplaced VSP event! tgn = %lu while EventId = %u !!!\n", tgn, fEventId);
1426 uint32_t tgNev =
static_cast<uint32_t
>(tgn);
1435 uint32_t uNbMessages = 0;
1437 uint64_t uiTrgTimeFLES = 0;
1438 uint64_t uiHitTimeFLES = 0;
1441 static const uint32_t kuBytesPerMessage = 4;
1443 uNbMessages = (size - (size % kuBytesPerMessage)) / kuBytesPerMessage;
1446 const uint32_t* pInBuff =
reinterpret_cast<const uint32_t*
>((*stti).content(uw02, 0));
1449 uint64_t uiTrgTime_TsMsb = 0;
1450 uint64_t uiHitTime_TsMsb = 0;
1451 uint64_t uiTrgTime_Epoch = 0;
1453 uint16_t uiTsMsbMessageNumber = 0;
1454 uint16_t uiEpochMessageNumber = 0;
1456 uint16_t usHitMissedEvts = 0;
1457 if (uNbMessages == 0)
1461 for (uint32_t uIdx = 0; uIdx < uNbMessages; ++uIdx) {
1463 uint32_t ulData =
static_cast<uint32_t
>(pInBuff[uIdx]);
1471 uiEpochMessageNumber++;
1473 if (uiEpochMessageNumber == 1)
1474 uiTrgTime_Epoch = mess.GetEpochVal();
1476 printf(
"fles WARNING: more than one EPOCH message in event tgN = %lu, exactly: %u\n", tgn,
1477 uiEpochMessageNumber);
1481 uiTsMsbMessageNumber++;
1482 uint64_t uVal = mess.GetTsMsbValBinning();
1483 if (uVal < fvulCurrentTsMsb[uw02]) {
1484 printf(
"TsMsbCycle: event trigger# %u", tgNev);
1485 printf(
"\tDPB: %u, Old TsMsb= %lu, new TsMsb=%lu, Old MsbCy=%u\n", uw02, fvulCurrentTsMsb[uw02],
1486 uVal, fvuCurrentTsMsbCycle[uw02]);
1488 if ((fvulCurrentTsMsb[uw02] - uVal) > 10000000)
1489 fvuCurrentTsMsbCycle[uw02]++;
1492 fvulCurrentTsMsb[uw02] = uVal;
1493 uiHitTime_TsMsb = uVal << 10;
1494 uiHitTime_TsMsb +=
static_cast<uint64_t
>(stsxyter::kulTsCycleNbBinsBinning)
1495 * fvuCurrentTsMsbCycle[uw02];
1496 if (uiTsMsbMessageNumber == 1) {
1498 uiHitTime_TsMsb & 0xFFE0000000;
1503 uint16_t usRawTs =
static_cast<uint16_t
>(mess.GetHitTimeBinning());
1504 uiHitTimeFLES = uiHitTime_TsMsb +
static_cast<uint64_t
>(usRawTs);
1505 uint16_t usElinkIdx = mess.GetLinkIndexHitBinning();
1506 uint16_t usChan = mess.GetHitChannel();
1507 uint16_t usRawAdc = mess.GetHitAdc();
1509 if (mess.IsHitMissedEvts())
1511 dig->
AppendHit(uiHitTimeFLES, usElinkIdx, usChan, usRawAdc);
1520 uiTrgTimeFLES = uiTrgTime_TsMsb + uiTrgTime_Epoch;
1523 time_slice_map.clear();
1527BmnStatus BmnRawSource::FillMSC16VE_E(UInt_t*
d, DeviceHeader* dev_hdr)
1531 const uint32_t len = dev_hdr->GetNWords();
1532 MSC16VE_EHeader* ms =
reinterpret_cast<MSC16VE_EHeader*
>(
d);
1535 if (ms->Hdr.Len > (len - 1)) {
1536 LOGF(error,
"MSC header payload length mismatch!");
1542 Bool_t hasValues = kFALSE;
1543 std::array<uint8_t, MSC_N_COUNTERS> cntrs = {};
1544 switch (ms->GetVersion()) {
1546 const uint8_t NumsInWord = 4;
1547 while (index < len) {
1548 uint8_t
type =
d[index] >> 28;
1552 UInt_t ext_cond = (
d[index] >> 24) & (BIT(4) - 1);
1553 UInt_t sliceNum = (
d[index]) & (BIT(24) - 1);
1554 auto sc_time_shift = ms->SliceInt * sliceNum * 1ns;
1555 SysPoint p{(ms->Tai.Sec - tai_utc_dif) * 1s + ms->Tai.NSec * 1ns + sc_time_shift};
1556 LOGF(debug,
"MSC ext_cond %2u sliceNum %7u time %s", ext_cond, sliceNum,
1558 new ((*msc)[msc->GetEntriesFast()])
1564 for (uint8_t
i = 0;
i < NumsInWord;
i++) {
1565 UInt_t cnt = (
d[index] >> (
i * ms->NCntrBits)) & (BIT(ms->NCntrBits) - 1);
1566 cntrs[
type * NumsInWord +
i] = cnt;
1575 UInt_t missing_hits =
d[index++];
1577 LOGF(info,
"missing_hits %3u !!!", missing_hits);
1578 LOGF(debug,
"missing_hits %u", missing_hits);
1582 SysPoint point{(ms->Tai.Sec - tai_utc_dif) * 1s + ms->Tai.NSec * 1ns};
1583 uint32_t n_slices = ms->Hdr.Len - 1 - (
sizeof(MSC16VE_EHeader) -
sizeof(MStreamHeader)) /
kNBYTESINWORD;
1586 vector<uint8_t>& vals = dig->
GetValues();
1587 vector<SysPoint>& times = dig->
GetTimes();
1589 int32_t istart = index;
1590 while (index < len) {
1591 uint8_t cnt =
d[index] & (BIT(ms->NCntrBits) - 1);
1592 uint8_t ext_cond = (
d[index] >> ms->NCntrBits) & (BIT(ms->ExtCondCnt) - 1);
1593 UInt_t sliceNum =
d[index] >> (ms->NCntrBits + ms->ExtCondCnt);
1594 auto sc_time_shift = ms->SliceInt * sliceNum * 1ns;
1595 SysPoint point_slice{point + sc_time_shift};
1596 int32_t iVal = index - istart;
1599 times[iVal] = point_slice;
1600 conds[iVal] = ext_cond;
1602 LOGF(debug,
"MSC ext_cond %2u cnt %2u sliceNum %7u time %s", ext_cond, cnt, sliceNum,
1615 LOGF(warning,
"MSC16 ver $u not implemented", ms->GetVersion());
1624BmnStatus BmnRawSource::FillVirtualDevice(UInt_t*
d, DeviceHeader* dh)
1626 LOGF(info,
"Found virtual device 0x%08X block", dh->Serial);
1627 LOGF(info,
"Ev %u type %u", fEventId, (UInt_t)fCurEvType);
1629 LOGF(info,
"Not T0 device");
1633 if (fExportExternalSpillStat) {
1634 std::ofstream outfile(Form(
"virt_device_run_%u_%08X_%02X_%s_t_%lld_%lld.txt", fRunId, dh->Serial, dh->DeviceId,
1635 fSubName.Data(), fTime_s, fTime_ns),
1636 ios::out | ios::binary);
1638 outfile << std::hex <<
d[
i];
1639 outfile.write(
reinterpret_cast<const char*
>(
d) + bin_block_len, dh->Len - bin_block_len);
1643 const Int_t date_len = 19;
1645 TPRegexp re_str_cfg_t0(
"(\\d{2})\\.(\\d{2})\\.(\\d{4})\\s(\\d{2}:\\d{2}:\\d{2})");
1646 int32_t re_subst_ret = re_str_cfg_t0.Substitute(str,
"$3-$2-$1 $4");
1647 LOGF(info,
"ts line return %d", re_subst_ret);
1649 LOGF(debug,
"cntr[%3d]: %8u",
i,
d[
i]);
1655 TTimeStamp ts_unix_sec(t_unix_sec, 0);
1656 TTimeStamp ts_2020_sec(t_2020_sec + TTimeStamp(2020, 1, 1, 0, 0, 0), 0);
1657 LOGF(info,
"unix ts: %s", ts_unix_sec.AsString());
1658 LOGF(info,
"2020 ts: %s", ts_2020_sec.AsString());
1660 lastT0->SetTriggerMask(trig_bit_conf);
1661 bitset<32> trig_bit_conf_bs(trig_bit_conf);
1662 LOGF(debug,
"trig bitset %u", trig_bit_conf);
1663 LOGF(debug,
"trig bitset %s", trig_bit_conf_bs.to_string());
1665 string tcfg(
reinterpret_cast<const char*
>(
d) + pos, dh->Len - pos);
1671 TTimeStamp(ts_unix_sec.GetSec() - 3 * 3600,
1672 ts_unix_sec.GetNanoSec());
1674 lastT0->SetTS(ts_unix_sec);
1676 if (t_2020_sec > 0) {
1677 lastT0->SetTS(ts_2020_sec);
1678 }
else if (re_subst_ret > 0) {
1680 TTimeStamp ts_from_string(
static_cast<UInt_t
>(dt.GetDate()),
static_cast<UInt_t
>(dt.GetTime()), 0u);
1681 LOGF(info,
"ts line: %s", ts_from_string.AsString());
1682 ts_from_string = TTimeStamp(
1683 ts_from_string.GetSec() - 3 * 3600,
1684 ts_from_string.GetNanoSec());
1692 lastT0->SetTS(ts_from_string);
1694 LOGF(warning,
"Unable to find raw T0 block timestamp!");
1700 lastT0->SetTimeSinceLastEvNs(duration_cast<nanoseconds>(tsle).count());
1706BmnStatus BmnRawSource::FillUT24VE_TRC(UInt_t*
d, UInt_t& serial, UInt_t& len)
1709 MStreamHeader* ms =
reinterpret_cast<MStreamHeader*
>(
d);
1713 MStreamTAI* ms0 =
reinterpret_cast<MStreamTAI*
>(
d + index);
1715 BmnSyncDigit* sd = FillWR(serial, fEventId, ms0->Sec, ms0->NSec);
1721 LOGF(error,
"UT24VE-TRC Error! MSHeader payload length larger than from device header!");
1726 LOGF(debug,
"FillUT24VE_TRC etype %u WR %08X ts: %s", (uint32_t)fCurEvType, serial,
1727 TTimeStamp(time_t(fTime_s), fTime_ns).AsString());
1731 while (++index < len) {
1732 uint32_t sig_states =
d[index];
1733 vec.push_back(sig_states);
1734 bitset<32> sig_states_bs(sig_states);
1735 LOGF(debug2,
"TRC states d[%3u] %s", index, sig_states_bs.to_string());
1740BmnSyncDigit* BmnRawSource::FillWR(UInt_t serial, ULong64_t iEvent, Long64_t t_sec, Long64_t t_ns)
1744 if (tai_utc_dif == 0) {
1745 tai_utc_dif = GetUTCShift(TTimeStamp(time_t(t_sec), t_ns));
1746 if (tai_utc_dif == 0)
1747 LOGF(warn,
"Possibly wrong state of %08X", serial);
1749 return new ((*sync)[sync->GetEntriesFast()])
BmnSyncDigit(serial, iEvent, t_sec - tai_utc_dif, t_ns);
1752BmnStatus BmnRawSource::FillFVME2TMWR(UInt_t*
d, UInt_t serial, UInt_t& idx, UInt_t& len)
1755 UInt_t word =
d[idx];
1756 UInt_t
id = word >> 28;
1759 UInt_t d0 =
d[idx + 0];
1760 UInt_t d1 =
d[idx + 1];
1761 UInt_t d2 =
d[idx + 2];
1762 UInt_t d3 =
d[idx + 3];
1763 if ((d0 >> 28) != 2 || (d1 >> 28) != 2 || (d2 >> 28) != 2 || (d3 >> 28) != 2)
1765 Long64_t ts_t0_s = -1;
1766 Long64_t ts_t0_ns = -1;
1767 Long64_t GlobalEvent = -1;
1768 ts_t0_ns = (d0 & 0x0FFFFFFF) | ((d1 & 0x3) << 28);
1769 ts_t0_s = ((d1 >> 4) & 0xFFFFFF) | ((d2 & 0xFFFF) << 24);
1770 GlobalEvent = ((d3 & 0x0FFFFFFF) << 12) | ((d2 >> 16) & 0xFFF);
1771 BmnSyncDigit* sd = FillWR(serial, GlobalEvent, ts_t0_s, ts_t0_ns);
1772 if (fPeriodId < 8) {
1777 LOGF(debug2,
"ts :\t %10lli %9lli TMWR 0x%08X", ts_t0_s, ts_t0_ns, serial);
1780 UInt_t d0 =
d[idx + 0];
1781 UInt_t d1 =
d[idx + 1];
1782 if (((d0 >> 28) != 4) || ((d1 >> 28) != 5))
1808 printf(
"unrecognized TMWR id %u\n",
id);
1816BmnStatus BmnRawSource::FillMSC(UInt_t*
d, UInt_t serial, UInt_t slot, UInt_t& idx)
1818 UInt_t
type =
d[idx] >> 28;
1821 std::array<UInt_t, MSC_N_COUNTERS>& cntrArrCur = dig->
GetValue();
1830 }
else if (type == 5) {
1831 UInt_t cnt =
d[idx] & (BIT(28) - 1);
1834 cntrArrCur[iCnt++] = cnt;
1837 type = (
d[++idx] >> 28) & (BIT(5) - 1);
1856 eventHeaderDAQ->
Clear();
1861 if (fRawTreeSpills) {
1882 TPRegexp re(
".+\\.root");
1883 if (re.MatchB(name)) {
1884 fRootFileIn =
new TFile(name,
"READ");
1885 if (fRootFileIn->IsOpen()) {
1887 TTree* RawTree = (TTree*)fRootFileIn->Get(
"BMN_RAW");
1889 RawTree->SetBranchAddress(
"BmnEventHeader.", &tempHdr);
1890 if (RawTree->GetEntriesFast()) {
1891 RawTree->GetEntry(0);
1892 fRunId = tempHdr->GetRunId();
1893 fRootFileName = name;
1897 fRootFileIn->Close();
1902 isRawRootInputFile =
true;
1906 FILE* file = fopen(name.Data(),
"rb");
1907 if (file ==
nullptr) {
1908 printf(
"File %s is not open!!!\n", name.Data());
1913 while (fread(&word,
kWORDSIZE, 1, file)) {
1916 printf(
"After checking %d words in input file run number not found!\n", cntr);
1917 printf(
"Let's get run number from file name\n");
1921 if (fread(&word,
kWORDSIZE, 1, file) != 1)
1923 if (fread(&fRunId,
kWORDSIZE, 1, file) != 1)
1933 TPRegexp(
".*\\w+_\\w+_\\w+_(\\d+)[^/]*\\.data").Substitute(name,
"$1");
1945 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1972, 1, 1, 0, 0, 9), 10));
1946 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1972, 7, 1, 0, 0, 10), 11));
1947 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1973, 1, 1, 0, 0, 11), 12));
1948 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1974, 1, 1, 0, 0, 12), 13));
1949 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1975, 1, 1, 0, 0, 13), 14));
1950 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1976, 1, 1, 0, 0, 14), 15));
1951 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1977, 1, 1, 0, 0, 15), 16));
1952 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1978, 1, 1, 0, 0, 16), 17));
1953 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1979, 1, 1, 0, 0, 17), 18));
1954 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1980, 1, 1, 0, 0, 18), 19));
1955 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1981, 7, 1, 0, 0, 19), 20));
1956 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1982, 7, 1, 0, 0, 20), 21));
1957 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1983, 7, 1, 0, 0, 21), 22));
1958 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1985, 7, 1, 0, 0, 22), 23));
1959 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1988, 1, 1, 0, 0, 23), 24));
1960 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1990, 1, 1, 0, 0, 24), 25));
1961 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1991, 1, 1, 0, 0, 25), 26));
1962 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1992, 7, 1, 0, 0, 26), 27));
1963 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1993, 7, 1, 0, 0, 27), 28));
1964 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1994, 7, 1, 0, 0, 28), 29));
1965 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1996, 1, 1, 0, 0, 29), 30));
1966 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1997, 7, 1, 0, 0, 30), 31));
1967 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(1999, 1, 1, 0, 0, 31), 32));
1968 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(2006, 1, 1, 0, 0, 32), 33));
1969 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(2009, 1, 1, 0, 0, 33), 34));
1970 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(2012, 7, 1, 0, 0, 34), 35));
1971 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(2015, 7, 1, 0, 0, 35), 36));
1972 leaps.insert(pair<TTimeStamp, Int_t>(TTimeStamp(2017, 1, 1, 0, 0, 36), 37));
1973 utc_valid = TTimeStamp(2026, 12, 30, 0, 0, 1);
1977Int_t BmnRawSource::GetUTCShift(TTimeStamp t)
1979 if (t < leaps.begin()->first) {
1980 LOGF(warning,
"Wrong time! %s", t.AsString());
1984 LOGF(warning,
"Warning! Leap seconds table expired!");
1986 auto it = leaps.lower_bound(t);
1987 if ((it == leaps.end()))
1989 else if (it->first > t)
1997 if (fDecoderConfigFileName.length() == 0)
1998 fDecoderConfigFileName =
string(getenv(
"VMCWORKDIR")) +
"/config/bmnconf.json";
1999 pt::read_json(fDecoderConfigFileName, conf);
2000 fExportJsonBlocks = conf.get<
bool>(
"Decoder.ExportJson",
false);
2001 fExportExternalSpillStat = conf.get<
bool>(
"Decoder.ExportExternalSpillStat",
false);
const Float_t d
Z-ccordinate of the first GEM-station.
void memset(T *dest, T i, size_t num)
uses binary expansion of copied volume for speed up
std::chrono::time_point< SysClock > SysPoint
#define ADC_SAMPLING_LIMIT
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 kT0_BIN_BLOCK_2020_SEC
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 kT0_BIN_BLOCK_UNIX_SEC
const uint32_t kHGND_SERIALS
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)
std::array< IntType, MSC_N_COUNTERS > & GetValue()
std::vector< IntType > & GetValues()
std::vector< uint8_t > & GetExtCond()
std::vector< SysPoint > & GetTimes()
BmnStatus ConvertRawToRoot()
BmnStatus ConvertRawToRootIterateFile(UInt_t limit=WAIT_LIMIT)
Int_t ReadEvent(UInt_t i=0)
BmnStatus ParseJsonTLV(UInt_t *buf, UInt_t &len)
void ClearRawSpillArrays()
BmnStatus ConvertRawToRootIterate(UInt_t *buf, UInt_t len)
BmnStatus InitConverter()
BmnRawSource(vector< TString > files, ULong_t period=8)
BmnStatus ConvertRawToRootIterateFileRead()
BmnStatus ConvertStatEvent(UInt_t *buf, UInt_t &len)
BmnStatus wait_file(Int_t len, UInt_t limit=WAIT_LIMIT)
Int_t GetRunIdFromFile(TString name)
Long64_t GetTime_sec() const
Long64_t GetTime_ns() const
T * Add(Int_t threadType=0)
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)
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)
static TString CalculateFileHash(TString file_path)
int GetStartEvent()
get start event of the current raw file
The StorableTimeslice class contains the data of a single timeslice.
a class to store JSON values
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json parse(InputType &&i, const parser_callback_t cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false)
deserialize from a compatible input
iterator begin() noexcept
returns an iterator to the first element
iterator end() noexcept
returns an iterator to one past the last element
iter_impl< basic_json > iterator
an iterator for a basic_json container
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)
Microslice descriptor struct.
uint64_t idx
Microslice index / start time.
uint32_t size
Content size (bytes)
uint16_t eq_id
Equipment identifier.