CbmMcbm2018UnpackerAlgoTof.cxx 58.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
// -----------------------------------------------------------------------------
// -----                                                                   -----
// -----                  CbmMcbm2018UnpackerAlgoTof                       -----
// -----               Created 10.02.2019 by P.-A. Loizeau                 -----
// -----                                                                   -----
// -----------------------------------------------------------------------------

#include "CbmMcbm2018UnpackerAlgoTof.h"

#include "CbmFormatDecHexPrintout.h"
Administrator's avatar
Administrator committed
11
#include "CbmFormatMsHeaderPrintout.h"
12
13
#include "CbmMcbm2018TofPar.h"
#include "CbmTofAddress.h"
Administrator's avatar
Administrator committed
14
#include "CbmTofDetectorId_v14a.h"  // in cbmdata/tof
15
16
17
18
19

#include "FairLogger.h"
#include "FairRootManager.h"
#include "FairRun.h"
#include "FairRunOnline.h"
Administrator's avatar
Administrator committed
20
#include "FairRuntimeDb.h"
21

Administrator's avatar
Administrator committed
22
23
#include "TCanvas.h"
#include "TH1.h"
24
#include "TH2.h"
Administrator's avatar
Administrator committed
25
#include "TList.h"
26
#include "TProfile.h"
Administrator's avatar
Administrator committed
27
28
#include "TROOT.h"
#include "TString.h"
29

Administrator's avatar
Administrator committed
30
31
#include <fstream>
#include <iomanip>
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <stdint.h>
#include <vector>

/*
static Int_t  NMappingWarnings=100;
static uint32_t pat_mess[8]={8*0};
std::vector< std::vector <uint32_t> > Pat_Request;
std::vector<Bool_t> bGdpbOK;
static Bool_t    bEnableOut=kFALSE;
static Int_t fiMsGood=0;
static Int_t fiMsBad=0;
*/
// -------------------------------------------------------------------------
Administrator's avatar
Administrator committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
CbmMcbm2018UnpackerAlgoTof::CbmMcbm2018UnpackerAlgoTof()
  : CbmStar2019Algo()
  ,
  /// From the class itself
  fbMonitorMode(kFALSE)
  , fbDebugMonitorMode(kFALSE)
  , fvbMaskedComponents()
  , fUnpackPar(nullptr)
  , fuNrOfGdpbs(0)
  , fGdpbIdIndexMap()
  , fuNrOfFeePerGdpb(0)
  , fuNrOfGet4PerFee(0)
  , fuNrOfChannelsPerGet4(0)
  , fuNrOfChannelsPerFee(0)
  , fuNrOfGet4(0)
  , fuNrOfGet4PerGdpb(0)
  , fuNrOfChannelsPerGdpb(0)
  , fuNrOfGbtx(0)
  , fuNrOfModules(0)
  , fviNrOfRpc()
  , fviRpcType()
  , fviRpcSide()
  , fviModuleId()
  , fviRpcChUId()
  , fdTimeOffsetNs(0.0)
  , fuDiamondDpbIdx(99)
  , fulCurrentTsIdx(0)
  , fulCurrentMsIdx(0)
  , fuCurrentMsSysId(0)
  , fdTsStartTime(-1.0)
  , fdTsStopTimeCore(-1.0)
  , fdMsTime(-1.0)
  , fuMsIndex(0)
  , fuCurrentEquipmentId(0)
  , fuCurrDpbId(0)
  , fuCurrDpbIdx(0)
  , fuGet4Id(0)
  , fuGet4Nr(0)
  , fvulCurrentEpoch()
  , fvulCurrentEpochCycle()
  , fvulCurrentEpochFull()
  , fdStartTime(0.0)
  , fdStartTimeMsSz(0.0)
  , ftStartTimeUnix(std::chrono::steady_clock::now())
  , fvvmEpSupprBuffer()
  , fvulGdpbTsMsb()
  , fvulGdpbTsLsb()
  , fvulStarTsMsb()
  , fvulStarTsMid()
  , fvulGdpbTsFullLast()
  , fvulStarTsFullLast()
  , fvuStarTokenLast()
  , fvuStarDaqCmdLast()
  , fvuStarTrigCmdLast()
  , fdRefTime(0.)
  , fdLastDigiTime(0.)
  , fdFirstDigiTimeDif(0.)
  , fdEvTime0(0.)
  , fhRawTDigEvT0(nullptr)
  , fhRawTDigRef0(nullptr)
  , fhRawTDigRef(nullptr)
  , fhRawTRefDig0(nullptr)
  , fhRawTRefDig1(nullptr)
  , fhRawDigiLastDigi(nullptr)
  , fhRawTotCh()
  , fhChCount()
  , fhChCountRemap()
  , fvbChanThere()
  , fhChanCoinc()
  , fhDetChanCoinc(nullptr) {}
CbmMcbm2018UnpackerAlgoTof::~CbmMcbm2018UnpackerAlgoTof() {
  /// Clear buffers
  for (UInt_t uGdpb = 0; uGdpb < fuNrOfGdpbs; ++uGdpb) {
    fvvmEpSupprBuffer[uGdpb].clear();
  }  // for( UInt_t uGdpb = 0; uGdpb < fuNrOfGdpbs; ++uGdpb )
  if (nullptr != fParCList) delete fParCList;
  if (nullptr != fUnpackPar) delete fUnpackPar;
123
124
125
}

// -------------------------------------------------------------------------
Administrator's avatar
Administrator committed
126
127
Bool_t CbmMcbm2018UnpackerAlgoTof::Init() {
  LOG(info) << "Initializing mCBM TOF 2019 unpacker algo";
128

Administrator's avatar
Administrator committed
129
  return kTRUE;
130
}
Administrator's avatar
Administrator committed
131
132
133
void CbmMcbm2018UnpackerAlgoTof::Reset() {}
void CbmMcbm2018UnpackerAlgoTof::Finish() {
  /*
134
135
136
   /// Printout Goodbye message and stats
  LOG(INFO)<<"<I> MS statistics - Good: " << fiMsGood <<", Bad: " << fiMsBad;
*/
Administrator's avatar
Administrator committed
137
  /// Write Output histos
138
139
140
}

