some improvements

This commit is contained in:
carina@hades 2022-10-25 16:56:52 -04:00
parent 03b6a03557
commit 02ea0c98f1
5 changed files with 92 additions and 70 deletions

View File

@ -189,7 +189,7 @@ inline void Data::SaveBuffer(const char * fileName){
fwrite(buffer, nByte, 1, haha); fwrite(buffer, nByte, 1, haha);
presentFileSizeByte = ftell(haha); presentFileSizeByte = ftell(haha);
printf("=========== file Size : %u Byte = %.2f MB\n", presentFileSizeByte, presentFileSizeByte/1024./1024.); ///printf("=========== file Size : %u Byte = %.2f MB\n", presentFileSizeByte, presentFileSizeByte/1024./1024.);
fclose(haha); fclose(haha);
} }

View File

@ -728,7 +728,7 @@ void Digitizer::SaveSettingAsText(std::string fileName){
if( haha.GetType() == RW::ReadWrite ) typeStr = "R/W"; if( haha.GetType() == RW::ReadWrite ) typeStr = "R/W";
if( haha.GetType() == RW::ReadONLY ) typeStr = "R "; if( haha.GetType() == RW::ReadONLY ) typeStr = "R ";
if( haha.GetType() == RW::WriteONLY ) typeStr = " W"; if( haha.GetType() == RW::WriteONLY ) typeStr = " W";
fprintf( txtFile, "0x%04X %30s 0x%08X %s %d\n", actualAddress, fprintf( txtFile, "0x%04X %30s 0x%08X %s %u\n", actualAddress,
haha.GetNameChar(), haha.GetNameChar(),
setting[i], setting[i],
typeStr.c_str(), typeStr.c_str(),

View File

@ -178,6 +178,7 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) {
chIDEntry = new TGNumberEntry(hfg1, 0, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber); hfg1->AddFrame(chIDEntry, haha); chIDEntry = new TGNumberEntry(hfg1, 0, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber); hfg1->AddFrame(chIDEntry, haha);
chIDEntry->SetWidth(50); chIDEntry->SetWidth(50);
chIDEntry->SetState(false); chIDEntry->SetState(false);
chIDEntry->Connect("Modified()", "MainWindow", this, "ChangePlot()");
bPlotSingleTrace = new TGTextButton(hfg1,"Plot Trace"); hfg1->AddFrame(bPlotSingleTrace, haha); bPlotSingleTrace = new TGTextButton(hfg1,"Plot Trace"); hfg1->AddFrame(bPlotSingleTrace, haha);
bPlotSingleTrace->Connect("Clicked()", "MainWindow", this, "PlotSingleTrace()"); bPlotSingleTrace->Connect("Clicked()", "MainWindow", this, "PlotSingleTrace()");
@ -226,8 +227,8 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) {
LogMsg((char*)"Please \"Open Digitizers\" to start."); LogMsg((char*)"Please \"Open Digitizers\" to start.");
HandleMenu(M_DIGITIZER_OPEN); HandleMenu(M_DIGITIZER_OPEN);
HandleMenu(M_BOARD_SETTINGS); //HandleMenu(M_BOARD_SETTINGS);
HandleMenu(M_CH_SETTING_PHA); //HandleMenu(M_CH_SETTING_PHA);
//HandleMenu(M_CH_SETTING_PSD); //HandleMenu(M_CH_SETTING_PSD);
//HandleMenu(M_REGISTER_SETTING); //HandleMenu(M_REGISTER_SETTING);
//HandleMenu(M_TRIGGER_SUMMARY); //HandleMenu(M_TRIGGER_SUMMARY);
@ -490,6 +491,7 @@ void MainWindow::LoadSettingFromFile(){
void MainWindow::ChangeBoard(){ void MainWindow::ChangeBoard(){
int boardID = boardIDEntry->GetNumber(); int boardID = boardIDEntry->GetNumber();
chIDEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 0, digi[boardID]->GetNChannel() -1 ); chIDEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 0, digi[boardID]->GetNChannel() -1 );
ChangePlot();
} }
void MainWindow::GoodBye(){ void MainWindow::GoodBye(){
@ -519,8 +521,10 @@ void MainWindow::StartRun(){
bPlotSingleTrace->SetEnabled(false); bPlotSingleTrace->SetEnabled(false);
bFitTrace->SetEnabled(false); bFitTrace->SetEnabled(false);
if( cbMode->GetSelected() == Mode_DataRun ) cbMode->SetEnabled(false); if( cbMode->GetSelected() == Mode_DataRun ) {
cbMode->SetEnabled(false);
HandleMenu(M_TRIGGER_SUMMARY);
}
bool threadFlag = false; bool threadFlag = false;
for( int i = 0 ; i < nDigi; i++) { for( int i = 0 ; i < nDigi; i++) {
@ -553,6 +557,8 @@ void MainWindow::StopRun(){
bFitTrace->SetEnabled(true); bFitTrace->SetEnabled(true);
cbMode->SetEnabled(true); cbMode->SetEnabled(true);
if( triggerSummary != NULL ) triggerSummary->CloseWindow();
if( cbMode->GetSelected() == Mode_DataRun ){ if( cbMode->GetSelected() == Mode_DataRun ){
int runID = runIDEntry->GetNumber(); int runID = runIDEntry->GetNumber();
runIDEntry->SetNumber(runID +1); runIDEntry->SetNumber(runID +1);
@ -598,7 +604,6 @@ void MainWindow::LogMsg(char * msg){
teLog->AddLine(outMsg); teLog->AddLine(outMsg);
printf("%s\n", outMsg.Data()); printf("%s\n", outMsg.Data());
//teLog->LineDown();
teLog->ShowBottom(); teLog->ShowBottom();
} }
@ -789,69 +794,74 @@ void * MainWindow::RunThread(void * ptr){
// Rate graph? // Rate graph?
data->SaveBuffer(dataFileName.Data()); data->SaveBuffer(dataFileName.Data());
data->DecodeBuffer(true, 0); data->DecodeBuffer(true, 0);
std::string msg = Form("File Size : %.2f MB", data->GetPresentFileSize() / 1024./1024. );
teLog->AddLine(msg.c_str());
teLog->LineDown();
teLog->ShowBottom();
}else{ CurrentTime = get_time();
if( CurrentTime - PreviousTime > 1000 ){
data->DecodeBuffer(false, 0); std::string msg = Form("File Size : %.2f MB", data->GetPresentFileSize() / 1024./1024. );
teLog->AddLine(msg.c_str());
fEcanvas->GetCanvas()->cd(); teLog->ShowBottom();
PreviousTime = CurrentTime;
///Fill trace
if( cbMode->GetSelected() == Mode_Oscilloscope){
unsigned short nData = data->NumEvents[ch];
traceLength = (data->Waveform1[ch][nData-1]).size();
if( traceLength > 0 ){
for( int i = 0; i < traceLength; i++) {
gAnaTrace1->SetPoint(i, i*ch2ns*(1+isDualTrace), (data->Waveform1[ch][nData-1])[i]);
if( isDualTrace) gAnaTrace2->SetPoint(i, i*ch2ns*(1+isDualTrace), (data->Waveform2[ch][nData-1])[i]);
}
if( traceLength <= gAnaTrace1->GetN() ){
for( int i = gAnaTrace1->GetN() -1 ; i >= traceLength ; i--){
gAnaTrace1->RemovePoint(i);
if( isDualTrace) gAnaTrace2->RemovePoint(i);
}
}
gAnaTrace1->GetYaxis()->SetRangeUser(0, 0x3FFF);
gAnaTrace1->Draw("APL");
gAnaTrace2->Draw("L");
}
} }
}else{
data->DecodeBuffer(false, 0);
} }
} }
CurrentTime = get_time(); if( cbMode->GetSelected() != Mode_DataRun){
ElapsedTime = CurrentTime - PreviousTime; /// milliseconds
if( ElapsedTime > 500 ){ fEcanvas->GetCanvas()->cd();
///Fill Channel Count ///Fill trace
for( int i = 0 ; i < digi[boardID]->GetNChannel(); i++){ if( cbMode->GetSelected() == Mode_Oscilloscope){
for( int j = 0; j < data->NumEvents[i]; j++) hChannel[boardID]->Fill(i);
unsigned short nData = data->NumEvents[ch];
traceLength = (data->Waveform1[ch][nData-1]).size();
if( traceLength > 0 ){
for( int i = 0; i < traceLength; i++) {
gAnaTrace1->SetPoint(i, i*ch2ns*(1+isDualTrace), (data->Waveform1[ch][nData-1])[i]);
if( isDualTrace) gAnaTrace2->SetPoint(i, i*ch2ns*(1+isDualTrace), (data->Waveform2[ch][nData-1])[i]);
}
if( traceLength <= gAnaTrace1->GetN() ){
for( int i = gAnaTrace1->GetN() -1 ; i >= traceLength ; i--){
gAnaTrace1->RemovePoint(i);
if( isDualTrace) gAnaTrace2->RemovePoint(i);
}
}
gAnaTrace1->GetYaxis()->SetRangeUser(0, 0x3FFF);
gAnaTrace1->Draw("APL");
gAnaTrace2->Draw("L");
}
} }
///Fill Energy histogram CurrentTime = get_time();
for( int i = 0; i < data->NumEvents[ch]; i++){ ElapsedTime = CurrentTime - PreviousTime; /// milliseconds
hEnergy[boardID][ch]->Fill( data->Energy[ch][i]);
if( ElapsedTime > 500 ){
///Fill Channel Count
for( int i = 0 ; i < digi[boardID]->GetNChannel(); i++){
for( int j = 0; j < data->NumEvents[i]; j++) hChannel[boardID]->Fill(i);
}
///Fill Energy histogram
for( int i = 0; i < data->NumEvents[ch]; i++){
hEnergy[boardID][ch]->Fill( data->Energy[ch][i]);
}
if( cbMode->GetSelected() == Mode_EnergyHist ) hEnergy[boardID][ch]->Draw("hist");
if( cbMode->GetSelected() == Mode_CountHist ) hChannel[boardID]->Draw("hist");
data->ClearData();
PreviousTime = CurrentTime;
} }
if( cbMode->GetSelected() == Mode_EnergyHist ) hEnergy[boardID][ch]->Draw("hist"); fEcanvas->GetCanvas()->Update();
if( cbMode->GetSelected() == Mode_CountHist ) hChannel[boardID]->Draw("hist"); gSystem->ProcessEvents();
data->ClearData();
PreviousTime = CurrentTime;
} }
fEcanvas->GetCanvas()->Update(); data->ClearData();
gSystem->ProcessEvents();
} }
return ptr; return ptr;

View File

@ -83,7 +83,7 @@ BoardSetting::BoardSetting(const TGWindow *p, UInt_t w, UInt_t h, Digitizer ** d
TGLabel * lbSettingFile = new TGLabel(hframe1, "Setting file :"); hframe1->AddFrame(lbSettingFile, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5,5,4,2)); TGLabel * lbSettingFile = new TGLabel(hframe1, "Setting file :"); hframe1->AddFrame(lbSettingFile, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5,5,4,2));
txtSettingFile = new TGTextEntry(hframe1, ""); hframe1->AddFrame(txtSettingFile, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5,5,3,3)); txtSettingFile = new TGTextEntry(hframe1, ""); hframe1->AddFrame(txtSettingFile, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5,5,3,3));
txtSettingFile->SetEnabled(false); txtSettingFile->SetEnabled(false);
txtSettingFile->Resize(650, 20); txtSettingFile->Resize(550, 20);
if( digi != NULL ) txtSettingFile->SetText( digi[boardID]->GetSettingFileName().c_str()); if( digi != NULL ) txtSettingFile->SetText( digi[boardID]->GetSettingFileName().c_str());
} }
@ -1501,6 +1501,7 @@ void BoardSetting::ProgramBoardFromFile(){
void BoardSetting::SaveSettingFile(){ void BoardSetting::SaveSettingFile(){
const char *filetypes[] = { "Setting File", "*.bin", const char *filetypes[] = { "Setting File", "*.bin",
"Text File", "*.txt",
0, 0}; 0, 0};
static TString dir("."); static TString dir(".");
@ -1514,14 +1515,23 @@ void BoardSetting::SaveSettingFile(){
if( fi.fFilename == NULL) return; if( fi.fFilename == NULL) return;
txtSettingFile->SetText(fi.fFilename); TString temp = fi.fFilename;
int len = temp.Length();
temp.Remove(0, len-3);
if( digi == NULL ) { if( temp == "bin" ){
txtSettingFile->SetText(fi.fFilename);
if( digi == NULL ) {
}else{
int boardID = boardIDEntry->GetNumber();
digi[boardID]->OpenSettingBinary( fi.fFilename );
}
}else if( temp == "txt") {
int boardID = boardIDEntry->GetNumber();
digi[boardID]->SaveSettingAsText( fi.fFilename );
}else{ }else{
int boardID = boardIDEntry->GetNumber(); LogMsg("Invalid file extension.");
//TODO saev as same file
digi[boardID]->OpenSettingBinary( fi.fFilename );
} }
} }

View File

@ -116,6 +116,8 @@ TriggerSummary::~TriggerSummary(){
updateFlag = false; updateFlag = false;
thread->Join();
///delete thread; /// Don;t delete the thread, otherwise, thread will not run after close and reopen. ///delete thread; /// Don;t delete the thread, otherwise, thread will not run after close and reopen.
fMain->Cleanup(); fMain->Cleanup();