Compare commits

..

No commits in common. "56f665a20f0fb472c7af277346f743c3aed27a4d" and "2483abef70bb14514e1680d97ac0e530c8b3031d" have entirely different histories.

12 changed files with 108 additions and 320 deletions

View File

@ -46,8 +46,6 @@ TGraph * gDigiTrace2 = NULL ;
Pixel_t red, blue, green;
InfluxDB * influx = NULL;
unsigned short nDigi = 0;
Digitizer ** digi = NULL;
@ -279,8 +277,6 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) {
DrawDummyGraph();
influx = new InfluxDB(ProgramSetting::databaseIP, false);
fMain->Move(300, 200);
}
@ -303,8 +299,6 @@ void MainWindow::GoodBye(){
delete gDigiTrace1;
delete gDigiTrace2;
delete influx;
printf("----- bye bye ---- \n");
gApplication->Terminate(0);
@ -315,38 +309,38 @@ MainWindow::~MainWindow() {
printf("----- %s \n", __func__);
//delete fMenuBar;
//delete fMenuFile;
//delete fMenuDigitizers;
//delete fMenuUtility;
//delete fEcanvas;
//
//delete boardIDEntry;
//delete chIDEntry;
//
//delete teLog;
//
//delete bOpenDigitizers;
//delete bStartRun;
//delete bStopRun;
//delete cbMode;
//
//delete dataPrefix;
//delete runIDEntry;
//delete cbDataRun;
//
//delete bPlotSingleTrace;
//delete bFitTrace;
//
//delete boardSetting;
//delete channelSettingPHA;
//delete channelSettingPSD;
//delete registerSetting;
//delete triggerSummary;
//delete programSetting;
//delete startStopDialog;
//
//delete runThread;
delete fMenuBar;
delete fMenuFile;
delete fMenuDigitizers;
delete fMenuUtility;
delete fEcanvas;
delete boardIDEntry;
delete chIDEntry;
delete teLog;
delete bOpenDigitizers;
delete bStartRun;
delete bStopRun;
delete cbMode;
delete dataPrefix;
delete runIDEntry;
delete cbDataRun;
delete bPlotSingleTrace;
delete bFitTrace;
delete boardSetting;
delete channelSettingPHA;
delete channelSettingPSD;
delete registerSetting;
delete triggerSummary;
delete programSetting;
delete startStopDialog;
delete runThread;
fMain->Cleanup();
delete fMain;
@ -544,25 +538,6 @@ void MainWindow::ChangeBoard(){
void MainWindow::UpdateExpName(){
dataPrefix->SetText(ProgramSetting::ExpName.c_str());
runIDEntry->SetNumber(lastRunID + 1);
influx->SetURL(ProgramSetting::databaseIP);
///Check database exist
influx->ShowDatabases();
std::vector<std::string> list = influx->GetDatabaseList();
bool dataBaseExist = false;
for( int i = 0; i < (int) list.size(); i++){
if( list[i] == ProgramSetting::databaseName ) {
dataBaseExist = true;
break;
}
}
if( !dataBaseExist ) influx->CreateDatabase(ProgramSetting::databaseName);
influx->ClearDataPointsBuffer();
influx->AddDataPoint("SavingData,ExpName=" + ProgramSetting::ExpName + " value=0");
influx->WriteData(ProgramSetting::databaseName);
}
void MainWindow::MakeElogEntry(bool start){
@ -611,12 +586,6 @@ void MainWindow::StartRun(){
cbMode->SetEnabled(false);
MakeElogEntry(true);
influx->ClearDataPointsBuffer();
influx->AddDataPoint("SavingData,ExpName=" + ProgramSetting::ExpName + " value=1");
influx->AddDataPoint("RunID value=" + std::to_string(lastRunID));
influx->PrintDataPoints();
influx->WriteData(ProgramSetting::databaseName);
bool threadFlag = false;
for( int i = 0 ; i < nDigi; i++) {
digi[i]->StartACQ();
@ -665,10 +634,6 @@ void MainWindow::StopRun(){
LogMsg(Form("Stop Data Run"));
influx->ClearDataPointsBuffer();
influx->AddDataPoint("SavingData,ExpName=" + ProgramSetting::ExpName + " value=0");
influx->WriteData(ProgramSetting::databaseName);
int runID = runIDEntry->GetNumber();
runIDEntry->SetNumber(runID +1);
MakeElogEntry(false);
@ -701,6 +666,14 @@ void MainWindow::OpenChannelSetting(Int_t boardID){
}
}
//TODO, should merge into LogMsg.
void MainWindow::UpdateChannelSetting(){
if( digi == NULL ) return;
if( channelSettingPHA != NULL ) channelSettingPHA->ChangeCh();
if( channelSettingPSD != NULL ) channelSettingPSD->ChangeCh();
}
void MainWindow::LogMsg(char * msg){
time_t now = time(0);
@ -805,7 +778,7 @@ void MainWindow::PlotSingleTrace(){
fEcanvas->GetCanvas()->cd();
gAnaTrace1->Draw("same L");
if( isDualTrace) gAnaTrace2->Draw("same L");
gAnaTrace2->Draw("same L");
gDigiTrace1->Draw("same L");
fEcanvas->GetCanvas()->Update();
break;
@ -929,19 +902,14 @@ void * MainWindow::Run(void * ptr){
CurrentTime = get_time();
if( CurrentTime - PreviousTime > 1e6 ){
//if( printFileSizeCount > 0 ){
// nLine = teLog->ReturnLineCount();
// teLog->GetText()->DelLine(nLine-1);
//}
//std::string msg = Form("File Size : %.2f MB", data->GetPresentFileSize() / 1024./1024. );
//teLog->AddLineFast(msg.c_str());
//teLog->Update();
//teLog->ShowBottom();
influx->ClearDataPointsBuffer();
influx->AddDataPoint("FileSize value=" + std::to_string(data->GetPresentFileSize()));
influx->WriteData(ProgramSetting::databaseName);
if( printFileSizeCount > 0 ){
nLine = teLog->ReturnLineCount();
teLog->GetText()->DelLine(nLine-1);
}
std::string msg = Form("File Size : %.2f MB", data->GetPresentFileSize() / 1024./1024. );
teLog->AddLineFast(msg.c_str());
teLog->Update();
teLog->ShowBottom();
PreviousTime = CurrentTime;
printFileSizeCount ++;
@ -979,7 +947,7 @@ void * MainWindow::Run(void * ptr){
/// since the gDummy fixed the draw range, it does not really matter to remove extra points
gAnaTrace1->Draw("same L");
if( isDualTrace) gAnaTrace2->Draw("same L");
gAnaTrace2->Draw("same L");
}
}

View File

@ -16,7 +16,7 @@
#include "macro.h"
#include "ClassDigitizer.h"
#include "influxdb.h"
#include "programSetting.h"
#include "boardSetting.h"
#include "channelSettingPHA.h"
@ -91,6 +91,7 @@ public:
void ChangePlot();
void OpenChannelSetting(Int_t);
void UpdateChannelSetting();
void LogMsg(char * );
void GoodBye();
static void DrawDummyGraph();

View File

@ -11,7 +11,7 @@ CAENLIBS = -lCAENDigitizer
ROOTLIBS = `root-config --cflags --glibs`
OBJS = influxdb.o startStopDialog.o programSetting.o triggerSummary.o registerSetting.o channelSettingPSD.o channelSettingPHA.o boardSetting.o ClassDigitizer.o FSUDAQ.o
OBJS = startStopDialog.o programSetting.o triggerSummary.o registerSetting.o channelSettingPSD.o channelSettingPHA.o boardSetting.o ClassDigitizer.o FSUDAQ.o
#########################################################################
@ -23,9 +23,9 @@ clean :
ClassDigitizer.o : ClassDigitizer.cpp ClassDigitizer.h RegisterAddress.h macro.h ClassData.h
$(CC) $(COPTS) -c ClassDigitizer.cpp
../test : test.cpp ClassDigitizer.o influxdb.o
../test : test.cpp ClassDigitizer.o
@echo "--------- making test"
$(CC) $(COPTS) -o ../test test.cpp ClassDigitizer.o influxdb.o $(CAENLIBS) $(ROOTLIBS) -lcurl
$(CC) $(COPTS) -o ../test test.cpp ClassDigitizer.o $(CAENLIBS) $(ROOTLIBS)
../Analysis/EventBuilder : EventBuilder.cpp ClassData.h
@echo "--------- making EventBuilder"
@ -37,7 +37,7 @@ ClassDigitizer.o : ClassDigitizer.cpp ClassDigitizer.h RegisterAddress.h macro.h
../FSUDAQ : FSUDAQDict.cxx $(OBJS) ClassData.h
@echo "----------- creating FSUDAQ"
$(CC) $(COPTS) FSUDAQDict.cxx $(OBJS) -o ../FSUDAQ $(CAENLIBS) $(ROOTLIBS) -lcurl
$(CC) $(COPTS) FSUDAQDict.cxx $(OBJS) -o ../FSUDAQ $(CAENLIBS) $(ROOTLIBS)
@ln -s -f DAQ/FSUDAQDict_rdict.pcm ../.
FSUDAQDict.cxx : FSUDAQ.h FSUDAQLinkDef.h
@ -64,10 +64,6 @@ registerSetting.o : registerSetting.h registerSetting.cpp
@echo "----------- creating registerSetting.o"
$(CC) $(COPTS) -c registerSetting.cpp $(ROOTLIBS)
influxdb.o : influxdb.h influxdb.cpp
@echo "----------- creating influxdb.o"
$(CC) $(COPTS) -c influxdb.cpp -lcurl
triggerSummary.o : triggerSummary.h triggerSummary.cpp
@echo "----------- creating triggerSummary.o"
$(CC) $(COPTS) -c triggerSummary.cpp $(ROOTLIBS)

View File

@ -809,6 +809,7 @@ void BoardSetting::LogMsg(TString msg){
}
void BoardSetting::DisableEdit(){ // When ACQ is running, disable all control
}
void BoardSetting::EnableEdit(){ // When ACQ is running, disable all control

View File

@ -2,14 +2,24 @@
source ~/FSUDAQ/FSUDAQ.sh
echo "======================================= making elog Entry"
echo ${DataPath}
echo ${ExpName}
echo ${ElogIP}
elogIDFile=${DataPath}"/elogID.txt"
source ${elogIDFile}
echo ${ElogID}
isStart=$1
Comment=$2
elogFileName=${DataPath}"/elogText.txt"
echo ${isStart}
echo ${Comment}
#Get file size
RUN=${lastRunID}
runLen=${#lastRunID}
@ -28,11 +38,16 @@ if [ ${isStart} == "1" ]; then
echo "Start Run Comment : "${Comment}" <br />">> ${elogFileName}
echo "-------------------------------------------------------------------------- <br />" >> ${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 ${elogFileName})
echo "==========="${IDStr}
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}"
@ -47,6 +62,10 @@ else
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}')
@ -57,7 +76,10 @@ else
sed -i "1,${cutLineNum}d" ${elogFileName2}
echo "Run Stop at $(date) <br />" >> ${elogFileName2}
#Comment
echo "End Run Comment : "${Comment}" <br />" >> ${elogFileName2}
totalFileSize=$(du -hc ${DataPath}"/data/"${ExpName}_run${RUN}* | tail -1| awk {'print $1'})
echo "File Size : "${totalFileSize}" <br />">> ${elogFileName2}
echo "************************************************************************** <br />" >> ${elogFileName2}

View File

@ -1,138 +0,0 @@
#include "influxdb.h"
InfluxDB::InfluxDB(std::string url, bool verbose){
curl = curl_easy_init();
if( verbose) curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
this->databaseIP = url;
respondCode = 0;
dataPoints = "";
}
InfluxDB::~InfluxDB(){
curl_easy_cleanup(curl);
}
void InfluxDB::SetURL(std::string url){
this->databaseIP = url;
}
std::string InfluxDB::ShowDatabases(){
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_URL, (databaseIP + "/query").c_str());
std::string postFields="q=Show databases";
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, static_cast<long>(postFields.length()));
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postFields.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallBack);
std::string readBuffer;
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
Execute();
printf("|%s|\n", readBuffer.c_str());
databaseList.clear();
size_t pos = readBuffer.find("values");
if( pos > 0 ){
std::string kaka = readBuffer.substr(pos+8);
pos = kaka.find("}");
kaka = kaka.substr(0, pos);
int len = kaka.length();
bool startFlag = false;
std::string lala;
char yaya = '"';
for( int i = 0; i < len; i++){
if( startFlag == false && kaka[i] == yaya ) {
startFlag = true;
lala = "";
continue;
}
if( startFlag && kaka[i] == yaya ){
startFlag = false;
databaseList.push_back(lala);
continue;
}
if( startFlag ) lala += kaka[i];
}
}
return readBuffer;
}
std::string InfluxDB::Query(std::string databaseName, std::string query){
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_URL, (databaseIP + "/query?db=" + databaseName).c_str());
std::string postFields = "q=" + query;
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, static_cast<long>(postFields.length()));
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postFields.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallBack);
std::string readBuffer;
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
Execute();
printf("|%s|\n", readBuffer.c_str());
return readBuffer;
}
void InfluxDB::CreateDatabase(std::string databaseName){
curl_easy_setopt(curl, CURLOPT_URL, (databaseIP + "/query").c_str());
curl_easy_setopt(curl, CURLOPT_POST, 1);
std::string postFields = "q=CREATE DATABASE " + databaseName;
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, static_cast<long>(postFields.length()));
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postFields.c_str());
Execute();
}
void InfluxDB::AddDataPoint(std::string fullString){
dataPoints += fullString + "\n";
}
void InfluxDB::ClearDataPointsBuffer(){
dataPoints = "";
}
void InfluxDB::PrintDataPoints(){
printf("%s\n", dataPoints.c_str());
}
void InfluxDB::WriteData(std::string databaseName){
curl_easy_setopt(curl, CURLOPT_URL, (databaseIP + "write?db=" + databaseName).c_str());
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, static_cast<long>(dataPoints.length()));
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, dataPoints.c_str());
Execute();
}
void InfluxDB::Execute(){
respond = curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &respondCode);
//printf("==== respond code %ld \n", respondCode);
if( respond != CURLE_OK) printf("############# fail\n");
}
size_t InfluxDB::WriteCallBack(char *contents, size_t size, size_t nmemb, void *userp){
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}

