polishing the DAQ

This commit is contained in:
Ryan Tang 2023-03-15 19:10:17 -04:00
parent e7c9380e5b
commit 47983c1f8a
4 changed files with 161 additions and 22 deletions

View File

@ -2,6 +2,7 @@
#include <cstring> #include <cstring>
#include <algorithm> #include <algorithm>
#include <sys/stat.h>
Digitizer2Gen::Digitizer2Gen(){ Digitizer2Gen::Digitizer2Gen(){
printf("======== %s \n",__func__); printf("======== %s \n",__func__);
@ -543,14 +544,18 @@ void Digitizer2Gen::OpenOutFile(std::string fileName, const char * mode){
} }
void Digitizer2Gen::CloseOutFile(){ void Digitizer2Gen::CloseOutFile(){
if( outFile != NULL ) fclose(outFile); if( outFile != NULL ) {
fclose(outFile);
int result = chmod(outFileName, S_IRUSR | S_IRGRP | S_IROTH);
if( result != 0 ) printf("somewrong when set file (%s) to read only.", outFileName);
}
} }
void Digitizer2Gen::SaveDataToFile(){ void Digitizer2Gen::SaveDataToFile(){
if( outFileSize > (unsigned int) MaxOutFileSize){ if( outFileSize > (unsigned int) MaxOutFileSize){
FinishedOutFilesSize += ftell(outFile); FinishedOutFilesSize += ftell(outFile);
fclose(outFile); CloseOutFile();
outFileIndex ++; outFileIndex ++;
sprintf(outFileName, "%s_%03d.sol", outFileNameBase.c_str(), outFileIndex); sprintf(outFileName, "%s_%03d.sol", outFileNameBase.c_str(), outFileIndex);
outFile = fopen(outFileName, "a+b"); outFile = fopen(outFileName, "a+b");

61
grafanaScreenShot.sh Executable file
View File

@ -0,0 +1,61 @@
#!/bin/bash
#url=http://localhost:3000/dashboard/snapshot/qHdJjri9Uk7DPbwnFh0fIBDEELMn4nzP
#url="http://localhost:3000/d/iXH6cG-Vz/test-dashboard?orgId=1&refresh=5s&from=1678824051707&to=1678827651708"
#firefox -screenshot http://solarisdaq:3000/dashboard/snapshot/qHdJjri9Uk7DPbwnFh0fIBDEELMn4nzP haha.png
#cutycapt --url=${url} --out=haha.png
#wget --output-document="haha.png" ${url}
usr=GeneralSOLARIS
pwd='gam$hippie'
APIKEY=eyJrIjoid25Bc3U3NEdxVDZYV2xrdEJ0QTlxNTdFM25JcXVTTlAiLCJuIjoiYWRtaW5LRVkiLCJpZCI6MX0=
url=http://localhost:3000/
#curl http://${usr}:${pwd}@localhost:3000/api/search
#curl http://${usr}:${pwd}@localhost:3000/api/admin/settings
#curl -v -H "Accept: application/json" -H "Content-Type: application/json" http://${usr}:${pwd}@localhost:3000/api/dashboard/snapshots
#get list of snapshot
#curl -v http://${usr}:${pwd}@localhost:3000/api/dashboard/snapshots
#delet snapshot
#curl -X DELETE http://${usr}:${pwd}@localhost:3000/api/snapshots/HzQd70cK1NhqZ7lDV7bSU4GkmNMezacs
#curl -v -X -d ${msg} http://${usr}:${pwd}@localhost:3000/api/snapshots
#curl -X DELETE -H "Authorization: Bearer ${APIKEY}" ${url}api/snapshots/Yn7MnDIzXsOL3VoRS617N17K5ojTsnOk
# curl -X POST -H "Authorization: Bearer ${APIKEY}" -H "Accept: application/json" -H "Content-Type: application/json" -d '{
# "dashboard": {
# "editable":false,
# "nav":[{"enable":false, "type":"timepicker"}],
# "rows": [ {} ],
# "style":"dark",
# "tags":[],
# "templating":{ "list":[]},
# "time":{ },
# "timezone":"browser",
# "title":"Home",
# "version":5
# },
# "expires": 2
# }' ${url}/api/snapshots
#curl -v -X GET -H "Authorization: Bearer ${APIKEY}" -H "Accept: application/json" ${url}api/dashboard/snapshots
#curl -v -X GET -H "Authorization: Bearer ${APIKEY}" -H "Accept: application/json" ${url}api/search
#successfull single panel
#curl 'http://localhost:3000/render/d-solo/iXH6cG-Vz/test-dashboard?orgId=1&refresh=5s&from=now-6h&to=now&panelId=2&width=1000&height=500&tz=America%2FNew_York' -H "Authorization: Bearer ${APIKEY}" --compressed > haha.png
curl 'http://localhost:3000/render/d-solo/iXH6cG-Vz/test-dashboard?orgId=1&refresh=5s&from=now-6h&to=now&panelId=2' -H "Authorization: Bearer ${APIKEY}" --compressed > haha.png
eog haha.png

View File

@ -63,6 +63,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
scalarThread = new ScalarThread(); scalarThread = new ScalarThread();
connect(scalarThread, &ScalarThread::updataScalar, this, &MainWindow::UpdateScalar); connect(scalarThread, &ScalarThread::updataScalar, this, &MainWindow::UpdateScalar);
} }
QWidget * mainLayoutWidget = new QWidget(this); QWidget * mainLayoutWidget = new QWidget(this);
@ -119,7 +120,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
layout1->addWidget(bnDigiSettings, 2, 1); layout1->addWidget(bnDigiSettings, 2, 1);
layout1->addWidget(bnSOLSettings, 2, 2, 1, 2); layout1->addWidget(bnSOLSettings, 2, 2, 1, 2);
layout1->setColumnStretch(0, 2); layout1->setColumnStretch(0, 2);
layout1->setColumnStretch(1, 2); layout1->setColumnStretch(1, 2);
layout1->setColumnStretch(2, 1); layout1->setColumnStretch(2, 1);
@ -280,7 +280,12 @@ MainWindow::~MainWindow(){
if( digiSetting != NULL ) delete digiSetting; if( digiSetting != NULL ) delete digiSetting;
printf("-------- delete influx\n"); printf("-------- delete influx\n");
if( influx != NULL ) delete influx; if( influx != NULL ) {
influx->ClearDataPointsBuffer();
influx->AddDataPoint("ProgramStart value=0");
influx->WriteData(DatabaseName.toStdString());
delete influx;
}
} }
@ -338,17 +343,20 @@ void MainWindow::StartACQ(){
// ============ update expName.sh // ============ update expName.sh
WriteExpNameSh(); WriteExpNameSh();
WriteRunTimeStampDat(true);
}else{ }else{
LogMsg("=========================== Start no-save Run"); LogMsg("=========================== Start no-save Run");
} }
//============================= start digitizer //============================= start digitizer
for( int i =0 ; i < nDigi; i ++){ for( int i = 0 ; i < nDigi; i ++){
if( digi[i]->IsDummy () ) continue; if( digi[i]->IsDummy () ) continue;
//digi[i]->Reset(); for( int ch = 0; ch < (int) digi[i]->GetNChannels(); ch ++) oldTimeStamp[i][ch] = 0;
//digi[i]->ProgramPHA(false);
digi[i]->SetPHADataFormat(1);// only save 1 trace digi[i]->SetPHADataFormat(1);// only save 1 trace
//Additional settings
digi[i]->WriteValue("/ch/0..63/par/WaveAnalogProbe0", "ADCInput"); digi[i]->WriteValue("/ch/0..63/par/WaveAnalogProbe0", "ADCInput");
if( chkSaveRun->isChecked() ){ if( chkSaveRun->isChecked() ){
@ -361,6 +369,16 @@ void MainWindow::StartACQ(){
//TODO ========================== Sync start. //TODO ========================== Sync start.
readDataThread[i]->SetSaveData(chkSaveRun->isChecked()); readDataThread[i]->SetSaveData(chkSaveRun->isChecked());
readDataThread[i]->start(); readDataThread[i]->start();
}
if( influx ){
influx->ClearDataPointsBuffer();
if( chkSaveRun->isChecked() ){
influx->AddDataPoint("RunID start=1,value=" + std::to_string(runID) + ",expName=\"" + expName.toStdString()+ + "\",comment=\"" + startComment.replace(' ', '_').toStdString() + "\"");
}
influx->AddDataPoint("StartStop value=1");
influx->WriteData(DatabaseName.toStdString());
} }
if( !scalar->isVisible() ) scalar->show(); if( !scalar->isVisible() ) scalar->show();
@ -427,16 +445,22 @@ void MainWindow::StopACQ(){
scalarThread->quit(); scalarThread->quit();
scalarThread->wait(); scalarThread->wait();
} }
if( chkSaveRun->isChecked() ){
LogMsg("=========================== <b><font style=\"color : red;\">Run-" + runIDStr + "</font></b> stopped."); if( influx ){
}else{ influx->ClearDataPointsBuffer();
LogMsg("=========================== no-Save Run stopped."); if( chkSaveRun->isChecked() ){
influx->AddDataPoint("RunID start=0,value=" + std::to_string(runID) + ",expName=\"" + expName.toStdString()+ "\",comment=\"" + stopComment.replace(' ', '_').toStdString() + "\"");
}
influx->AddDataPoint("StartStop value=0");
influx->WriteData(DatabaseName.toStdString());
} }
if( chkSaveRun->isChecked() ){ if( chkSaveRun->isChecked() ){
LogMsg("=========================== <b><font style=\"color : red;\">Run-" + runIDStr + "</font></b> stopped.");
WriteRunTimeStampDat(false);
// ============= elog // ============= elog
QString msg = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.z") + "<br />"; QString msg = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.z") + "<br />";
for( int i = 0; i < nDigi; i++){ for( int i = 0; i < nDigi; i++){
if( digi[i]->IsDummy () ) continue; if( digi[i]->IsDummy () ) continue;
msg += "FileSize ("+ QString::number(digi[i]->GetSerialNumber()) +"): " + QString::number(digi[i]->GetTotalFilesSize()/1024./1024.) + " MB <br />"; msg += "FileSize ("+ QString::number(digi[i]->GetSerialNumber()) +"): " + QString::number(digi[i]->GetTotalFilesSize()/1024./1024.) + " MB <br />";
@ -444,6 +468,10 @@ void MainWindow::StopACQ(){
msg += "comment : " + stopComment + "<br />" msg += "comment : " + stopComment + "<br />"
+ "======================"; + "======================";
AppendElog(msg, chromeWindowID); AppendElog(msg, chromeWindowID);
}else{
LogMsg("=========================== no-Save Run stopped.");
} }
lbScalarACQStatus->setText("<font style=\"color: red;\"><b>ACQ Off</b></font>"); lbScalarACQStatus->setText("<font style=\"color: red;\"><b>ACQ Off</b></font>");
@ -454,6 +482,12 @@ void MainWindow::AutoRun(){
if( chkSaveRun->isChecked() == false){ if( chkSaveRun->isChecked() == false){
StartACQ(); StartACQ();
bnStartACQ->setEnabled(false);
bnStopACQ->setEnabled(true);
bnOpenScope->setEnabled(false);
chkSaveRun->setEnabled(false);
cbAutoRun->setEnabled(false);
if( digiSetting ) digiSetting->EnableControl();
return; return;
} }
@ -478,7 +512,7 @@ void MainWindow::AutoRun(){
} }
}); });
} }
int timeMiliSec = cbAutoRun->currentData().toInt() * 60 * 1000; int timeMiliSec = cbAutoRun->currentData().toInt() * 60 * 1000;
///=========== single timed run ///=========== single timed run
@ -554,6 +588,10 @@ void MainWindow::OpenDigitizers(){
cbAutoRun->setEnabled(true); cbAutoRun->setEnabled(true);
bnOpenScalar->setEnabled(true); bnOpenScalar->setEnabled(true);
for( int ch = 0; ch < (int) digi[i]->GetNChannels(); ch++) {
oldTimeStamp[i][ch] = 0;
oldSavedCount[i][ch] = 0;
}
}else{ }else{
digi[i]->SetDummy(i); digi[i]->SetDummy(i);
LogMsg("Cannot open digitizer. Use a dummy with serial number " + QString::number(i) + " and " + QString::number(digi[i]->GetNChannels()) + " ch."); LogMsg("Cannot open digitizer. Use a dummy with serial number " + QString::number(i) + " and " + QString::number(digi[i]->GetNChannels()) + " ch.");
@ -770,6 +808,7 @@ void MainWindow::UpdateScalar(){
double acceptRate[MaxNumberOfChannel] = {0}; double acceptRate[MaxNumberOfChannel] = {0};
///===== Get trigger for all channel ///===== Get trigger for all channel
unsigned long totalFileSize = 0;
for( int iDigi = 0; iDigi < nDigi; iDigi ++ ){ for( int iDigi = 0; iDigi < nDigi; iDigi ++ ){
if( digi[iDigi]->IsDummy() ) return; if( digi[iDigi]->IsDummy() ) return;
@ -782,28 +821,39 @@ void MainWindow::UpdateScalar(){
//} //}
//=========== another method, directly readValue //=========== another method, directly readValue
digiMTX.lock();
for( int ch = 0; ch < digi[iDigi]->GetNChannels(); ch ++){ for( int ch = 0; ch < digi[iDigi]->GetNChannels(); ch ++){
std::string time = digi[iDigi]->ReadValue(PHA::CH::ChannelRealtime, ch); // for refreashing SelfTrgRate and SavedCount digiMTX.lock();
std::string timeStr = digi[iDigi]->ReadValue(PHA::CH::ChannelRealtime, ch); // for refreashing SelfTrgRate and SavedCount
haha[ch] = digi[iDigi]->ReadValue(PHA::CH::SelfTrgRate, ch); haha[ch] = digi[iDigi]->ReadValue(PHA::CH::SelfTrgRate, ch);
std::string kakaStr = digi[iDigi]->ReadValue(PHA::CH::ChannelSavedCount, ch);
digiMTX.unlock();
unsigned long kaka = std::stoul(kakaStr.c_str()) ;
unsigned long time = std::stoul(timeStr.c_str()) ;
leTrigger[iDigi][ch]->setText(QString::fromStdString(haha[ch])); leTrigger[iDigi][ch]->setText(QString::fromStdString(haha[ch]));
std::string kaka = digi[iDigi]->ReadValue(PHA::CH::ChannelSavedCount, ch); if( oldTimeStamp[iDigi][ch] > 0 && time > oldTimeStamp[iDigi][ch]){
acceptRate[ch] = atoi(kaka.c_str())*1e9*1.0 / atol(time.c_str()); acceptRate[ch] = (kaka - oldSavedCount[iDigi][ch]) * 1e9 *1.0 / (time - oldTimeStamp[iDigi][ch]);
}else{
acceptRate[ch] = 0;
}
oldSavedCount[iDigi][ch] = kaka;
oldTimeStamp[iDigi][ch] = time;
//if( kaka != "0" ) printf("%s, %s | %.2f\n", time.c_str(), kaka.c_str(), acceptRate); //if( kaka != "0" ) printf("%s, %s | %.2f\n", time.c_str(), kaka.c_str(), acceptRate);
leAccept[iDigi][ch]->setText(QString::number(acceptRate[ch],'f', 1)); leAccept[iDigi][ch]->setText(QString::number(acceptRate[ch],'f', 1));
} }
digiMTX.unlock();
///============== push the trigger, acceptRate rate database ///============== push the trigger, acceptRate rate database
if( influx ){ if( influx ){
for( int ch = 0; ch < digi[iDigi]->GetNChannels(); ch++ ){ for( int ch = 0; ch < digi[iDigi]->GetNChannels(); ch++ ){
influx->AddDataPoint("Rate,Bd=" + std::to_string(digi[iDigi]->GetSerialNumber()) + ",Ch=" + std::to_string(ch) + " value=" + haha[ch]); influx->AddDataPoint("Rate,Bd=" + std::to_string(digi[iDigi]->GetSerialNumber()) + ",Ch=" + QString::number(ch).rightJustified(2, '0').toStdString() + " value=" + haha[ch]);
if( !std::isnan(acceptRate[ch]) ) influx->AddDataPoint("AccpRate,Bd=" + std::to_string(digi[iDigi]->GetSerialNumber()) + ",Ch=" + std::to_string(ch) + " value=" + std::to_string(acceptRate[ch])); if( !std::isnan(acceptRate[ch]) ) influx->AddDataPoint("AccpRate,Bd=" + std::to_string(digi[iDigi]->GetSerialNumber()) + ",Ch=" + QString::number(ch).rightJustified(2, '0').toStdString() + " value=" + std::to_string(acceptRate[ch]));
} }
} }
totalFileSize += digi[iDigi]->GetTotalFilesSize();
} }
if( influx && influx->GetDataLength() > 0 ){ if( influx && influx->GetDataLength() > 0 ){
if( chkSaveRun->isChecked() ) influx->AddDataPoint("FileSize value=" + std::to_string(totalFileSize));
//influx->PrintDataPoints(); //influx->PrintDataPoints();
influx->WriteData(DatabaseName.toStdString()); influx->WriteData(DatabaseName.toStdString());
influx->ClearDataPointsBuffer(); influx->ClearDataPointsBuffer();
@ -1051,7 +1101,7 @@ void MainWindow::SetupInflux(){
if( foundDatabase ){ if( foundDatabase ){
LogMsg("<font style=\"color : green;\"> Database <b>" + DatabaseName + "</b> found."); LogMsg("<font style=\"color : green;\"> Database <b>" + DatabaseName + "</b> found.");
influx->AddDataPoint("Rate,Bd=0,Ch=0 value=1"); influx->AddDataPoint("ProgramStart value=1");
influx->WriteData(DatabaseName.toStdString()); influx->WriteData(DatabaseName.toStdString());
influx->ClearDataPointsBuffer(); influx->ClearDataPointsBuffer();
if( influx->IsWriteOK() ){ if( influx->IsWriteOK() ){
@ -1654,3 +1704,20 @@ void MainWindow::AppendElog(QString appendHtmlText, int screenID){
} }
void MainWindow::WriteRunTimeStampDat(bool isStartRun){
QFile file(dataPath + "/" + expName + "/RunTimeStampe.dat");
file.open(QIODevice::Text | QIODevice::WriteOnly | QIODevice::Append);
QString dateTime = QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss");
if( isStartRun ){
file.write(("Start Run | " + dateTime + " | " + startComment + "\n").toStdString().c_str());
}else{
file.write((" Stop Run | " + dateTime + " | " + stopComment + "\n").toStdString().c_str());
}
file.close();
}

View File

@ -77,6 +77,8 @@ private slots:
void WriteElog(QString htmlText, QString subject = "", QString category = "", int runNumber = 0); void WriteElog(QString htmlText, QString subject = "", QString category = "", int runNumber = 0);
void AppendElog(QString appendHtmlText, int screenID = -1); void AppendElog(QString appendHtmlText, int screenID = -1);
void WriteRunTimeStampDat(bool isStartRun);
signals : signals :
private: private:
@ -163,6 +165,10 @@ private:
QTimer * runTimer; QTimer * runTimer;
unsigned int autoRunStartRunID; unsigned int autoRunStartRunID;
//-------------- calculate instant accept Rate
unsigned long oldSavedCount[MaxNumberOfDigitizer][MaxNumberOfChannel];
unsigned long oldTimeStamp[MaxNumberOfDigitizer][MaxNumberOfChannel];
}; };