///////////////////////////////////////////////////////// /// $Id: IMidasTpcPulse.cxx,v 1.5 2010/06/11 07:40:35 litchfld Exp $ /// /// Implement the COMET::IMidasTpcPulse class. #include "TString.h" #include "ICOMETLog.hxx" #include "IMidasTpcPulse.hxx" #include "IMidasItr.cxx" #include "oaRawEventUtils.hxx" #include template class COMET::IMidasItr; //_____________________________________________________________________________ COMET::IMidasTpcPulse::IMidasTpcPulse(UShort_t version, const UShort_t* data, const UShort_t* eod, const COMET::IMidasBank* parent) : IMidasObj(version,0,parent) { fFirstSample = data; fHasStartTime = false; fStartTime = 0; fNumSamples = 0; fNeedNewChan = false; UShort_t adc = LoadShort(fFirstSample,0,RAWTPC_LE_BYTE_SWAP); //std::cout << "TPCPULSE:::The mask gives = "<< std::hex << "0x" << (adc & RAWTPC_MS_NEW_CHAN) << " 0x" << adc << std::dec << std::endl; if ( (adc & 0xE000) == RAWTPC_MS_NEW_CHAN ){ //std::cout << "TPCPULSE:::There is a new Channel here!!!!!!!!!!!!!" << std::endl; fNeedNewChan = true; // const LoadShort(fFirstSample,RAWTPC_PS_CHANH_ARGS,RAWTPC_LE_BYTE_SWAP); int tempAsic1 = (adc & RAWTPC_MS_ARG1) >> RAWTPC_SS_ARG1; int tempAsic2 = (adc & RAWTPC_MS_ARG2) >> RAWTPC_SS_ARG2; fPulseFEC = (10*(tempAsic1%6)/2 + tempAsic2)/RAWTPC_ASIC_PER_FEC; fPulseASIC = (10*(tempAsic1%6)/2 + tempAsic2)%RAWTPC_ASIC_PER_FEC; fPulseCHAN = (tempAsic1/6)%RAWTPC_CHAN_PER_ASIC; // Should that 6 be a symbol? //std::cout << "TPCPULSE:::There is a new Channel here!!!!!!!!!!!!!" << " fec " << fPulseFEC << " ASIC " << fPulseASIC << " CHAN " << fPulseCHAN << std::endl; fFirstSample += 2; adc = LoadShort(fFirstSample,0,RAWTPC_LE_BYTE_SWAP); } // It entry is a time, collect it. if ( (adc & 0xF000) == RAWTPC_MS_CELL_INDEX_FLAG ) { fHasStartTime = true; fStartTime = adc & RAWTPC_MS_CELL_INDEX_WORD; fStartTime -= 10; ++fFirstSample; } // Now walk forward until we find another time or hit EOD. const UShort_t* sampleAdr = fFirstSample; while( sampleAdr < eod && (LoadShort(sampleAdr,0,RAWTPC_LE_BYTE_SWAP)&0xF000) == 0x0 ) sampleAdr++; fNumSamples = sampleAdr - fFirstSample; //std::cout << "TPCPULSE::NumSamples ---------> " << fNumSamples << " Start time " << fStartTime << " " << sampleAdr << " 0x" << std::hex << LoadShort(sampleAdr,0,RAWTPC_LE_BYTE_SWAP) << std::dec << std::endl; } //_____________________________________________________________________________ COMET::IMidasTpcPulse::IMidasTpcPulse(UShort_t version, UShort_t invalid_code) : IMidasObj(version,invalid_code) { if ( invalid_code == IMidasObj::NotInvalid ) { COMETError("IMidasTpcPulse ctor called with invalid code set to 'NotInvalid'"); this->SetInvalidCode(IMidasObj::UnknownInvalid); } fFirstSample = 0; fHasStartTime = false; fStartTime = 0; fNumSamples = 0; fNeedNewChan = false; } //_____________________________________________________________________________ Short_t COMET::IMidasTpcPulse::GetADC(UInt_t sampleNo /* = 0 */) const { if ( sampleNo >= this->GetNumberSamples() ) return 0; return LoadShort(fFirstSample,sampleNo,RAWTPC_LE_BYTE_SWAP); } //_____________________________________________________________________________ Short_t COMET::IMidasTpcPulse::GetTime(UInt_t sampleNo /* = 0 */) const { if ( sampleNo >= this->GetNumberSamples() ) return 0; return fStartTime + sampleNo; } //_____________________________________________________________________________ Int_t COMET::IMidasTpcPulse::GetSize() const { // Size is 2 bytes per sample plus two more of there is the pulse starts with a time // If there is a new channel created, we need more size for the sub-header Int_t size = 2*fNumSamples; if ( fHasStartTime ) size += sizeof(UShort_t); if ( fNeedNewChan ) size += 2.*sizeof(UShort_t); // We need to account for the additional 2 short words. return size; } //_____________________________________________________________________________ void COMET::IMidasTpcPulse::Print(const Option_t* opt /* = "" */ ) const { // Assemble a list of the first few and last few ADCs UInt_t num_samples = this->GetNumberSamples(); UInt_t start_gap = 999999999; UInt_t end_gap = 999999999; if ( num_samples > 6 ) { start_gap = 3; end_gap = num_samples - 4; } std::ostringstream os; for ( UInt_t sample_no = 0; sample_no < num_samples; ++sample_no ) { if ( sample_no < start_gap or sample_no > end_gap ) { os << this->GetADC(sample_no) << " "; continue; } if ( sample_no == start_gap ) os << "..." << " "; } COMETLog(" Pulse length: " << this->GetNumberSamples() << " Start time " << this->GetTime() << " ADCs " << os.str() << " object size " << sizeof(*this)); }