From d6a29e1b8f6416389f66af12c978ff906bbfafcc Mon Sep 17 00:00:00 2001 From: "carina@hades" Date: Fri, 14 Oct 2022 18:27:31 -0400 Subject: [PATCH] added programSetting.h/cpp, added bufferSize calculation, not tested --- ClassData.h | 25 ++++++++------ ClassDigitizer.cpp | 79 +++++++++++++++++++++++++++++-------------- ClassDigitizer.h | 64 +++++++++++++++++------------------ FSUDAQ.cpp | 38 ++++++++++----------- FSUDAQ.h | 8 +++-- Makefile | 13 +++---- boardSetting.cpp | 5 --- channelSettingPHA.cpp | 46 ++++--------------------- programSetting.cpp | 67 ++++++++++++++++++++++++++++++++++++ programSetting.h | 38 +++++++++++++++++++++ registerSetting.cpp | 6 ++-- registerSetting.h | 6 ++-- test.cpp | 29 ++++++++++------ 13 files changed, 263 insertions(+), 161 deletions(-) create mode 100644 programSetting.cpp create mode 100644 programSetting.h diff --git a/ClassData.h b/ClassData.h index d37b97b..50418a9 100644 --- a/ClassData.h +++ b/ClassData.h @@ -30,6 +30,7 @@ class Data{ double TriggerRate[MaxNChannels]; /// Hz unsigned long TotNumEvents[MaxNChannels]; unsigned long long Timestamp[MaxNChannels][MaxNData]; + unsigned short fineTime[MaxNChannels][MaxNData]; /// 10 bits, in unit of ch2ns / 1000 = ps unsigned short Energy[MaxNChannels][MaxNData]; unsigned short Energy2[MaxNChannels][MaxNData]; /// in PSD, Energy = Qshort, Energy2 = Qlong @@ -46,6 +47,7 @@ class Data{ ~Data(); void AllocateMemory(); + void AllocateMemory(unsigned long size); void SetSaveWaveToMemory(bool OnOff) { this->SaveWaveToMemory = OnOff; } @@ -98,15 +100,15 @@ inline Data::~Data(){ delete buffer; } -inline void Data::AllocateMemory(){ - +inline void Data::AllocateMemory(unsigned long size){ delete buffer; - //TODO calculate Suitable buffer size - BufferSize = 10* 1024* 1024; /// 10M byte + BufferSize = size; buffer = (char *) malloc( BufferSize); printf("Allocated %d byte for buffer \n", BufferSize); - ///for( int i = 0 ; i < MaxNChannels ; i++ ) Events[i] = (CAEN_DGTZ_DPP_PHA_Event_t *) malloc( BufferSize); - ///printf("Allocated %d byte for Events for each channel \n", BufferSize); +} + +inline void Data::AllocateMemory(){ + AllocateMemory( 10 * 1024 * 1024 ); /// 10 M Byte } inline void Data::ClearTriggerRate(){ for( int i = 0 ; i < MaxNChannels; i++) TriggerRate[i] = 0.0; } @@ -121,6 +123,7 @@ inline void Data::ClearData(){ ///TriggerRate[i] = 0.0; for( int j = 0; j < MaxNData; j++){ Timestamp[i][j] = 0; + fineTime[i][j] = 0; Energy[i][j] = 0; Energy2[i][j] = 0; Waveform1[i][j].clear(); @@ -400,9 +403,9 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe nw = nw +1 ; word = ReadBuffer(nw, verbose); unsigned int extra2 = word; unsigned long long extTimeStamp = 0; - if( extra2Option == 0 || extra2Option == 2 ) extTimeStamp = (extra2 >> 15); + if( extra2Option == 0 || extra2Option == 2 ) extTimeStamp = (extra2 >> 16); - unsigned long long timeStamp = (extTimeStamp << 30) ; + unsigned long long timeStamp = (extTimeStamp << 31) ; timeStamp = timeStamp + timeStamp0; if( verbose >= 2) printf("TimeStamp : %llu\n", timeStamp); @@ -432,7 +435,7 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe if( rollOver == 0 ) { Energy[channel][NumEvents[channel]] = energy; Timestamp[channel][NumEvents[channel]] = timeStamp; - + if(extra2Option == 0 || extra2Option == 2 ) fineTime[channel][NumEvents[channel]] = (extra2 & 0x07FF ); NumEvents[channel] ++; TotNumEvents[channel] ++; } @@ -591,9 +594,9 @@ inline int Data::DecodePSDDualChannelBlock(unsigned int ChannelMask, bool fastDe nw = nw +1 ; word = ReadBuffer(nw, verbose); unsigned int extra = word; unsigned long long extTimeStamp = 0; - if( extraOption == 0 || extraOption == 2 ) extTimeStamp = (extra >> 15); + if( extraOption == 0 || extraOption == 2 ) extTimeStamp = (extra >> 16); - unsigned long long timeStamp = (extTimeStamp << 30) ; + unsigned long long timeStamp = (extTimeStamp << 31) ; timeStamp = timeStamp + timeStamp0; nw = nw +1 ; word = ReadBuffer(nw, verbose); diff --git a/ClassDigitizer.cpp b/ClassDigitizer.cpp index a211ff0..3a27d26 100644 --- a/ClassDigitizer.cpp +++ b/ClassDigitizer.cpp @@ -20,7 +20,7 @@ void Digitizer::Initalization(){ portID = -1; boardID = -1; handle = -1; - NChannel = 0; + NChannel = 16; ADCbits = 1; DPPType = 0; DPPTypeStr = ""; @@ -58,7 +58,7 @@ void Digitizer::Reset(){ } -void Digitizer::PrintBoard(){ +void Digitizer::PrintBoard (){ printf("Connected to Model %s with handle %d using %s\n", BoardInfo.ModelName, handle, LinkType == CAEN_DGTZ_USB ? "USB" : "Optical Link"); printf("Sampling rate : %.0f MHz = %.1f ns \n", 1000/ch2ns, ch2ns); printf("Number of Channels : %d = 0x%X\n", NChannel, channelMask); @@ -313,9 +313,9 @@ int Digitizer::ProgramPHABoard(){ ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(Register::DPP::PreTrigger) + 0x7000 , 124 ); ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(Register::DPP::InputDynamicRange) + 0x7000 , 0x0 ); - ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(Register::DPP::NumberEventsPerAggregate_G) + 0x7000, 511); + ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(Register::DPP::NumberEventsPerAggregate_G) + 0x7000, 10); ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(Register::DPP::AggregateOrganization), 0); - ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(Register::DPP::MaxAggregatePerBlockTransfer), 40); + ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(Register::DPP::MaxAggregatePerBlockTransfer), 200); ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(Register::DPP::DPPAlgorithmControl) + 0x7000, 0xe30200f); if( ret != 0 ) { printf("==== set channels error.\n"); return 0;} @@ -350,16 +350,47 @@ void Digitizer::StopACQ(){ } unsigned int Digitizer::CalByteForBuffer(){ + unsigned int numAggBLT; + unsigned int chMask ; + unsigned int boardCfg ; + unsigned int eventAgg[NChannel/2]; + unsigned int recordLength[NChannel/2]; - //TODO - unsigned int numAggBLT = ReadRegister(Register::DPP::MaxAggregatePerBlockTransfer); + if( isConnected ){ + numAggBLT = ReadRegister(Register::DPP::MaxAggregatePerBlockTransfer, 0, false); + chMask = ReadRegister(Register::DPP::ChannelEnableMask, 0, false); + boardCfg = ReadRegister(Register::DPP::BoardConfiguration, 0, false); + + for( int pCh = 0; pCh < NChannel/2; pCh++){ + eventAgg[pCh] = ReadRegister(Register::DPP::NumberEventsPerAggregate_G, pCh * 2 , false); + recordLength[pCh] = ReadRegister(Register::DPP::RecordLength_G, pCh * 2 , false); + } + }else{ + numAggBLT = GetSettingFromMemory(Register::DPP::MaxAggregatePerBlockTransfer); + chMask = GetSettingFromMemory(Register::DPP::ChannelEnableMask); + boardCfg = GetSettingFromMemory(Register::DPP::BoardConfiguration); + for( int pCh = 0; pCh < NChannel/2; pCh++){ + eventAgg[pCh] = GetSettingFromMemory(Register::DPP::NumberEventsPerAggregate_G, pCh * 2 ); + recordLength[pCh] = GetSettingFromMemory(Register::DPP::RecordLength_G, pCh * 2); + } + } - /// Channel Mask - /// is takeing waveForm - /// Record Length + //printf(" Channel Mask : %04X \n", chMask); + //printf("Max number of Agg per Readout : %u \n", numAggBLT); + //printf(" is Extra2 enabed : %u \n", ((boardCfg >> 17) & 0x1) ); + // + //for( int pCh = 0; pCh < NChannel/2; pCh++){ + // printf("Paied Ch : %d, RecordLength (bit value): %u, Event per Agg. : %u \n", pCh, recordLength[pCh], eventAgg[pCh]); + //} - return 0; + unsigned int bufferSize = 4; /// Board Agg. header + /// Cal size for each dual channel aggregation + for( int pCh = 0; pCh < NChannel/2 ; pCh++){ + if( (chMask & ( 3 << (2 * pCh) )) == 0 ) continue; + bufferSize += ( 2 + ((boardCfg >> 17) & 0x1) + recordLength[pCh]*4 ) * eventAgg[pCh] ; + } + return bufferSize * 4 * numAggBLT; /// 1 word = 4 byte; } void Digitizer::ReadData(){ @@ -383,7 +414,7 @@ void Digitizer::ReadData(){ //=========================================================== //=========================================================== //=========================================================== -void Digitizer::WriteRegister(Reg registerAddress, uint32_t value, int ch, bool isSave2MemAndFile){ +void Digitizer::WriteRegister (Reg registerAddress, uint32_t value, int ch, bool isSave2MemAndFile){ if( !isConnected ) return; //printf("0x%X, ch:%02d, 0x%X=%u\n", registerAddress, ch, value, value); @@ -396,7 +427,7 @@ void Digitizer::WriteRegister(Reg registerAddress, uint32_t value, int ch, bool ErrorMsg("WriteRegister:" + std::to_string(registerAddress)); } -uint32_t Digitizer::ReadRegister(Reg registerAddress, unsigned short ch, bool isSave2MemAndFile, string str ){ +uint32_t Digitizer::ReadRegister(Reg registerAddress, unsigned short ch, bool isSave2MemAndFile, std::string str ){ if( !isConnected ) return 0; uint32_t data[1]; @@ -410,7 +441,6 @@ uint32_t Digitizer::ReadRegister(Reg registerAddress, unsigned short ch, bool is if( str != "" ) printf("%s : 0x%04X(0x%04X) is 0x%08X \n", str.c_str(), registerAddress.ActualAddress(ch), registerAddress.GetAddress(), data[0]); return data[0]; - } void Digitizer::PrintACQStatue(){ @@ -420,7 +450,7 @@ void Digitizer::PrintACQStatue(){ printf("=================== Print ACQ status \n"); printf(" 32 28 24 20 16 12 8 4 0\n"); printf(" | | | | | | | | |\n"); - cout <<" 0b" << bitset<32>(status) << endl; + std::cout <<" 0b" << std::bitset<32>(status) << std::endl; printf(" Acq state (0x%1X): %s \n", (status >> 2) & 0x1, ((status >> 2) & 0x1) == 0? "stopped" : "running"); printf(" Event Ready (0x%1X): %s \n", (status >> 3) & 0x1, ((status >> 3) & 0x1) == 0? "no event in buffer" : "event in buffer"); printf(" Event Full (0x%1X): %s \n", (status >> 4) & 0x1, ((status >> 4) & 0x1) == 0? "not full" : "full"); @@ -429,11 +459,9 @@ void Digitizer::PrintACQStatue(){ printf(" Ch shutDown (0x%1X): %s \n", (status >> 19) & 0x1, ((status >> 19) & 0x1) == 0? "Channels are on" : "channels are shutdown"); printf(" TRG-IN 0x%1X \n", (status >> 16) & 0x1); printf(" Ch temp state 0x%04X \n", (status >> 20) & 0xF); - } //========================================== setting file IO - Reg Digitizer::FindRegister(uint32_t address){ Reg tempReg; @@ -513,13 +541,13 @@ void Digitizer::ProgramSettingsToBoard(){ } } -void Digitizer::SetSettingToMemory(Reg registerAddress, unsigned int value, int ch ){ +void Digitizer::SetSettingToMemory(Reg registerAddress, unsigned int value, unsigned short ch ){ unsigned short index = registerAddress.Index(ch); if( index > SETTINGSIZE ) return; setting[index] = value; } -unsigned int Digitizer::GetSettingFromMemory(Reg registerAddress, int ch ){ +unsigned int Digitizer::GetSettingFromMemory(Reg registerAddress, unsigned short ch ){ unsigned short index = registerAddress.Index(ch); if( index > SETTINGSIZE ) return 0xFFFF; return setting[index] ; @@ -529,7 +557,7 @@ void Digitizer::PrintSettingFromMemory(){ for( int i = 0; i < SETTINGSIZE; i++) printf("%4d | 0x%04X |0x%08X = %u \n", i, i*4, setting[i], setting[i]); } -void Digitizer::OpenSettingBinary(string fileName){ +void Digitizer::OpenSettingBinary(std::string fileName){ if( settingFile != NULL ) delete settingFile; settingFile = fopen(fileName.c_str(), "r+"); @@ -555,7 +583,7 @@ void Digitizer::OpenSettingBinary(string fileName){ } } -void Digitizer::LoadSettingBinary(string fileName){ +void Digitizer::LoadSettingBinary(std::string fileName){ settingFile = fopen(fileName.c_str(), "r+"); @@ -572,11 +600,10 @@ void Digitizer::LoadSettingBinary(string fileName){ size_t dummy = fread( setting, SETTINGSIZE * sizeof(unsigned int), 1, settingFile); ProgramSettingsToBoard(); - } } -unsigned int Digitizer::ReadSettingFromFile(Reg registerAddress, int ch){ +unsigned int Digitizer::ReadSettingFromFile(Reg registerAddress, unsigned short ch){ if ( !settingFileExist ) return -1; unsigned short index = registerAddress.Index(ch); @@ -593,10 +620,10 @@ unsigned int Digitizer::ReadSettingFromFile(Reg registerAddress, int ch){ } -void Digitizer::SaveSettingToFile(Reg registerAddress, unsigned int value, int ch){ +void Digitizer::SaveSettingToFile(Reg registerAddress, unsigned int value, unsigned short ch){ if ( !settingFileExist ) return ; - unsigned short index = registerAddress,Index(ch); + unsigned short index = registerAddress.Index(ch); setting[index] = value; settingFile = fopen (settingFileName.c_str(),"r+"); @@ -608,7 +635,7 @@ void Digitizer::SaveSettingToFile(Reg registerAddress, unsigned int value, int c fclose (settingFile); } -void Digitizer::SaveSettingAsText(string fileName){ +void Digitizer::SaveSettingAsText(std::string fileName){ FILE * txtFile = fopen(fileName.c_str(), "w+"); @@ -651,7 +678,7 @@ void Digitizer::SaveSettingAsText(string fileName){ } } -void Digitizer::ErrorMsg(string header){ +void Digitizer::ErrorMsg(std::string header){ switch (ret){ ///case CAEN_DGTZ_Success : /** 0 */ printf("%s | Operation completed successfully.\n", header.c_str()); break; case CAEN_DGTZ_CommError : /** -1 */ printf("%s | Communication Error.\n", header.c_str()); break; diff --git a/ClassDigitizer.h b/ClassDigitizer.h index 31f17f5..2f50d1d 100644 --- a/ClassDigitizer.h +++ b/ClassDigitizer.h @@ -16,8 +16,6 @@ #include "ClassData.h" #include "RegisterAddress.h" -using namespace std; - //################################################################ class Digitizer{ @@ -50,14 +48,14 @@ class Digitizer{ bool AcqRun; /// true when digitizer is taking data /// ------- setting - string settingFileName; /// + std::string settingFileName; /// FILE * settingFile; /// bool settingFileExist; /// bool isSettingFilledinMemeory; /// false for disabled ReadAllSettingFromBoard() unsigned int setting[SETTINGSIZE]; /// Setting, 4bytes x 2048 = 8192 bytes ///---------- protected functions - void ErrorMsg(string header = ""); + void ErrorMsg(std::string header = ""); public: Digitizer(); /// no digitizer open @@ -72,44 +70,44 @@ class Digitizer{ void Initalization(); void Reset(); - void PrintBoard(); - virtual int ProgramBoard(); /// program a generic board, no program channel - int ProgramPHABoard(); /// program a default PHA board + void PrintBoard() ; + virtual int ProgramBoard() ; /// program a generic board, no program channel + int ProgramPHABoard() ; /// program a default PHA board ///================ ACQ control void StopACQ(); void StartACQ(); void ReadData(); - bool IsRunning() {return AcqRun;} - Data * GetData(){ return data;} + bool IsRunning() const {return AcqRun;} + Data * GetData() const {return data;} void PrintACQStatue(); unsigned int CalByteForBuffer(); ///=================Settings /// write value to digitizer, memory, and settingFile (if exist) - void WriteRegister(Reg registerAddress, uint32_t value, int ch = -1, bool isSave2MemAndFile = true); + void WriteRegister (Reg registerAddress, uint32_t value, int ch = -1, bool isSave2MemAndFile = true); /// read value from digitizer and memory, and save to memory, and settingFile(if exist), /// ch must be >= 0, /// for board setting, ignore ch - uint32_t ReadRegister(Reg registerAddress, unsigned short ch = 0, bool isSave2MemAndFile = true, string str = "" ); + uint32_t ReadRegister (Reg registerAddress, unsigned short ch = 0, bool isSave2MemAndFile = true, std::string str = "" ); uint32_t PrintRegister(uint32_t address, std::string msg); ///================ Get Settings - std::string GetModelName() {return BoardInfo.ModelName;} - int GetSerialNumber() {return BoardInfo.SerialNumber;} - int GetChannelMask() {return channelMask;} - bool GetChannelOnOff(unsigned ch) {return (channelMask & ( 1 << ch) );} - float GetCh2ns() {return ch2ns;} - int GetNChannel() {return NChannel;} - int GetHandle() {return handle;} - bool GetConnectionStatus() {return isConnected;} - int GetDPPType() {return DPPType;} - std::string GetDPPTypeString() {return DPPTypeStr;} - int GetADCBits() {return BoardInfo.ADC_NBits;} - std::string GetROCVersion() {return BoardInfo.ROC_FirmwareRel;} - std::string GetAMCVersion() {return BoardInfo.AMC_FirmwareRel;} - CAEN_DGTZ_ConnectionType GetLinkType() {return LinkType;} + std::string GetModelName() const {return BoardInfo.ModelName;} + int GetSerialNumber() const {return BoardInfo.SerialNumber;} + int GetChannelMask() const {return channelMask;} + bool GetChannelOnOff(unsigned ch) const {return (channelMask & ( 1 << ch) );} + float GetCh2ns() const {return ch2ns;} + int GetNChannel() const {return NChannel;} + int GetHandle() const {return handle;} + bool GetConnectionStatus() const {return isConnected;} + int GetDPPType() const {return DPPType;} + std::string GetDPPTypeString() const {return DPPTypeStr;} + int GetADCBits() const {return BoardInfo.ADC_NBits;} + std::string GetROCVersion() const {return BoardInfo.ROC_FirmwareRel;} + std::string GetAMCVersion() const {return BoardInfo.AMC_FirmwareRel;} + CAEN_DGTZ_ConnectionType GetLinkType() const {return LinkType;} ///================ Setting Reg FindRegister(uint32_t address); @@ -118,18 +116,18 @@ class Digitizer{ void ProgramSettingsToBoard (); /// simply read settings from memory - void SetSettingToMemory (Reg registerAddress, unsigned int value, int ch = -1); - unsigned int GetSettingFromMemory (Reg registerAddress, int ch = -1); + void SetSettingToMemory (Reg registerAddress, unsigned int value, unsigned short ch = -1); + unsigned int GetSettingFromMemory (Reg registerAddress, unsigned short ch = -1); void PrintSettingFromMemory (); unsigned int * GetSetting() {return setting;}; /// memory <--> file - void SaveSettingAsText (string fileName); - string GetSettingFileName() {return settingFileName;} - void OpenSettingBinary (string fileName); /// Open setting file, if file not exist, call create and save settings, if file exit set the settignFileName but not overwrite - void LoadSettingBinary (string fileName); /// load settign file to memory, if digitizer connected, program digitizer - void SaveSettingToFile (Reg registerAddress, unsigned int value, int ch = -1); - unsigned int ReadSettingFromFile (Reg registerAddress, int ch = -1); /// read from setting binary + void SaveSettingAsText (std::string fileName); + std::string GetSettingFileName() {return settingFileName;} + void OpenSettingBinary (std::string fileName); /// Open setting file, if file not exist, call create and save settings, if file exit set the settignFileName but not overwrite + void LoadSettingBinary (std::string fileName); /// load settign file to memory, if digitizer connected, program digitizer + void SaveSettingToFile (Reg registerAddress, unsigned int value, unsigned short ch = 0); /// also save to memory + unsigned int ReadSettingFromFile (Reg registerAddress, unsigned short ch = 0); /// read from setting binary ///=================== Relic methods ///void SetRecordLength (unsigned int ns, int ch = -1); /// when ch == -1, mean set all channels diff --git a/FSUDAQ.cpp b/FSUDAQ.cpp index d0fb9a2..1715c0f 100644 --- a/FSUDAQ.cpp +++ b/FSUDAQ.cpp @@ -26,15 +26,13 @@ enum MenuIdentifiers{ M_FILE_OPEN, M_EXIT, M_LOAD_SETTINGS, - M_VIEW_SETTINGS, // TODO M_TRIGGER_SUMMARY, M_CH_SETTING_PHA, M_CH_SETTING_PSD, M_REGISTER_SETTING, M_BOARD_SETTINGS, M_PROGRAM_SETTINGS, - M_FINDPEAKS, - M_SHOW_CHANNELS_RATE + M_FINDPEAKS }; enum ModeIdentifiers{ @@ -103,16 +101,15 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) { fMenuDigitizers->AddEntry("&Channel Settings (PHA)", M_CH_SETTING_PHA); fMenuDigitizers->AddEntry("&Channel Settings (PSD)", M_CH_SETTING_PSD); fMenuDigitizers->AddEntry("&Register Setting", M_REGISTER_SETTING); - //fMenuDigitizers->AddSeparator(); - //fMenuDigitizers->AddEntry("&Program Settings", M_PROGRAM_SETTINGS); + fMenuDigitizers->AddSeparator(); + fMenuDigitizers->AddEntry("&Program Settings", M_PROGRAM_SETTINGS); fMenuDigitizers->Connect("Activated(Int_t)", "MainWindow", this, "HandleMenu(Int_t)"); fMenuBar->AddPopup("&Digitizers", fMenuDigitizers, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0)); fMenuDigitizers->DisableEntry( M_REGISTER_SETTING); fMenuUtility = new TGPopupMenu(gClient->GetRoot()); - fMenuUtility->AddEntry("Plot Channels Rate", M_SHOW_CHANNELS_RATE); - fMenuDigitizers->AddSeparator(); + //fMenuDigitizers->AddSeparator(); fMenuUtility->AddEntry("Find &Peaks", M_FINDPEAKS); fMenuUtility->Connect("Activated(Int_t)", "MainWindow", this, "HandleMenu(Int_t)"); fMenuBar->AddPopup("&Utility", fMenuUtility, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0)); @@ -204,8 +201,8 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) { /// Map all subwindows of main frame fMain->MapSubwindows(); /// Initialize the layout algorithm - fMain->Resize(fMain->GetDefaultSize()); fMain->SetWMPosition(200, 200); //does not work?? + fMain->Resize(fMain->GetDefaultSize()); /// Map main frame fMain->MapWindow(); @@ -216,8 +213,10 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) { boardSetting = NULL; channelSettingPHA = NULL; + channelSettingPSD = NULL; registerSetting = NULL; - ///scalarPanel = NULL; + triggerSummary = NULL; + programSetting = NULL; LogMsg((char*)"Please \"Open Digitizers\" to start."); @@ -242,17 +241,20 @@ MainWindow::~MainWindow() { delete fMenuFile; delete fMenuDigitizers; delete fMenuUtility; + delete fEcanvas; delete boardIDEntry; delete chIDEntry; delete teLog; - //delete tePath; delete bOpenDigitizers; delete bStartRun; delete bStopRun; delete cbMode; + + delete dataPrefix; + delete runIDEntry; delete bPlotSingleTrace; delete bFitTrace; @@ -262,9 +264,9 @@ MainWindow::~MainWindow() { delete boardSetting; delete channelSettingPHA; delete channelSettingPSD; - delete registerSetting; delete triggerSummary; + delete programSetting; delete fillHistThread; @@ -297,7 +299,7 @@ void MainWindow::HandleMenu(Int_t id){ ///========================= File Open case M_FILE_OPEN:{ - + LogMsg((char *) "Not implemented."); }break; @@ -342,11 +344,9 @@ void MainWindow::HandleMenu(Int_t id){ ///========================= Program setting case M_PROGRAM_SETTINGS:{ - LogMsg((char*)"[Program settings] Not impelmented"); - }break; - - ///====================== Show channel rate; - case M_SHOW_CHANNELS_RATE:{ + programSetting = new ProgramSetting(gClient->GetRoot()); + + LogMsg((char*) Form("database : %s, name : %s ", ProgramSetting::IP.c_str(), ProgramSetting::databaseName.c_str() )); }break; @@ -367,7 +367,7 @@ void MainWindow::OpenDigitizers(){ for( int i = 0 ; i < nDigi; i++ ) delete digi[i]; LogMsg((char*)"============= detect digitizers"); - vector DPPType; + std::vector DPPType; DPPType.clear(); portID.clear(); boardID.clear(); @@ -407,7 +407,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_" + std::to_string(digi[i]->GetSerialNumber()) + ".bin"); } fMenuDigitizers->DisableEntry( M_DIGITIZER_OPEN); diff --git a/FSUDAQ.h b/FSUDAQ.h index 5c4ff93..3c6c2d7 100644 --- a/FSUDAQ.h +++ b/FSUDAQ.h @@ -22,6 +22,7 @@ #include "channelSettingPSD.h" #include "registerSetting.h" #include "triggerSummary.h" +#include "programSetting.h" class TGWindow; class TGMainFrame; @@ -52,9 +53,9 @@ private: TGTextButton *bFitTrace; unsigned short nDigi; - vector portID; - vector boardID; - vector serialNum; + std::vector portID; + std::vector boardID; + std::vector serialNum; static Digitizer ** digi; static BoardSetting * boardSetting; @@ -62,6 +63,7 @@ private: ChannelSettingPSD * channelSettingPSD; RegisterSetting * registerSetting; TriggerSummary * triggerSummary; + ProgramSetting * programSetting; TThread * fillHistThread; diff --git a/Makefile b/Makefile index 23ca7ea..dbcf712 100755 --- a/Makefile +++ b/Makefile @@ -11,8 +11,7 @@ CAENLIBS = -lCAENDigitizer ROOTLIBS = `root-config --cflags --glibs` -#OBJS = channelSettingPSD.o channelSettingPHA.o boardSetting.o ClassDigitizer.o DigitizerPHA.o DigitizerPSD.o FSUDAQ.o -OBJS = triggerSummary.o registerSetting.o channelSettingPSD.o channelSettingPHA.o boardSetting.o ClassDigitizer.o FSUDAQ.o +OBJS = programSetting.o triggerSummary.o registerSetting.o channelSettingPSD.o channelSettingPHA.o boardSetting.o ClassDigitizer.o FSUDAQ.o ######################################################################### @@ -24,12 +23,6 @@ clean : ClassDigitizer.o : ClassDigitizer.cpp ClassDigitizer.h RegisterAddress.h macro.h ClassData.h $(CC) $(COPTS) -c ClassDigitizer.cpp -#DigitizerPHA.o : DigitizerPHA.cpp DigitizerPHA.h ClassDigitizer.o -# $(CC) $(COPTS) -c DigitizerPHA.cpp -# -#DigitizerPSD.o : DigitizerPSD.cpp DigitizerPSD.h ClassDigitizer.o -# $(CC) $(COPTS) -c DigitizerPSD.cpp - test : test.cpp ClassDigitizer.o @echo "--------- making test" $(CC) $(COPTS) -o test test.cpp ClassDigitizer.o $(CAENLIBS) $(ROOTLIBS) @@ -70,6 +63,10 @@ triggerSummary.o : triggerSummary.h triggerSummary.cpp @echo "----------- creating triggerSummary.o" $(CC) $(COPTS) -c triggerSummary.cpp $(ROOTLIBS) +programSetting.o : programSetting.h programSetting.cpp + @echo "----------- creating programSetting.o" + $(CC) $(COPTS) -c programSetting.cpp $(ROOTLIBS) + #CutsCreator: $(OBJS3) src/CutsCreator.c # g++ -std=c++17 -pthread src/CutsCreator.c -o CutsCreator $(ROOTLIBS) diff --git a/boardSetting.cpp b/boardSetting.cpp index 0758920..7897171 100644 --- a/boardSetting.cpp +++ b/boardSetting.cpp @@ -713,11 +713,6 @@ BoardSetting::~BoardSetting(){ isOpened = false; printf("close BoardSetting window\n"); - - //for( int i = 0; i < nDigi; i++) digi[i] = 0; - //pha = 0; - //psd = 0; - //delete readStatusThread; delete boardIDEntry; for(int i = 0; i < NUM_BOARD_INFO; i++) delete entry[i]; diff --git a/channelSettingPHA.cpp b/channelSettingPHA.cpp index 84cab36..9712dc5 100644 --- a/channelSettingPHA.cpp +++ b/channelSettingPHA.cpp @@ -557,46 +557,14 @@ void ChannelSettingPHA::SetAllChannels(){ short ch = chIDEntry->GetNumber(); ///use memory from this channel and set to all other channal - - //digi[boardID] - - - - /* - uint32_t bit = 0; - bit += numTrapScale->GetNumber(); - bit += ((cbDecimation->GetSelected() & 0x3) << 8) ; - bit += ((cbDecimationGain->GetSelected() & 0x3) << 10); - bit += ((cbPeakMean->GetSelected() & 0x3) << 12); - bit += ((cbPolarity->GetSelected() & 0x3) << 16); - bit += ((cbTriggerMode->GetSelected() & 0x3) << 18); - bit += ((cbBaseLineAvg->GetSelected() & 0x7) << 20); - bit += ((cbDisableSelfTrigger->GetSelected() & 0x1) << 24); - bit += ((cbRollOver->GetSelected() & 0x1) << 26); - bit += ((cbPileUp->GetSelected() & 0x1) << 27); - - printf(" DPP1 bit: 0x%x\n", bit); - digi[boardID]->WriteRegister(Register::DPP::DPPAlgorithmControl, bit, -1); - - bit = 0; - if( cbLocalShapedTrigger->GetSelected() >= 0 ){ - bit += cbLocalShapedTrigger->GetSelected(); - bit += ( 1 << 2); + for( int p = 0; (int) RegisterPHAList.size(); p++){ + unsigned short temp = digi[boardID]->GetSettingFromMemory(RegisterPHAList[p], ch); + + for( int i = 0; i < digi[boardID]->GetNChannel() ; i++){ + if( i == ch ) continue; + digi[boardID]->WriteRegister(RegisterPHAList[p], temp, i); + } } - if( cbLocalTriggerValid->GetSelected() >= 0 ){ - bit += ((cbLocalTriggerValid->GetSelected() << 4) & 0x3); - bit += ( 1 << 6); - } - bit += ((cbExtra2WordOption->GetSelected() & 0x7) << 8 ); - bit += ((cbVetoSource->GetSelected() & 0x3) << 14 ); - bit += ((cbTriggerCounterRate->GetSelected() & 0x3) << 16 ); - bit += ((cbBaselineCal->GetSelected() & 0x1) << 18 ); - bit += ((cbTagCorrelatedEvent->GetSelected() & 0x1) << 19 ); - bit += ((cbBaselineOptimize->GetSelected() & 0x1) << 29 ); - - printf(" DPP2 bit: 0x%x\n", bit); - digi[boardID]->WriteRegister(Register::DPP::PHA::DPPAlgorithmControl2_G, bit, -1); - */ } void ChannelSettingPHA::SetChannelMask(){ diff --git a/programSetting.cpp b/programSetting.cpp new file mode 100644 index 0000000..a5ea67c --- /dev/null +++ b/programSetting.cpp @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "programSetting.h" + +std::string ProgramSetting::IP = "http://fsunuc.physics.fsu.edu/influx/"; +std::string ProgramSetting::databaseName = "testing"; + +ProgramSetting::ProgramSetting(const TGWindow *p){ + fMain = new TGMainFrame(p, 600, 400); + fMain->SetWindowName("Program Setting"); + fMain->Connect("CloseWindow()", "ProgramSetting", this, "CloseWindow()"); + + TGVerticalFrame * vframe = new TGVerticalFrame(fMain); fMain->AddFrame(vframe); + + {///============== Database + TGGroupFrame * gfDatabase = new TGGroupFrame(vframe, "Database Setting", kHorizontalFrame); vframe->AddFrame(gfDatabase, new TGLayoutHints(kLHintsExpandY, 5, 5, 5, 5)); + + TGVerticalFrame * vfDB = new TGVerticalFrame(gfDatabase); gfDatabase->AddFrame(vfDB); + + TGHorizontalFrame * hfDB1 = new TGHorizontalFrame(vfDB); vfDB->AddFrame(hfDB1); + TGLabel * lbIP = new TGLabel(hfDB1, "IP :"); hfDB1->AddFrame(lbIP, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5,5,3,3)); + txtIP = new TGTextEntry(hfDB1, IP.c_str()); hfDB1->AddFrame(txtIP, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5,5,3,3)); + txtIP->Resize(300, 20); + txtIP->Connect("ReturnPressed()", "ProgramSetting", this, "SetDataBase()"); + + TGHorizontalFrame * hfDB2 = new TGHorizontalFrame(vfDB); vfDB->AddFrame(hfDB2); + TGLabel * lbDBName = new TGLabel(hfDB2, "DB Name :"); hfDB2->AddFrame(lbDBName, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5,5,3,3)); + txtDBName = new TGTextEntry(hfDB2, databaseName.c_str()); hfDB2->AddFrame(txtDBName, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5,5,3,3)); + txtDBName->Connect("ReturnPressed()", "ProgramSetting", this, "SetDataBase()"); + + } + + {///============== Read Time event building + + + } + + fMain->MapSubwindows(); + fMain->Resize(fMain->GetDefaultSize()); + fMain->MapWindow(); +} + +ProgramSetting::~ProgramSetting(){ + + delete txtIP; + delete txtDBName; + + fMain->Cleanup(); + delete fMain; +} + +void ProgramSetting::SetDataBase(){ + + IP = txtIP->GetText(); + databaseName = txtDBName->GetText(); + + printf("IP: %s\n", IP.c_str()); + printf("Name: %s\n", databaseName.c_str()); + +} diff --git a/programSetting.h b/programSetting.h new file mode 100644 index 0000000..87b735e --- /dev/null +++ b/programSetting.h @@ -0,0 +1,38 @@ +#ifndef PROGRAM_SETTING_H +#define PROGRAM_SETTING_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "ClassDigitizer.h" +#include "macro.h" + +class TGWindow; +class TGMainFrame; + +class ProgramSetting{ + RQ_OBJECT("ProgramSetting") + private: + TGMainFrame * fMain; + + TGTextEntry * txtIP; + TGTextEntry * txtDBName; + + public: + ProgramSetting(const TGWindow *p); + virtual ~ProgramSetting(); + + void CloseWindow() { delete this;} + + static std::string IP; + static std::string databaseName; + + void SetDataBase(); +}; + +#endif diff --git a/registerSetting.cpp b/registerSetting.cpp index 4882fd7..901156d 100644 --- a/registerSetting.cpp +++ b/registerSetting.cpp @@ -134,14 +134,16 @@ RegisterSetting::~RegisterSetting(){ delete bSetALLChannel; delete lbValueUnit; - delete txtInfo; + //delete txtInfo; for(int i = 0; i < MaxNChannels; i++) { delete txtValueHex[i]; delete txtValueDec[i]; delete txtValueUnit[i]; } - + + for( int i = 0; i < nDigi; i++ ) digi[i] = 0; + fMain->Cleanup(); delete fMain; diff --git a/registerSetting.h b/registerSetting.h index 7c5b8e7..cb851c4 100644 --- a/registerSetting.h +++ b/registerSetting.h @@ -26,15 +26,13 @@ class RegisterSetting{ TGComboBox * cbName; TGCheckButton * bSetALLChannel; + TGLabel * lbValueUnit; + //TGLabel * txtInfo; TGTextEntry * txtValueHex[MaxNChannels]; TGTextEntry * txtValueDec[MaxNChannels]; TGTextEntry * txtValueUnit[MaxNChannels]; - TGLabel * lbValueUnit; - - TGLabel * txtInfo; - unsigned int value[MaxNChannels]; int textID; diff --git a/test.cpp b/test.cpp index d1e64e6..ba9eddb 100644 --- a/test.cpp +++ b/test.cpp @@ -8,8 +8,8 @@ #include "TGraph.h" #include "TH1.h" -#include /* struct timeval, select() */ -#include /* tcgetattr(), tcsetattr() */ +#include /** struct timeval, select() */ +#include /** tcgetattr(), tcsetattr() */ static struct termios g_old_kbd_mode; @@ -19,7 +19,7 @@ static void cooked(void){ static void uncooked(void){ struct termios new_kbd_mode; - /* put keyboard (stdin, actually) in raw, unbuffered mode */ + /** put keyboard (stdin, actually) in raw, unbuffered mode */ tcgetattr(0, &g_old_kbd_mode); memcpy(&new_kbd_mode, &g_old_kbd_mode, sizeof(struct termios)); new_kbd_mode.c_lflag &= ~(ICANON | ECHO); @@ -32,9 +32,9 @@ static void raw(void){ static char init; if(init) return; - /* put keyboard (stdin, actually) in raw, unbuffered mode */ + /** put keyboard (stdin, actually) in raw, unbuffered mode */ uncooked(); - /* when we exit, go back to normal, "cooked" mode */ + /** when we exit, go back to normal, "cooked" mode */ atexit(cooked); init = 1; @@ -47,7 +47,7 @@ int keyboardhit(){ int status; raw(); - /* check stdin (fd 0) for activity */ + /** check stdin (fd 0) for activity */ FD_ZERO(&read_handles); FD_SET(0, &read_handles); timeout.tv_sec = timeout.tv_usec = 0; @@ -61,11 +61,9 @@ int keyboardhit(){ int getch(void){ unsigned char temp; - raw(); - /* stdin = fd 0 */ + /** stdin = fd 0 */ if(read(0, &temp, 1) != 1) return 0; - //printf("%s", &temp); return temp; } @@ -91,9 +89,18 @@ int main(int argc, char* argv[]){ //dig->OpenSettingBinary("setting_323.bin"); dig->LoadSettingBinary("setting_323.bin"); //dig->PrintSettingFromMemory(); - printf("##############################################################\n"); - dig->SaveSettingAsText("haha.txt"); + //printf("##############################################################\n"); + //dig->SaveSettingAsText("haha.txt"); + //for( int i = 0; i < dig->GetNChannel(); i++){ + // dig->SaveSettingToFile(Register::DPP::NumberEventsPerAggregate_G, 10, i); + //} + + dig->SaveSettingToFile(Register::DPP::MaxAggregatePerBlockTransfer, 200, 0); + + unsigned int bSize = dig->CalByteForBuffer(); + + printf("Buffer Size : %u byte = %.2f MB \n", bSize, bSize/1024./1024.); /* const int nBoard = 2;