/
CodaDecoder.C
709 lines (608 loc) · 21.9 KB
/
CodaDecoder.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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
290
291
292
293
294
295
296
297
298
299
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
333
334
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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
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
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
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
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
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
656
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
703
704
705
706
707
708
709
////////////////////////////////////////////////////////////////////
//
// CodaDecoder
//
// Object Oriented version of decoder
// Sept, 2014 R. Michaels
//
/////////////////////////////////////////////////////////////////////
#include "CodaDecoder.h"
#include "THaCrateMap.h"
#include "THaBenchmark.h"
#include "THaUsrstrutils.h"
#include "TError.h"
#include <iostream>
using namespace std;
namespace Decoder {
// static const Int_t MAX_EVTYPES = 200;
// static const Int_t MAX_PHYS_EVTYPES = 14;
//_____________________________________________________________________________
CodaDecoder::CodaDecoder()
{
irn = new Int_t[MAXROC];
fbfound = new Int_t[MAXROC*MAXSLOT];
memset(irn, 0, MAXROC*sizeof(Int_t));
memset(fbfound, 0, MAXROC*MAXSLOT*sizeof(Int_t));
fDebugFile = 0;
fDebug=0;
fNeedInit=true;
first_decode=kFALSE;
fMultiBlockMode=kFALSE;
fBlockIsDone=kFALSE;
for(int i=0; i<MAX_PSFACT; ++i)
psfact[i] = -1;
}
//_____________________________________________________________________________
CodaDecoder::~CodaDecoder()
{
delete [] irn;
delete [] fbfound;
}
//_____________________________________________________________________________
Int_t CodaDecoder::GetPrescaleFactor(Int_t trigger_type) const
{
// To get the prescale factors for trigger number "trigger_type"
// (valid types are 1,2,3...)
if ( (trigger_type > 0) && (trigger_type <= MAX_PSFACT)) {
return psfact[trigger_type - 1];
}
if (fDebug > 0) {
Warning( "CodaDecoder::GetPrescaleFactor", "Requested prescale factor for "
"undefined trigger type %d", trigger_type );
}
return 0;
}
//_____________________________________________________________________________
Int_t CodaDecoder::Init() {
Int_t ret = HED_OK;
ret = init_cmap();
// if (fMap) fMap->print();
if (ret != HED_OK) return ret;
ret = init_slotdata(fMap);
first_decode = kFALSE;
fNeedInit = kFALSE;
return ret;
}
//_____________________________________________________________________________
Int_t CodaDecoder::LoadEvent(const UInt_t* evbuffer)
{
// Main engine for decoding, called by public LoadEvent() methods
static Int_t fdfirst=1;
static Int_t chkfbstat=1;
if (fDebugFile) *fDebugFile << "CodaDecode:: Loading event ... "<<endl;
if (fDebugFile) *fDebugFile << "evbuffer ptr "<<evbuffer<<endl;
assert( evbuffer );
assert( fMap || fNeedInit );
Int_t ret = HED_OK;
buffer = evbuffer;
if(fDebugFile) {
*fDebugFile << "CodaDecode:: dumping "<<endl;
dump(evbuffer);
}
if (first_decode || fNeedInit) {
ret = init_cmap();
if (fDebugFile) {
*fDebugFile << "\n CodaDecode:: Print of Crate Map"<<endl;
fMap->print(fDebugFile);
} else {
// fMap->print();
}
if( ret != HED_OK ) return ret;
ret = init_slotdata(fMap);
if( ret != HED_OK ) return ret;
FindUsedSlots();
first_decode=kFALSE;
}
if( fDoBench ) fBench->Begin("clearEvent");
for( Int_t i=0; i<fNSlotClear; i++ ) crateslot[fSlotClear[i]]->clearEvent();
if( fDoBench ) fBench->Stop("clearEvent");
event_length = evbuffer[0]+1; // in longwords (4 bytes)
event_type = evbuffer[1]>>16;
if(event_type < 0) return HED_ERR;
event_num = 0;
if (event_type == PRESTART_EVTYPE) {
// Usually prestart is the first 'event'. Call SetRunTime() to
// re-initialize the crate map since we now know the run time.
// This won't happen for split files (no prestart). For such files,
// the user should call SetRunTime() explicitly.
SetRunTime(static_cast<ULong64_t>(evbuffer[2]));
run_num = evbuffer[3];
run_type = evbuffer[4];
evt_time = fRunTime;
} else if( event_type == PRESCALE_EVTYPE || event_type == TS_PRESCALE_EVTYPE ) {
ret = prescale_decode(evbuffer);
if( ret != HED_OK )
return ret;
}
if (event_type <= MAX_PHYS_EVTYPE) {
event_num = evbuffer[4];
recent_event = event_num;
FindRocs(evbuffer);
if ((fdfirst==1) & (fDebugFile!=0)) {
fdfirst=0;
CompareRocs();
}
// Decode each ROC
// This is not part of the loop above because it may exit prematurely due
// to errors, which would leave the rocdat[] array incomplete.
for( Int_t i=0; i<nroc; i++ ) {
Int_t iroc = irn[i];
const RocDat_t* proc = rocdat+iroc;
Int_t ipt = proc->pos + 1;
Int_t iptmax = proc->pos + proc->len;
if (fMap->isFastBus(iroc)) { // checking that slots found = expected
if (GetEvNum() > 200 && chkfbstat < 3) chkfbstat=2;
if (chkfbstat == 1) ChkFbSlot(iroc, evbuffer, ipt, iptmax);
if (chkfbstat == 2) {
ChkFbSlots();
chkfbstat = 3;
}
}
Int_t status;
// If at least one module is in a bank, must split the banks for this roc
if (fMap->isBankStructure(iroc)) {
if (fDebugFile) *fDebugFile << "\nCodaDecode::Calling bank_decode "<<i<<" "<<iroc<<" "<<ipt<<" "<<iptmax<<endl;
/*status =*/ bank_decode(iroc,evbuffer,ipt,iptmax);
}
if (fDebugFile) *fDebugFile << "\nCodaDecode::Calling roc_decode "<<i<<" "<<evbuffer<<" "<<iroc<<" "<<ipt<<" "<<iptmax<<endl;
status = roc_decode(iroc,evbuffer, ipt, iptmax);
// do something with status
if (status == -1) break;
}
}
return ret;
}
//_____________________________________________________________________________
Int_t CodaDecoder::LoadFromMultiBlock()
{
// LoadFromMultiBlock : This assumes the data are in multiblock mode.
// For modules that are in multiblock mode, the next event is loaded.
// For other modules not in multiblock mode (e.g. scalers) or other data (e.g. flags)
// the data remain "stale" until the next block of events.
if (!fMultiBlockMode) return HED_ERR;
fBlockIsDone = kFALSE;
for( Int_t i=0; i<fNSlotClear; i++ ) {
if (crateslot[fSlotClear[i]]->GetModule()->IsMultiBlockMode()) crateslot[fSlotClear[i]]->clearEvent();
}
for( Int_t i=0; i<nroc; i++ ) {
Int_t roc = irn[i];
Int_t minslot = fMap->getMinSlot(roc);
Int_t maxslot = fMap->getMaxSlot(roc);
for (Int_t slot = minslot; slot <= maxslot; slot++) {
if (fMap->slotUsed(roc,slot) && crateslot[idx(roc,slot)]->GetModule()->IsMultiBlockMode()) {
crateslot[idx(roc,slot)]->LoadNextEvBuffer();
if (crateslot[idx(roc,slot)]->BlockIsDone()) fBlockIsDone = kTRUE;
}
}
}
return HED_OK;
}
//_____________________________________________________________________________
Int_t CodaDecoder::roc_decode( Int_t roc, const UInt_t* evbuffer,
Int_t ipt, Int_t istop )
{
// Decode a Readout controller
assert( evbuffer && fMap );
if( fDoBench ) fBench->Begin("roc_decode");
Int_t slot;
Int_t Nslot = fMap->getNslot(roc);
Int_t minslot = fMap->getMinSlot(roc);
Int_t maxslot = fMap->getMaxSlot(roc);
Int_t retval = HED_OK;
Int_t nwords;
synchmiss = false;
synchextra = false;
buffmode = false;
const UInt_t* p = evbuffer+ipt; // Points to ROC ID word (1 before data)
const UInt_t* pstop =evbuffer+istop; // Points to last word of data
fBlockIsDone = kFALSE;
Int_t firstslot, incrslot;
Int_t n_slots_checked, n_slots_done;
Bool_t slotdone;
Int_t status = SD_ERR;
n_slots_done = 0;
if (istop >= event_length) {
cerr << "ERROR:: roc_decode: stop point exceeds event length (?!)"<<endl;
goto err;
}
if (fMap->isFastBus(roc)) { // higher slot # appears first in multiblock mode
firstslot=maxslot; // the decoding order improves efficiency
incrslot = -1;
} else {
firstslot=minslot;
incrslot = 1;
}
if (fDebugFile) {
*fDebugFile << "CodaDecode:: roc_decode:: roc# "<<dec<<roc<<" nslot "<<Nslot<<endl;
*fDebugFile << "CodaDecode:: roc_decode:: firstslot "<<dec<<firstslot<<" incrslot "<<incrslot<<endl;
}
if (Nslot <= 0) goto err;
fMap->setSlotDone(); // clears the "done" bits
while ( p++ < pstop && n_slots_done < Nslot ) {
if (fDebugFile) {
*fDebugFile << "CodaDecode::roc_decode:: evbuff "<<(p-evbuffer)<<" "<<hex<<*p<<dec<<endl;
*fDebugFile << "CodaDecode::roc_decode:: n_slots_done "<<n_slots_done<<" "<<firstslot<<endl;
}
LoadIfFlagData(p);
n_slots_checked = 0;
slot = firstslot;
slotdone = kFALSE;
// bank structure is decoded with bank_decode
if (fMap->getBank(roc,slot) >= 0) {
n_slots_done++;
slotdone=kTRUE;
}
while(!slotdone && n_slots_checked < Nslot-n_slots_done && slot >= 0 && slot < MAXSLOT) {
if (!fMap->slotUsed(roc,slot) || fMap->slotDone(slot)) {
slot = slot + incrslot;
continue;
}
++n_slots_checked;
if (fDebugFile) {
*fDebugFile<< "roc_decode:: slot logic "<<roc<<" "<<slot<<" "<<firstslot<<" "<<n_slots_checked<<" "<<Nslot-n_slots_done<<endl;
}
nwords = crateslot[idx(roc,slot)]->LoadIfSlot(p, pstop);
if (nwords > 0) {
p = p + nwords - 1;
fMap->setSlotDone(slot);
n_slots_done++;
if(fDebugFile) *fDebugFile << "CodaDecode:: slot "<<slot<<" is DONE "<<nwords<<endl;
slotdone = kTRUE;
}
if (crateslot[idx(roc,slot)]->IsMultiBlockMode()) fMultiBlockMode = kTRUE;
if (crateslot[idx(roc,slot)]->BlockIsDone()) fBlockIsDone = kTRUE;
if (fDebugFile) {
*fDebugFile<< "CodaDecode:: roc_decode:: after LoadIfSlot "<<p << " "<<pstop<<" "<<" "<<hex<<*p<<" "<<dec<<nwords<<endl;
}
slot = slot + incrslot;
}
} //end while(p++<pstop)
goto exit;
err:
retval = (status == SD_ERR) ? HED_ERR : HED_WARN;
exit:
if( fDoBench ) fBench->Stop("roc_decode");
return retval;
}
//_____________________________________________________________________________
Int_t CodaDecoder::bank_decode( Int_t roc, const UInt_t* evbuffer,
Int_t ipt, Int_t istop )
{
// Split a roc into banks, if using bank structure
// Then loop over slots and decode it from a bank if the slot
// belongs to a bank.
assert( evbuffer && fMap );
if( fDoBench ) fBench->Begin("bank_decode");
Int_t retval = HED_OK;
if (!fMap->isBankStructure(roc)) return retval;
fBlockIsDone = kFALSE;
Int_t pos,len,bank,head;
memset(bankdat,0,MAXBANK*sizeof(BankDat_t));
if (fDebugFile) *fDebugFile << "CodaDecode:: bank_decode ... "<<roc<<" "<<ipt<<" "<<istop<<endl;
pos = ipt+1; // ipt points to ROC ID word
while (pos < istop) {
len = evbuffer[pos];
head = evbuffer[pos+1];
bank = (head>>16)&0xffff;
if (fDebugFile) *fDebugFile << "bank 0x"<<hex<<bank<<" head 0x"<<head<<" len 0x"<<len<<dec<<endl;
if (bank >= 0 && bank < MAXBANK) {
bankdat[bank].pos=pos+2;
bankdat[bank].len=len-1;
}
pos += len+1;
}
Int_t minslot = fMap->getMinSlot(roc);
Int_t maxslot = fMap->getMaxSlot(roc);
for (Int_t slot = minslot; slot <= maxslot; slot++) {
if (!fMap->slotUsed(roc,slot)) continue;
bank=fMap->getBank(roc,slot);
if (bank < 0 || bank >= Decoder::MAXBANK) {
cerr << "CodaDecoder::ERROR: bank number out of range "<<endl;
return 0;
}
pos = bankdat[bank].pos;
len = bankdat[bank].len;
if (fDebugFile) *fDebugFile << "CodaDecode:: loading bank "<<roc<<" "<<slot<<" "<<bank<<" "<<pos<<" "<<len<<endl;
crateslot[idx(roc,slot)]->LoadBank(evbuffer,pos,len);
if (crateslot[idx(roc,slot)]->IsMultiBlockMode()) fMultiBlockMode = kTRUE;
if (crateslot[idx(roc,slot)]->BlockIsDone()) fBlockIsDone = kTRUE;
}
if( fDoBench ) fBench->Stop("bank_decode");
return retval;
}
//_____________________________________________________________________________
Int_t CodaDecoder::LoadIfFlagData(const UInt_t* evbuffer)
{
// Need to generalize this ... too Hall A specific
//
// Looks for buffer mode and synch problems. The latter are recoverable
// but extremely rare, so I haven't bothered to write recovery a code yet,
// but at least this warns you.
assert( evbuffer );
UInt_t word = *evbuffer;
UInt_t upword = word & 0xffff0000;
if (fDebugFile) *fDebugFile << "CodaDecode:: TestBit on : Flag data ? "<<hex<<word<<dec<<endl;
if( word == 0xdc0000ff) synchmiss = true;
if( upword == 0xdcfe0000) {
synchextra = true;
Int_t slot = (word&0xf800)>>11;
Int_t nhit = (word&0x7ff);
if(fDebug>0) {
cout << "THaEvData: WARNING: Fastbus slot ";
cout << slot << " has extra hits "<<nhit<<endl;
}
}
if( upword == 0xfabc0000) {
datascan = *(evbuffer+3);
if(fDebug>0 && (synchmiss || synchextra)) {
cout << "THaEvData: WARNING: Synch problems !"<<endl;
cout << "Data scan word 0x"<<hex<<datascan<<dec<<endl;
}
}
if( upword == 0xfabb0000) buffmode = false;
if((word&0xffffff00) == 0xfafbbf00) {
buffmode = true;
synchflag = word&0xff;
}
return HED_OK;
}
Int_t CodaDecoder::FindRocs(const UInt_t *evbuffer) {
assert( evbuffer && fMap );
#ifdef FIXME
if( fDoBench ) fBench->Begin("physics_decode");
#endif
Int_t status = HED_OK;
if( (evbuffer[1]&0xffff) != 0x10cc ) std::cout<<"Warning, header error"<<std::endl;
if( event_type > MAX_PHYS_EVTYPE ) std::cout<<"Warning, Event type makes no sense"<<std::endl;
memset(rocdat,0,MAXROC*sizeof(RocDat_t));
// Set pos to start of first ROC data bank
Int_t pos = evbuffer[2]+3; // should be 7
nroc = 0;
while( pos+1 < event_length && nroc < MAXROC ) {
Int_t len = evbuffer[pos];
Int_t iroc = (evbuffer[pos+1]&0xff0000)>>16;
if( iroc>=MAXROC ) {
#ifdef FIXME
if(fDebug>0) {
cout << "ERROR in EvtTypeHandler::FindRocs "<<endl;
cout << " illegal ROC number " <<dec<<iroc<<endl;
}
if( fDoBench ) fBench->Stop("physics_decode");
#endif
return HED_ERR;
}
// Save position and length of each found ROC data block
// Save position and length of each found ROC data block
rocdat[iroc].pos = pos;
rocdat[iroc].len = len;
irn[nroc++] = iroc;
pos += len+1;
}
if (fDebugFile) {
*fDebugFile << "CodaDecode:: num rocs "<<dec<<nroc<<endl;
for (Int_t i=0; i < nroc; i++) {
Int_t iroc=irn[i];
*fDebugFile << " CodaDecode:: roc num "<<iroc<<" pos "<<rocdat[iroc].pos<<" len "<<rocdat[iroc].len<<endl;
}
}
return status;
}
// To initialize the THaSlotData member on first call to decoder
int CodaDecoder::init_slotdata(const THaCrateMap* map)
{
// Update lists of used/clearable slots in case crate map changed
if(!map) return HED_ERR;
for (Int_t iroc = 0; iroc<MAXROC; iroc++) {
if ( !map->crateUsed(iroc) ) continue;
for (Int_t islot=0; islot < MAXSLOT; islot++) {
if ( !map->slotUsed(iroc,islot) ) continue;
makeidx(iroc,islot);
}
}
if (fDebugFile) *fDebugFile << "CodaDecode:: fNSlotUsed "<<fNSlotUsed<<endl;
for( int i=0; i<fNSlotUsed; i++ ) {
THaSlotData* crslot = crateslot[fSlotUsed[i]];
int crate = crslot->getCrate();
int slot = crslot->getSlot();
crslot->loadModule(map);
if (fDebugFile) *fDebugFile << "CodaDecode:: crate, slot "<<crate<<" "<<slot<<" Dev type = "<<crslot->devType()<<endl;
if( !map->crateUsed(crate) || !map->slotUsed(crate,slot) ||
!map->slotClear(crate,slot)) {
for( int k=0; k<fNSlotClear; k++ ) {
if( crslot == crateslot[fSlotClear[k]] ) {
for( int j=k+1; j<fNSlotClear; j++ )
fSlotClear[j-1] = fSlotClear[j];
fNSlotClear--;
break;
}
}
}
if( !map->crateUsed(crate) || !map->slotUsed(crate,slot)) {
for( int j=i+1; j<fNSlotUsed; j++ )
fSlotUsed[j-1] = fSlotUsed[j];
fNSlotUsed--;
}
}
return HED_OK;
}
//_____________________________________________________________________________
void CodaDecoder::dump(const UInt_t* evbuffer) const
{
if( !evbuffer ) return;
if ( !fDebugFile ) return;
Int_t len = evbuffer[0]+1;
Int_t type = evbuffer[1]>>16;
Int_t num = evbuffer[4];
*fDebugFile << "\n\n Raw Data Dump " << hex << endl;
*fDebugFile << "\n Event number " << dec << num;
*fDebugFile << " length " << len << " type " << type << endl;
Int_t ipt = 0;
for (Int_t j=0; j<(len/5); j++) {
*fDebugFile << dec << "\n evbuffer[" << ipt << "] = ";
for (Int_t k=j; k<j+5; k++) {
*fDebugFile << hex << evbuffer[ipt++] << " ";
}
}
if (ipt < len) {
*fDebugFile << dec << "\n evbuffer[" << ipt << "] = ";
for (Int_t k=ipt; k<len; k++) {
*fDebugFile << hex << evbuffer[ipt++] << " ";
}
*fDebugFile << endl;
}
*fDebugFile<<dec<<endl;
}
//_____________________________________________________________________________
void CodaDecoder::CompareRocs( )
{
if (!fMap || !fDebugFile) return;
*fDebugFile<< "Comparing cratemap rocs with found rocs"<<endl;
for (Int_t i=0; i<nroc; i++) {
Int_t iroc = irn[i];
if (!fMap->crateUsed(iroc)) {
*fDebugFile << "ERROR CompareRocs:: roc "<<iroc<<" in data but not in map"<<endl;
}
}
for (Int_t iroc1 = 0; iroc1<MAXROC; iroc1++) {
if ( !fMap->crateUsed(iroc1) ) continue;
Int_t ifound=0;
for( Int_t i=0; i<nroc; i++ ) {
Int_t iroc2 = irn[i];
if (iroc1 == iroc2) {
ifound=1;
break;
}
}
if (!ifound) *fDebugFile << "ERROR: CompareRocs: roc "<<iroc1<<" in cratemap but not found data"<<endl;
}
}
//_____________________________________________________________________________
void CodaDecoder::ChkFbSlot( Int_t roc, const UInt_t* evbuffer,
Int_t ipt, Int_t istop )
{
const UInt_t* p = evbuffer+ipt; // Points to ROC ID word (1 before data)
const UInt_t* pstop =evbuffer+istop; // Points to last word of data in roc
while (p++ < pstop) {
Int_t slot = (UInt_t(*p))>>27; // A "self-reported" slot.
Int_t index = MAXSLOT*roc + slot;
if ((slot > 0) && (index >=0 && index < MAXROC*MAXSLOT)) fbfound[index]=1;
}
}
//_____________________________________________________________________________
void CodaDecoder::ChkFbSlots()
{
// This checks the fastbus slots to see if slots are appearing in both the
// data and the cratemap. If they appear in one but not the other, a warning
// is issued, which usually means the cratemap is wrong.
Int_t slotstat[MAXROC*MAXSLOT];
for (Int_t iroc=0; iroc<MAXROC; iroc++) {
if ( !fMap->isFastBus(iroc) ) continue;
for (Int_t islot=0; islot<MAXSLOT; islot++) {
Int_t index = MAXSLOT*iroc + islot;
slotstat[index]=0;
if (fbfound[index] && fMap->slotUsed(iroc, islot)) {
if (fDebugFile) *fDebugFile << "FB slot in cratemap and in data. (good!). roc = "<<iroc<<" slot = "<<islot<<endl;
slotstat[index]=1;
}
if ( !fbfound[index] && fMap->slotUsed(iroc, islot)) {
if (fDebugFile) *fDebugFile << "FB slot NOT in data, but in cratemap (bad!). roc = "<<iroc<<" slot = "<<islot<<endl;
slotstat[index]=2;
}
if ( fbfound[index] && !fMap->slotUsed(iroc, islot)) {
if (fDebugFile) *fDebugFile << "FB slot in data, but NOT in cratemap (bad!). roc = "<<iroc<<" slot = "<<islot<<endl;
slotstat[index]=3;
}
}
}
// Why do we care? If the cratemap has info about additional hardware
// that just wasn't read out by the DAQ, so what?
// for (Int_t iroc=0; iroc<MAXROC; iroc++) {
// if ( !fMap->isFastBus(iroc) ) continue;
// for (Int_t islot=0; islot<MAXSLOT; islot++) {
// Int_t index = MAXSLOT*iroc + islot;
// if (slotstat[index]==2) cout << "Decoder:: WARNING: Fastbus module in (roc,slot) = ("<<iroc<<","<<islot<<") found in cratemap but NOT in data !"<<endl;
// }
// }
for (Int_t iroc=0; iroc<MAXROC; iroc++) {
if ( !fMap->isFastBus(iroc) ) continue;
for (Int_t islot=0; islot<MAXSLOT; islot++) {
Int_t index = MAXSLOT*iroc + islot;
if (slotstat[index]==3) cout << "Decoder:: WARNING: Fastbus module in (roc,slot) = ("<<iroc<<","<<islot<<") found in data but NOT in cratemap !"<<endl;
}
}
}
//_____________________________________________________________________________
void CodaDecoder::SetRunTime( ULong64_t tloc )
{
// Set run time and re-initialize crate map (and possibly other
// database parameters for the new time.
if( fRunTime == tloc )
return;
fRunTime = tloc;
fNeedInit = true; // force re-init
}
//_____________________________________________________________________________
Int_t CodaDecoder::prescale_decode(const UInt_t* evbuffer)
{
// Decodes prescale factors from either
// TS_PRESCALE_EVTYPE(default) = PS factors
// read from Trig. Super. registors (since 11/03)
// - or -
// PRESCALE_EVTYPE = PS factors from traditional
// "prescale.dat" file.
assert( evbuffer );
assert( event_type == TS_PRESCALE_EVTYPE ||
event_type == PRESCALE_EVTYPE );
const Int_t HEAD_OFF1 = 2;
const Int_t HEAD_OFF2 = 4;
static const char* const pstr[] = { "ps1", "ps2", "ps3", "ps4",
"ps5", "ps6", "ps7", "ps8",
"ps9", "ps10", "ps11", "ps12" };
// TS registers -->
if( event_type == TS_PRESCALE_EVTYPE) {
// this is more authoritative
for (Int_t j = 0; j < 8; j++) {
Int_t k = j + HEAD_OFF1;
Int_t ps = 0;
if (k < event_length) {
ps = evbuffer[k];
if (psfact[j]!=0 && ps != psfact[j]) {
Warning("prescale_decode","Mismatch in prescale factor: "
"Trig %d oldps %d TS_PRESCALE %d. Setting to TS_PRESCALE",
j+1,psfact[j],ps);
}
}
psfact[j]=ps;
if (fDebug > 1)
cout << "%% TS psfact "<<dec<<j<<" "<<psfact[j]<<endl;
}
}
// "prescale.dat" -->
else if( event_type == PRESCALE_EVTYPE ) {
if( event_length <= HEAD_OFF2 )
return HED_ERR; //oops, event too short?
THaUsrstrutils sut;
sut.string_from_evbuffer(evbuffer+HEAD_OFF2, event_length-HEAD_OFF2);
for(Int_t trig=0; trig<MAX_PSFACT; trig++) {
Int_t ps = sut.getint(pstr[trig]);
Int_t psmax = 65536; // 2^16 for trig > 3
if (trig < 4) psmax = 16777216; // 2^24 for 1st 4 trigs
if (trig > 7) ps = 1; // cannot prescale trig 9-12
ps = ps % psmax;
if (psfact[trig]==-1) // not read before
psfact[trig] = ps;
else if (ps != psfact[trig]) {
Warning("prescale_decode","Mismatch in prescale factor: "
"Trig %d oldps %d prescale.dat %d, Keeping old value",
trig+1,psfact[trig],ps);
}
if (fDebug > 1)
cout << "** psfact[ "<<trig+1<< " ] = "<<psfact[trig]<<endl;
}
}
// Ok in any case
return HED_OK;
}
//_____________________________________________________________________________
} // namespace Decoder
ClassImp(Decoder::CodaDecoder)