#include #include #include #include #include #include #include #include #include #include #include "programSetting.h" std::string ProgramSetting::databaseIP = "http://fsunuc.physics.fsu.edu/influx/"; std::string ProgramSetting::databaseName = "testing"; std::string ProgramSetting::DataSavingPath = "/home/catrina/FSUDAQ"; std::string ProgramSetting::ExpName = "Test"; std::string ProgramSetting::ElogIP = "128.186.111.127"; const std::string ProgramSetting::settingFileName = "FSUDAQ.sh"; ///this is declared at FSUDAQ.cpp extern unsigned short lastRunID; ProgramSetting::ProgramSetting(const TGWindow *p){ printf("----- %s \n", __func__); fMain = new TGMainFrame(p, 600, 400); fMain->SetWindowName("Program Setting"); fMain->Connect("CloseWindow()", "ProgramSetting", this, "CloseWindow()"); TGLayoutHints * haha = new TGLayoutHints(kLHintsRight | kLHintsCenterY, 5,5,5,2); TGLayoutHints * kaka = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5,5,0,0); TGVerticalFrame * vframe = new TGVerticalFrame(fMain); fMain->AddFrame(vframe); {///============== Data Saving Path TGGroupFrame * gfData = new TGGroupFrame(vframe, "Data Storage", kHorizontalFrame); vframe->AddFrame(gfData, new TGLayoutHints(kLHintsNormal, 5, 5, 5, 5)); TGHorizontalFrame * hfData = new TGHorizontalFrame(gfData); gfData->AddFrame(hfData, new TGLayoutHints(kLHintsNormal, 0, 0, 5, 0)); TGVerticalFrame * vfLabel = new TGVerticalFrame(hfData, 200); hfData->AddFrame(vfLabel ); TGVerticalFrame * vfTxt = new TGVerticalFrame(hfData); hfData->AddFrame(vfTxt); TGVerticalFrame * vfAux = new TGVerticalFrame(hfData); hfData->AddFrame(vfAux); TGLabel * lbExpName = new TGLabel(vfLabel, "ExpName :"); vfLabel->AddFrame(lbExpName, haha); TGLabel * lbDataPath = new TGLabel(vfLabel, "Data Absolute Path :"); vfLabel->AddFrame(lbDataPath, haha); txtExpName = new TGTextEntry(vfTxt, ExpName.c_str()); vfTxt->AddFrame(txtExpName, kaka); txtExpName->Connect("ReturnPressed()", "ProgramSetting", this, "SetSetting()"); txtExpName->Resize(300, 20); txtDataPath = new TGTextEntry(vfTxt, DataSavingPath.c_str()); vfTxt->AddFrame(txtDataPath, kaka); txtDataPath->Connect("ReturnPressed()", "ProgramSetting", this, "SetSetting()"); txtDataPath->Resize(300, 20); TGLabel * lbdummy0 = new TGLabel(vfAux, ""); vfAux->AddFrame(lbdummy0, haha); TGTextButton * bSetFolder = new TGTextButton(vfAux, "Set Folder"); vfAux->AddFrame(bSetFolder, kaka); bSetFolder->Connect("Clicked()", "ProgramSetting", this, "SetFolder()"); } {///============== Database & Elog TGGroupFrame * gfDatabase = new TGGroupFrame(vframe, "Database & Elog Setting", kHorizontalFrame); vframe->AddFrame(gfDatabase, new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5)); TGHorizontalFrame * hfDB1 = new TGHorizontalFrame(gfDatabase); gfDatabase->AddFrame(hfDB1, new TGLayoutHints(kLHintsNormal, 0, 0, 5, 0)); TGVerticalFrame * vfLabel = new TGVerticalFrame(hfDB1, 200); hfDB1->AddFrame(vfLabel); TGVerticalFrame * vfTxt = new TGVerticalFrame(hfDB1); hfDB1->AddFrame(vfTxt); TGLabel * lbIP = new TGLabel(vfLabel, "IP :"); vfLabel->AddFrame(lbIP, haha); TGLabel * lbDBName = new TGLabel(vfLabel, "DB Name :"); vfLabel->AddFrame(lbDBName, haha); TGLabel * lbElogIP = new TGLabel(vfLabel, "Elog IP :"); vfLabel->AddFrame(lbElogIP, haha); txtIP = new TGTextEntry(vfTxt, databaseIP.c_str()); vfTxt->AddFrame(txtIP, kaka); txtIP->Resize(300, 20); txtIP->Connect("ReturnPressed()", "ProgramSetting", this, "SetSetting()"); txtDBName = new TGTextEntry(vfTxt, databaseName.c_str()); vfTxt->AddFrame(txtDBName, kaka); txtDBName->Resize(300, 20); txtDBName->Connect("ReturnPressed()", "ProgramSetting", this, "SetSetting()"); txtElogIP = new TGTextEntry(vfTxt, ElogIP.c_str()); vfTxt->AddFrame(txtElogIP, kaka); txtElogIP->Resize(300, 20); txtElogIP->Connect("ReturnPressed()", "ProgramSetting", this, "SetSetting()"); } {///============== Read Time event building } fMain->MapSubwindows(); fMain->Resize(fMain->GetDefaultSize()); fMain->MapWindow(); } ProgramSetting::~ProgramSetting(){ printf("----- %s \n", __func__); delete txtIP; delete txtDBName; delete txtDataPath; delete txtExpName; delete txtElogIP; fMain->Cleanup(); delete fMain; } void ProgramSetting::SetSetting(){ DataSavingPath = txtDataPath->GetText(); ExpName = txtExpName->GetText(); databaseIP = txtIP->GetText(); databaseName = txtDBName->GetText(); ElogIP = txtElogIP->GetText(); PrintSettings(); SaveProgramSetting(); Emit("SetSetting()"); } void ProgramSetting::SetFolder(){ const char *filetypes[] = { "All Files", "*.*", 0, 0 }; TGFileInfo fi; fi.fFileTypes = filetypes; fi.SetIniDir("."); printf("fIniDir = %s\n", fi.fIniDir); new TGFileDialog(gClient->GetRoot(), fMain, kDOpen, &fi); printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir); if( fi.fFilename == NULL) return; txtDataPath->SetText(fi.fFilename); SetSetting(); } void ProgramSetting::PrintSettings(){ printf("Data Saving Path : %s\n", DataSavingPath.c_str()); printf(" ExpName : %s\n", ExpName.c_str()); printf(" IP : %s\n", databaseIP.c_str()); printf(" Name : %s\n", databaseName.c_str()); printf(" Elog IP : %s\n", ElogIP.c_str()); printf(" last run ID : %d\n", lastRunID); } void ProgramSetting::LoadProgramSetting(){ std::ifstream fileIn; fileIn.open(ProgramSetting::settingFileName.c_str(), std::ios::in); if( fileIn ){ std::string line; int lineNum = 0; size_t pos = 0; while (fileIn.good() ){ std::getline(fileIn, line); lineNum ++; pos = line.find("="); if( pos > 1 ){ pos += 2; ///printf("%d | %s , %d \n", lineNum, line.c_str(), pos); switch ( lineNum ){ case 1: ProgramSetting::ExpName = line.substr(pos); break; case 2: ProgramSetting::DataSavingPath = line.substr(pos); break; case 3: ProgramSetting::databaseIP = line.substr(pos); break; case 4: ProgramSetting::databaseName = line.substr(pos); break; case 5: ProgramSetting::ElogIP = line.substr(pos); break; case 6: lastRunID = std::atoi(line.substr(pos).c_str()); break; } } } fileIn.close(); }else{ printf("%s | Cannot open file : %s.\n", __func__, ProgramSetting::settingFileName.c_str()); printf("Creating One with default setting"); SaveProgramSetting(); } PrintSettings(); } void ProgramSetting::SaveProgramSetting(){ printf("+++++++ %s \n", __func__); FILE * fileOut = fopen(ProgramSetting::settingFileName.c_str(), "w"); if( fileOut != NULL ){ fputs( ("ExpName = " + ProgramSetting::ExpName + "\n").c_str(), fileOut); fputs( ("DataPath = " + ProgramSetting::DataSavingPath + "\n").c_str(), fileOut); fputs( ("DatabaseIP = " + ProgramSetting::databaseIP + "\n").c_str(), fileOut); fputs( ("DatabaseName = " + ProgramSetting::databaseName + "\n").c_str(), fileOut); fputs( ("ElogIP = " + ProgramSetting::ElogIP + "\n").c_str(), fileOut); fputs( ("lastRunID = " + std::to_string(lastRunID) + "\n").c_str(), fileOut); fclose(fileOut); }else{ printf("%s | Cannot open file : %s.\n", __func__, ProgramSetting::settingFileName.c_str()); } }