2022-10-14 18:27:31 -04:00
|
|
|
#include <TApplication.h>
|
|
|
|
#include <TGClient.h>
|
2022-10-31 16:39:19 -04:00
|
|
|
#include <TSystem.h>
|
2022-10-14 18:27:31 -04:00
|
|
|
#include <TCanvas.h>
|
|
|
|
#include <TF1.h>
|
|
|
|
#include <TRandom.h>
|
|
|
|
#include <TRootEmbeddedCanvas.h>
|
|
|
|
#include <TGTableContainer.h>
|
|
|
|
#include <TGFileDialog.h>
|
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
2022-10-31 16:39:19 -04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <experimental/filesystem>
|
2022-10-26 18:38:55 -04:00
|
|
|
|
2022-10-14 18:27:31 -04:00
|
|
|
#include "programSetting.h"
|
|
|
|
|
2022-10-31 16:39:19 -04:00
|
|
|
namespace fs = std::experimental::filesystem;
|
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
std::string ProgramSetting::databaseIP = "http://fsunuc.physics.fsu.edu/influx/";
|
2022-10-14 18:27:31 -04:00
|
|
|
std::string ProgramSetting::databaseName = "testing";
|
2022-10-31 15:00:04 -04:00
|
|
|
std::string ProgramSetting::DataSavingPath = "/home/catrina/FSUDAQ";
|
2022-10-26 18:38:55 -04:00
|
|
|
std::string ProgramSetting::ExpName = "Test";
|
|
|
|
std::string ProgramSetting::ElogIP = "128.186.111.127";
|
|
|
|
|
2022-10-31 16:39:19 -04:00
|
|
|
bool ProgramSetting::EnableElog = false;
|
|
|
|
bool ProgramSetting::EnableDatabase = false;
|
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
const std::string ProgramSetting::settingFileName = "FSUDAQ.sh";
|
|
|
|
|
|
|
|
///this is declared at FSUDAQ.cpp
|
|
|
|
extern unsigned short lastRunID;
|
2022-10-31 16:39:19 -04:00
|
|
|
extern unsigned short nDigi;
|
|
|
|
extern Digitizer ** digi;
|
2022-10-14 18:27:31 -04:00
|
|
|
|
|
|
|
ProgramSetting::ProgramSetting(const TGWindow *p){
|
2022-10-31 15:00:04 -04:00
|
|
|
|
|
|
|
printf("----- %s \n", __func__);
|
|
|
|
|
2022-10-14 18:27:31 -04:00
|
|
|
fMain = new TGMainFrame(p, 600, 400);
|
|
|
|
fMain->SetWindowName("Program Setting");
|
|
|
|
fMain->Connect("CloseWindow()", "ProgramSetting", this, "CloseWindow()");
|
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
TGLayoutHints * haha = new TGLayoutHints(kLHintsRight | kLHintsCenterY, 5,5,5,2);
|
|
|
|
TGLayoutHints * kaka = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5,5,0,0);
|
|
|
|
|
2022-10-14 18:27:31 -04:00
|
|
|
TGVerticalFrame * vframe = new TGVerticalFrame(fMain); fMain->AddFrame(vframe);
|
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
{///============== Data Saving Path
|
|
|
|
TGGroupFrame * gfData = new TGGroupFrame(vframe, "Data Storage", kHorizontalFrame); vframe->AddFrame(gfData, new TGLayoutHints(kLHintsNormal, 5, 5, 5, 5));
|
2022-10-14 18:27:31 -04:00
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
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);
|
2022-10-31 15:00:04 -04:00
|
|
|
TGVerticalFrame * vfAux = new TGVerticalFrame(hfData); hfData->AddFrame(vfAux);
|
2022-10-14 18:27:31 -04:00
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
TGLabel * lbExpName = new TGLabel(vfLabel, "ExpName :"); vfLabel->AddFrame(lbExpName, haha);
|
|
|
|
TGLabel * lbDataPath = new TGLabel(vfLabel, "Data Absolute Path :"); vfLabel->AddFrame(lbDataPath, haha);
|
2022-10-14 18:27:31 -04:00
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
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);
|
2022-10-14 18:27:31 -04:00
|
|
|
|
2022-10-31 15:00:04 -04:00
|
|
|
|
|
|
|
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()");
|
|
|
|
|
2022-10-14 18:27:31 -04:00
|
|
|
}
|
2022-10-26 18:38:55 -04:00
|
|
|
|
|
|
|
{///============== Database & Elog
|
|
|
|
TGGroupFrame * gfDatabase = new TGGroupFrame(vframe, "Database & Elog Setting", kHorizontalFrame); vframe->AddFrame(gfDatabase, new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5));
|
2022-10-18 17:23:29 -04:00
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
TGHorizontalFrame * hfDB1 = new TGHorizontalFrame(gfDatabase); gfDatabase->AddFrame(hfDB1, new TGLayoutHints(kLHintsNormal, 0, 0, 5, 0));
|
2022-10-18 17:23:29 -04:00
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
TGVerticalFrame * vfLabel = new TGVerticalFrame(hfDB1, 200); hfDB1->AddFrame(vfLabel);
|
|
|
|
TGVerticalFrame * vfTxt = new TGVerticalFrame(hfDB1); hfDB1->AddFrame(vfTxt);
|
2022-10-31 16:39:19 -04:00
|
|
|
TGVerticalFrame * vfOnOff = new TGVerticalFrame(hfDB1); hfDB1->AddFrame(vfOnOff);
|
2022-10-26 18:38:55 -04:00
|
|
|
|
2022-10-31 16:39:19 -04:00
|
|
|
TGLabel * lbIP = new TGLabel(vfLabel, "DB IP :"); vfLabel->AddFrame(lbIP, haha);
|
2022-10-26 18:38:55 -04:00
|
|
|
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()");
|
2022-10-31 16:39:19 -04:00
|
|
|
|
|
|
|
TGLabel * lbdummy0 = new TGLabel(vfOnOff, ""); vfOnOff->AddFrame(lbdummy0, haha);
|
|
|
|
|
|
|
|
cbDatabase = new TGCheckButton(vfOnOff, "Enable Database", 1); vfOnOff->AddFrame(cbDatabase, kaka);
|
|
|
|
cbDatabase->SetState(kButtonUp);
|
|
|
|
cbDatabase->Connect("Clicked()", "ProgramSetting", this, "SetDataBaseElogOnOff()");
|
|
|
|
|
|
|
|
cbElog = new TGCheckButton(vfOnOff, "Enable Elog", 1); vfOnOff->AddFrame(cbElog, kaka);
|
|
|
|
cbElog->SetState(kButtonUp);
|
|
|
|
cbElog->Connect("Clicked()", "ProgramSetting", this, "SetDataBaseElogOnOff()");
|
|
|
|
|
2022-10-18 17:23:29 -04:00
|
|
|
}
|
|
|
|
|
2022-10-14 18:27:31 -04:00
|
|
|
{///============== Read Time event building
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fMain->MapSubwindows();
|
|
|
|
fMain->Resize(fMain->GetDefaultSize());
|
|
|
|
fMain->MapWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgramSetting::~ProgramSetting(){
|
|
|
|
|
2022-10-31 15:00:04 -04:00
|
|
|
printf("----- %s \n", __func__);
|
|
|
|
|
2022-10-14 18:27:31 -04:00
|
|
|
delete txtIP;
|
|
|
|
delete txtDBName;
|
2022-10-26 14:55:06 -04:00
|
|
|
delete txtDataPath;
|
2022-10-26 18:38:55 -04:00
|
|
|
delete txtExpName;
|
|
|
|
delete txtElogIP;
|
2022-10-31 16:39:19 -04:00
|
|
|
|
|
|
|
delete cbDatabase;
|
|
|
|
delete cbElog;
|
2022-10-14 18:27:31 -04:00
|
|
|
|
|
|
|
fMain->Cleanup();
|
|
|
|
delete fMain;
|
|
|
|
}
|
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
void ProgramSetting::SetSetting(){
|
2022-10-14 18:27:31 -04:00
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
DataSavingPath = txtDataPath->GetText();
|
|
|
|
ExpName = txtExpName->GetText();
|
|
|
|
|
|
|
|
databaseIP = txtIP->GetText();
|
2022-10-14 18:27:31 -04:00
|
|
|
databaseName = txtDBName->GetText();
|
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
ElogIP = txtElogIP->GetText();
|
|
|
|
|
|
|
|
PrintSettings();
|
|
|
|
|
|
|
|
SaveProgramSetting();
|
|
|
|
|
2022-10-31 16:39:19 -04:00
|
|
|
gSystem->mkdir(( ProgramSetting::DataSavingPath + "/data").c_str());
|
|
|
|
gSystem->mkdir(( ProgramSetting::DataSavingPath + "/settings").c_str());
|
|
|
|
|
|
|
|
///save digitizer settings to the settings folder
|
|
|
|
for( int i = 0; i < nDigi; i ++){
|
|
|
|
digi[i]->OpenSettingBinary(ProgramSetting::DataSavingPath + "/settings/setting_" + std::to_string(digi[i]->GetSerialNumber()) + ".bin");
|
|
|
|
}
|
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
Emit("SetSetting()");
|
2022-10-14 18:27:31 -04:00
|
|
|
|
|
|
|
}
|
2022-10-18 17:23:29 -04:00
|
|
|
|
2022-10-31 15:00:04 -04:00
|
|
|
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;
|
|
|
|
|
2022-10-31 16:39:19 -04:00
|
|
|
txtDataPath->SetText(fi.fFilename, false);
|
2022-10-31 15:00:04 -04:00
|
|
|
|
|
|
|
SetSetting();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
void ProgramSetting::PrintSettings(){
|
2022-10-18 17:23:29 -04:00
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
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);
|
2022-10-18 17:23:29 -04:00
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProgramSetting::LoadProgramSetting(){
|
|
|
|
|
|
|
|
std::ifstream fileIn;
|
|
|
|
fileIn.open(ProgramSetting::settingFileName.c_str(), std::ios::in);
|
2022-10-18 17:23:29 -04:00
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
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);
|
2022-10-31 16:39:19 -04:00
|
|
|
|
|
|
|
gSystem->CopyFile(ProgramSetting::settingFileName.c_str(), (ProgramSetting::DataSavingPath + "/FSUDAQ.sh").c_str(), true); /// overwrite
|
|
|
|
|
2022-10-26 18:38:55 -04:00
|
|
|
}else{
|
|
|
|
printf("%s | Cannot open file : %s.\n", __func__, ProgramSetting::settingFileName.c_str());
|
|
|
|
}
|
|
|
|
|
2022-10-18 17:23:29 -04:00
|
|
|
}
|
2022-10-31 16:39:19 -04:00
|
|
|
|
|
|
|
void ProgramSetting::SetDataBaseElogOnOff(){
|
|
|
|
|
|
|
|
EnableDatabase = ( cbDatabase->GetState() == kButtonDown ? true : false );
|
|
|
|
EnableElog = ( cbElog->GetState() == kButtonDown ? true : false );
|
|
|
|
|
|
|
|
}
|