diff --git a/ClassDigitizer.cpp b/ClassDigitizer.cpp index 7f471f5..c04125c 100644 --- a/ClassDigitizer.cpp +++ b/ClassDigitizer.cpp @@ -363,29 +363,44 @@ void Digitizer::WriteRegister(uint32_t registerAddress, uint32_t value, int ch ) if( ch < 0 ){ for( int i = 0; i < NChannel/2; i++){ ret = CAEN_DGTZ_WriteRegister(handle, registerAddress + 4*i, value); - if( ret == 0 ) SetSettingToMemory(registerAddress, value, i); + if( ret == 0 ) { + SetSettingToMemory(registerAddress, value, i); + SaveSettingToFile(registerAddress, value, i); + } ///ReadRegister(registerAddress, i); } }else{ ret = CAEN_DGTZ_WriteRegister(handle, registerAddress + 4*(ch/2), value); - if( ret == 0 ) SetSettingToMemory(registerAddress, value, ch); + if( ret == 0 ) { + SetSettingToMemory(registerAddress, value, ch); + SaveSettingToFile(registerAddress, value, ch); + } ///ReadRegister(registerAddress, ch); } }else if( registerAddress < 0x8000){ if( ch < 0 ) { ret = CAEN_DGTZ_WriteRegister(handle, registerAddress + 0x7000, value); if( ret == 0 ){ - for( int i = 0; i < NChannel; i++) SetSettingToMemory(registerAddress, value, i); + for( int i = 0; i < NChannel; i++) { + SetSettingToMemory(registerAddress, value, i); + SaveSettingToFile(registerAddress, value, i); + } ///for( int i = 0; i < NChannel; i++) ReadRegister(registerAddress, i); } }else{ ret = CAEN_DGTZ_WriteRegister(handle, registerAddress + (ch<<8), value); - if( ret == 0 ) SetSettingToMemory(registerAddress, value, ch); + if( ret == 0 ) { + SetSettingToMemory(registerAddress, value, ch); + SaveSettingToFile(registerAddress, value, ch); + } ///ReadRegister(registerAddress, ch); } }else{ ret = CAEN_DGTZ_WriteRegister(handle, registerAddress, value); - if( ret == 0 ) SetSettingToMemory(registerAddress, value); + if( ret == 0 ) { + SetSettingToMemory(registerAddress, value); + SaveSettingToFile(registerAddress, value); + } //ReadRegister(registerAddress); } @@ -397,7 +412,10 @@ void Digitizer::WriteRegister(uint32_t registerAddress, uint32_t value, int ch ) registerAddress == Register::DPP::TriggerValidationMask_G ){ //ReadRegister(registerAddress, ch + (ch%2 == 1 ? -1 : +1)); - if( ret == 0 ) SetSettingToMemory(registerAddress, value, ch); + if( ret == 0 ) { + SetSettingToMemory(registerAddress, value, ch); + SaveSettingToFile(registerAddress, value, ch); + } } ErrorMsg("WriteRegister:" + std::to_string(registerAddress)); @@ -834,13 +852,14 @@ void Digitizer::PrintSettingFromMemory(){ } void Digitizer::OpenSettingBinary(string fileName){ - settingFile = NULL; - this->settingFileName = fileName; + delete settingFile; settingFile = fopen(fileName.c_str(), "r+"); if( settingFile == NULL ){ + this->settingFileName = ""; printf("cannot open file %s. \n", fileName.c_str()); CreateAndSaveSettingToFile(fileName); }else{ + this->settingFileName = fileName; settingFileExist = true; printf("setting file already exist.\n"); } @@ -866,8 +885,7 @@ void Digitizer::CreateAndSaveSettingToFile(string fileName){ void Digitizer::LoadSettingBinary(string fileName){ - settingFileName = fileName; - settingFile = fopen(settingFileName.c_str(), "r"); + settingFile = fopen(fileName.c_str(), "r+"); if( settingFile == NULL ) { printf(" %s does not exist.\n", fileName.c_str()); @@ -876,6 +894,8 @@ void Digitizer::LoadSettingBinary(string fileName){ }else{ settingFileExist = true; + settingFileName = fileName; + size_t dummy = fread( setting, SETTINGSIZE * sizeof(unsigned int), 1, settingFile); if( isConnected ) { diff --git a/ClassDigitizer.h b/ClassDigitizer.h index 06c796b..745df2f 100644 --- a/ClassDigitizer.h +++ b/ClassDigitizer.h @@ -122,11 +122,13 @@ class Digitizer{ void SetSettingFromMemory (uint32_t registerAddress, int ch = -1); - void OpenSettingBinary (string fileName); - void LoadSettingBinary (string fileName); /// load settign file to memory + void OpenSettingBinary (string fileName); /// Open setting file, if file not exist, call CreateAndSaveSetiingFile, if file exit simple set the settignFileName + void LoadSettingBinary (string fileName); /// load settign file to memory, if digitizer connected, program digitizer void CreateAndSaveSettingToFile (string fileName); void SaveSettingToFile (uint32_t registerAddress, unsigned int value, int ch = -1); unsigned int ReadSettingFromFile (uint32_t registerAddress, int ch = -1); /// read from setting binary + + string GetSettingFileName() {return settingFileName;} virtual int ProgramBoard(); diff --git a/FSUDAQ.cpp b/FSUDAQ.cpp index 6702d01..dcf7342 100644 --- a/FSUDAQ.cpp +++ b/FSUDAQ.cpp @@ -219,8 +219,8 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) { LogMsg((char*)"Please \"Open Digitizers\" to start."); - //HandleMenu(M_DIGITIZER_OPEN); - //HandleMenu(M_BOARD_SETTINGS); + HandleMenu(M_DIGITIZER_OPEN); + HandleMenu(M_BOARD_SETTINGS); //HandleMenu(M_CH_SETTING_PHA); //HandleMenu(M_CH_SETTING_PSD); //HandleMenu(M_REGISTER_SETTING); @@ -405,7 +405,7 @@ void MainWindow::OpenDigitizers(){ digi[i]->GetDPPTypeString().c_str(), digi[i]->GetModelName().c_str())); - digi[i]->OpenSettingBinary("setting_" + to_string(digi[i]->GetSerialNumber()) + ".bin"); + digi[i]->OpenSettingBinary("./setting_" + to_string(digi[i]->GetSerialNumber()) + ".bin"); } fMenuDigitizers->DisableEntry( M_DIGITIZER_OPEN); diff --git a/boardSetting.cpp b/boardSetting.cpp index c9abbc2..b3bcf71 100644 --- a/boardSetting.cpp +++ b/boardSetting.cpp @@ -66,11 +66,27 @@ BoardSetting::BoardSetting(const TGWindow *p, UInt_t w, UInt_t h, Digitizer ** d TGTextButton * bSoftwareReset = new TGTextButton(hframe0, "Reset Settings to default"); hframe0->AddFrame(bSoftwareReset, layoutHints); bSoftwareReset->Connect("Clicked()", "BoardSetting", this, "ResetSettingToDefault()"); + TGTextButton * bSoftwareClear = new TGTextButton(hframe0, "Clear Buffer"); hframe0->AddFrame(bSoftwareClear, layoutHints); bSoftwareClear->Connect("Clicked()", "BoardSetting", this, "ClearBuffer()"); + {///=========== Setting file + TGHorizontalFrame *hframe1 = new TGHorizontalFrame(vframe); vframe->AddFrame(hframe1, new TGLayoutHints(kLHintsLeft, 5, 5, 0, 0)); + + TGTextButton * bProgramBoardFromFile = new TGTextButton(hframe1, "Open File"); hframe1->AddFrame(bProgramBoardFromFile, new TGLayoutHints( kLHintsLeft | kLHintsCenterY, 5,5,3,3)); + bProgramBoardFromFile->Connect("Clicked()", "BoardSetting", this, "ProgramBoardFromFile()"); + + 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->SetEnabled(false); + txtSettingFile->Resize(650, 20); + if( digi != NULL ) txtSettingFile->SetText( digi[boardID]->GetSettingFileName().c_str()); + + } + {///============ fixed info - TGHorizontalFrame * hframeInfo = new TGHorizontalFrame(vframe); vframe->AddFrame(hframeInfo, new TGLayoutHints(kLHintsExpandX)); + TGGroupFrame * gInfo = new TGGroupFrame(vframe, "Board Info", kHorizontalFrame); vframe->AddFrame(gInfo, new TGLayoutHints(kLHintsExpandX, 5, 0, 0, 0)); + TGHorizontalFrame * hframeInfo = new TGHorizontalFrame(gInfo); gInfo->AddFrame(hframeInfo, new TGLayoutHints(kLHintsExpandX)); int numCol = 3; TGVerticalFrame * vframeInfo[numCol]; @@ -212,8 +228,6 @@ BoardSetting::BoardSetting(const TGWindow *p, UInt_t w, UInt_t h, Digitizer ** d TGTextButton * bProgramDefaultBoard = new TGTextButton(hRow0, "Program Default Board"); hRow0->AddFrame(bProgramDefaultBoard, new TGLayoutHints( kLHintsExpandX | kLHintsExpandY, 5, 0, 5, 0)); bProgramDefaultBoard->Connect("Clicked()", "BoardSetting", this, "ProgramDefaultBoard()"); - - TGTextButton * bUpdateStatus = new TGTextButton(hRow0, "Update Status and Settings"); hRow0->AddFrame(bUpdateStatus, new TGLayoutHints( kLHintsExpandX | kLHintsExpandY, 5, 0, 5, 0)); bUpdateStatus->Connect("Clicked()", "BoardSetting", this, "ChangeBoard()"); @@ -794,6 +808,9 @@ void BoardSetting::ChangeBoard(){ int boardID = boardIDEntry->GetNumber(); + txtSettingFile->SetText( digi[boardID]->GetSettingFileName().c_str() ); + + for( int i = 0; i < NUM_BOARD_INFO; i++){ switch (i) { case 0 : entry[i]->SetText( Form("%s", (digi[boardID]->GetModelName()).c_str()) ); break; @@ -1346,8 +1363,7 @@ void BoardSetting::ReadData(){ data->PrintStat(); //Fill Histogram - - + data->ClearData(); ReadStatus(); @@ -1368,3 +1384,32 @@ void BoardSetting::ProgramDefaultBoard(){ ChangeBoard(); } + +void BoardSetting::ProgramBoardFromFile(){ + const char *filetypes[] = { "Setting File", "*.bin", + "ROOT files", "*.root", + "ROOT macros", "*.C", + "Text files", "*.[tT][xX][tT]", + 0, 0 }; + + static TString dir("."); + TGFileInfo fi; + fi.fFileTypes = filetypes; + fi.SetIniDir(dir); + printf("fIniDir = %s\n", fi.fIniDir); + new TGFileDialog(gClient->GetRoot(), fMain, kFDOpen, &fi); + printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir); + dir = fi.fIniDir; + + txtSettingFile->SetText(fi.fFilename); + + if( digi == NULL ) { + + }else{ + int boardID = boardIDEntry->GetNumber(); + digi[boardID]->LoadSettingBinary( fi.fFilename ); + + ChangeBoard(); + } + +} diff --git a/boardSetting.h b/boardSetting.h index 1eb9f6d..a50a834 100644 --- a/boardSetting.h +++ b/boardSetting.h @@ -26,6 +26,8 @@ class BoardSetting{ TGNumberEntry * boardIDEntry; TGTextEntry * entry[NUM_BOARD_INFO]; + + TGTextEntry * txtSettingFile; int nDigi; Digitizer ** digi; @@ -175,5 +177,6 @@ class BoardSetting{ void ReadData(); void ProgramDefaultBoard(); + void ProgramBoardFromFile(); }; #endif diff --git a/channelSettingPHA.cpp b/channelSettingPHA.cpp index 9bfc63a..e3b2978 100644 --- a/channelSettingPHA.cpp +++ b/channelSettingPHA.cpp @@ -264,6 +264,7 @@ ChannelSettingPHA::ChannelSettingPHA(const TGWindow *p, UInt_t w, UInt_t h, Digi TGLabel * lbTrapScale = new TGLabel(vfDPPCtrl11, "Trap. Scaling [bit] :"); vfDPPCtrl11->AddFrame(lbTrapScale, haha); numTrapScale = new TGNumberEntry(vfDPPCtrl12, 14, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative ); vfDPPCtrl12->AddFrame(numTrapScale); numTrapScale->Resize(width, 20); + numTrapScale->Connect("Changed()", "ChannelSettingPHA", this, "SetDPPAlgorithm1()"); TGLabel * lbDecimation = new TGLabel(vfDPPCtrl11, "Decimation :"); vfDPPCtrl11->AddFrame(lbDecimation, haha); cbDecimation = new TGComboBox(vfDPPCtrl12); vfDPPCtrl12->AddFrame(cbDecimation); @@ -623,7 +624,7 @@ void ChannelSettingPHA::SetDPPAlgorithm1(){ unsigned short ch2ns = digi[boardID]->GetCh2ns(); uint32_t bit = 0; - bit += numTrapScale->GetNumber(); + bit += (unsigned int) numTrapScale->GetNumber(); bit += ((cbDecimation->GetSelected() & 0x3) << 8) ; bit += ((cbDecimationGain->GetSelected() & 0x3) << 10); bit += ((cbPeakMean->GetSelected() & 0x3) << 12);