44 LOG(info) <<
"Init parameter containers for CbmMcbm2018UnpackerAlgoRich";
52 LOG(info) <<
"ReInit parameter containers for CbmMcbm2018UnpackerAlgoRich";
91 LOG(warning) <<
"fvMsComponentsList.size() > 1 for RICH. Unpacking may not work due to implementation limitations.";
94 LOG(info) <<
"CbmMcbm2018UnpackerAlgoRich::AddMsComponentToList => Component " << component <<
" with detector ID 0x"
95 << std::hex << usDetectorId << std::dec <<
" added to list";
100 LOG(debug2) <<
"CbmMcbm2018UnpackerAlgoRich::ProcessTs(ts): this method do not have implementation.";
111 if (0 == ts.index()) {
return kTRUE; }
113 LOG(debug2) <<
"CbmMcbm2018UnpackerAlgoRich::ProcessTs(ts, " << component <<
")";
120 TString sCompList =
"";
125 <<
"CbmMcbm2018UnpackerAlgoRich::ProcessTs => More than 1 component in list, unpacking impossible! List is "
130 LOG(debug) <<
"Components: " << ts.num_components();
131 LOG(debug) <<
"Microslices: " << ts.num_microslices(component);
133 const uint64_t compSize = ts.size_component(component);
134 LOG(debug) <<
"Component " << component <<
" has size " << compSize;
143 <<
" Overlap MS, for a core duration of " <<
fdTsCoreSizeInNs <<
" ns and a full duration of "
149 LOG(info) <<
"In each TS " <<
fuNbMsLoop <<
" MS will be looped over";
152 for (
size_t iMS = 0; iMS <
fuNbMsLoop; ++iMS) {
154 if (
IsLog()) LOG(debug) <<
"=======================================================";
155 const fles::MicrosliceView mv = ts.get_microslice(component, iMS);
156 const fles::MicrosliceDescriptor& msDesc = mv.desc();
159 if (
IsLog()) LOG(debug) <<
"msDesc.size=" << msDesc.size <<
" msDesc.idx=" << msDesc.idx;
181 std::stringstream stream;
195 const fles::MicrosliceView mv = ts.get_microslice(uMsCompIdx, uMsIdx);
196 const fles::MicrosliceDescriptor& msDesc = mv.desc();
199 reader.
SetData(mv.content(), msDesc.size);
203 if (reader.
GetSize() <= 8)
return true;
213 uint32_t msIndexWord1 = reader.
NextWord();
216 uint32_t msIndexWord2 = reader.
NextWord();
227 uint32_t trbNum = reader.
NextWord();
236 uint32_t mbsNum = word & 0xffffff;
237 uint32_t nofCtsCh = (word >> 24) & 0xff;
239 LOG(debug4) <<
GetLogHeader(reader) <<
"MBS mbsNum:0x" << std::hex << mbsNum << std::dec
240 <<
" nofCtsCh:" << nofCtsCh;
242 for (uint32_t i = 0; i < nofCtsCh; i++) {
243 uint32_t wordEpoch = reader.
NextWord();
245 if (
IsLog()) LOG(debug4) <<
GetLogHeader(reader) <<
"MBS ch:" << i <<
" epoch:" << epoch;
247 uint32_t wordTime = reader.
NextWord();
267 uint32_t hubId = word & 0xffff;
268 uint32_t hubSize = (word >> 16) & 0xffff;
270 LOG(debug4) <<
GetLogHeader(reader) <<
"hubId:0x" << std::hex << hubId << std::dec <<
" hubSize:" << hubSize;
279 size_t totalSize = 0;
282 uint32_t subSubEventId = word & 0xffff;
283 uint32_t subSubEventSize = (word >> 16) & 0xffff;
286 totalSize += (1 + subSubEventSize);
289 LOG(debug4) <<
GetLogHeader(reader) <<
counter << ((isLast) ?
" CTS" :
" DiRICH") <<
" subSubEventId:0x"
290 << std::hex << subSubEventId << std::dec <<
" subSubEventSize:" << subSubEventSize;
294 if (((subSubEventId >> 12) & 0xF) != 0x7) {
295 LOG(error) <<
GetLogHeader(reader) <<
"ERROR: subSubEventId has strange value:0x" << std::hex << subSubEventId
306 uint16_t histAddr = ((subSubEventId >> 8) & 0xF) * 18 + ((subSubEventId >> 4) & 0xF) * 2 + (subSubEventId & 0xF);
310 if ((totalSize == hubSize && !isLast) || (totalSize != hubSize && isLast)) {
311 if (
IsLog()) LOG(error) <<
"ERROR: totalSize OR isLast is wrong";
314 if (totalSize >= hubSize || isLast)
break;
318 int lastWordsCounter = 0;
323 if (word == 0x600dda7a)
break;
324 if (lastWordsCounter >= 7) {
326 <<
"CbmMcbm2018UnpackerAlgoRich::ProcessHubBlock() ERROR: No word == 0x600dda7a";
332 uint32_t subSubEventSize, uint32_t subSubEventId)
335 uint32_t ctsState = word & 0xffff;
336 uint32_t nofInputs = (word >> 16) & 0xf;
337 uint32_t nofTrigCh = (word >> 20) & 0x1f;
338 uint32_t inclLastIdle = (word >> 25) & 0x1;
339 uint32_t inclTrigInfo = (word >> 26) & 0x1;
340 uint32_t inclTime = (word >> 27) & 0x1;
341 uint32_t ETM = (word >> 28) & 0x3;
342 uint32_t ctsInfoSize = 2 * nofInputs + 2 * nofTrigCh + 2 * inclLastIdle + 3 * inclTrigInfo + inclTime;
345 case 1: ctsInfoSize += 1;
break;
346 case 2: ctsInfoSize += 4;
break;
349 if (
IsLog()) LOG(debug4) <<
GetLogHeader(reader) <<
"CTS ctsState:" << ctsState <<
" ctsInfoSize:" << ctsInfoSize;
350 for (uint32_t i = 0; i < ctsInfoSize; i++) {
354 int nofTimeWords = subSubEventSize - ctsInfoSize - 1;
359 uint32_t subSubEventId)
363 bool wasHeader =
false;
364 bool wasEpoch =
false;
365 bool wasTime =
false;
366 bool wasTrailer =
false;
368 bool errorInData =
false;
372 std::vector<double> raisingTime(33, -1.);
374 for (
int i = 0; i < nofTimeWords; i++) {
379 if (!wasHeader || !wasEpoch || wasTrailer) {
380 LOG(error) <<
GetLogHeader(reader) <<
"illegal position of TDC Time (before header/epoch or after trailer)";
388 if (!wasHeader || wasTrailer) {
389 LOG(error) <<
GetLogHeader(reader) <<
"illegal position of TDC Epoch (before header or after trailer)";
395 if (
IsLog()) LOG(debug4) <<
GetLogHeader(reader) <<
"SubSubEv[" << i <<
"] epoch:" << epoch;
398 if (wasEpoch || wasTime || wasTrailer) {
399 LOG(error) <<
GetLogHeader(reader) <<
"illegal position of TDC Header (after time/epoch/trailer)";
406 if (
IsLog()) LOG(debug4) <<
GetLogHeader(reader) <<
"SubSubEv[" << i <<
"] header";
409 if (!wasEpoch || !wasTime || !wasHeader) {
410 LOG(error) <<
GetLogHeader(reader) <<
"illegal position of TDC Trailer (before time/epoch/header)";
417 if (
IsLog()) LOG(debug4) <<
GetLogHeader(reader) <<
"SubSubEv[" << i <<
"] trailer";
423 LOG(error) <<
GetLogHeader(reader) <<
"Wrong TDC word!!! marker:" << ((word >> 29) & 0x7);
435 return ((
double) epoch) * 2048. * 5. + ((double) coarse) * 5. - ((
double) fine) * 0.005;
439 uint32_t tdcWord, uint32_t subSubEventId,
440 std::vector<double>& raisingTime)
458 <<
" CH0 Last:" << std::setprecision(15) <<
fLastCh0ReTime[subSubEventId]
466 double fullTimeCorr = dT - mbsCorr;
469 <<
" time:" << std::setprecision(15) << fullTime <<
" fullTimeCorr:" << fullTimeCorr;
472 LOG(error) <<
"ERROR: channel number is out of limit. Channel:" << td.
fChannel;
477 raisingTime[td.
fChannel] = fullTimeCorr;
480 if (raisingTime[td.
fChannel] == -1.) {
483 LOG(debug4) <<
GetLogHeader(reader) <<
"SubSubEv[" << iTdc <<
"] "
484 <<
"No raising channel was found before. Skip this falling edge time.";
488 double ToT = fullTimeCorr - raisingTime[td.
fChannel];
490 LOG(debug4) <<
GetLogHeader(reader) <<
"SubSubEv[" << iTdc <<
"] "
495 if (
h !=
nullptr)
h->Fill(ToT);
498 if (h2 !=
nullptr) h2->Fill(td.
fChannel, ToT);
513 Int_t pixelUID = this->
GetPixelUID(fpgaID, channel);
515 uint64_t msRefTS = 0;
518 std::cout <<
"MS before TS Start: " << MSidx <<
" " <<
fdTsStartTime << std::endl;
524 if (msRefTS == 0)
return;
526 Double_t lastTime = 0.;
528 if (
fDigiVect.size() < 1) {
fDigiVect.emplace_back(pixelUID, finalTime, tot - ToTcorr); }
531 if (
fDigiVect[0].GetTime() > finalTime) {
534 else if (lastTime > finalTime) {
535 for (
int i =
fDigiVect.size() - 1; i >= 0; i--) {
537 if (lastTime <= finalTime) {
544 fDigiVect.emplace_back(pixelUID, finalTime, tot - ToTcorr);
556 std::vector<std::string> tdcErrorLabels = {
"RingBuffOverw.",
"noRefTime",
"refTimePrecedes",
557 "trigW/oRefTime",
"markMisRefTime",
"multiRefTime",
558 "refTime<40ns",
"noValidation",
"trigger!=0x1"};
559 fhTdcErrors =
new TH2D(
"fhTdcErrors",
"Errors in TDC msgs;;", nofTdc, -0.5, nofTdc - 0.5, tdcErrorLabels.size(), -0.5,
560 (
double) tdcErrorLabels.size() - 0.5);
561 for (
size_t i = 0; i < tdcErrorLabels.size(); i++) {
562 fhTdcErrors->GetYaxis()->SetBinLabel(i + 1, tdcErrorLabels[i].c_str());
568 for (Int_t iTdc = 0; iTdc < nofTdc; iTdc++) {
571 fhTdcErrors->GetXaxis()->SetBinLabel(iTdc + 1, Form(
"0x%4x", tdcId));
574 for (Int_t iCh = 0; iCh <= 32; iCh++) {
580 std::stringstream cName, cTitle;
582 cName <<
"cToT2d_TDC_0x" << std::hex << tdc;
583 cTitle <<
"ToTs of TDC 0x" << std::hex << tdc;
584 TCanvas* c =
new TCanvas(cName.str().c_str(), cTitle.str().c_str(), 10, 10);
595 fhEventSize =
new TH1I(
"fhEventSize",
"Size of the Event from TrbNet; Size [bytes]", 350, 0., 70000.);
599 new TH2I(
"fhSubEventSize",
"fhSubEventSize; HubId ; Size [bytes]; Entries", 6, 0, 6, 10000, 0., 10000.);
603 new TH2I(
"fhSubSubEventSize",
"fhSubSubEventSize; DiRICH ; Size [words]; Entries", 72, 0, 72, 510, 0., 510.);
606 fhChnlSize =
new TH2I(
"fhChnlSize",
"fhChnlSize; channel; Size [words]; Entries", 33, 0, 33, 25, 0, 25.);
617 std::stringstream name, subFolder;
618 name <<
"ToT_tdc0x" << std::hex << tdc << std::dec <<
"_ch" << channel;
619 std::string title = name.str() +
";ToT [ns];Entries";
620 subFolder <<
"ToT/tdc0x" << std::hex << tdc;
621 h =
new TH1D(name.str().c_str(), title.c_str(), 100, -1., 49.);
632 std::stringstream name;
633 name <<
"ToT_2d_tdc0x" << std::hex << tdc;
634 std::string title = name.str() +
";channels;ToT [ns]";
635 std::string subFolder =
"ToT2d";
636 h =
new TH2D(name.str().c_str(), title.c_str(), 33, 0, 32, 200, -1., 49.);
645 const fles::MicrosliceView mv = ts.get_microslice(uMsCompIdx, uMsIdx);
646 const fles::MicrosliceDescriptor& msDesc = mv.desc();
647 const uint8_t* ptr = mv.content();
648 const size_t size = msDesc.size;
650 if (
size == 0)
return kTRUE;
666 int nofHeaderErrorBits = 1;
667 int histBinOffsetHeaderError = 0;
668 for (
int i = 0; i < nofHeaderErrorBits; i++) {
669 if (((errbits >> i) & 0x1) == 1)
fhTdcErrors->Fill(
fMapFEE[tdcId], i + histBinOffsetHeaderError);
682 int nofTrailerErrorBits = 8;
683 int histBinOffsetTrailerError = 1;
684 for (
int i = 0; i < nofTrailerErrorBits; i++) {
685 if (((errbits >> i) & 0x1) == 1)
fhTdcErrors->Fill(
fMapFEE[tdcId], i + histBinOffsetTrailerError);
ClassImp(CbmConverterManager)
CbmMcbm2018RichTdcWordType
static constexpr size_t size()
bool IsLastSubSubEvent(uint32_t subSubEventSize)
std::string GetWordAsHexString(uint32_t word)
void SetData(const uint8_t *data, size_t size)
Int_t GetNaddresses(void) const
Double_t GetToTshift(Int_t tdc, Int_t ch) const
Int_t GetAddress(Int_t ind) const
static uint16_t ProcessHeader(uint32_t tdcWord)
static CbmMcbm2018RichTdcWordType GetTdcWordType(uint32_t tdcWord)
static uint32_t ProcessEpoch(uint32_t tdcWord)
static void ProcessTimeData(uint32_t tdcWord, CbmMcbm2018RichTdcTimeData &outData)
static uint16_t ProcessTrailer(uint32_t tdcWord)
TH1D * GetTotH1(uint32_t fpgaID, uint32_t channel)
virtual Bool_t InitContainers()
Bool_t CreateHistograms()
std::map< uint16_t, uint16_t > fMapFEE
std::string GetLogHeader(CbmMcbm2018RichMicrosliceReader &reader)
Bool_t fbDebugMonitorMode
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Bool_t fbMonitorMode
Control flags.
void ProcessMbs(CbmMcbm2018RichMicrosliceReader &reader, bool isPrev)
Bool_t DebugMs(const fles::Timeslice &ts, size_t uMsCompIdx, size_t uMsIdx)
std::map< uint32_t, double > fPrevLastCh0ReTime
virtual Bool_t ReInitContainers()
std::map< uint32_t, std::map< Int_t, TH1D * > > fhTotMap
virtual ~CbmMcbm2018UnpackerAlgoRich()
std::map< uint32_t, TH2D * > fhTot2dMap
void ProcessTrbPacket(CbmMcbm2018RichMicrosliceReader &reader)
TH2D * GetTotH2(uint32_t fpgaID)
virtual TList * GetParList()
void WriteOutputDigi(Int_t fpgaID, Int_t channel, Double_t time, Double_t tot, uint64_t MSidx)
CbmMcbm2018UnpackerAlgoRich()
double CalculateTime(uint32_t epoch, uint32_t coarse, uint32_t fine)
void ErrorMsg(uint16_t errbits, CbmMcbm2018RichErrorType type, uint16_t tdcId=0)
CbmMcbm2018RichPar * fUnpackPar
virtual Bool_t ProcessMs(const fles::Timeslice &ts, size_t uMsCompIdx, size_t uMsIdx)
void ProcessHubBlock(CbmMcbm2018RichMicrosliceReader &reader)
std::map< uint32_t, double > fLastCh0ReTime
void ProcessTimeDataWord(CbmMcbm2018RichMicrosliceReader &reader, int iTdc, uint32_t epoch, uint32_t tdcWord, uint32_t subSubEventId, std::vector< double > &raisingTime)
virtual Bool_t ProcessTs(const fles::Timeslice &ts)
std::vector< TCanvas * > fcTot2d
void ProcessCtsSubSubEvent(CbmMcbm2018RichMicrosliceReader &reader, uint32_t subSubEventSize, uint32_t subSubEventId)
Int_t Debug(const uint8_t *ptr, const size_t size)
Int_t GetPixelUID(Int_t fpgaID, Int_t ch) const
void ProcessSubSubEvent(CbmMcbm2018RichMicrosliceReader &reader, int nofTimeWords, uint32_t subSubEventId)
Double_t fdTsCoreSizeInNs
void AddHistoToVector(TNamed *pointer, std::string sFolder="")
std::vector< size_t > fvMsComponentsList
void AddCanvasToVector(TCanvas *pointer, std::string sFolder="")
std::vector< CbmRichDigi > fDigiVect
Double_t fdTsFullSizeInNs
Data class with information on a STS local track.