// -------------------------------------------------------------------------
Administrator's avatar
Administrator committed
141
142
Bool_t CbmMcbm2018UnpackerAlgoTof::InitContainers() {
  LOG(info) << "Init parameter containers for CbmMcbm2018UnpackerAlgoTof";
143

Administrator's avatar
Administrator committed
144
  Bool_t initOK = ReInitContainers();
145

Administrator's avatar
Administrator committed
146
  return initOK;
147
}
Administrator's avatar
Administrator committed
148
149
150
151
152
153
154
155
156
157
158
159
Bool_t CbmMcbm2018UnpackerAlgoTof::ReInitContainers() {
  LOG(info) << "**********************************************";
  LOG(info) << "ReInit parameter containers for CbmMcbm2018UnpackerAlgoTof";

  fUnpackPar = (CbmMcbm2018TofPar*) fParCList->FindObject("CbmMcbm2018TofPar");
  if (nullptr == fUnpackPar) {
    LOG(ERROR) << " CbmMcbm2018TofPar not found ";
    return kFALSE;
  }
  Bool_t initOK = InitParameters();

  return initOK;
160
}
Administrator's avatar
Administrator committed
161
162
163
164
TList* CbmMcbm2018UnpackerAlgoTof::GetParList() {
  if (nullptr == fParCList) fParCList = new TList();
  fUnpackPar = new CbmMcbm2018TofPar("CbmMcbm2018TofPar");
  fParCList->Add(fUnpackPar);
165

Administrator's avatar
Administrator committed
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
  return fParCList;
}
Bool_t CbmMcbm2018UnpackerAlgoTof::InitParameters() {
  LOG(INFO) << "InitParameters from " << fUnpackPar;
  fdMsSizeInNs = fUnpackPar->GetSizeMsInNs();

  fuNrOfGdpbs = fUnpackPar->GetNrOfGdpbs();
  LOG(info) << "Nr. of Tof GDPBs: " << fuNrOfGdpbs;

  fuNrOfFeePerGdpb = fUnpackPar->GetNrOfFeesPerGdpb();
  LOG(info) << "Nr. of FEES per Tof GDPB: " << fuNrOfFeePerGdpb;

  fuNrOfGet4PerFee = fUnpackPar->GetNrOfGet4PerFee();
  LOG(info) << "Nr. of GET4 per Tof FEE: " << fuNrOfGet4PerFee;

  fuNrOfChannelsPerGet4 = fUnpackPar->GetNrOfChannelsPerGet4();
  LOG(info) << "Nr. of channels per GET4: " << fuNrOfChannelsPerGet4;

  fuNrOfChannelsPerFee = fuNrOfGet4PerFee * fuNrOfChannelsPerGet4;
  LOG(info) << "Nr. of channels per FEE: " << fuNrOfChannelsPerFee;

  fuNrOfGet4 = fuNrOfGdpbs * fuNrOfFeePerGdpb * fuNrOfGet4PerFee;
  LOG(info) << "Nr. of GET4s: " << fuNrOfGet4;

  fuNrOfGet4PerGdpb = fuNrOfFeePerGdpb * fuNrOfGet4PerFee;
  LOG(info) << "Nr. of GET4s per GDPB: " << fuNrOfGet4PerGdpb;

  fuNrOfChannelsPerGdpb = fuNrOfGet4PerGdpb * fuNrOfChannelsPerGet4;
  LOG(info) << "Nr. of channels per GDPB: " << fuNrOfChannelsPerGdpb;

  fGdpbIdIndexMap.clear();
  for (UInt_t i = 0; i < fuNrOfGdpbs; ++i) {
    fGdpbIdIndexMap[fUnpackPar->GetGdpbId(i)] = i;
    LOG(info) << "GDPB Id of TOF  " << i << " : " << std::hex
              << fUnpackPar->GetGdpbId(i) << std::dec;
  }  // for( UInt_t i = 0; i < fuNrOfGdpbs; ++i )

  fuNrOfGbtx = fUnpackPar->GetNrOfGbtx();
  LOG(info) << "Nr. of GBTx: " << fuNrOfGbtx;

  fviRpcType.resize(fuNrOfGbtx);
  fviModuleId.resize(fuNrOfGbtx);
  fviNrOfRpc.resize(fuNrOfGbtx);
  fviRpcSide.resize(fuNrOfGbtx);
  for (UInt_t uGbtx = 0; uGbtx < fuNrOfGbtx; ++uGbtx) {
    fviNrOfRpc[uGbtx]  = fUnpackPar->GetNrOfRpc(uGbtx);
    fviRpcType[uGbtx]  = fUnpackPar->GetRpcType(uGbtx);
    fviRpcSide[uGbtx]  = fUnpackPar->GetRpcSide(uGbtx);
    fviModuleId[uGbtx] = fUnpackPar->GetModuleId(uGbtx);
  }  // for( UInt_t uGbtx = 0; uGbtx < fuNrOfGbtx; ++uGbtx)

  UInt_t uNrOfChannels = fuNrOfGet4 * fuNrOfChannelsPerGet4;
  LOG(info) << "Nr. of possible Tof channels: " << uNrOfChannels;

  //   CbmTofDetectorId* fTofId = new CbmTofDetectorId_v14a();
  fviRpcChUId.resize(uNrOfChannels);
  UInt_t iCh = 0;
  for (UInt_t iGbtx = 0; iGbtx < fuNrOfGbtx; ++iGbtx) {
    switch (fviRpcType[iGbtx]) {

      case 0:                         // CBM modules
        if (fviRpcSide[iGbtx] < 2) {  // mTof modules
          const Int_t RpcMap[5] = {4, 2, 0, 3, 1};
          for (Int_t iRpc = 0; iRpc < fviNrOfRpc[iGbtx]; iRpc++) {
            Int_t iStrMax = 32;
            Int_t iChNext = 1;

            for (Int_t iStr = 0; iStr < iStrMax; iStr++) {
              Int_t iStrMap = iStr;
              Int_t iRpcMap = RpcMap[iRpc];

              if (fviRpcSide[iGbtx] == 0) iStrMap = 31 - iStr;
              if (fviModuleId[iGbtx] > -1)
                fviRpcChUId[iCh] =
                  CbmTofAddress::GetUniqueAddress(fviModuleId[iGbtx],
                                                  iRpcMap,
                                                  iStrMap,
                                                  fviRpcSide[iGbtx],
                                                  fviRpcType[iGbtx]);
              else
                fviRpcChUId[iCh] = 0;
              //	 LOG(debug)<<Form("Map Ch %d to Address 0x%08x",iCh,fviRpcChUId[iCh]);
              iCh += iChNext;
            }
          }
        }
        break;

      case 1:                         // STAR eTOF  modules
        if (fviRpcSide[iGbtx] < 2) {  // mTof modules
          const Int_t RpcMap[3] = {0, 1, 2};
          for (Int_t iRpc = 0; iRpc < fviNrOfRpc[iGbtx]; iRpc++) {
            Int_t iStrMax = 32;
            Int_t iChNext = 1;

            for (Int_t iStr = 0; iStr < iStrMax; iStr++) {
              Int_t iStrMap = iStr;
              Int_t iRpcMap = RpcMap[iRpc];

              if (fviRpcSide[iGbtx] == 0) iStrMap = 31 - iStr;
              if (fviModuleId[iGbtx] > -1)
                fviRpcChUId[iCh] =
                  CbmTofAddress::GetUniqueAddress(fviModuleId[iGbtx],
                                                  iRpcMap,
                                                  iStrMap,
                                                  fviRpcSide[iGbtx],
                                                  fviRpcType[iGbtx]);
              else
                fviRpcChUId[iCh] = 0;
              //	 LOG(DEBUG)<<Form("Map Ch %d to Address 0x%08x",iCh,fviRpcChUId[iCh]);
              iCh += iChNext;
            }
          }
        }
        iCh += 64;
        break;

        /// Special Treatment for the T0 diamond
      case 5: {
        LOG(info) << " Map diamond  at GBTX  -  iCh = " << iCh;
        for (UInt_t uFee = 0; uFee < fUnpackPar->GetNrOfFeePerGbtx(); ++uFee) {
          for (UInt_t uCh = 0; uCh < fUnpackPar->GetNrOfChannelsPerFee();
               ++uCh) {
            /*
290
291
292
293
294
295
296
297
298
299
	      if( uFee < 4 && 0 == uCh ) {
                  fviRpcChUId[ iCh ] = CbmTofAddress::GetUniqueAddress(
                                             fviModuleId[iGbtx],
                                             0, uFee + 4 * fviRpcSide[iGbtx],
                                             0, fviRpcType[iGbtx] );
		  LOG(info) << Form( "Map T0 Ch %d to Address 0x%08x", iCh, fviRpcChUId[iCh] );
	      }
	      else fviRpcChUId[ iCh ] = 0;
*/

Administrator's avatar
Administrator committed
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
            /// Mapping for the 2019 beamtime
            if (0 == uFee && 1 == fviNrOfRpc[iGbtx]) {
              switch (uCh % 8) {
                case 0:
                case 2:
                case 4: {
                  /// 2019 mapping with 320/640 Mb/s FW
                  /// => 4 GET4 per GBTx
                  /// => 1 T0 channel per GET4
                  /// => 1-2 eLinks per GET4 => GET4 ID = GET4 * 2 (+ 1)
                  UInt_t uChannelT0 = uCh / 8 + 4 * fviRpcSide[iGbtx];
                  fviRpcChUId[iCh]  = CbmTofAddress::GetUniqueAddress(
                    fviModuleId[iGbtx], 0, uChannelT0, 0, fviRpcType[iGbtx]);
                  LOG(info) << Form("T0 channel: %u from GBTx %2u Fee %2u "
                                    "Channel %2u, indx %d address %08x",
                                    uChannelT0,
                                    iGbtx,
                                    uFee,
                                    uCh,
                                    iCh,
                                    fviRpcChUId[iCh]);
                  break;
                }  // Valid T0 channel
                default: {
                  fviRpcChUId[iCh] = 0;
                }  // Invalid T0 channel
              }    // switch( uCh % 4 )
            }      // if( 0 == uFee )

            iCh++;
          }  // for( UInt_t uCh = 0; uCh < fUnpackPar->GetNrOfChannelsPerFee(); ++uCh )
        }  // for( UInt_t uFee = 0; uFee < fUnpackPar->GetNrOfFeePerGbtx(); ++uFee )
      }  // if( 5 == fviRpcType[iGbtx] )
333
334
      break;

Administrator's avatar
Administrator committed
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
      case 78:  // cern-20-gap + ceramic module
      {
        LOG(info) << " Map CERN 20 gap  at GBTX  -  iCh = " << iCh;
        const Int_t StrMap[32] = {0,  1,  2,  3,  4,  31, 5,  6,  7,  30, 8,
                                  9,  10, 29, 11, 12, 13, 14, 28, 15, 16, 17,
                                  18, 27, 26, 25, 24, 23, 22, 21, 20, 19};
        Int_t iModuleId        = 0;
        Int_t iModuleType      = 7;
        Int_t iRpcMap          = 0;
        for (Int_t iFeet = 0; iFeet < 2; iFeet++) {
          for (Int_t iStr = 0; iStr < 32; iStr++) {
            Int_t iStrMap  = 31 - 12 - StrMap[iStr];
            Int_t iSideMap = iFeet;
            if (iStrMap < 20)
              fviRpcChUId[iCh] = CbmTofAddress::GetUniqueAddress(
                iModuleId, iRpcMap, iStrMap, iSideMap, iModuleType);
            else
              fviRpcChUId[iCh] = 0;
            iCh++;
          }
        }

        LOG(info) << " Map end CERN 20 gap  at GBTX  -  iCh = " << iCh;
      }
        // fall through is intended
      case 8:  // ceramics
      {
        Int_t iModuleId   = 0;
        Int_t iModuleType = 8;
        for (Int_t iRpc = 0; iRpc < 8; iRpc++) {
          fviRpcChUId[iCh] = CbmTofAddress::GetUniqueAddress(
            iModuleId, 7 - iRpc, 0, 0, iModuleType);
          iCh++;
        }
        iCh += (24 + 2 * 32);
      }

        LOG(info) << " Map end ceramics  box  at GBTX  -  iCh = " << iCh;
        break;

      case 9:  // Star2 boxes
      {
        LOG(info) << " Map Star2 box  at GBTX  -  iCh = " << iCh;
        const Int_t iRpc[5]  = {1, -1, 1, 0, 0};
        const Int_t iSide[5] = {1, -1, 0, 1, 0};
        for (Int_t iFeet = 0; iFeet < 5; iFeet++) {
          for (Int_t iStr = 0; iStr < 32; iStr++) {
            Int_t iStrMap  = iStr;
            Int_t iRpcMap  = iRpc[iFeet];
            Int_t iSideMap = iSide[iFeet];
            if (iSideMap == 0) iStrMap = 31 - iStr;
            if (iSideMap > -1)
              fviRpcChUId[iCh] =
                CbmTofAddress::GetUniqueAddress(fviModuleId[iGbtx],
                                                iRpcMap,
                                                iStrMap,
                                                iSideMap,
                                                fviRpcType[iGbtx]);
            else
              fviRpcChUId[iCh] = 0;
            iCh++;
          }
        }
      } break;

      case 6:  // Buc box
      {
        LOG(info) << " Map Buc box  at GBTX  -  iCh = " << iCh;
        const Int_t iRpc[5]  = {0, -1, 0, 1, 1};
        const Int_t iSide[5] = {1, -1, 0, 1, 0};
        for (Int_t iFeet = 0; iFeet < 5; iFeet++) {
          for (Int_t iStr = 0; iStr < 32; iStr++) {
            Int_t iStrMap  = iStr;
            Int_t iRpcMap  = iRpc[iFeet];
            Int_t iSideMap = iSide[iFeet];
            switch (fviRpcSide[iGbtx]) {
              case 0:; break;
              case 1:  // HD cosmic 2019, Buc2018, v18n
                iStrMap = 31 - iStr;
                iRpcMap = 1 - iRpcMap;
                break;
              case 2:  // v18m_cosmicHD
                //		 iStrMap=31-iStr;
                iSideMap = 1 - iSideMap;
                break;
              case 3:
                iStrMap  = 31 - iStr;
                iRpcMap  = 1 - iRpcMap;
                iSideMap = 1 - iSideMap;
                break;
              case 4:  // HD cosmic 2019, Buc2018, v18o
                iRpcMap = 1 - iRpcMap;
                break;
              case 5:  // HD cosmic 2020, Buc2018, v20a
                iStrMap = 31 - iStr;
                break;
              default:;
            }
            if (iSideMap > -1)
              fviRpcChUId[iCh] =
                CbmTofAddress::GetUniqueAddress(fviModuleId[iGbtx],
                                                iRpcMap,
                                                iStrMap,
                                                iSideMap,
                                                fviRpcType[iGbtx]);
            else
              fviRpcChUId[iCh] = 0;

            iCh++;
          }
        }
      } break;

      case -1:
        LOG(info) << " Found unused GBTX link at iCh = " << iCh;
        iCh += 160;
        break;

      default: LOG(error) << "Invalid Tof Type  specifier ";
    }
  }
  TString sPrintout = "";
  for (UInt_t uCh = 0; uCh < uNrOfChannels; ++uCh) {
    if (0 == uCh % 8) sPrintout += "\n";
    if (0 == uCh % fuNrOfChannelsPerGdpb)
      sPrintout += Form("\n Gdpb %u\n", uCh / fuNrOfChannelsPerGdpb);
    sPrintout += Form(" 0x%08x", fviRpcChUId[uCh]);
  }  // for( UInt_t i = 0; i < uNrOfChannels; ++i)
  LOG(info) << sPrintout;

  // Request masks
  /*
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
   LOG(INFO) << " Load " << fUnpackPar->GetNrReqPattern() << " GET4 Request masks for " << fuNrOfGdpbs << " Gdpbs ";
   if(fUnpackPar->GetNrReqPattern()>0){
     bGdpbOK.resize(fuNrOfGdpbs);
     Pat_Request.resize(fuNrOfGdpbs);
     Int_t iInd=0;
     for(Int_t iGdpb=0; iGdpb<fuNrOfGdpbs; iGdpb++) {
       bGdpbOK[iGdpb]=kTRUE;
       Pat_Request[iGdpb].resize(fUnpackPar->GetNrReqPattern());
       for (Int_t iPat=0; iPat<fUnpackPar->GetNrReqPattern(); iPat++) {
	 UInt_t PatGet4=fUnpackPar->GetReqPattern(iInd++);
         for( UInt_t uBit = 0; uBit < 32; ++uBit ) {
	   if( ( PatGet4 >> uBit ) & 0x1 ) {
	     UInt_t iGet4=iPat*32+uBit;
	     UInt_t uElink=fUnpackPar->Get4IdxToElinkIdx(iGet4);
	     UInt_t ubit=uElink%32;
	     UInt_t iEPat=(uElink-ubit)/32;
	     Pat_Request[iGdpb][iEPat] |= (0x1 << ubit);
	   }
	 }
       }
     }
   }
   */
Administrator's avatar
Administrator committed
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
  /// Internal status initialization
  fvulCurrentEpoch.resize(fuNrOfGdpbs, 0);
  fvulCurrentEpochCycle.resize(fuNrOfGdpbs, 0);
  fvulCurrentEpochFull.resize(fuNrOfGdpbs, 0);

  /// STAR Trigger decoding and monitoring
  fvulGdpbTsMsb.resize(fuNrOfGdpbs);
  fvulGdpbTsLsb.resize(fuNrOfGdpbs);
  fvulStarTsMsb.resize(fuNrOfGdpbs);
  fvulStarTsMid.resize(fuNrOfGdpbs);
  fvulGdpbTsFullLast.resize(fuNrOfGdpbs);
  fvulStarTsFullLast.resize(fuNrOfGdpbs);
  fvuStarTokenLast.resize(fuNrOfGdpbs);
  fvuStarDaqCmdLast.resize(fuNrOfGdpbs);
  fvuStarTrigCmdLast.resize(fuNrOfGdpbs);
  for (UInt_t uGdpb = 0; uGdpb < fuNrOfGdpbs; ++uGdpb) {
    fvulGdpbTsMsb[uGdpb]      = 0;
    fvulGdpbTsLsb[uGdpb]      = 0;
    fvulStarTsMsb[uGdpb]      = 0;
    fvulStarTsMid[uGdpb]      = 0;
    fvulGdpbTsFullLast[uGdpb] = 0;
    fvulStarTsFullLast[uGdpb] = 0;
    fvuStarTokenLast[uGdpb]   = 0;
    fvuStarDaqCmdLast[uGdpb]  = 0;
    fvuStarTrigCmdLast[uGdpb] = 0;
  }  // for (Int_t iGdpb = 0; iGdpb < fuNrOfGdpbs; ++iGdpb)

  /// Buffer initialization
  fvvmEpSupprBuffer.resize(fuNrOfGdpbs);

  return kTRUE;
521
522
523
}
// -------------------------------------------------------------------------