View File

@ -1,52 +0,0 @@
#ifndef INFLUXDB_H
#define INFLUXDB_H
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <curl/curl.h>
class InfluxDB{
private:
CURL * curl;
CURLcode respond;
long respondCode;
std::string databaseIP;
std::string dataPoints;
std::vector<std::string> databaseList;
static size_t WriteCallBack(char *contents, size_t size, size_t nmemb, void *userp);
void Execute();
public:
/// url = https://fsunuc.physics.fsu.edu/InfluxDB/
InfluxDB(std::string url, bool verbose = false);
~InfluxDB();
void SetURL(std::string url);
/// Query
std::string ShowDatabases(); /// this save the list of database into databaseList
std::string Query(std::string databaseName, std::string query);
/// the ShowDatabases() function must be called before
std::vector<std::string> GetDatabaseList() {return databaseList;}
void CreateDatabase(std::string databaseName);
/// for single or batch write,
/// 1, addDataPoint first, you can add as many as you like
/// 2, writeData.
void AddDataPoint(std::string fullString);
void ClearDataPointsBuffer();
void PrintDataPoints();
void WriteData(std::string databaseName);
};
#endif

View File

@ -63,7 +63,6 @@ void StartStopDialog::DoClose(){
}
void StartStopDialog::DoOK(){
Comment = "";
Comment = txtComment->GetText();
isOK = true;
TTimer::SingleShot(500, "StartStopDialog", this, "CloseWindow()");

View File

@ -2,8 +2,6 @@
#include "ClassData.h"
#include "ClassDigitizer.h"
#include "influxdb.h"
#include "TROOT.h"
#include "TSystem.h"
#include "TApplication.h"
@ -15,7 +13,6 @@
#include <sys/time.h> /** struct timeval, select() */
#include <termios.h> /** tcgetattr(), tcsetattr() */
#include <vector>
static struct termios g_old_kbd_mode;
@ -75,25 +72,7 @@ int getch(void){
int main(int argc, char* argv[]){
InfluxDB influx("https://fsunuc.physics.fsu.edu/influx/", false);
influx.ShowDatabases();
std::vector<std::string> qaqa = influx.GetDatabaseList();
for( int i = 0; i < (int) qaqa.size(); i++) printf("%s\n", qaqa[i].c_str());
//influx.Query("testing", "Show measurements");
//influx.AddDataPoint("Rate,Bd=0,Ch=0 value=10");
//influx.AddDataPoint("Rate,Bd=0,Ch=7 value=20");
//influx.AddDataPoint("Rate,Bd=0,Ch=15 value=30");
//
//influx.PrintDataPoints();
//
//influx.WriteData("testing");
/**////##################### Demo for loading and change setting without open a digitizer
/**
Digitizer * dig = new Digitizer();
dig->OpenDigitizer(0, 1, false, true);
dig->LoadSettingBinaryToMemory("expDir/settings/setting_323.bin");

View File

@ -15,7 +15,8 @@
extern unsigned short nDigi;
extern Digitizer ** digi;
extern InfluxDB * influx;
//extern bool ProgramSetting::EnableDatabase;
bool TriggerSummary::updateFlag = true;
TGTextEntry * TriggerSummary::txtTrigger[MaxNBoards][MaxNChannels] = {NULL};
@ -26,7 +27,6 @@ TGNumberEntry * TriggerSummary::numUpdateTime = NULL;
unsigned short TriggerSummary::value[MaxNBoards][MaxNChannels] = {0};
bool TriggerSummary::onOff[MaxNBoards][MaxNChannels] = {true};
TriggerSummary::TriggerSummary(const TGWindow *p, const TGWindow *main){
fMain = new TGTransientFrame(p,main);
@ -153,24 +153,38 @@ TriggerSummary::~TriggerSummary(){
void * TriggerSummary::UpdateTriggerRate(void * ptr){
std::string tempDBPath = ProgramSetting::DataSavingPath + "/tempDB.txt";
std::string cmd = "curl -XPOST " + ProgramSetting::databaseIP + "/write?db=" + ProgramSetting::databaseName + " --data-binary @" + tempDBPath;
std::ofstream myfile;
unsigned int t1 = get_time();
unsigned int t2 = 0;
while( updateFlag){
if( ProgramSetting::EnableDatabase) influx->ClearDataPointsBuffer();
for( int bd = 0; bd < nDigi; bd++){
uint32_t chMask = digi[bd]->GetChannelMask();
for( int ch = 0; ch < digi[bd]->GetNChannel(); ch++){
if( (chMask & ( 1 << ch) ) == 0 ) continue;
txtTrigger[bd][ch]->SetText(Form("%.2f", digi[bd]->GetData()->TriggerRate[ch]));
value[bd][ch] = digi[bd]->GetSettingFromMemory(Register::DPP::PHA::TriggerThreshold, ch);
txtThresholdValue[bd][ch]->SetText(Form("%d", value[bd][ch]), false);
influx->AddDataPoint(Form("Rate,Bd=%d,Ch=%d value=%.2f", bd, ch, digi[bd]->GetData()->TriggerRate[ch]));
}
}
influx->WriteData(ProgramSetting::databaseName);
t2 = get_time();
if( ProgramSetting::EnableDatabase && (t2 - t1) > 5*1e6){
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";
}
}
myfile.close();
int temp = system(cmd.c_str());
t1 = t2;
}
usleep(numUpdateTime->GetNumber() * 1000);
}

View File

@ -10,7 +10,6 @@
#include <TGLabel.h>
#include "ClassDigitizer.h"
#include "macro.h"
#include "influxdb.h"
class TGWindow;
class TGMainFrame;

View File

@ -11,8 +11,7 @@ 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. libcurl4-nss-dev (for the libcurl, used in InfluxDB class)
7. InfluxDB 1.8 (recommanded for trigger rate, optional for database)
6. InfluxDB 1.8 (recommanded for trigger rate, optional for database)
7. Elog (optional for auto make elog entry)
## Folder Structure