From 4118d87d68f7d3f7d1daf56813b8840bebc72342 Mon Sep 17 00:00:00 2001 From: Ole Hansen Date: Tue, 6 Sep 2022 19:48:42 -0400 Subject: [PATCH] THcHitList: Prevent underflow and print warning if TI time is invalid --- src/THcHitList.cxx | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/THcHitList.cxx b/src/THcHitList.cxx index 9a3f00bd..8db4d8f9 100644 --- a/src/THcHitList.cxx +++ b/src/THcHitList.cxx @@ -211,24 +211,32 @@ Int_t THcHitList::DecodeToHitList( const THaEvData& evdata, Bool_t suppresswarni if(fadc) { fFADCSlotMap[slot] = fadc; } - } + } } break; } } } if(fDisableSlipCorrection) fTISlot = -1; - + UInt_t titime = 0; Bool_t TI_TRIGGER_TIME_FOUND = kFALSE; if(fTISlot>0) { - UInt_t FUDGE=7; + const UInt_t FUDGE = 7; if (evdata.GetNumHits(fTICrate, fTISlot, 2) > 0) { - TI_TRIGGER_TIME_FOUND = kTRUE; - titime = evdata.GetData(fTICrate, fTISlot, 2, 0)-FUDGE; - // Need to get the FADC time for all modules in this crate - // that have hits. Make a map with these times. - fTrigTimeShiftMap.clear(); + TI_TRIGGER_TIME_FOUND = kTRUE; + titime = evdata.GetData(fTICrate, fTISlot, 2, 0); + if( titime >= FUDGE ) + titime -= FUDGE; + else { + Warning(Here("DecodeToHitList"), "Invalid TI time %u - %u < 0 " + " for crate/slot = %d/%d", + titime, FUDGE, fTICrate, fTISlot); + titime = 0; + } + // Need to get the FADC time for all modules in this crate + // that have hits. Make a map with these times. + fTrigTimeShiftMap.clear(); } } @@ -240,7 +248,7 @@ Int_t THcHitList::DecodeToHitList( const THaEvData& evdata, Bool_t suppresswarni // Get the indexed reference times for this event for(Int_t i=0;i0 && TI_TRIGGER_TIME_FOUND) { // Get the trigger time for this module if(fTrigTimeShiftMap.find(fRefIndexMaps[i].slot) - == fTrigTimeShiftMap.end()) { // + == fTrigTimeShiftMap.end()) { // if(fFADCSlotMap.find(fRefIndexMaps[i].slot) != fFADCSlotMap.end()) { fTrigTimeShiftMap[fRefIndexMaps[i].slot] = fFADCSlotMap[fRefIndexMaps[i].slot]->GetTriggerTime() - titime; @@ -342,7 +350,7 @@ Int_t THcHitList::DecodeToHitList( const THaEvData& evdata, Bool_t suppresswarni } for ( UInt_t i=0; i < fdMap->GetSize(); i++ ) { THaDetMap::Module* d = fdMap->GetModule(i); - + // Loop over all channels that have a hit. // cout << "Crate/Slot: " << d->crate << "/" << d->slot << endl; Int_t plane = d->plane; @@ -451,7 +459,7 @@ Int_t THcHitList::DecodeToHitList( const THaEvData& evdata, Bool_t suppresswarni // Set F250 parameters. rawhit->SetF250Params(fNSA, fNSB, fNPED); } - + // Copy the samples UInt_t nsamples=evdata.GetNumEvents(Decoder::kSampleADC, d->crate, d->slot, chan); @@ -467,7 +475,7 @@ Int_t THcHitList::DecodeToHitList( const THaEvData& evdata, Bool_t suppresswarni Int_t timeshift=0; if(fTISlot>0 && TI_TRIGGER_TIME_FOUND) { // Get the trigger time for this module if(fTrigTimeShiftMap.find(d->slot) - == fTrigTimeShiftMap.end()) { // + == fTrigTimeShiftMap.end()) { // if(fFADCSlotMap.find(d->slot) != fFADCSlotMap.end()) { fTrigTimeShiftMap[d->slot] = fFADCSlotMap[d->slot]->GetTriggerTime() - titime; @@ -496,7 +504,7 @@ Int_t THcHitList::DecodeToHitList( const THaEvData& evdata, Bool_t suppresswarni timeshift=0; if(fTISlot>0 && TI_TRIGGER_TIME_FOUND) { // Get the trigger time for this module if(fTrigTimeShiftMap.find(d->slot) - == fTrigTimeShiftMap.end()) { // + == fTrigTimeShiftMap.end()) { // if(fFADCSlotMap.find(d->slot) != fFADCSlotMap.end()) { fTrigTimeShiftMap[d->slot] = fFADCSlotMap[d->slot]->GetTriggerTime() - titime; @@ -584,9 +592,9 @@ Int_t THcHitList::DecodeToHitList( const THaEvData& evdata, Bool_t suppresswarni } } else if ( fTISlot>0 && !TI_TRIGGER_TIME_FOUND) { cout << "TI Trigger Time Not found for event type = " << evdata.GetEvType() << " event num = " << evdata.GetEvNum() << " TI Crate = " << fTICrate << " TI Slot = " << fTISlot<< endl; - } - -#endif + } + +#endif fRawHitList->Sort(fNRawHits); fNTDCRef_miss += (tdcref_miss ? 1 : 0);