Administrator's avatar
Administrator committed
524
525
526
527
528
void CbmMcbm2018UnpackerAlgoTof::AddMsComponentToList(size_t component,
                                                      UShort_t usDetectorId) {
  /// Check for duplicates and ignore if it is the case
  for (UInt_t uCompIdx = 0; uCompIdx < fvMsComponentsList.size(); ++uCompIdx)
    if (component == fvMsComponentsList[uCompIdx]) return;
529

Administrator's avatar
Administrator committed
530
531
  /// Add to list
  fvMsComponentsList.push_back(component);
532

Administrator's avatar
Administrator committed
533
534
535
  LOG(info) << "CbmMcbm2018UnpackerAlgoTof::AddMsComponentToList => Component "
            << component << " with detector ID 0x" << std::hex << usDetectorId
            << std::dec << " added to list";
536
537
538
}
// -------------------------------------------------------------------------

Administrator's avatar
Administrator committed
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
Bool_t CbmMcbm2018UnpackerAlgoTof::ProcessTs(const fles::Timeslice& ts) {
  fulCurrentTsIdx = ts.index();
  fdTsStartTime   = static_cast<Double_t>(ts.descriptor(0, 0).idx);
  LOG(DEBUG) << "ProcessTs " << fulCurrentTsIdx;

  /// Ignore First TS as first MS is typically corrupt
  if (0 == fulCurrentTsIdx) { return kTRUE; }  // if( 0 == fulCurrentTsIdx )

  /// On first TS, extract the TS parameters from header (by definition stable over time)
  if (-1.0 == fdTsCoreSizeInNs) {
    fuNbCoreMsPerTs  = ts.num_core_microslices();
    fuNbOverMsPerTs  = ts.num_microslices(0) - ts.num_core_microslices();
    fdTsCoreSizeInNs = fdMsSizeInNs * (fuNbCoreMsPerTs);
    fdTsFullSizeInNs = fdMsSizeInNs * (fuNbCoreMsPerTs + fuNbOverMsPerTs);
    LOG(info) << "Timeslice parameters: each TS has " << fuNbCoreMsPerTs
              << " Core MS and " << fuNbOverMsPerTs
              << " Overlap MS, for a core duration of " << fdTsCoreSizeInNs
              << " ns and a full duration of " << fdTsFullSizeInNs << " ns";

    /// Ignore overlap ms if flag set by user
    fuNbMsLoop = fuNbCoreMsPerTs;
    if (kFALSE == fbIgnoreOverlapMs) fuNbMsLoop += fuNbOverMsPerTs;
    LOG(info) << "In each TS " << fuNbMsLoop << " MS will be looped over";
  }  // if( -1.0 == fdTsCoreSizeInNs )

  /// Compute time of TS core end
  fdTsStopTimeCore = fdTsStartTime + fdTsCoreSizeInNs;
  //      LOG(info) << Form( "TS %5d Start %12f Stop %12f", fulCurrentTsIdx, fdTsStartTime, fdTsStopTimeCore );

  /// Loop over core microslices (and overlap ones if chosen)
  for (fuMsIndex = 0; fuMsIndex < fuNbMsLoop; fuMsIndex++) {
    /// Loop over registered components
    for (UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size();
         ++uMsCompIdx) {
      UInt_t uMsComp = fvMsComponentsList[uMsCompIdx];

      if (kFALSE == ProcessMs(ts, uMsComp, fuMsIndex)) {
        LOG(error) << "Failed to process ts " << fulCurrentTsIdx << " MS "
                   << fuMsIndex << " for component " << uMsComp;
        return kFALSE;
      }  // if( kFALSE == ProcessMs( ts, uMsCompIdx, fuMsIndex ) )
    }  // for( UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size(); ++uMsCompIdx )
  }    // for( fuMsIndex = 0; fuMsIndex < uNbMsLoop; fuMsIndex ++ )

  /// Fill plots if in monitor mode
  if (fbMonitorMode) {
    if (kFALSE == FillHistograms()) {
      LOG(error) << "Failed to fill histos in ts " << fulCurrentTsIdx;
      return kFALSE;
    }  // if( kFALSE == FillHistograms() )

    fhVectorSize->Fill(fulCurrentTsIdx, fDigiVect.size());
    fhVectorCapacity->Fill(fulCurrentTsIdx, fDigiVect.capacity());
  }  // if( fbMonitorMode )

  if (fuTsMaxVectorSize < fDigiVect.size()) {
    fuTsMaxVectorSize = fDigiVect.size() * fdCapacityIncFactor;
    fDigiVect.shrink_to_fit();
    fDigiVect.reserve(fuTsMaxVectorSize);
  }  // if( fuTsMaxVectorSize < fDigiVect.size() )
     /*
600
601
602
603
604
605
606
607
608
   if(!bEnableOut) {
     LOG(DEBUG) << "Ts  "<<   fulCurrentTsIdx << " removed ";
     fiMsBad++;
     fDigiVect.clear();
   }else {
     LOG(DEBUG) << "Ts  "<<   fulCurrentTsIdx << " accepted ";
     fiMsGood++;
   }
*/
Administrator's avatar
Administrator committed
609
610
611
612
613
614
615
616
  /// Sort the buffers of hits due to the time offsets applied
  sort(fDigiVect.begin(),
       fDigiVect.end(),
       [](const CbmTofDigi& a, const CbmTofDigi& b) -> bool {
         return a.GetTime() < b.GetTime();
       });

  return kTRUE;
617
618
}

