From d5ff42cf5c65e7dbb2a82f9d62686e680a0e10be Mon Sep 17 00:00:00 2001 From: Jure Bericic <bericic@jlab.org> Date: Mon, 12 Dec 2016 11:19:11 -0500 Subject: [PATCH] Small fixes for THcRawHodoHit and THcTrigRawHit. - Now throwing an error for invalid signal in THcRawHodoHit::GetRawData and THcRawHodoHit::GetData. - THcRawHodoHit::GetData now only subtracts reference time for TDC channels. - THcRawHodoHit::SetReference now prints warning when trying to set reference time for ADC and does not set it. - Fix in THcTrigRawHit::Clear to set fHasMulti to kFALSE. - THcTrigRawHit::SetReference now prints warning when trying to set reference time for ADC and does not set it. --- src/THcRawHodoHit.cxx | 38 +++++++++++++++++++++++++------------- src/THcTrigRawHit.cxx | 12 ++++++++++-- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/THcRawHodoHit.cxx b/src/THcRawHodoHit.cxx index 4b8f955..7051cbc 100644 --- a/src/THcRawHodoHit.cxx +++ b/src/THcRawHodoHit.cxx @@ -17,6 +17,8 @@ Class representing a single raw hit for a hodoscope paddle #include <cassert> #include <stdexcept> +#include "TString.h" + #include "THcRawHodoHit.h" using namespace std; @@ -126,13 +128,13 @@ Int_t THcRawHodoHit::GetData(Int_t signal, UInt_t ihit) { } else if (signal==3) { value = fTDC_neg[ihit]; } else { - cout << "THcRawHodoHit::GetData(): requested invalid signal #" - << signal << endl; - return(-1); // Actually should throw an exception + TString msg = TString::Format( + "THcRawHodoHit::GetData(): requested invalid signal #%d.", + signal + ); + throw std::out_of_range(msg.Data()); } - // We are return -1 as a error, but reference subtracted - // time can be negative. - if(fHasRef[signal]) { + if(fHasRef[signal] && (signal == 2 || signal == 3)) { value -= fReferenceTime[signal]; } return(value); @@ -158,16 +160,26 @@ Int_t THcRawHodoHit::GetRawData(Int_t signal, UInt_t ihit) { } else if (signal==3) { return(fTDC_neg[ihit]); } else { - cout << "THcRawHodoHit::GetData(): requested invalid signal #" - << signal << endl; - return(-1); // Actually should throw an exception + TString msg = TString::Format( + "THcRawHodoHit::GetRawData(): requested invalid signal #%d.", + signal + ); + throw std::out_of_range(msg.Data()); } } // Set the reference time void THcRawHodoHit::SetReference(Int_t signal, Int_t reference) { - fReferenceTime[signal] = reference; - fHasRef[signal] = kTRUE; + if (signal == 2 || signal == 3) { + fReferenceTime[signal] = reference; + fHasRef[signal] = kTRUE; + } else if (signal == 0 || signal == 1) { + std::cerr + << "Warning:" + << " THcRawHodoHit::SetReference():" + << " signals 0 and 1 (ADC) should not have reference time!" + << " Check map file!"; + } } Int_t THcRawHodoHit::GetReference(Int_t signal) { if(fHasRef[signal]) { @@ -224,8 +236,8 @@ THcRawHodoHit& THcRawHodoHit::operator=( const THcRawHodoHit& rhs ) for(UInt_t is=0;is<fNRawSamplesNeg;is++) { fADC_Samples_neg[is] = rhs.fADC_Samples_neg[is]; } - - + + } return *this; } diff --git a/src/THcTrigRawHit.cxx b/src/THcTrigRawHit.cxx index 0b1feb2..43b36ac 100644 --- a/src/THcTrigRawHit.cxx +++ b/src/THcTrigRawHit.cxx @@ -219,6 +219,7 @@ Returns `0` if reference time is not available. #include "THcTrigRawHit.h" +#include <iostream> #include <string> #include <stdexcept> @@ -273,7 +274,7 @@ void THcTrigRawHit::Clear(Option_t* opt) { for (UInt_t i=0; i<fNPlanes; ++i) { fHasReference[i] = kFALSE; - fHasReference[i] = kFALSE; + fHasMulti[i] = kFALSE; fNRawHits[i] = 0; } fNRawSamples = 0; @@ -346,7 +347,14 @@ void THcTrigRawHit::SetDataTimePedestalPeak( void THcTrigRawHit::SetReference(Int_t signal, Int_t reference) { - if (signal == 0 || signal == 1) { + if (signal == 0) { + std::cerr + << "Warning:" + << " `THcTrigRawHit::SetReference`:" + << " signal 0 (ADC) should not have reference time!" + << " Check map file!"; + } + else if (signal == 1) { fReferenceTime[signal] = reference; fHasReference[signal] = kTRUE; } -- GitLab