diff --git a/ClassData.h b/ClassData.h index d0586df..b08d0af 100644 --- a/ClassData.h +++ b/ClassData.h @@ -65,7 +65,7 @@ class Data{ unsigned int GetPresentFileSize() {return presentFileSizeByte;} void PrintBuffer() const; //Incorrect - void DecodeBuffer(bool fastDecode, int verbose = 0); + void DecodeBuffer(bool fastDecode, int verbose = 0); /// fastDecode will not save waveform void DecodeBuffer(char * buffer, unsigned int size, bool fastDecode, int verbose = 0); // for outside data void PrintStat() const; @@ -192,9 +192,8 @@ inline void Data::SaveBuffer(const char * fileName){ inline void Data::PrintStat() const{ - printf("========= %d \n", IsNotRollOverFakeAgg); if( IsNotRollOverFakeAgg ) { - printf(" this is roll-over fake event.\n"); + printf(" this is roll-over fake event or no events.\n"); return; } printf("%2s | %6s | %9s | %6s\n", "ch", "# Evt.", "Rate [Hz]", "Tot. Evt."); @@ -330,64 +329,64 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe nSample = ( word & 0xFFFF ) * 8; extra2Option = ( (word >> 24 ) & 0x7 ); - - unsigned int digitalProbe = ( (word >> 16 ) & 0xF ); - unsigned int analogProbe2 = ( (word >> 20 ) & 0x3 ); - unsigned int analogProbe1 = ( (word >> 22 ) & 0x3 ); - bool hasWaveForm = ( (word >> 27 ) & 0x1 ); hasExtra2 = ( (word >> 28 ) & 0x1 ); - bool hasTimeStamp = ( (word >> 29 ) & 0x1 ); - bool hasEnergy = ( (word >> 30 ) & 0x1 ); - hasDualTrace = ( (word >> 31 ) & 0x1 ); - - if( verbose >= 2 ) { - printf("DualTrace : %d, Energy : %d, Time: %d, Wave : %d, Extra2: %d \n", - hasDualTrace, hasEnergy, hasTimeStamp, hasWaveForm, hasExtra2); - } - - if( verbose >= 3){ - if( hasExtra2 ){ - printf("...... extra 2 : "); - switch (extra2Option){ - case 0: printf("[0:15] trapwzoid baseline * 4 [16:31] Extended timestamp (16-bit)\n"); break; - case 1: printf("Reserved\n"); break; - case 2: printf("[0:9] Fine time stamp [10:15] Reserved [16:31] Extended timestamp (16-bit)\n"); break; - case 3: printf("Reserved\n"); break; - case 4: printf("[0:15] Total trigger counter [16:31] Lost trigger counter\n"); break; - case 5: printf("[0:15] Event after Zero crossing [16:31] Event before Zero crossing\n"); break; - case 6: printf("Reserved\n"); break; - case 7: printf("Reserved\n"); break; + if( !fastDecode) { + unsigned int digitalProbe = ( (word >> 16 ) & 0xF ); + unsigned int analogProbe2 = ( (word >> 20 ) & 0x3 ); + unsigned int analogProbe1 = ( (word >> 22 ) & 0x3 ); + bool hasWaveForm = ( (word >> 27 ) & 0x1 ); + bool hasTimeStamp = ( (word >> 29 ) & 0x1 ); + bool hasEnergy = ( (word >> 30 ) & 0x1 ); + hasDualTrace = ( (word >> 31 ) & 0x1 ); + + if( verbose >= 2 ) { + printf("DualTrace : %d, Energy : %d, Time: %d, Wave : %d, Extra2: %d \n", + hasDualTrace, hasEnergy, hasTimeStamp, hasWaveForm, hasExtra2); + } + if( verbose >= 3){ + if( hasExtra2 ){ + printf("...... extra 2 : "); + switch (extra2Option){ + case 0: printf("[0:15] trapwzoid baseline * 4 [16:31] Extended timestamp (16-bit)\n"); break; + case 1: printf("Reserved\n"); break; + case 2: printf("[0:9] Fine time stamp [10:15] Reserved [16:31] Extended timestamp (16-bit)\n"); break; + case 3: printf("Reserved\n"); break; + case 4: printf("[0:15] Total trigger counter [16:31] Lost trigger counter\n"); break; + case 5: printf("[0:15] Event after Zero crossing [16:31] Event before Zero crossing\n"); break; + case 6: printf("Reserved\n"); break; + case 7: printf("Reserved\n"); break; + } + } + printf("...... Analog Probe 1 : "); + switch (analogProbe1 ){ + case 0 : printf("Input \n"); break; + case 1 : printf("RC-CR (1st derivative) \n"); break; + case 2 : printf("RC-CR2 (2st derivative) \n"); break; + case 3 : printf("trapazoid \n"); break; + } + printf("...... Analog Probe 2 : "); + switch (analogProbe2 ){ + case 0 : printf("Input \n"); break; + case 1 : printf("Theshold \n"); break; + case 2 : printf("trapezoid - baseline \n"); break; + case 3 : printf("baseline \n"); break; + } + printf("...... Digital Probe : "); + switch (digitalProbe ){ + case 0 : printf("Peaking \n"); break; + case 1 : printf("Armed (trigger) \n"); break; + case 2 : printf("Peak Run \n"); break; + case 3 : printf("Pile up \n"); break; + case 4 : printf("Peaking \n"); break; + case 5 : printf("Trigger Validation Window \n"); break; + case 6 : printf("Baseline for energy calculation \n"); break; + case 7 : printf("Trigger holdoff \n"); break; + case 8 : printf("Trigger Validation \n"); break; + case 9 : printf("ACQ Busy \n"); break; + case 10 : printf("Trigger window \n"); break; + case 11 : printf("Ext. Trigger \n"); break; + case 12 : printf("Busy = memory is full \n"); break; } - } - printf("...... Analog Probe 1 : "); - switch (analogProbe1 ){ - case 0 : printf("Input \n"); break; - case 1 : printf("RC-CR (1st derivative) \n"); break; - case 2 : printf("RC-CR2 (2st derivative) \n"); break; - case 3 : printf("trapazoid \n"); break; - } - printf("...... Analog Probe 2 : "); - switch (analogProbe2 ){ - case 0 : printf("Input \n"); break; - case 1 : printf("Theshold \n"); break; - case 2 : printf("trapezoid - baseline \n"); break; - case 3 : printf("baseline \n"); break; - } - printf("...... Digital Probe : "); - switch (digitalProbe ){ - case 0 : printf("Peaking \n"); break; - case 1 : printf("Armed (trigger) \n"); break; - case 2 : printf("Peak Run \n"); break; - case 3 : printf("Pile up \n"); break; - case 4 : printf("Peaking \n"); break; - case 5 : printf("Trigger Validation Window \n"); break; - case 6 : printf("Baseline for energy calculation \n"); break; - case 7 : printf("Trigger holdoff \n"); break; - case 8 : printf("Trigger Validation \n"); break; - case 9 : printf("ACQ Busy \n"); break; - case 10 : printf("Trigger window \n"); break; - case 11 : printf("Ext. Trigger \n"); break; - case 12 : printf("Busy = memory is full \n"); break; } } nEvents = aggSize / (nSample/2 + 2 + hasExtra2 ); @@ -408,54 +407,57 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe //TODO Skip ///===== read waveform - if( SaveWaveToMemory ) { + if( !fastDecode && SaveWaveToMemory ) { tempWaveform1.clear(); tempWaveform2.clear(); tempDigiWaveform1.clear(); } unsigned int triggerAtSample = 0 ; - for( int wi = 0; wi < nSample/2; wi++){ - nw = nw +1 ; word = ReadBuffer(nw, verbose - 2); - bool isTrigger1 = (( word >> 31 ) & 0x1 ); - bool dp1 = (( word >> 30 ) & 0x1 ); - unsigned short wave1 = (( word >> 16) & 0x3FFF); - - bool isTrigger0 = (( word >> 15 ) & 0x1 ); - bool dp0 = (( word >> 14 ) & 0x1 ); - unsigned short wave0 = ( word & 0x3FFF); + if( fastDecode ){ + nw += nSample/2; + }else{ + for( int wi = 0; wi < nSample/2; wi++){ + nw = nw +1 ; word = ReadBuffer(nw, verbose - 2); + bool isTrigger1 = (( word >> 31 ) & 0x1 ); + bool dp1 = (( word >> 30 ) & 0x1 ); + unsigned short wave1 = (( word >> 16) & 0x3FFF); + + bool isTrigger0 = (( word >> 15 ) & 0x1 ); + bool dp0 = (( word >> 14 ) & 0x1 ); + unsigned short wave0 = ( word & 0x3FFF); - if( SaveWaveToMemory){ - if( hasDualTrace ){ - tempWaveform1.push_back(wave0); - tempWaveform2.push_back(wave1); - }else{ - tempWaveform1.push_back(wave0); - tempWaveform1.push_back(wave1); + if( SaveWaveToMemory){ + if( hasDualTrace ){ + tempWaveform1.push_back(wave0); + tempWaveform2.push_back(wave1); + }else{ + tempWaveform1.push_back(wave0); + tempWaveform1.push_back(wave1); + } + tempDigiWaveform1.push_back(dp0); + tempDigiWaveform1.push_back(dp1); } - tempDigiWaveform1.push_back(dp0); - tempDigiWaveform1.push_back(dp1); - } - if( isTrigger0 == 1 ) triggerAtSample = 2*wi ; - if( isTrigger1 == 1 ) triggerAtSample = 2*wi + 1; + if( isTrigger0 == 1 ) triggerAtSample = 2*wi ; + if( isTrigger1 == 1 ) triggerAtSample = 2*wi + 1; + + if( verbose >= 4 && ev == 0 ){ + printf("%4d| %5d, %d, %d \n", 2*wi, wave0, dp0, isTrigger0); + printf("%4d| %5d, %d, %d \n", 2*wi+1, wave1, dp1, isTrigger1); + } + } - if( verbose >= 4 && ev == 0 ){ - printf("%4d| %5d, %d, %d \n", 2*wi, wave0, dp0, isTrigger0); - printf("%4d| %5d, %d, %d \n", 2*wi+1, wave1, dp1, isTrigger1); - } + if( SaveWaveToMemory ) { + if( hasDualTrace ){ + Waveform1[channel][NumEvents[channel]] = tempWaveform1; + Waveform2[channel][NumEvents[channel]] = tempWaveform2; + }else{ + Waveform1[channel][NumEvents[channel]] = tempWaveform1; + } + DigiWaveform1[channel][NumEvents[channel]] = tempDigiWaveform1; + } } - - if( SaveWaveToMemory ) { - if( hasDualTrace ){ - Waveform1[channel][NumEvents[channel]] = tempWaveform1; - Waveform2[channel][NumEvents[channel]] = tempWaveform2; - }else{ - Waveform1[channel][NumEvents[channel]] = tempWaveform1; - } - DigiWaveform1[channel][NumEvents[channel]] = tempDigiWaveform1; - } - unsigned long long extTimeStamp = 0; unsigned int extra2 = 0; if( hasExtra2 ){ @@ -471,13 +473,12 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe nw = nw +1 ; word = ReadBuffer(nw, verbose); unsigned int extra = (( word >> 16) & 0x3FF); unsigned int energy = (word & 0x7FFF); - bool pileUpOrRollOver = ((word >> 15) & 0x1); - bool pileUp = (extra & 0x200); bool rollOver = (extra & 0x002); + bool pileUp = (extra & 0x200); + bool pileUpOrRollOver = ((word >> 15) & 0x1); if( verbose >= 3 ) { - printf("PileUp : %d , extra : 0x%03x, energy : %d \n", pileUp, extra, energy); - + printf("PileUp : %d , extra : 0x%03x, energy : %d \n", pileUp, extra, energy); printf(" lost event : %d \n", ((extra >> 0) & 0x1) ); printf(" roll-over : %d (fake event)\n", ((extra >> 1) & 0x1) ); printf(" fake-event : %d \n", ((extra >> 3) & 0x1) ); @@ -601,54 +602,56 @@ inline int Data::DecodePSDDualChannelBlock(unsigned int ChannelMask, bool fastDe if( verbose >= 2 ) printf("ch : %d, timeStamp %u \n", channel, timeStamp0); ///===== read waveform - if( SaveWaveToMemory ) { + if( !fastDecode && SaveWaveToMemory ) { tempWaveform1.clear(); tempWaveform2.clear(); tempDigiWaveform1.clear(); tempDigiWaveform2.clear(); } - for( int wi = 0; wi < nSample/2; wi++){ - nw = nw +1 ; word = ReadBuffer(nw, verbose - 2); - bool dp2b = (( word >> 31 ) & 0x1 ); - bool dp1b = (( word >> 30 ) & 0x1 ); - unsigned short waveb = (( word >> 16) & 0x3FFF); - - bool dp2a = (( word >> 15 ) & 0x1 ); - bool dp1a = (( word >> 14 ) & 0x1 ); - unsigned short wavea = ( word & 0x3FFF); - - if( SaveWaveToMemory){ - if( hasDualTrace ){ - tempWaveform1.push_back(wavea); - tempWaveform2.push_back(waveb); - }else{ - tempWaveform1.push_back(wavea); - tempWaveform1.push_back(waveb); + if( fastDecode ){ + nw += nSample/2; + }else{ + for( int wi = 0; wi < nSample/2; wi++){ + nw = nw +1 ; word = ReadBuffer(nw, verbose - 2); + bool dp2b = (( word >> 31 ) & 0x1 ); + bool dp1b = (( word >> 30 ) & 0x1 ); + unsigned short waveb = (( word >> 16) & 0x3FFF); + + bool dp2a = (( word >> 15 ) & 0x1 ); + bool dp1a = (( word >> 14 ) & 0x1 ); + unsigned short wavea = ( word & 0x3FFF); + + if( SaveWaveToMemory){ + if( hasDualTrace ){ + tempWaveform1.push_back(wavea); + tempWaveform2.push_back(waveb); + }else{ + tempWaveform1.push_back(wavea); + tempWaveform1.push_back(waveb); + } + tempDigiWaveform1.push_back(dp1a); + tempDigiWaveform1.push_back(dp1b); + tempDigiWaveform2.push_back(dp2a); + tempDigiWaveform2.push_back(dp2b); + } + + if( verbose >= 3 && ev == 0 ){ + printf("%4d| %5d, %d, %d \n", 2*wi, wavea, dp1a, dp2a); + printf("%4d| %5d, %d, %d \n", 2*wi+1, waveb, dp1b, dp2b); } - tempDigiWaveform1.push_back(dp1a); - tempDigiWaveform1.push_back(dp1b); - tempDigiWaveform2.push_back(dp2a); - tempDigiWaveform2.push_back(dp2b); } - - if( verbose >= 3 && ev == 0 ){ - printf("%4d| %5d, %d, %d \n", 2*wi, wavea, dp1a, dp2a); - printf("%4d| %5d, %d, %d \n", 2*wi+1, waveb, dp1b, dp2b); + if( SaveWaveToMemory ) { + if( hasDualTrace ){ + Waveform1[channel][NumEvents[channel]] = tempWaveform1; + Waveform2[channel][NumEvents[channel]] = tempWaveform2; + }else{ + Waveform1[channel][NumEvents[channel]] = tempWaveform1; + } + DigiWaveform1[channel][NumEvents[channel]] = tempDigiWaveform1; + DigiWaveform2[channel][NumEvents[channel]] = tempDigiWaveform2; } } - - if( SaveWaveToMemory ) { - if( hasDualTrace ){ - Waveform1[channel][NumEvents[channel]] = tempWaveform1; - Waveform2[channel][NumEvents[channel]] = tempWaveform2; - }else{ - Waveform1[channel][NumEvents[channel]] = tempWaveform1; - } - DigiWaveform1[channel][NumEvents[channel]] = tempDigiWaveform1; - DigiWaveform2[channel][NumEvents[channel]] = tempDigiWaveform2; - } - nw = nw +1 ; word = ReadBuffer(nw, verbose); unsigned int extra = word; unsigned long long extTimeStamp = 0; diff --git a/ClassDigitizer.cpp b/ClassDigitizer.cpp index bda6e3a..a9a504f 100644 --- a/ClassDigitizer.cpp +++ b/ClassDigitizer.cpp @@ -431,7 +431,7 @@ void Digitizer::PrintACQStatue(){ //=========================================================== void Digitizer::WriteRegister (Reg registerAddress, uint32_t value, int ch, bool isSave2MemAndFile){ - printf("%s[0x%04X](ch-%02d) [0x%04X]: %u \n", registerAddress.GetNameChar(), registerAddress.GetAddress(),ch, registerAddress.ActualAddress(ch), value); + printf("%s[0x%04X](ch-%02d) [0x%04X]: 0x%08X \n", registerAddress.GetNameChar(), registerAddress.GetAddress(),ch, registerAddress.ActualAddress(ch), value); if( !isConnected ) { SetSettingToMemory(registerAddress, value, ch); diff --git a/channelSettingPHA.cpp b/channelSettingPHA.cpp index 55226ba..538b091 100644 --- a/channelSettingPHA.cpp +++ b/channelSettingPHA.cpp @@ -115,7 +115,7 @@ ChannelSettingPHA::ChannelSettingPHA(const TGWindow *p, UInt_t w, UInt_t h, Digi TGLabel * lbEventAgg = new TGLabel(vfInput1, "Events / Aggregate"); vfInput1->AddFrame(lbEventAgg, layoutHintsR); numEventAgg = new TGNumberEntry(vfInput2, 512, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative); vfInput2->AddFrame(numEventAgg, layoutHints); numEventAgg->Resize(width, 20); - numEventAgg->SetLimits(TGNumberFormat::kNELLimitMinMax, 0, 511); + numEventAgg->SetLimits(TGNumberFormat::kNELLimitMinMax, 1, 511); numEventAgg->Connect("Modified()", "ChannelSettingPHA", this, "SetEventAggregate()"); TGLabel * lbBuffer = new TGLabel(vfInput1, "Buffer Size [MByte]"); vfInput1->AddFrame(lbBuffer, layoutHintsR); diff --git a/test.cpp b/test.cpp index e8bf4f6..83db752 100644 --- a/test.cpp +++ b/test.cpp @@ -92,44 +92,44 @@ int main(int argc, char* argv[]){ //dig->PrintSettingFromMemory(); - dig->WriteRegister(Register::DPP::SoftwareClear_W, 1); + //dig->WriteRegister(Register::DPP::SoftwareClear_W, 1); ///dig->SaveSettingAsText("haha.txt"); - unsigned short B = 1; /// BLT - unsigned short Eg = 10; /// Event / dual channel - unsigned short E2 = 1; /// extra 2; - unsigned short RL = 250; /// record Length - - for( int i = 0; i < dig->GetNChannel(); i++){ - dig->WriteRegister(Register::DPP::NumberEventsPerAggregate_G, Eg, i); - dig->WriteRegister(Register::DPP::RecordLength_G, RL, i); - } - dig->WriteRegister(Register::DPP::MaxAggregatePerBlockTransfer, B, 0); - dig->WriteRegister(Register::DPP::BoardConfiguration, 0x0F8115); /// has Extra2 - //dig->WriteRegister(Register::DPP::BoardConfiguration, 0x0D8115); /// no Extra2 - - - unsigned int bSize = dig->CalByteForBuffer(); - - //int bbbb = (((2 + E2 + RL*4) * Eg + 2)*8 + 4)*B *4; - //int bbb2 = (((2 + E2 + RL*4) * Eg + 2)*2 + 4)*B *4; - // - //printf("============== exp Buffer size : %8u byte \n", bbbb); - //printf("============== exp 2 ch size : %8u byte = %u words\n", bbb2, bbb2/4); - - usleep(1e6); - - ///using CAEN method - char * buffer = NULL; - uint32_t size; - CAEN_DGTZ_MallocReadoutBuffer(dig->GetHandle(), (char **)& buffer, &size); - - printf("CAEN calculated Buffer Size : %8u byte = %.2f MB \n", size, size/1024./1024.); - printf(" diff : %8u byte \n", size > bSize ? size - bSize : bSize - size); + /**** + {///============ Checking the buffer size calculation + unsigned short B = 1; /// BLT + unsigned short Eg = 10; /// Event / dual channel + unsigned short E2 = 1; /// extra 2; + unsigned short RL = 250; /// record Length - delete buffer; + //for( int i = 0; i < dig->GetNChannel(); i++){ + // dig->WriteRegister(Register::DPP::NumberEventsPerAggregate_G, Eg, i); + // dig->WriteRegister(Register::DPP::RecordLength_G, RL, i); + //} + //dig->WriteRegister(Register::DPP::MaxAggregatePerBlockTransfer, B, 0); + //dig->WriteRegister(Register::DPP::BoardConfiguration, 0x0F8115); /// has Extra2 + //dig->WriteRegister(Register::DPP::BoardConfiguration, 0x0D8115); /// no Extra2 + + unsigned int bSize = dig->CalByteForBuffer(); + int bbbb = (((2 + E2 + RL*4) * Eg + 2)*8 + 4)*B *4; + int bbb2 = (((2 + E2 + RL*4) * Eg + 2)*3 + 4)*B *4; + printf("============== exp Buffer size : %8u byte \n", bbbb); + printf("============== exp 3 ch size : %8u byte = %u words\n", bbb2, bbb2/4); + + usleep(1e6); + + ///using CAEN method + char * buffer = NULL; + uint32_t size; + CAEN_DGTZ_MallocReadoutBuffer(dig->GetHandle(), (char **)& buffer, &size); + + printf("CAEN calculated Buffer Size : %8u byte = %.2f MB \n", size, size/1024./1024.); + printf(" diff : %8u byte \n", size > bSize ? size - bSize : bSize - size); + + delete buffer; + }*/ dig->StartACQ(); @@ -137,7 +137,10 @@ int main(int argc, char* argv[]){ usleep(1000000); dig->ReadData(); printf("------------------- %d\n", i); - dig->GetData()->DecodeBuffer(false,2); + unsigned long time1 = get_time(); + dig->GetData()->DecodeBuffer(true,0); + unsigned long time2 = get_time(); + printf("********************* decode time : %lu usec\n", time2-time1); dig->GetData()->PrintStat(); }