modified data saving, only open outFile once

This commit is contained in:
splitPoleDAQ 2023-04-17 11:52:06 -04:00
parent 44499a8f21
commit 2e1ffe62dd
5 changed files with 77 additions and 40 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
*.o *.o
*.fsu
FSUDAQ_Qt6 FSUDAQ_Qt6
test test

View File

@ -9,6 +9,7 @@
#include <iostream> ///cout #include <iostream> ///cout
#include <bitset> #include <bitset>
#include <vector> #include <vector>
#include <sys/stat.h>
#include "CAENDigitizerType.h" #include "CAENDigitizerType.h"
#include "macro.h" #include "macro.h"
@ -18,8 +19,8 @@
class Data{ class Data{
public: public:
int DPPType;
int DPPType; /// this is set from the boardID from the Board Agg. header when it is > 0 std::string DPPTypeStr;
unsigned short boardSN; unsigned short boardSN;
float ch2ns; float ch2ns;
@ -31,7 +32,7 @@ class Data{
unsigned long TotNumEvents[MaxNChannels]; unsigned long TotNumEvents[MaxNChannels];
unsigned short NumEventsDecoded[MaxNChannels]; unsigned short NumEventsDecoded[MaxNChannels];
/// stored Raw event /// store a single Raw event
bool IsNotRollOverFakeAgg; bool IsNotRollOverFakeAgg;
unsigned short NumEvents[MaxNChannels]; unsigned short NumEvents[MaxNChannels];
unsigned long long Timestamp[MaxNChannels][MaxNData]; /// 47 bit unsigned long long Timestamp[MaxNChannels][MaxNData]; /// 47 bit
@ -58,11 +59,7 @@ class Data{
void ClearBuffer(); void ClearBuffer();
void CopyBuffer( const char * buffer, const unsigned int size); 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 PrintBuffer() const; //Incorrect
void DecodeBuffer(bool fastDecode, int verbose = 0); /// fastDecode will not save waveform 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 DecodeBuffer(char * buffer, unsigned int size, bool fastDecode, int verbose = 0); // for outside data
@ -70,13 +67,26 @@ class Data{
void PrintStat() const; void PrintStat() const;
void PrintData() 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: protected:
unsigned int nw; unsigned int nw;
bool SaveWaveToMemory; 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 ///for temperary
std::vector<unsigned short> tempWaveform1; std::vector<unsigned short> tempWaveform1;
@ -88,9 +98,7 @@ class Data{
int DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDecode, int verbose); int DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDecode, int verbose);
int DecodePSDDualChannelBlock(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; ch2ns = 2.0;
boardSN = 0; boardSN = 0;
DPPType = V1730_DPP_PHA_CODE; DPPType = V1730_DPP_PHA_CODE;
DPPTypeStr = "";
IsNotRollOverFakeAgg = false; IsNotRollOverFakeAgg = false;
buffer = NULL; buffer = NULL;
for ( int i = 0; i < MaxNChannels; i++) TotNumEvents[i] = 0; for ( int i = 0; i < MaxNChannels; i++) TotNumEvents[i] = 0;
@ -107,9 +116,13 @@ inline Data::Data(){
ClearTriggerRate(); ClearTriggerRate();
SaveWaveToMemory = true; SaveWaveToMemory = true;
nw = 0; 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(){ inline Data::~Data(){
@ -168,34 +181,42 @@ inline void Data::CopyBuffer(const char * buffer, const unsigned int size){
std::memcpy(this->buffer, buffer, size); std::memcpy(this->buffer, buffer, size);
} }
inline void Data::SetOutputFileName(std::string fileName){ inline void Data::OpenSaveFile(std::string fileNamePrefix){
this->outputFileName = fileName;
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]; if( outFileSize > (unsigned int) MaxSaveFileSize){
sprintf(saveFileName, "%s_%03d_%03d_%03u.fsu", outputFileName.c_str() , boardSN, DPPType, saveFileIndex); FinishedOutFilesSize += ftell(outFile);
CloseSaveFile();
FILE * haha = fopen(saveFileName, "a+"); outFileIndex ++;
fseek(haha, 0L, SEEK_END); char saveFileName[100];
unsigned int inFileSize = ftell(haha); /// unsigned int = Max ~ 4 GB sprintf(saveFileName, "%s_%03d_%3s_%03u.fsu", outFilePrefix.c_str() , boardSN, DPPTypeStr.c_str(), outFileIndex);
///printf("file Size = %u Byte\n", inFileSize); outFileName = saveFileName;
outFile = fopen(outFileName.c_str(), "wb"); //overwrite binary
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+");
} }
fwrite(buffer, nByte, 1, haha);
presentFileSizeByte = ftell(haha); fwrite(buffer, nByte, 1, outFile);
///printf("=========== file Size : %u Byte = %.2f MB\n", presentFileSizeByte, presentFileSizeByte/1024./1024.); 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{ inline void Data::PrintStat() const{

View File

@ -113,6 +113,21 @@ int Digitizer::OpenDigitizer(int boardID, int portID, bool program, bool verbose
///====================== Check DPP firmware revision ///====================== Check DPP firmware revision
sscanf(BoardInfo.AMC_FirmwareRel, "%d", &DPPType); sscanf(BoardInfo.AMC_FirmwareRel, "%d", &DPPType);
data->DPPType = 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. /// 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)); ret = CAEN_DGTZ_WriteRegister(handle, Register::DPP::BoardID, (DPPType & 0xF));
if ( verbose ){ if ( verbose ){

View File

@ -29,7 +29,7 @@ public:
if( ret == CAEN_DGTZ_Success ){ if( ret == CAEN_DGTZ_Success ){
digiMTX[ID].lock(); digiMTX[ID].lock();
if( isSaveData ) { if( isSaveData ) {
digi->GetData()->SaveBuffer(); digi->GetData()->SaveData();
}else{ }else{
digi->GetData()->DecodeBuffer(false); digi->GetData()->DecodeBuffer(false);
} }

View File

@ -137,7 +137,6 @@ MainWindow::~MainWindow(){
if( digi ) CloseDigitizers(); if( digi ) CloseDigitizers();
} }
//*************************************************************** //***************************************************************
@ -172,6 +171,7 @@ void MainWindow::OpenDigitizers(){
for( unsigned int i = 0; i < nDigi; i++){ for( unsigned int i = 0; i < nDigi; i++){
digi[i] = new Digitizer(portList[i].first, portList[i].second); digi[i] = new Digitizer(portList[i].first, portList[i].second);
readDataThread[i] = new ReadDataThread(digi[i], i); readDataThread[i] = new ReadDataThread(digi[i], i);
connect(readDataThread[i], &ReadDataThread::sendMsg, this, &MainWindow::LogMsg);
} }
LogMsg(QString("Done. Opened %1 digitizer(s).").arg(nDigi)); LogMsg(QString("Done. Opened %1 digitizer(s).").arg(nDigi));
@ -220,7 +220,7 @@ void MainWindow::StartACQ(){
if( digi == nullptr ) return; if( digi == nullptr ) return;
for( unsigned int i = 0; i < nDigi ; i++){ for( unsigned int i = 0; i < nDigi ; i++){
digi[i]->GetData()->SetOutputFileName("haha"); digi[i]->GetData()->OpenSaveFile("haha");
digi[i]->StartACQ(); digi[i]->StartACQ();
readDataThread[i]->SetSaveData(true); readDataThread[i]->SetSaveData(true);
readDataThread[i]->start(); readDataThread[i]->start();
@ -233,12 +233,12 @@ void MainWindow::StopACQ(){
for( unsigned int i = 0; i < nDigi; i++){ for( unsigned int i = 0; i < nDigi; i++){
digi[i]->StopACQ(); digi[i]->StopACQ();
digi[i]->GetData()->CloseSaveFile();
if( readDataThread[i]->isRunning() ) { if( readDataThread[i]->isRunning() ) {
readDataThread[i]->quit(); readDataThread[i]->quit();
readDataThread[i]->wait(); readDataThread[i]->wait();
} }
} }
} }