diff --git a/.gitignore b/.gitignore index cdd7369..869cd46 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.o +*.fsu FSUDAQ_Qt6 test diff --git a/ClassData.h b/ClassData.h index e92965d..614dee8 100644 --- a/ClassData.h +++ b/ClassData.h @@ -9,6 +9,7 @@ #include ///cout #include #include +#include #include "CAENDigitizerType.h" #include "macro.h" @@ -18,8 +19,8 @@ class Data{ public: - - int DPPType; /// this is set from the boardID from the Board Agg. header when it is > 0 + int DPPType; + std::string DPPTypeStr; unsigned short boardSN; float ch2ns; @@ -31,7 +32,7 @@ class Data{ unsigned long TotNumEvents[MaxNChannels]; unsigned short NumEventsDecoded[MaxNChannels]; - /// stored Raw event + /// store a single Raw event bool IsNotRollOverFakeAgg; unsigned short NumEvents[MaxNChannels]; unsigned long long Timestamp[MaxNChannels][MaxNData]; /// 47 bit @@ -58,11 +59,7 @@ class Data{ void ClearBuffer(); void CopyBuffer( const char * buffer, const unsigned int size); - - void SetOutputFileName(std::string fileName); - void SaveBuffer(); - unsigned int GetPresentFileSize() {return presentFileSizeByte;} - + void PrintBuffer() const; //Incorrect 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 @@ -70,13 +67,26 @@ class Data{ void PrintStat() const; void PrintData() const; + + //^================= Saving data + void OpenSaveFile(std::string fileNamePrefix); + void SaveData(); + void CloseSaveFile(); + unsigned int GetFileSize() const {return outFileSize;} + uint64_t GetTotalFileSize() const {return FinishedOutFilesSize + outFileSize;} + protected: unsigned int nw; bool SaveWaveToMemory; - std::string outputFileName; + unsigned int outFileIndex; + std::string outFilePrefix; + std::string outFileName; + FILE * outFile; + unsigned int outFileSize; // should be max at 2 GB + uint64_t FinishedOutFilesSize; // sum of files size. ///for temperary std::vector tempWaveform1; @@ -88,9 +98,7 @@ class Data{ int DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDecode, int verbose); int DecodePSDDualChannelBlock(unsigned int ChannelMask, bool fastDecode, int verbose); - - unsigned int presentFileSizeByte; - unsigned short saveFileIndex; + }; @@ -100,6 +108,7 @@ inline Data::Data(){ ch2ns = 2.0; boardSN = 0; DPPType = V1730_DPP_PHA_CODE; + DPPTypeStr = ""; IsNotRollOverFakeAgg = false; buffer = NULL; for ( int i = 0; i < MaxNChannels; i++) TotNumEvents[i] = 0; @@ -107,9 +116,13 @@ inline Data::Data(){ ClearTriggerRate(); SaveWaveToMemory = true; nw = 0; - saveFileIndex = 0; - outputFileName = ""; + outFileIndex = 0; + outFilePrefix = ""; + outFileName = ""; + outFile = nullptr; + outFileSize = 0; // should be max at 2 GB + FinishedOutFilesSize = 0; // sum of files size. } inline Data::~Data(){ @@ -168,34 +181,42 @@ inline void Data::CopyBuffer(const char * buffer, const unsigned int size){ std::memcpy(this->buffer, buffer, size); } -inline void Data::SetOutputFileName(std::string fileName){ - this->outputFileName = fileName; +inline void Data::OpenSaveFile(std::string fileNamePrefix){ + + outFilePrefix = fileNamePrefix; + char saveFileName[100]; + sprintf(saveFileName, "%s_%03d_%3s_%03u.fsu", outFilePrefix.c_str() , boardSN, DPPTypeStr.c_str(), outFileIndex); + + outFileName = saveFileName; + outFile = fopen(saveFileName, "wb"); // overwrite binary + fseek(outFile, 0L, SEEK_END); + outFileSize = ftell(outFile); + } -inline void Data::SaveBuffer(){ +inline void Data::SaveData(){ - char saveFileName[100]; - sprintf(saveFileName, "%s_%03d_%03d_%03u.fsu", outputFileName.c_str() , boardSN, DPPType, saveFileIndex); - - FILE * haha = fopen(saveFileName, "a+"); - fseek(haha, 0L, SEEK_END); - unsigned int inFileSize = ftell(haha); /// unsigned int = Max ~ 4 GB - ///printf("file Size = %u Byte\n", inFileSize); - - if( inFileSize > (unsigned int)MaxSaveFileSize ) { /// 2 GB - fclose(haha); - saveFileIndex ++; - sprintf(saveFileName, "%s_%03u.fsu", outputFileName.c_str() , saveFileIndex); - fclose(haha); - haha = fopen(saveFileName, "a+"); + if( outFileSize > (unsigned int) MaxSaveFileSize){ + FinishedOutFilesSize += ftell(outFile); + CloseSaveFile(); + outFileIndex ++; + char saveFileName[100]; + sprintf(saveFileName, "%s_%03d_%3s_%03u.fsu", outFilePrefix.c_str() , boardSN, DPPTypeStr.c_str(), outFileIndex); + outFileName = saveFileName; + outFile = fopen(outFileName.c_str(), "wb"); //overwrite binary } - - fwrite(buffer, nByte, 1, haha); - presentFileSizeByte = ftell(haha); - ///printf("=========== file Size : %u Byte = %.2f MB\n", presentFileSizeByte, presentFileSizeByte/1024./1024.); + fwrite(buffer, nByte, 1, outFile); + outFileSize = ftell(outFile); - fclose(haha); +} + +inline void Data::CloseSaveFile(){ + if( outFile != NULL ){ + fclose(outFile); + int result = chmod(outFileName.c_str(), S_IRUSR | S_IRGRP | S_IROTH); + if( result != 0 ) printf("somewrong when set file (%s) to read only.", outFileName.c_str()); + } } inline void Data::PrintStat() const{ diff --git a/ClassDigitizer.cpp b/ClassDigitizer.cpp index 615cf0d..4894ef1 100644 --- a/ClassDigitizer.cpp +++ b/ClassDigitizer.cpp @@ -113,6 +113,21 @@ int Digitizer::OpenDigitizer(int boardID, int portID, bool program, bool verbose ///====================== Check DPP firmware revision sscanf(BoardInfo.AMC_FirmwareRel, "%d", &DPPType); data->DPPType = DPPType; + switch( DPPType ) { + case 0x80 : data->DPPTypeStr = "PHA"; break; // x724 + case 0x82 : data->DPPTypeStr = "xCI"; break; // x720 + case 0x83 : data->DPPTypeStr = "PSD"; break; // x720 + case 0x84 : data->DPPTypeStr = "PSD"; break; // x751 + case 0x85 : data->DPPTypeStr = "ZLE"; break; // x751 + case 0x86 : data->DPPTypeStr = "PSD"; break; // x743 + case 0x87 : data->DPPTypeStr = "QDC"; break; // x740 + case 0x88 : data->DPPTypeStr = "PSD"; break; // x730 + case 0x89 : data->DPPTypeStr = "DAW"; break; // x724 + case 0x8B : data->DPPTypeStr = "PHA"; break; // x730 + case 0x8C : data->DPPTypeStr = "ZLE"; break; // x730 + case 0x8D : data->DPPTypeStr = "DAW"; break; // x730 + default : data->DPPTypeStr = "STD"; break; // stardard + } /// change address 0xEF08 (5 bits), this will reflected in the 2nd word of the Board Agg. header. ret = CAEN_DGTZ_WriteRegister(handle, Register::DPP::BoardID, (DPPType & 0xF)); if ( verbose ){ diff --git a/CustomThreads.h b/CustomThreads.h index 9b6b4c7..d9cc63c 100644 --- a/CustomThreads.h +++ b/CustomThreads.h @@ -29,7 +29,7 @@ public: if( ret == CAEN_DGTZ_Success ){ digiMTX[ID].lock(); if( isSaveData ) { - digi->GetData()->SaveBuffer(); + digi->GetData()->SaveData(); }else{ digi->GetData()->DecodeBuffer(false); } diff --git a/mainWindow.C b/mainWindow.C index 14eafba..b92fe6a 100644 --- a/mainWindow.C +++ b/mainWindow.C @@ -137,7 +137,6 @@ MainWindow::~MainWindow(){ if( digi ) CloseDigitizers(); - } //*************************************************************** @@ -172,6 +171,7 @@ void MainWindow::OpenDigitizers(){ for( unsigned int i = 0; i < nDigi; i++){ digi[i] = new Digitizer(portList[i].first, portList[i].second); readDataThread[i] = new ReadDataThread(digi[i], i); + connect(readDataThread[i], &ReadDataThread::sendMsg, this, &MainWindow::LogMsg); } LogMsg(QString("Done. Opened %1 digitizer(s).").arg(nDigi)); @@ -220,7 +220,7 @@ void MainWindow::StartACQ(){ if( digi == nullptr ) return; for( unsigned int i = 0; i < nDigi ; i++){ - digi[i]->GetData()->SetOutputFileName("haha"); + digi[i]->GetData()->OpenSaveFile("haha"); digi[i]->StartACQ(); readDataThread[i]->SetSaveData(true); readDataThread[i]->start(); @@ -233,12 +233,12 @@ void MainWindow::StopACQ(){ for( unsigned int i = 0; i < nDigi; i++){ digi[i]->StopACQ(); + digi[i]->GetData()->CloseSaveFile(); if( readDataThread[i]->isRunning() ) { readDataThread[i]->quit(); readDataThread[i]->wait(); } - } }