isolate Digitizer setting and file logic, MaxAgg fix, add all program setting to FSUDAQ.sh, etc

This commit is contained in:
carina@hades 2022-11-02 15:43:23 -04:00
parent faf30e1aa2
commit 029e56ebbc
14 changed files with 345 additions and 166 deletions

View File

@ -309,7 +309,7 @@ int Digitizer::ProgramPHABoard(){
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::AggregateOrganization), 0);
ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(Register::DPP::AggregateOrganization), 2);
ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(Register::DPP::MaxAggregatePerBlockTransfer), 4);
ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(Register::DPP::DPPAlgorithmControl) + 0x7000, 0xC30200f);
@ -445,7 +445,7 @@ void Digitizer::PrintACQStatue(){
//===========================================================
void Digitizer::WriteRegister (Reg registerAddress, uint32_t value, int ch, bool isSave2MemAndFile){
printf("%s[0x%04X](ch-%02d) [0x%04X]: 0x%08X \n", registerAddress.GetNameChar(), registerAddress.GetAddress(),ch, registerAddress.ActualAddress(ch), value);
printf("%30s[0x%04X](ch-%02d) [0x%04X]: 0x%08X \n", registerAddress.GetNameChar(), registerAddress.GetAddress(),ch, registerAddress.ActualAddress(ch), value);
if( !isConnected ) {
SetSettingToMemory(registerAddress, value, ch);
@ -531,10 +531,12 @@ Reg Digitizer::FindRegister(uint32_t address){
return tempReg;
}
void Digitizer::ReadAllSettingsFromBoard(){
void Digitizer::ReadAllSettingsFromBoard(bool force){
if( !isConnected ) return;
if( isSettingFilledinMemeory ) return;
if( isSettingFilledinMemeory && !force) return;
printf("===== %s \n", __func__);
/// board setting
for( int p = 0; p < (int) RegisterDPPList[p]; p++){
if( RegisterDPPList[p].GetType() == RW::WriteONLY) continue;
@ -563,23 +565,33 @@ void Digitizer::ReadAllSettingsFromBoard(){
void Digitizer::ProgramSettingsToBoard(){
if( !isConnected ) return;
if( isDummy ) return;
Reg haha;
/// board setting
for( int p = 0; p < (int) RegisterDPPList[p]; p++){
if( RegisterDPPList[p].GetType() == RW::ReadONLY) continue;
ReadRegister(RegisterDPPList[p]);
haha = RegisterDPPList[p];
WriteRegister(haha, GetSettingFromMemory(haha), -1, false);
usleep(100 * 1000);
}
/// Channels Setting
for( int ch = 0; ch < NChannel; ch ++){
if( DPPType == V1730_DPP_PHA_CODE ){
for( int p = 0; p < (int) RegisterPHAList[p]; p++){
if( RegisterPHAList[p].GetType() == RW::ReadONLY) continue;
ReadRegister(RegisterPHAList[p], ch);
haha = RegisterPHAList[p];
WriteRegister(haha, GetSettingFromMemory(haha, ch), ch, false);
usleep(100 * 1000);
}
}
if( DPPType == V1730_DPP_PSD_CODE ){
for( int p = 0; p < (int) RegisterPSDList[p]; p++){
if( RegisterPSDList[p].GetType() == RW::ReadONLY) continue;
ReadRegister(RegisterPSDList[p], ch);
haha = RegisterPHAList[p];
WriteRegister(haha, GetSettingFromMemory(haha, ch), ch, false);
usleep(100 * 1000);
}
}
}
@ -601,37 +613,30 @@ 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]);
}
int Digitizer::OpenSettingBinary(std::string fileName){
if( settingFile != NULL ) delete settingFile;
void Digitizer::SetSettingBinaryPath(std::string fileName){
settingFile = fopen(fileName.c_str(), "r+");
if( settingFile == NULL ){
printf("cannot open file %s. Create one.\n", fileName.c_str());
ReadAllSettingsFromBoard();
SaveAllSettingsAsBin(fileName);
this->settingFileName = fileName;
settingFile = fopen(settingFileName.c_str(), "w+");
if( isSettingFilledinMemeory == false) ReadAllSettingsFromBoard();
fwrite(setting, SETTINGSIZE * sizeof(unsigned int), 1, settingFile);
fseek(settingFile, 0L, SEEK_END);
unsigned int inFileSize = ftell(settingFile);
printf("Created file : %s. file size : %d Byte\n", settingFileName.c_str(), inFileSize);
fclose (settingFile);
settingFileExist = true;
return 0;
}else{
this->settingFileName = fileName;
settingFileExist = true;
fclose(settingFile);
printf("setting file already exist. do nothing. Should program the digitizer\n");
return -1;
}
}
int Digitizer::LoadSettingBinary(std::string fileName){
int Digitizer::LoadSettingBinaryToMemory(std::string fileName){
settingFile = fopen(fileName.c_str(), "r+");
settingFile = fopen(fileName.c_str(), "r");
if( settingFile == NULL ) {
printf(" %s does not exist or cannot load.\n", fileName.c_str());
@ -653,15 +658,18 @@ int Digitizer::LoadSettingBinary(std::string fileName){
/// load binary to memoery
DPPType = fileDPP;
printf("DPPType in the file is %s(0x%X). \n", GetDPPString(fileDPP).c_str(), fileDPP);
settingFile = fopen(fileName.c_str(), "r+");
settingFile = fopen(fileName.c_str(), "r");
size_t dummy = fread( setting, SETTINGSIZE * sizeof(unsigned int), 1, settingFile);
fclose (settingFile);
uint32_t boardInfo = GetSettingFromMemory(Register::DPP::BoardInfo_R);
if( (boardInfo & 0xFF) == 0x0E ) ch2ns = 4.0;
if( (boardInfo & 0xFF) == 0x0B ) ch2ns = 2.0;
ProgramSettingsToBoard(); /// do nothing if not connected.
///Should seperate file<->memory, memory<->board
///ProgramSettingsToBoard(); /// do nothing if not connected.
return 0;
}
}
@ -699,10 +707,26 @@ void Digitizer::SaveSettingToFile(Reg registerAddress, unsigned int value, unsig
fclose (settingFile);
}
void Digitizer::SaveSettingAsText(std::string fileName){
void Digitizer::SaveAllSettingsAsBin(std::string fileName){
if( !isSettingFilledinMemeory ) return;
FILE * txtFile = fopen(fileName.c_str(), "w+");
FILE * binFile = fopen(fileName.c_str(), "w+");
if( binFile == NULL ) {
printf("Cannot open %s.\n", fileName.c_str());
return;
}
fwrite(setting, SETTINGSIZE * sizeof(unsigned int), 1, binFile);
fseek(binFile, 0L, SEEK_END);
unsigned int inFileSize = ftell(binFile);
printf("Created file : %s. file size : %d Byte\n", fileName.c_str(), inFileSize);
fclose (binFile);
}
void Digitizer::SaveAllSettingsAsText(std::string fileName){
if( !isSettingFilledinMemeory ) return;
FILE * txtFile = fopen(fileName.c_str(), "w+");
if( txtFile == NULL ) {
printf("Cannot open %s.\n", fileName.c_str());
return;

View File

@ -115,26 +115,25 @@ class Digitizer{
///================ Setting
Reg FindRegister(uint32_t address);
/// board <--> memory functions
void ReadAllSettingsFromBoard ();
void ReadAllSettingsFromBoard (bool force = false);
void ProgramSettingsToBoard ();
/// simply read settings from memory
void SetSettingToMemory (Reg registerAddress, unsigned int value, unsigned short ch = 0);
unsigned int GetSettingFromMemory (Reg registerAddress, unsigned short ch = 0);
void PrintSettingFromMemory ();
unsigned int * GetSetting() {return setting;};
unsigned int * GetSettings() {return setting;};
/// memory <--> file
void SaveSettingAsText (std::string fileName);
void SaveAllSettingsAsText (std::string fileName);
void SaveAllSettingsAsBin (std::string fileName);
std::string GetSettingFileName() {return settingFileName;}
/// Open setting file, if file not exist, call create and save settings, return 0
/// if file exit, set the settignFileName but not overwrite, return -1;
int OpenSettingBinary (std::string fileName);
/// tell the digitizer where to look at the setting file.
/// if not exist, call SaveAllSettinsAsBin();
void SetSettingBinaryPath (std::string fileName);
/// load setting file to memory
/// if connected and DPPtype match, program digitizer
/// else assumed not connected and save settings to memory;
/// if problem, return -1; load without problem, return 0;
int LoadSettingBinary (std::string fileName);
int LoadSettingBinaryToMemory (std::string fileName);
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

View File

@ -408,6 +408,7 @@ void MainWindow::HandleMenu(Int_t id){
case M_PROGRAM_SETTINGS:{
programSetting = new ProgramSetting(gClient->GetRoot());
programSetting->Connect("SetSetting()", "MainWindow", this, "UpdateExpName()");
programSetting->Connect("LogMsg(char*)", "MainWindow", this, "LogMsg(char*)");
}break;
///====================== Fit Gaussian
@ -465,7 +466,12 @@ void MainWindow::OpenDigitizers(){
digi[i]->GetDPPString().c_str(),
digi[i]->GetModelName().c_str()));
digi[i]->OpenSettingBinary(ProgramSetting::DataSavingPath + "/settings/setting_" + std::to_string(digi[i]->GetSerialNumber()) + ".bin");
digi[i]->SetSettingBinaryPath(ProgramSetting::DataSavingPath + "/settings/setting_" + std::to_string(digi[i]->GetSerialNumber()) + ".bin");
///The maxAggBLT is always 1 when open digitizer.
uint32_t maxAggBLT = digi[i]->ReadSettingFromFile(Register::DPP::MaxAggregatePerBlockTransfer);
digi[i]->WriteRegister(Register::DPP::MaxAggregatePerBlockTransfer, maxAggBLT);
}
fMenuDigitizers->DisableEntry( M_DIGITIZER_OPEN);
@ -522,10 +528,11 @@ void MainWindow::LoadSettingFromFile(){
digi = new Digitizer *[1];
nDigi = 1;
digi[0] = new Digitizer();
loadStatus = digi[0]->LoadSettingBinary( fi.fFilename );
loadStatus = digi[0]->LoadSettingBinaryToMemory( fi.fFilename );
boardIDEntry->SetNumber(0, false);
}else{
loadStatus = digi[0]->LoadSettingBinary( fi.fFilename ); /// still dummy digitizer
loadStatus = digi[0]->LoadSettingBinaryToMemory( fi.fFilename );
digi[0]->ProgramSettingsToBoard();
}
HandleMenu(M_BOARD_SETTINGS);
@ -545,13 +552,15 @@ void MainWindow::UpdateExpName(){
}
void MainWindow::MakeElogEntry(bool start){
if( ProgramSetting::EnableElog == false ) return;
TString cmd = Form("%s/DAQ/elogEntry.sh %d", ProgramSetting::programPath.c_str(), start);
if( !ProgramSetting::EnableElog ) return;
printf("==== Creating elog \n");
TString cmd = Form("%s/DAQ/elogEntry.sh %d \"%s\"", ProgramSetting::programPath.c_str(), start, StartStopDialog::Comment.Data());
int temp = system(cmd.Data());
}
void MainWindow::StartRun(){
LogMsg(Form("%s",__func__));
if( digi == NULL) return;
for( int bd = 0; bd < nDigi; bd++){
@ -567,21 +576,8 @@ void MainWindow::StartRun(){
runIDEntry->SetState(false);
bPlotSingleTrace->SetEnabled(false);
bFitTrace->SetEnabled(false);
if( cbDataRun->GetState() == kButtonDown ) {
startStopDialog = new StartStopDialog(gClient->GetRoot(), fMain, 400, 200, true);
}
if( StartStopDialog::isOK){
cbMode->SetEnabled(false);
MakeElogEntry(true);
if( !TriggerSummary::isOpened ) {
triggerSummary = new TriggerSummary(gClient->GetRoot(), 600, 600);
TriggerSummary::isManualOpened = false;
}
if( cbDataRun->GetState() == kButtonUp ) {
bool threadFlag = false;
for( int i = 0 ; i < nDigi; i++) {
digi[i]->StartACQ();
@ -589,20 +585,45 @@ void MainWindow::StartRun(){
}
if( threadFlag ) runThread->Run();
}else{
bStartRun->SetEnabled(true);
bStopRun->SetEnabled(false);
dataPrefix->SetEnabled(true);
runIDEntry->SetState(true);
bPlotSingleTrace->SetEnabled(true);
bFitTrace->SetEnabled(true);
cbMode->SetEnabled(true);
startStopDialog = new StartStopDialog(gClient->GetRoot(), fMain, 400, 200, true);
if( StartStopDialog::isOK){
LogMsg(Form("Start Data Run"));
cbMode->SetEnabled(false);
MakeElogEntry(true);
bool threadFlag = false;
for( int i = 0 ; i < nDigi; i++) {
digi[i]->StartACQ();
if( digi[i]->IsRunning() ) threadFlag = true;
}
if( threadFlag ) runThread->Run();
}else{
bStartRun->SetEnabled(true);
bStopRun->SetEnabled(false);
dataPrefix->SetEnabled(true);
runIDEntry->SetState(true);
bPlotSingleTrace->SetEnabled(true);
bFitTrace->SetEnabled(true);
cbMode->SetEnabled(true);
}
}
if( !TriggerSummary::isOpened ) {
triggerSummary = new TriggerSummary(gClient->GetRoot(), 600, 600);
TriggerSummary::isManualOpened = false;
}
}
void MainWindow::StopRun(){
LogMsg(Form("%s",__func__));
if( digi == NULL) return;
for( int i = 0; i < nDigi; i++) digi[i]->StopACQ();
@ -625,8 +646,11 @@ void MainWindow::StopRun(){
///if( cbMode->GetSelected() == Mode_DataRun ){
if( cbDataRun->GetState() == kButtonDown ) {
startStopDialog = new StartStopDialog(gClient->GetRoot(), fMain, 400, 200, false);
if( StartStopDialog::isOK){
LogMsg(Form("Stop Data Run"));
int runID = runIDEntry->GetNumber();
lastRunID = runID + 1;
runIDEntry->SetNumber(runID +1);

View File

@ -614,6 +614,9 @@ BoardSetting::BoardSetting(const TGWindow *p, UInt_t w, UInt_t h){
TGTextButton * bProgramDefaultBoard = new TGTextButton(vfButton, "Program Default Board"); vfButton->AddFrame(bProgramDefaultBoard, new TGLayoutHints( kLHintsExpandX | kLHintsExpandY, 5, 0, 5, 0));
bProgramDefaultBoard->Connect("Clicked()", "BoardSetting", this, "ProgramDefaultBoard()");
TGTextButton * bProgramBoard = new TGTextButton(vfButton, "Program Board from File"); vfButton->AddFrame(bProgramBoard, new TGLayoutHints( kLHintsExpandX | kLHintsExpandY, 5, 0, 5, 0));
bProgramBoard->Connect("Clicked()", "BoardSetting", this, "ProgramBoardFromLoadedFile()");
TGTextButton * bUpdateStatus = new TGTextButton(vfButton, "Update Status and Settings"); vfButton->AddFrame(bUpdateStatus, new TGLayoutHints( kLHintsExpandX | kLHintsExpandY, 5, 0, 5, 0));
bUpdateStatus->Connect("Clicked()", "BoardSetting", this, "ChangeBoard()");
@ -900,6 +903,7 @@ void BoardSetting::ChangeBoard(){
txtSettingFile->SetText( digi[boardID]->GetSettingFileName().c_str() );
digi[boardID]->ReadAllSettingsFromBoard(true);
for( int i = 0; i < NUM_BOARD_INFO; i++){
switch (i) {
@ -1504,17 +1508,33 @@ void BoardSetting::ProgramBoardFromFile(){
///digi = new Digitizer *[1];
///nDigi = 1;
///digi[0] = new Digitizer();
///loadStatus = digi[0]->LoadSettingBinary( fi.fFilename );
///loadStatus = digi[0]->LoadSettingBinaryToMemory( fi.fFilename );
}else{
int boardID = boardIDEntry->GetNumber();
loadStatus = digi[boardID]->LoadSettingBinary( fi.fFilename );
LogMsg(Form("Program Board %03d From file %s. It may take ~ 10 sec.", digi[boardID]->GetSerialNumber(), fi.fFilename));
loadStatus = digi[boardID]->LoadSettingBinaryToMemory( fi.fFilename );
digi[boardID]->ProgramSettingsToBoard();
}
if( loadStatus == 0 ) ChangeBoard();
if( loadStatus == 0 ) {
ChangeBoard();
}else{
LogMsg(Form("program board fail."));
}
}
void BoardSetting::ProgramBoardFromLoadedFile(){
if( digi == NULL ) return;
int boardID = boardIDEntry->GetNumber();
LogMsg(Form("Program Board %03d From file %s. It may take ~ 10 sec.", digi[boardID]->GetSerialNumber(), digi[boardID]->GetSettingFileName().c_str()));
digi[boardID]->ProgramSettingsToBoard();
ChangeBoard();
}
void BoardSetting::SaveSettingFile(){
const char *filetypes[] = { "Setting File", "*.bin",
@ -1540,11 +1560,11 @@ void BoardSetting::SaveSettingFile(){
}else{
int boardID = boardIDEntry->GetNumber();
digi[boardID]->OpenSettingBinary( fi.fFilename );
digi[boardID]->SaveAllSettingsAsBin( fi.fFilename );
}
}else if( temp == "txt") {
int boardID = boardIDEntry->GetNumber();
digi[boardID]->SaveSettingAsText( fi.fFilename );
digi[boardID]->SaveAllSettingsAsText( fi.fFilename );
}else{
LogMsg("Invalid file extension.");
}

View File

@ -181,6 +181,7 @@ class BoardSetting{
void ReadData();
void ProgramDefaultBoard();
void ProgramBoardFromFile();
void ProgramBoardFromLoadedFile();
void SaveSettingFile();
void CaliADC();

View File

@ -2,14 +2,63 @@
source ~/FSUDAQ/FSUDAQ.sh
echo $ElogIP
elogFileName="elogText.txt"
echo "======================================= making elog Entry"
echo ${DataPath}
echo ${ExpName}
echo ${ElogIP}
#make text file for elog text
echo "**************************************" > ${elogFileName}
echo "Run-${lastRunID} start at $(date)" >> ${elogFileName}
elogIDFile=${DataPath}"/elogID.txt"
source ${elogIDFile}
echo ${ElogID}
isStart=$1
Comment=$2
#push to elog
elog -h ${ElogIP} -l ${ExpName} -u GeneralFox fsuphysics888 -a Author="GeneralFox" -a Category="Run" -a RunNo=${lastRunID} -a Subject="Start Run" -n 2 -m elogText.txt
elogFileName=${DataPath}"/elogText.txt"
echo ${isStart}
echo ${Comment}
if [ ${isStart} == "1" ]; then
#make text file for elog text
echo "**************************************" > ${elogFileName}
echo "Run-${lastRunID} start at $(date)" >> ${elogFileName}
echo ${Comment} >> ${elogFileName}
#push to elog
IDStr=$(elog -h ${ElogIP} -l ${ExpName} -u GeneralFox fsuphysics888 -a Author="GeneralFox" -a Category="Run" -a RunNo=${lastRunID} -a Subject="Run Log" -n 2 -m elogText.txt)
IDStr=$(echo ${IDStr} | tail -1 | awk '{print $4}')
echo ${IDStr}
if [ ${IDStr:0:3} == "ID=" ] && [[ ${IDStr:3} =~ ${re} ]]; then
elogIDStr="Elog"${IDStr}
echo "Elog is succefully pushed at ${elogIDStr}"
echo ${elogIDStr} >> ${elogIDFile}
fi
else
elogFileName2=elogText2.txt
#download elog entry
echo "====== getting elog entry"
elog -h ${ElogIP} -l elog/${ExpName} -u GeneralFox fsuphysics888 -w ${ElogID} > ${elogFileName2}
echo "======================="
cat ${elogFileName2}
# echo "remove header"
# cutLineNum=$(grep -n "==============" ${elogFileName2} | cut -d: -f1)
# #check encoding
# encoding=$(grep "Encoding" ${elogFileName2} | awk '{print $2}')
# if [ $encoding = "plain" ]; then encodingID=1 ; fi
# if [ $encoding = "HTML" ]; then encodingID=2 ; fi
# if [ $encoding = "ELcode" ]; then encodingID=0 ; fi
# #remove all header
# sed -i "1,${cutLineNum}d" ${elogFileName2}
fi

View File

@ -19,9 +19,9 @@ namespace fs = std::experimental::filesystem;
std::string ProgramSetting::databaseIP = "https://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";
std::string ProgramSetting::DataSavingPath = "/home/catrina/FSUDAQ/expDir";
std::string ProgramSetting::ExpName = "ZZZZZ";
std::string ProgramSetting::ElogIP = "elog.physics.fsu.edu";
bool ProgramSetting::EnableElog = true;
bool ProgramSetting::EnableDatabase = true;
@ -167,6 +167,27 @@ ProgramSetting::~ProgramSetting(){
delete fMain;
}
void ProgramSetting::LogMsg(TString msg){
Emit("LogMsg(char*)", msg.Data());
}
void ProgramSetting::SetDataBaseElogOnOff(){
EnableDatabase = ( cbDatabase->GetState() == kButtonDown ? true : false );
EnableElog = ( cbElog->GetState() == kButtonDown ? true : false );
int status = SaveProgramSetting();
if( status == 1 ) LogMsg(Form("Saved Program settings to %s",ProgramSetting::settingFileName.c_str()));
}
void ProgramSetting::SetSearchRange(){
maxPort = numPort->GetNumber();
maxBoardPrePort = numPort->GetNumber();
int status = SaveProgramSetting();
if( status == 1 ) LogMsg(Form("Saved Program settings to %s",ProgramSetting::settingFileName.c_str()));
}
void ProgramSetting::SetSetting(){
DataSavingPath = txtDataPath->GetText();
@ -179,14 +200,17 @@ void ProgramSetting::SetSetting(){
PrintSettings();
SaveProgramSetting();
int status = SaveProgramSetting();
if( status == 1 ) LogMsg(Form("Saved Program settings to %s",ProgramSetting::settingFileName.c_str()));
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");
if( digi != NULL ){
for( int i = 0; i < nDigi; i ++){
digi[i]->SaveAllSettingsAsBin(ProgramSetting::DataSavingPath + "/settings/setting_" + std::to_string(digi[i]->GetSerialNumber()) + ".bin");
}
}
Emit("SetSetting()");
@ -212,14 +236,19 @@ void ProgramSetting::SetFolder(){
}
///============= Static function
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);
printf(" Data Saving Path : %s\n", DataSavingPath.c_str());
printf(" ExpName : %s\n", ExpName.c_str());
printf(" Database Enable : %d\n", EnableDatabase);
printf(" Database IP : %s\n", databaseIP.c_str());
printf(" Database Name : %s\n", databaseName.c_str());
printf(" Elog Enable : %d\n", EnableElog);
printf(" Elog IP : %s\n", ElogIP.c_str());
printf(" Max Port Scan : %d\n", maxPort);
printf("Max Board / Port Scan : %d\n", maxBoardPrePort);
printf(" last run ID : %d\n", lastRunID);
}
@ -234,23 +263,32 @@ void ProgramSetting::LoadProgramSetting(){
size_t pos = 0;
while (fileIn.good() ){
std::getline(fileIn, line);
lineNum ++;
pos = line.find("=");
if( pos > 1 ){
lineNum ++;
pos += 1;
///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;
case 1: ProgramSetting::ExpName = line.substr(pos); break;
case 2: ProgramSetting::DataSavingPath = line.substr(pos); break;
case 3: ProgramSetting::EnableDatabase = std::atoi(line.substr(pos).c_str()); break;
case 4: ProgramSetting::databaseIP = line.substr(pos); break;
case 5: ProgramSetting::databaseName = line.substr(pos); break;
case 6: ProgramSetting::EnableElog = std::atoi(line.substr(pos).c_str()); break;
case 7: ProgramSetting::ElogIP = line.substr(pos); break;
case 8: ProgramSetting::maxPort = std::atoi(line.substr(pos).c_str()); break;
case 9: ProgramSetting::maxBoardPrePort = std::atoi(line.substr(pos).c_str()); break;
case 10: lastRunID = std::atoi(line.substr(pos).c_str()); break;
}
}
}
fileIn.close();
if( lineNum < 10 ) {
printf("Something wrong with the %s file. Creating a new one.\n", ProgramSetting::settingFileName.c_str());
SaveProgramSetting();
}
}else{
printf("%s | Cannot open file : %s.\n", __func__, ProgramSetting::settingFileName.c_str());
printf("Creating One with default setting");
@ -260,7 +298,7 @@ void ProgramSetting::LoadProgramSetting(){
PrintSettings();
}
void ProgramSetting::SaveProgramSetting(){
int ProgramSetting::SaveProgramSetting(){
printf("+++++++ %s \n", __func__);
@ -271,29 +309,25 @@ void ProgramSetting::SaveProgramSetting(){
fputs( ("ExpName=" + ProgramSetting::ExpName + "\n").c_str(), fileOut);
fputs( ("DataPath=" + ProgramSetting::DataSavingPath + "\n").c_str(), fileOut);
fputs( ("EnableDatabase=" + std::to_string(ProgramSetting::EnableDatabase) + "\n").c_str(), fileOut);
fputs( ("DatabaseIP=" + ProgramSetting::databaseIP + "\n").c_str(), fileOut);
fputs( ("DatabaseName=" + ProgramSetting::databaseName + "\n").c_str(), fileOut);
fputs( ("EnableElog=" + std::to_string(ProgramSetting::EnableElog) + "\n").c_str(), fileOut);
fputs( ("ElogIP=" + ProgramSetting::ElogIP + "\n").c_str(), fileOut);
fputs( ("MaxPort=" + std::to_string(ProgramSetting::maxPort) + "\n").c_str(), fileOut);
fputs( ("MaxBoardPrePort=" + std::to_string(ProgramSetting::maxBoardPrePort) + "\n").c_str(), fileOut);
fputs( ("lastRunID=" + std::to_string(lastRunID) + "\n").c_str(), fileOut);
fclose(fileOut);
gSystem->CopyFile(ProgramSetting::settingFileName.c_str(), (ProgramSetting::DataSavingPath + "/FSUDAQ.sh").c_str(), true); /// overwrite
return 1;
}else{
printf("%s | Cannot open file : %s.\n", __func__, filePath.c_str());
return 0;
}
}
void ProgramSetting::SetDataBaseElogOnOff(){
EnableDatabase = ( cbDatabase->GetState() == kButtonDown ? true : false );
EnableElog = ( cbElog->GetState() == kButtonDown ? true : false );
}
void ProgramSetting::SetSearchRange(){
maxPort = numPort->GetNumber();
maxBoardPrePort = numPort->GetNumber();
return 0;
}

View File

@ -54,10 +54,11 @@ class ProgramSetting{
const static std::string programPath;
void SetSetting(); // *SIGNAL*
void LogMsg(TString msg); // *SIGNAL*
static void PrintSettings();
static void LoadProgramSetting();
static void SaveProgramSetting();
static int SaveProgramSetting(); /// return 1 for OK. return 0 for not OK
void SetFolder();

View File

@ -1,34 +1,38 @@
#include "startStopDialog.h"
TString StartStopDialog::startComment = "";
TString StartStopDialog::stopComment = "";
TString StartStopDialog::Comment = "";
bool StartStopDialog::isOK = false;
StartStopDialog::StartStopDialog(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h, bool isStart){
this->isStart = isStart;
startComment = "";
stopComment = "";
this->isOK = false;
Comment = "";
fMain = new TGTransientFrame(p, main, w, h, kVerticalFrame);
fMain->DontCallClose(); /// to avoid double deletions.
//fMain->SetCleanup(kDeepCleanup); /// use hierarchical cleaning
fMain->Connect("CloseWindow()", "StartStopDialog", this, "CloseWindow()");
TGHorizontalFrame * fFrame1 = new TGHorizontalFrame(fMain); fMain->AddFrame(fFrame1, new TGLayoutHints(kLHintsCenterX | kLHintsExpandX ));
TGHorizontalFrame * fFrame1 = new TGHorizontalFrame(fMain); fMain->AddFrame(fFrame1, new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 5, 5, 5, 5));
txtComment = new TGTextEntry(fFrame1, ""); fFrame1->AddFrame(txtComment);
txtComment->Resize(300, 20);
txtComment->Connect("ReturnPressed()", "StartStopDialog", this, "DoOK()");
TGHorizontalFrame * fFrame2 = new TGHorizontalFrame(fMain); fMain->AddFrame(fFrame2,new TGLayoutHints(kLHintsCenterX | kLHintsExpandX));
TGHorizontalFrame * fFrame2 = new TGHorizontalFrame(fMain); fMain->AddFrame(fFrame2,new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 5, 5, 5, 5));
TGTextButton * bOK = new TGTextButton(fFrame2, "OK"); fFrame2->AddFrame(bOK, new TGLayoutHints(kLHintsCenterX));
bOK->Connect("Clicked()", "StartStopDialog", this, "DoOK()");
TGTextButton * bCancel = new TGTextButton(fFrame2, "Cancel"); fFrame2->AddFrame(bCancel, new TGLayoutHints(kLHintsCenterX));
bCancel->Connect("Clicked()", "StartStopDialog", this, "DoClose()");
TGHorizontalFrame * fFrame3 = new TGHorizontalFrame(fMain); fMain->AddFrame(fFrame3,new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 5, 5, 5, 5));
if( isStart ){
TGLabel * lbInfo = new TGLabel(fFrame3, "* Cancel or Close this dialog box will cancel START run.\n Only OK or press Enter will process."); fFrame3->AddFrame(lbInfo);
}else{
TGLabel * lbInfo = new TGLabel(fFrame3, "* Cancel or Close this dialog box will cancel STOP run.\n* Only OK or press Enter will process."); fFrame3->AddFrame(lbInfo);
}
fMain->MapSubwindows();
fMain->Resize();
@ -47,8 +51,7 @@ StartStopDialog::StartStopDialog(const TGWindow *p, const TGWindow *main, UInt_t
StartStopDialog::~StartStopDialog(){
printf("-------- %s \n", __func__);
isOK = false;
printf("-------- %s |%s| %d\n", __func__, Comment.Data(), isOK);
delete txtComment;
fMain->DeleteWindow(); /// deletes fMain
}
@ -60,8 +63,7 @@ void StartStopDialog::DoClose(){
}
void StartStopDialog::DoOK(){
if( isStart ) startComment = txtComment->GetText();
if( !isStart ) stopComment = txtComment->GetText();
Comment = txtComment->GetText();
isOK = true;
TTimer::SingleShot(500, "StartStopDialog", this, "CloseWindow()");
}

View File

@ -31,8 +31,7 @@ class StartStopDialog{
void CloseWindow() { delete this;}
static TString startComment;
static TString stopComment;
static TString Comment;
static bool isOK;
};

View File

@ -75,20 +75,26 @@ int main(int argc, char* argv[]){
/**////##################### Demo for loading and change setting without open a digitizer
Digitizer * dig = new Digitizer();
dig->OpenDigitizer(0, 1, false, true);
dig->LoadSettingBinary("expDir/settings/setting_323.bin");
dig->LoadSettingBinaryToMemory("expDir/settings/setting_323.bin");
//dig->ProgramPHABoard();
//dig->OpenSettingBinary("setting_323.bin");
//dig->ReadAllSettingsFromBoard();
//dig->PrintSettingFromMemory();
dig->StopACQ();
//dig->StopACQ();
//dig->WriteRegister(Register::DPP::SoftwareClear_W, 1);
printf("========== %d \n", dig->ReadSettingFromFile(Register::DPP::MaxAggregatePerBlockTransfer));
dig->WriteRegister(Register::DPP::SoftwareClear_W, 1);
///dig->SaveSettingAsText("haha.txt");
///std::remove("Test_323_139_000.fsu");
//printf("========== %d \n", dig->ReadRegister(Register::DPP::MaxAggregatePerBlockTransfer));
delete dig;
/**
{///============ Checking the buffer size calculation
@ -140,23 +146,23 @@ int main(int argc, char* argv[]){
delete buffer;
}/**/
dig->GetData()->SetSaveWaveToMemory(true);
//dig->GetData()->SetSaveWaveToMemory(true);
dig->StartACQ();
for( int i = 0; i < 60; i++){
usleep(500*1000);
dig->ReadData();
printf("------------------- %d\n", i);
unsigned long time1 = get_time();
dig->GetData()->DecodeBuffer(false,0);
unsigned long time2 = get_time();
printf("********************* decode time : %lu usec\n", time2-time1);
dig->GetData()->PrintStat();
//dig->GetData()->SaveBuffer("Test");
}
dig->StopACQ();
//dig->StartACQ();
//
//for( int i = 0; i < 60; i++){
// usleep(500*1000);
// dig->ReadData();
// printf("------------------- %d\n", i);
// unsigned long time1 = get_time();
// dig->GetData()->DecodeBuffer(false,0);
// unsigned long time2 = get_time();
// printf("********************* decode time : %lu usec\n", time2-time1);
// dig->GetData()->PrintStat();
// //dig->GetData()->SaveBuffer("Test");
//}
//
//dig->StopACQ();
/**///##################### test with 2 digitizers
@ -170,7 +176,7 @@ int main(int argc, char* argv[]){
int port = i/3;
dig[i] = new Digitizer(board, port, false, true);
dig[i]->OpenSettingBinary("setting_" + to_string(dig[i]->GetSerialNumber()) + ".bin");
dig[i]->LoadSettingBinary("setting_" + to_string(dig[0]->GetSerialNumber()) + ".bin");
dig[i]->LoadSettingBinaryToMemory("setting_" + to_string(dig[0]->GetSerialNumber()) + ".bin");
}
dig[0]->SaveSettingAsText("haha.txt");

View File

@ -27,7 +27,7 @@ TGTextEntry * TriggerSummary::txtThreshold[MaxNBoards][MaxNChannels] = {NULL};
TGCheckButton * TriggerSummary::cbChannelEnable[MaxNBoards][MaxNChannels] = {NULL};
TGNumberEntry * TriggerSummary::numUpdateTime = NULL;
unsigned short TriggerSummary::value[MaxNBoards][MaxNChannels] = {0};
bool TriggerSummary::onOff[MaxNBoards][MaxNChannels] = {1};
bool TriggerSummary::onOff[MaxNBoards][MaxNChannels] = {true};
TriggerSummary::TriggerSummary(const TGWindow *p, UInt_t w, UInt_t h){
@ -98,6 +98,8 @@ TriggerSummary::TriggerSummary(const TGWindow *p, UInt_t w, UInt_t h){
txtThreshold[bd][ch]->SetEnabled(false);
cbChannelEnable[bd][ch]->SetState(kButtonUp);
onOff[bd][ch] = false;
}else{
onOff[bd][ch] = true;
}
}
}
@ -152,8 +154,10 @@ TriggerSummary::~TriggerSummary(){
}
void * TriggerSummary::UpdateTriggerRate(void * ptr){
std::string cmd = "curl -XPOST " + ProgramSetting::databaseIP + "/write?db=" + ProgramSetting::databaseName + " --data-binary @tempDB.txt";
std::string tempDBPath = ProgramSetting::DataSavingPath + "/tempDB.txt";
std::string cmd = "curl -XPOST " + ProgramSetting::databaseIP + "/write?db=" + ProgramSetting::databaseName + " --data-binary @" + tempDBPath;
std::ofstream myfile;
@ -172,7 +176,7 @@ void * TriggerSummary::UpdateTriggerRate(void * ptr){
t2 = get_time();
if( ProgramSetting::EnableDatabase && (t2 - t1) > 5*1e6){
myfile.open( "tempDB.txt");
myfile.open(tempDBPath);
for( int bd = 0; bd < nDigi; bd++){
for( int ch = 0; ch < digi[bd]->GetNChannel(); ch++){
myfile << "Rate,Bd=" << bd << ",Ch=" << ch << " value=" << digi[bd]->GetData()->TriggerRate[ch] << "\n";
@ -192,14 +196,17 @@ void * TriggerSummary::UpdateTriggerRate(void * ptr){
void TriggerSummary::SetThreshold(){
if( digi == NULL ) return;
for( int bd = 0; bd < nDigi; bd++){
for( int ch = 0; ch < digi[bd]->GetNChannel(); ch++){
bool isACQRunning = digi[bd]->IsRunning();
for( int ch = 0; ch < digi[bd]->GetNChannel(); ch++){
unsigned int haha = atoi( txtThreshold[bd][ch]->GetText());
if( value[bd][ch] != haha ){
if( digi[bd]->IsRunning() ) {
if( isACQRunning ) {
digi[bd]->StopACQ();
usleep(100*1000);
}
@ -214,7 +221,7 @@ void TriggerSummary::SetThreshold(){
}
txtThresholdValue[bd][ch]->SetText(Form("%d", value[bd][ch]), false);
if( digi[bd]->IsRunning() ) {
if( isACQRunning ) {
usleep(100*1000);
digi[bd]->StartACQ();
}
@ -227,13 +234,16 @@ void TriggerSummary::SetChannelEnable(){
if( digi == NULL ) return;
for( int bd = 0; bd < nDigi; bd++){
bool isACQRunning = digi[bd]->IsRunning();
for( int ch = 0; ch < digi[bd]->GetNChannel(); ch++){
bool state = ( cbChannelEnable[bd][ch]->GetState() == kButtonDown ? true : false);
if( onOff[bd][ch] != state ){
if( digi[bd]->IsRunning() ) {
if( isACQRunning ) {
digi[bd]->StopACQ();
usleep(100*1000);
}
@ -242,7 +252,7 @@ void TriggerSummary::SetChannelEnable(){
onOff[bd][ch] = state;
txtThreshold[bd][ch]->SetEnabled(state);
if( digi[bd]->IsRunning() ) {
if( isACQRunning ) {
usleep(100*1000);
digi[bd]->StartACQ();
}

6
FSUDAQ.sh Executable file → Normal file
View File

@ -1,6 +1,10 @@
ExpName=ZZZZZ
DataPath=/home/catrina/FSUDAQ/expDir
EnableDatabase=1
DatabaseIP=https://fsunuc.physics.fsu.edu/influx/
DatabaseName=testing
EnableElog=1
ElogIP=elog.physics.fsu.edu
lastRunID=13
MaxPort=2
MaxBoardPrePort=2
lastRunID=1

View File

@ -11,6 +11,8 @@ For other information, please see https://fsunuc.physics.fsu.edu/wiki/index.php/
3. CAENDigitizer 2.12+
4. CAEN A3818 Driver 1.61+ (for optical link)
5. CERN ROOT 6
6. InfluxDB 1.8 (recommanded for trigger rate, optional for database)
7. Elog (optional for auto make elog entry)
## Folder Structure
@ -21,8 +23,12 @@ FSUDAQ \
├── (Symbolic link to experiment folder) \
│   ├── data \
│   │   └── *.fsu \
│   ├── settings \
│   ├── FSUDAQ.sh \
│   └── settings \
│   ├── elogText.txt \
│   ├── elogText2.txt \
│   ├── elogID.txt \
│   └── tempDB.txt \
├── FSUDAQ \
├── FSUDAQDict_rdict.pcm -> DAQ/FSUDAQDict_rdict.pcm \
├── FSUDAQ.sh \
@ -89,4 +95,4 @@ Once at least one digitizer is connected. The Board Setting and Channel Setting
If no digitizer is open, user can open a setting file. once the setting file is open, the Board setting and Channel setting panels will open. User can change the settings.
User can use the Save button at the board setting to save the setting file into text format.
User can use the Save button at the board setting to save the setting file into text format.