Administrator's avatar
Administrator committed
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
Bool_t CbmMcbm2018UnpackerAlgoTof::ProcessMs(const fles::Timeslice& ts,
                                             size_t uMsCompIdx,
                                             size_t uMsIdx) {
  auto msDescriptor    = ts.descriptor(uMsCompIdx, uMsIdx);
  fuCurrentEquipmentId = msDescriptor.eq_id;
  const uint8_t* msContent =
    reinterpret_cast<const uint8_t*>(ts.content(uMsCompIdx, uMsIdx));

  uint32_t uSize  = msDescriptor.size;
  fulCurrentMsIdx = msDescriptor.idx;
  //   Double_t dMsTime = (1e-9) * static_cast<double>(fulCurrentMsIdx);
  LOG(debug) << "Microslice: " << fulCurrentMsIdx << " from EqId " << std::hex
             << fuCurrentEquipmentId << std::dec << " has size: " << uSize;

  if (0 == fvbMaskedComponents.size())
    fvbMaskedComponents.resize(ts.num_components(), kFALSE);

  fuCurrDpbId = static_cast<uint32_t>(fuCurrentEquipmentId & 0xFFFF);
  //   fuCurrDpbIdx = fDpbIdIndexMap[ fuCurrDpbId ];

  /// Check if this sDPB ID was declared in parameter file and stop there if not
  auto it = fGdpbIdIndexMap.find(fuCurrDpbId);
  if (it == fGdpbIdIndexMap.end()) {
    if (kFALSE == fvbMaskedComponents[uMsCompIdx]) {
      LOG(info)
        << "---------------------------------------------------------------";
      LOG(info) << FormatMsHeaderPrintout(msDescriptor);
      LOG(warning) << "Could not find the gDPB index for AFCK id 0x" << std::hex
                   << fuCurrDpbId << std::dec << " in timeslice "
                   << fulCurrentTsIdx << " in microslice " << uMsIdx
                   << " component " << uMsCompIdx << "\n"
                   << "If valid this index has to be added in the TOF "
                      "parameter file in the DbpIdArray field";
      fvbMaskedComponents[uMsCompIdx] = kTRUE;
    }  // if( kFALSE == fvbMaskedComponents[ uMsComp ] )
    else
      return kTRUE;
656

Administrator's avatar
Administrator committed
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
    /// Try to get it from the second message in buffer (first is epoch cycle without gDPB ID)
    /// TODO!!!!

    return kFALSE;
  }  // if( it == fGdpbIdIndexMap.end() )
  else
    fuCurrDpbIdx = fGdpbIdIndexMap[fuCurrDpbId];

  fuCurrentMsSysId = static_cast<unsigned int>(msDescriptor.sys_id);

  // If not integer number of message in input buffer, print warning/error
  if (0 != (uSize % sizeof(gdpbv100::Message)))
    LOG(error) << "The input microslice buffer does NOT "
               << "contain only complete gDPB messages!";

  // Compute the number of complete messages in the input microslice buffer
  uint32_t uNbMessages =
    (uSize - (uSize % sizeof(gdpbv100::Message))) / sizeof(gdpbv100::Message);

  // Prepare variables for the loop on contents
  Int_t messageType = -111;
  const uint64_t* pInBuff =
    reinterpret_cast<const uint64_t*>(msContent);  // for epoch cycle
  const gdpbv100::Message* pMess =
    reinterpret_cast<const gdpbv100::Message*>(pInBuff);
  for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
    /// Catch the Epoch cycle block which is always the first 64b of the MS
    if (0 == uIdx) {
      ProcessEpochCycle(pInBuff[uIdx]);
      continue;
    }  // if( 0 == uIdx )

    /// Get message type
    messageType = pMess[uIdx].getMessageType();

    fuGet4Id = fUnpackPar->ElinkIdxToGet4Idx(pMess[uIdx].getGdpbGenChipId());
    if (fuDiamondDpbIdx == fuCurrDpbIdx || 0x90 == fuCurrentMsSysId)
      fuGet4Id = pMess[uIdx].getGdpbGenChipId();
    fuGet4Nr = (fuCurrDpbIdx * fuNrOfGet4PerGdpb) + fuGet4Id;

    if (fuNrOfGet4PerGdpb <= fuGet4Id && !pMess[uIdx].isStarTrigger()
        && (gdpbv100::kuChipIdMergedEpoch != fuGet4Id))
      LOG(warning) << "Message with Get4 ID too high: " << fuGet4Id << " VS "
                   << fuNrOfGet4PerGdpb << " set in parameters.";

    /*
703
704
705
706
707
708
709
710
711
712
713
714
         if( 1 == uIdx && gdpbv100::MSG_EPOCH != messageType )
            LOG(warning) << " in timeslice " << fulCurrentTsIdx
                         << " in microslice " << fuMsIndex
                         << " component " << uMsCompIdx
                         << " first message is not an epoch: type " << messageType;

         if( uNbMessages - 1 == uIdx && gdpbv100::MSG_EPOCH != messageType )
            LOG(warning) << " in timeslice " << fulCurrentTsIdx
                         << " in microslice " << fuMsIndex
                         << " component " << uMsCompIdx
                         << " last message is not an epoch: type " << messageType;
*/
Administrator's avatar
Administrator committed
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
    /// FIXME mCBM 2018-2019: the 2nd message in the microslice should ALWAYS be
    /// an EPOCH, but we observed a few cases were a HIT from the previous MS is
    /// inserted first
    /// ===> This HIT is in wrong TS and not properly time sorted if in first MS
    /// ===> Temporary solution: simply ignore these hits, may decrease efficiency
    /// ====> Not sufficient if more than one HIT is in wrong MS !!!
    if (1 == uIdx && gdpbv100::MSG_EPOCH != messageType) {
      LOG(debug) << " CbmMcbm2018UnpackerAlgoTof ==> In timeslice "
                 << fulCurrentTsIdx << " in microslice " << fuMsIndex
                 << " component " << uMsCompIdx
                 << " first message is not an epoch: type " << messageType
                 << " -> It will be ignored! ";
      continue;
    }  // if( 1 == uIdx && gdpbv100::MSG_EPOCH != messageType )

    switch (messageType) {
      case gdpbv100::MSG_HIT: {
        if (pMess[uIdx].getGdpbHitIs24b()) {
          LOG(error) << "This event builder does not support 24b hit message!!!"
                     << " Message " << uIdx << "/" << uNbMessages << " 0x"
                     << FormatHexPrintout(pMess[uIdx].getData(), '0', 16);
          continue;
        }  // if( getGdpbHitIs24b() )
        else {
          fvvmEpSupprBuffer[fuCurrDpbIdx].push_back(pMess[uIdx]);
        }  // else of if( getGdpbHitIs24b() )
        break;
      }  // case gdpbv100::MSG_HIT:
      case gdpbv100::MSG_EPOCH: {
        if (gdpbv100::kuChipIdMergedEpoch == fuGet4Id) {
          ProcessEpoch(pMess[uIdx], uIdx);
        }  // if this epoch message is a merged one valid for all chips
        else {
          /// Should be checked in monitor task, here we just jump it
          LOG(debug2) << "This event builder does not support unmerged epoch "
                         "messages!!!.";
          continue;
        }  // if single chip epoch message
        break;
      }  // case gdpbv100::MSG_EPOCH:
      case gdpbv100::MSG_SLOWC: {
        fvvmEpSupprBuffer[fuCurrDpbIdx].push_back(pMess[uIdx]);
        break;
      }  // case gdpbv100::MSG_SLOWC:
      case gdpbv100::MSG_SYST: {
        fvvmEpSupprBuffer[fuCurrDpbIdx].push_back(pMess[uIdx]);
        break;
      }  // case gdpbv100::MSG_SYST:
      case gdpbv100::MSG_STAR_TRI_A:
      case gdpbv100::MSG_STAR_TRI_B:
      case gdpbv100::MSG_STAR_TRI_C:
      case gdpbv100::MSG_STAR_TRI_D: {
        ProcessStarTrigger(pMess[uIdx]);

        /// If A message, check that the following ones are B, C, D
        /// ==> TBD only if necessary
        /*
772
773
774
775
            if( gdpbv100::MSG_STAR_TRI_A == messageType )
            {
            } // if( gdpbv100::MSG_STAR_TRI_A == messageType )
*/
Administrator's avatar
Administrator committed
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
        break;
      }  // case gdpbv100::MSG_STAR_TRI_A-D
      default:
        LOG(error) << "Message type " << std::hex << std::setw(2)
                   << static_cast<uint16_t>(messageType)
                   << " not included in Get4 unpacker.";
    }  // switch( mess.getMessageType() )
  }    // for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx ++)

  /// FIXME: in the 2018-2019 data, we had only the epoch message before each
  ///        block of data in the MS
  /// ===> Until it is decided either to get rid of the epoch suppr. buffer or
  ///      to implement the "closing epoch" in the FW, do the following:
  /// For now this method is used to fake a "closing" epoch at the end of the MS
  ProcessEndOfMsEpoch();

  return kTRUE;
793
794
795
}

// -------------------------------------------------------------------------
Administrator's avatar
Administrator committed
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
void CbmMcbm2018UnpackerAlgoTof::ProcessEpochCycle(
  const uint64_t& ulCycleData) {
  ULong64_t ulEpochCycleVal = ulCycleData & gdpbv100::kulEpochCycleFieldSz;

  if (!(ulEpochCycleVal == fvulCurrentEpochCycle[fuCurrDpbIdx]
        || ulEpochCycleVal == fvulCurrentEpochCycle[fuCurrDpbIdx] + 1)
      && 0 < fulCurrentMsIdx) {
    LOG(warning) << "CbmMcbm2018UnpackerAlgoTof::ProcessEpochCycle => "
                 << " Missmatch in epoch cycles detected for Gdpb "
                 << fuCurrDpbIdx
                 << ", probably fake cycles due to epoch index corruption! "
                 << Form(" Current cycle 0x%09llX New cycle 0x%09llX",
                         fvulCurrentEpochCycle[fuCurrDpbIdx],
                         ulEpochCycleVal);
  }  // if epoch cycle did not stay constant or increase by exactly 1, except if first MS of the TS
  if (ulEpochCycleVal != fvulCurrentEpochCycle[fuCurrDpbIdx]) {
    LOG(info) << "CbmMcbm2018UnpackerAlgoTof::ProcessEpochCycle   => "
              << " New epoch cycle for Gdpb " << fuCurrDpbIdx
              << Form(": Current cycle 0x%09llX New cycle 0x%09llX",
                      fvulCurrentEpochCycle[fuCurrDpbIdx],
                      ulEpochCycleVal);
  }  // if( ulEpochCycleVal != fvulCurrentEpochCycle[fuCurrDpbIdx] )
  fvulCurrentEpochCycle[fuCurrDpbIdx] = ulEpochCycleVal;

  return;
821
}
Administrator's avatar
Administrator committed
822
823
824
825
void CbmMcbm2018UnpackerAlgoTof::ProcessEpoch(const gdpbv100::Message& mess,
                                              uint32_t /*uMesgIdx*/) {
  ULong64_t ulEpochNr = mess.getGdpbEpEpochNb();
  /*
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
   if( (  6 == fulCurrentTsIdx && 2 == fuCurrDpbIdx ) ||
       ( 57 == fulCurrentTsIdx && 0 == fuCurrDpbIdx ) )
      LOG(info) << Form( "Gdpb %d TS %3llu MS %3u Msg %4u Ep %08llx",
                           fuCurrDpbIdx, fulCurrentTsIdx, fuMsIndex, uMesgIdx, ulEpochNr );

   if( !( ulEpochNr == fvulCurrentEpoch[ fuCurrDpbIdx ] + 1 ||
//          ulEpochNr == fvulCurrentEpoch[ fuCurrDpbIdx ] || // For the fake "closing epoch"
          ( 0 == ulEpochNr && gdpbv100::kuEpochCounterSz == fvulCurrentEpoch[ fuCurrDpbIdx ] )
        )
     )
   {
      Int_t iDiff = ulEpochNr;
      iDiff -= fvulCurrentEpoch[ fuCurrDpbIdx ];
      LOG(info) << "CbmMcbm2018UnpackerAlgoTof::ProcessEpoch        => "
                << " Non consecutive epochs for Gdpb " << fuCurrDpbIdx
                << " in TS " << fulCurrentTsIdx
                << " MS " << fuMsIndex
                << " Msg " << uMesgIdx
                << Form( " : old Ep %08llx new Ep %08llx Diff %d ", fvulCurrentEpoch[ fuCurrDpbIdx ], ulEpochNr, iDiff )
                << std::endl;
   } // if epoch neither +1 nor equal nor overflow
*/
Administrator's avatar
Administrator committed
848
  /*
849
850
851
852
853
854
855
856
857
858
859
860
861
   /// Check for epoch cycle, except for the first epoch in MS buffer (2nd message) where this is taken care
   /// by the epoch cycle index (1st message)
   if( 0 < fvulCurrentEpoch[ fuCurrDpbIdx ] && ulEpochNr < fvulCurrentEpoch[ fuCurrDpbIdx ] &&
       1 < uMesgIdx )
   {
      LOG(info) << "CbmMcbm2018UnpackerAlgoTof::ProcessEpoch        => "
                << " New epoch cycle for Gdpb " << fuCurrDpbIdx
                << Form( ": Current cycle 0x%09llX New cycle 0x%09llX", fvulCurrentEpochCycle[fuCurrDpbIdx], fvulCurrentEpochCycle[fuCurrDpbIdx] + 1 )
                << Form( "(old Ep %08llx new Ep %08llx)", fvulCurrentEpoch[ fuCurrDpbIdx ], ulEpochNr )
                << std::endl;
      fvulCurrentEpochCycle[ fuCurrDpbIdx ]++;
   } // if( 0 < fvulCurrentEpoch[ fuCurrDpbIdx ] && ulEpochNr < fvulCurrentEpoch[ fuCurrDpbIdx ] && 1 < uMesgIdx)
*/
Administrator's avatar
Administrator committed
862
863
864
865
  fvulCurrentEpoch[fuCurrDpbIdx] = ulEpochNr;
  fvulCurrentEpochFull[fuCurrDpbIdx] =
    ulEpochNr
    + (gdpbv100::kuEpochCounterSz + 1) * fvulCurrentEpochCycle[fuCurrDpbIdx];
866

Administrator's avatar
Administrator committed
867
  /*
868
869
870
871
872
873
   /// Re-align the epoch number of the message in case it will be used later:
   /// We received the epoch after the data instead of the one before!
   if( 0 < ulEpochNr )
      mess.setGdpbEpEpochNb( ulEpochNr - 1 );
      else mess.setGdpbEpEpochNb( gdpbv100::kuEpochCounterSz );
*/
Administrator's avatar
Administrator committed
874
875
  /// Process the corresponding messages buffer for current gDPB
  ProcessEpSupprBuffer();
876
}
Administrator's avatar
Administrator committed
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
void CbmMcbm2018UnpackerAlgoTof::ProcessEndOfMsEpoch() {
  /// Used to fake a "closing" epoch at the end of the MS
  ULong64_t ulEpochNr =
    (fvulCurrentEpoch[fuCurrDpbIdx] + 1) % gdpbv100::kuEpochCounterSz;

  if (0 < fvulCurrentEpoch[fuCurrDpbIdx]
      && ulEpochNr < fvulCurrentEpoch[fuCurrDpbIdx]) {
    LOG(info) << "CbmMcbm2018UnpackerAlgoTof::ProcessEndOfMsEpoch => "
              << " New epoch cycle for Gdpb " << fuCurrDpbIdx
              << Form(": Current cycle 0x%09llX New cycle 0x%09llX",
                      fvulCurrentEpochCycle[fuCurrDpbIdx],
                      fvulCurrentEpochCycle[fuCurrDpbIdx] + 1)
              << Form("(old Ep %08llx new Ep %08llx)",
                      fvulCurrentEpoch[fuCurrDpbIdx],
                      ulEpochNr);
    fvulCurrentEpochCycle[fuCurrDpbIdx]++;
  }  // if( 0 < fvulCurrentEpoch[ fuCurrDpbIdx ] && ulEpochNr < fvulCurrentEpoch[ fuCurrDpbIdx ] )
     /*
895
896
897
   fvulCurrentEpoch[ fuCurrDpbIdx ] = ulEpochNr;
   fvulCurrentEpochFull[ fuCurrDpbIdx ] = ulEpochNr + ( gdpbv100::kuEpochCounterSz + 1 ) * fvulCurrentEpochCycle[ fuCurrDpbIdx ];
*/
Administrator's avatar
Administrator committed
898
899
900
  fvulCurrentEpochFull[fuCurrDpbIdx] =
    ulEpochNr
    + (gdpbv100::kuEpochCounterSz + 1) * fvulCurrentEpochCycle[fuCurrDpbIdx];
901

Administrator's avatar
Administrator committed
902
903
  /// Process the corresponding messages buffer for current gDPB
  ProcessEpSupprBuffer();
904
}
Administrator's avatar
Administrator committed
905
906
void CbmMcbm2018UnpackerAlgoTof::ProcessStarTrigger(
  const gdpbv100::Message& mess) {
907
908
  Int_t iMsgIndex = mess.getStarTrigMsgIndex();

Administrator's avatar
Administrator committed
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
  switch (iMsgIndex) {
    case 0: fvulGdpbTsMsb[fuCurrDpbIdx] = mess.getGdpbTsMsbStarA(); break;
    case 1:
      fvulGdpbTsLsb[fuCurrDpbIdx] = mess.getGdpbTsLsbStarB();
      fvulStarTsMsb[fuCurrDpbIdx] = mess.getStarTsMsbStarB();
      break;
    case 2: fvulStarTsMid[fuCurrDpbIdx] = mess.getStarTsMidStarC(); break;
    case 3: {
      ULong64_t ulNewGdpbTsFull =
        (fvulGdpbTsMsb[fuCurrDpbIdx] << 24) + (fvulGdpbTsLsb[fuCurrDpbIdx]);
      ULong64_t ulNewStarTsFull = (fvulStarTsMsb[fuCurrDpbIdx] << 48)
                                  + (fvulStarTsMid[fuCurrDpbIdx] << 8)
                                  + mess.getStarTsLsbStarD();
      UInt_t uNewToken   = mess.getStarTokenStarD();
      UInt_t uNewDaqCmd  = mess.getStarDaqCmdStarD();
      UInt_t uNewTrigCmd = mess.getStarTrigCmdStarD();

      if ((uNewToken == fvuStarTokenLast[fuCurrDpbIdx])
          && (ulNewGdpbTsFull == fvulGdpbTsFullLast[fuCurrDpbIdx])
          && (ulNewStarTsFull == fvulStarTsFullLast[fuCurrDpbIdx])
          && (uNewDaqCmd == fvuStarDaqCmdLast[fuCurrDpbIdx])
          && (uNewTrigCmd == fvuStarTrigCmdLast[fuCurrDpbIdx])) {
        UInt_t uTrigWord = ((fvuStarTrigCmdLast[fuCurrDpbIdx] & 0x00F) << 16)
                           + ((fvuStarDaqCmdLast[fuCurrDpbIdx] & 0x00F) << 12)
                           + ((fvuStarTokenLast[fuCurrDpbIdx] & 0xFFF));
        LOG(warning) << "Possible error: identical STAR tokens found twice in "
                        "a row => ignore 2nd! "
                     << " TS " << fulCurrentTsIdx << " gDBB #" << fuCurrDpbIdx
                     << " "
                     << Form("token = %5u ", fvuStarTokenLast[fuCurrDpbIdx])
                     << Form("gDPB ts  = %12llu ",
                             fvulGdpbTsFullLast[fuCurrDpbIdx])
                     << Form("STAR ts = %12llu ",
                             fvulStarTsFullLast[fuCurrDpbIdx])
                     << Form("DAQ cmd = %2u ", fvuStarDaqCmdLast[fuCurrDpbIdx])
                     << Form("TRG cmd = %2u ", fvuStarTrigCmdLast[fuCurrDpbIdx])
                     << Form("TRG Wrd = %5x ", uTrigWord);
        return;
      }  // if exactly same message repeated

      // GDPB TS counter reset detection
      if (ulNewGdpbTsFull < fvulGdpbTsFullLast[fuCurrDpbIdx])
        LOG(debug) << "Probable reset of the GDPB TS: old = "
                   << Form("%16llu", fvulGdpbTsFullLast[fuCurrDpbIdx])
                   << " new = " << Form("%16llu", ulNewGdpbTsFull)
                   << " Diff = -"
                   << Form("%8llu",
                           fvulGdpbTsFullLast[fuCurrDpbIdx] - ulNewGdpbTsFull)
                   << " GDPB #" << Form("%2u", fuCurrDpbIdx);

      // STAR TS counter reset detection
      if (ulNewStarTsFull < fvulStarTsFullLast[fuCurrDpbIdx])
        LOG(debug) << "Probable reset of the STAR TS: old = "
                   << Form("%16llu", fvulStarTsFullLast[fuCurrDpbIdx])
                   << " new = " << Form("%16llu", ulNewStarTsFull)
                   << " Diff = -"
                   << Form("%8llu",
                           fvulStarTsFullLast[fuCurrDpbIdx] - ulNewStarTsFull)
                   << " GDPB #" << Form("%2u", fuCurrDpbIdx);

      /// Check needed to avoid double counting
      if (fulCurrentMsIdx < fuNbCoreMsPerTs) {
        fvulGdpbTsFullLast[fuCurrDpbIdx] = ulNewGdpbTsFull;
        fvulStarTsFullLast[fuCurrDpbIdx] = ulNewStarTsFull;
        fvuStarTokenLast[fuCurrDpbIdx]   = uNewToken;
        fvuStarDaqCmdLast[fuCurrDpbIdx]  = uNewDaqCmd;
        fvuStarTrigCmdLast[fuCurrDpbIdx] = uNewTrigCmd;
      }  // if( fuCurrentMs < fuNbCoreMsPerTs )

      /// FIXME: for now do nothing with it!
      /*
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
         Double_t dTot = 1.;
         Double_t dTime = fulGdpbTsFullLast * 6.25;
         if( 0. == fdFirstDigiTimeDif && 0. != fdLastDigiTime )
         {
            fdFirstDigiTimeDif = dTime - fdLastDigiTime;
            LOG(info) << "Reference fake digi time shift initialized to " << fdFirstDigiTimeDif;
         } // if( 0. == fdFirstDigiTimeDif && 0. != fdLastDigiTime )

	 //         dTime -= fdFirstDigiTimeDif;

         LOG(debug) << "Insert fake digi with time " << dTime << ", Tot " << dTot;
         fhRawTRefDig0->Fill( dTime - fdLastDigiTime);
         fhRawTRefDig1->Fill( dTime - fdLastDigiTime);

         fDigi = new CbmTofDigiExp(0x00005006, dTime, dTot); // fake start counter signal
         fBuffer->InsertData<CbmTofDigi>(fDigi);
*/
Administrator's avatar
Administrator committed
997
998
999
1000
      break;
    }  // case 3
    default: LOG(error) << "Unknown Star Trigger messageindex: " << iMsgIndex;
  }  // switch( iMsgIndex )
For faster browsing, not all history is shown. View entire blame