2023-11-16 19:20:29 -05:00
|
|
|
#include "../macro.h"
|
|
|
|
#include "../ClassData.h"
|
|
|
|
#include "../ClassDigitizer.h"
|
2023-11-21 18:03:10 -05:00
|
|
|
#include "../MultiBuilder.h"
|
2024-03-01 16:58:27 -05:00
|
|
|
#include "../ClassInfluxDB.h"
|
2023-04-11 11:13:23 -04:00
|
|
|
|
|
|
|
#include <TROOT.h>
|
|
|
|
#include <TSystem.h>
|
|
|
|
#include <TApplication.h>
|
|
|
|
#include <TCanvas.h>
|
|
|
|
#include <TGraph.h>
|
|
|
|
#include <TH1.h>
|
|
|
|
#include <TFile.h>
|
|
|
|
#include <TTree.h>
|
|
|
|
|
|
|
|
#include <sys/time.h> /** struct timeval, select() */
|
|
|
|
#include <termios.h> /** tcgetattr(), tcsetattr() */
|
|
|
|
#include <vector>
|
2024-03-01 16:58:27 -05:00
|
|
|
#include <regex>
|
2023-04-11 11:13:23 -04:00
|
|
|
|
|
|
|
static struct termios g_old_kbd_mode;
|
|
|
|
|
2023-04-11 14:23:38 -04:00
|
|
|
static void cooked(void);
|
|
|
|
static void uncooked(void);
|
|
|
|
static void raw(void);
|
|
|
|
int keyboardhit();
|
|
|
|
int getch(void);
|
2023-04-11 11:13:23 -04:00
|
|
|
|
2024-03-06 20:10:33 -05:00
|
|
|
#include <curl/curl.h>
|
2024-03-01 16:58:27 -05:00
|
|
|
|
|
|
|
size_t WriteCallBack(char *contents, size_t size, size_t nmemb, void *userp){
|
|
|
|
// printf(" InfluxDB::%s \n", __func__);
|
|
|
|
((std::string*)userp)->append((char*)contents, size * nmemb);
|
|
|
|
return size * nmemb;
|
|
|
|
}
|
|
|
|
|
2024-03-06 20:10:33 -05:00
|
|
|
void testInflux(){
|
2024-03-01 16:58:27 -05:00
|
|
|
InfluxDB * influx = new InfluxDB();
|
|
|
|
|
|
|
|
influx->SetURL("https://fsunuc.physics.fsu.edu/influx/");
|
|
|
|
//influx->SetURL("http://128.186.111.5:8086/");
|
|
|
|
|
|
|
|
influx->SetToken("wS-Oy17bU99qH0cTPJ-Q5tbiOWfaKyoASUx7WwmdM7KG8EJ1BpRowYkqpnPw8oeatnDaZfZtwIFT0kv_aIOAxQ==");
|
|
|
|
|
|
|
|
influx->TestingConnection();
|
|
|
|
|
|
|
|
influx->CheckDatabases();
|
|
|
|
influx->PrintDataBaseList();
|
|
|
|
|
|
|
|
// printf("=-------------------------\n");
|
|
|
|
// influx->TestingConnection(true);
|
|
|
|
|
|
|
|
printf("%s \n", influx->Query("testing", "show measurements").c_str());
|
|
|
|
|
|
|
|
// printf("%s \n", influx->Query("testing", "SELECT * from haha ORDER by time DESC LIMIT 5").c_str());
|
|
|
|
|
|
|
|
delete influx;
|
|
|
|
|
|
|
|
// CURL *curl = curl_easy_init();
|
|
|
|
// CURLcode res;
|
|
|
|
|
|
|
|
// struct curl_slist * headers = nullptr;
|
|
|
|
|
|
|
|
// headers = curl_slist_append(headers, "Authorization: Token wS-Oy17bU99qH0cTPJ-Q5tbiOWfaKyoASUx7WwmdM7KG8EJ1BpRowYkqpnPw8oeatnDaZfZtwIFT0kv_aIOAxQ==");
|
|
|
|
// // // headers = curl_slist_append(headers, "Content-Type: text/plain; charset=utf-8");
|
|
|
|
// headers = curl_slist_append(headers, "Accept: application/csv");
|
|
|
|
|
|
|
|
|
|
|
|
// printf("%s\n",headers->data);
|
|
|
|
// printf("%s\n", headers->next->data);
|
|
|
|
|
|
|
|
|
|
|
|
// curl_slist_free_all(headers);
|
|
|
|
|
|
|
|
// // printf("%p \n",headers);
|
|
|
|
|
|
|
|
// headers = curl_slist_append(headers, "Accept: application/csv");
|
|
|
|
|
|
|
|
// printf("%s\n",headers->data);
|
|
|
|
|
|
|
|
|
|
|
|
// curl_easy_setopt(curl, CURLOPT_POST, 1);
|
|
|
|
// curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
|
|
|
|
|
|
|
// std::string databaseIP = "https://fsunuc.physics.fsu.edu/influx/";
|
|
|
|
// std::string databaseIP = "http://128.186.111.5:8086/";
|
|
|
|
|
|
|
|
|
|
|
|
//*===================== Check version
|
|
|
|
|
|
|
|
// curl_easy_setopt(curl, CURLOPT_URL, (databaseIP + "ping").c_str());
|
|
|
|
// curl_easy_setopt(curl, CURLOPT_HEADER, 1);
|
|
|
|
|
|
|
|
//*===================== Query data
|
|
|
|
|
|
|
|
//=============== query databases
|
|
|
|
// curl_easy_setopt(curl, CURLOPT_URL, (databaseIP + "query").c_str());
|
|
|
|
// std::string postFields="q=Show databases";
|
|
|
|
|
|
|
|
//=============== query measurement
|
|
|
|
// curl_easy_setopt(curl, CURLOPT_URL, (databaseIP + "query?db=testing").c_str());
|
|
|
|
// std::string postFields="q=SELECT * FROM \"haha\"";
|
|
|
|
|
|
|
|
//=============== write measurement
|
|
|
|
// curl_easy_setopt(curl, CURLOPT_URL, (databaseIP + "write?db=testing").c_str());
|
|
|
|
// std::string postFields = "haha,BD=1 state=2.345";
|
|
|
|
// postFields += "\n";
|
|
|
|
// postFields += "haha,BD=2 state=9.876";
|
|
|
|
// postFields += "\n";
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
// // //curl_easy_setopt(curl, CURLOPT_URL, "https://fsunuc.physics.fsu.edu/influx/api/v2/write?org=FSUFoxLab&bucket=testing");
|
|
|
|
|
|
|
|
// res = curl_easy_perform(curl);
|
|
|
|
// long respondCode;
|
|
|
|
// curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &respondCode);
|
|
|
|
|
|
|
|
// printf("respond code : %ld \n", respondCode);
|
|
|
|
// if( res == CURLE_OK ) {
|
|
|
|
// printf("================respond \n%s\n", readBuffer.c_str());
|
|
|
|
// }else{
|
|
|
|
// printf("=========== curl_easy_perform fail.\n");
|
|
|
|
// }
|
|
|
|
|
|
|
|
// curl_slist_free_all(headers);
|
|
|
|
// curl_easy_cleanup(curl);
|
|
|
|
|
|
|
|
|
|
|
|
// std::regex pattern(R"(X-Influxdb-Version: (.*))");
|
|
|
|
// std::smatch match;
|
|
|
|
|
|
|
|
// if (regex_search(readBuffer, match, pattern)) {
|
|
|
|
// // Extract and print the version
|
|
|
|
// std::string version = match[1];
|
|
|
|
|
|
|
|
// unsigned short vno = -1;
|
|
|
|
// size_t dotPosition = version.find('.');
|
|
|
|
// if( dotPosition != std::string::npos){
|
|
|
|
// vno = atoi(version.substr(dotPosition-1, 1).c_str());
|
|
|
|
// }
|
|
|
|
// printf("%s | %d\n", version.c_str(), vno);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//============================================= end of influxDB example
|
|
|
|
|
2024-03-06 20:10:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CheckBufferSize(int MaxAggPreRead, int EvtPreAgg){
|
|
|
|
|
|
|
|
|
|
|
|
//Buffer depends on
|
|
|
|
|
|
|
|
Digitizer * digi = new Digitizer(0, 26006, false, true);
|
|
|
|
digi->Reset();
|
|
|
|
digi->ProgramBoard();
|
|
|
|
|
|
|
|
digi->WriteRegister(DPP::SoftwareClear_W, 1);
|
|
|
|
|
|
|
|
digi->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::RecordTrace, 0, -1);
|
|
|
|
digi->WriteRegister(DPP::RecordLength_G, 10, -1);
|
|
|
|
|
|
|
|
digi->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::EnableExtra2, 1, -1);
|
|
|
|
|
|
|
|
digi->WriteRegister(DPP::MaxAggregatePerBlockTransfer, MaxAggPreRead);
|
|
|
|
digi->WriteRegister(DPP::NumberEventsPerAggregate_G, EvtPreAgg);
|
|
|
|
|
|
|
|
unsigned int bufferSize = digi->CalByteForBuffer(true);
|
|
|
|
unsigned int bufferSizeCAEN = digi->CalByteForBufferCAEN();
|
|
|
|
|
|
|
|
printf("Manual Buffer Size : %u Byte = %u words\n", bufferSize, bufferSize/4);
|
|
|
|
printf(" CAEN Buffer Size : %u Byte = %u words\n", bufferSizeCAEN, bufferSizeCAEN/4);
|
|
|
|
|
|
|
|
unsigned int haha = bufferSize*2 + 16 *( 1- MaxAggPreRead );
|
|
|
|
printf("---- %u %u \n", haha, haha/4);
|
|
|
|
|
|
|
|
|
|
|
|
delete digi;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetOneAgg(){
|
|
|
|
|
|
|
|
Digitizer * digi = new Digitizer(0, 26006, false, true);
|
|
|
|
|
|
|
|
if( digi->IsConnected() ){
|
|
|
|
digi->Reset();
|
|
|
|
digi->ProgramBoard();
|
|
|
|
|
|
|
|
digi->WriteRegister(DPP::SoftwareClear_W, 1);
|
|
|
|
|
|
|
|
digi->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::RecordTrace, 0, -1);
|
|
|
|
digi->WriteRegister(DPP::RecordLength_G, 10, -1);
|
|
|
|
|
|
|
|
digi->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::EnableExtra2, 1, -1);
|
|
|
|
|
|
|
|
digi->WriteRegister(DPP::MaxAggregatePerBlockTransfer, 1);
|
|
|
|
digi->WriteRegister(DPP::NumberEventsPerAggregate_G, 2);
|
|
|
|
|
|
|
|
unsigned int bufferSize = digi->CalByteForBuffer(true);
|
|
|
|
unsigned int bufferSizeCAEN = digi->CalByteForBufferCAEN();
|
|
|
|
|
|
|
|
printf("Manual Buffer Size : %u Byte = %u words\n", bufferSize, bufferSize/4);
|
|
|
|
printf(" CAEN Buffer Size : %u Byte = %u words\n", bufferSizeCAEN, bufferSizeCAEN/4);
|
|
|
|
|
|
|
|
|
|
|
|
digi->StartACQ();
|
|
|
|
|
|
|
|
usleep(5000*1000); // wait 1sec
|
|
|
|
|
|
|
|
|
|
|
|
digi->ReadData();
|
|
|
|
digi->GetData()->DecodeBuffer(false, 4);
|
|
|
|
|
|
|
|
digi->StopACQ();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete digi;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//^======================================
|
|
|
|
int main(int argc, char* argv[]){
|
|
|
|
|
|
|
|
|
|
|
|
// CheckBufferSize(5, 4);
|
2023-10-12 16:27:56 -04:00
|
|
|
|
2024-03-06 20:10:33 -05:00
|
|
|
GetOneAgg();
|
2023-10-11 18:28:19 -04:00
|
|
|
|
|
|
|
|
2023-11-21 18:03:10 -05:00
|
|
|
// digi->WriteRegister(DPP::QDC::PreTrigger, 60, -1);
|
2023-10-11 18:28:19 -04:00
|
|
|
|
2023-11-21 18:03:10 -05:00
|
|
|
// digi->WriteRegister(DPP::QDC::TriggerThreshold_sub2, 17, -1);
|
|
|
|
// digi->SetBits(DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::ChargeSensitivity, 0, -1);
|
|
|
|
// digi->SetBits(DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::InputSmoothingFactor, 4, -1);
|
|
|
|
// digi->SetBits(DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::BaselineAvg, 2, -1);
|
2023-10-11 18:28:19 -04:00
|
|
|
|
2023-11-21 18:03:10 -05:00
|
|
|
// digi->WriteRegister(DPP::QDC::GateWidth, 608/16, -1);
|
2023-10-11 18:28:19 -04:00
|
|
|
|
2023-11-21 18:03:10 -05:00
|
|
|
// digi->WriteRegister(DPP::QDC::GroupEnableMask, 0x01);
|
2023-10-11 18:28:19 -04:00
|
|
|
|
2023-11-21 18:03:10 -05:00
|
|
|
// digi->WriteRegister(DPP::QDC::NumberEventsPerAggregate, 10, -1);
|
|
|
|
// digi->WriteRegister(DPP::AggregateOrganization, 0, -1);
|
|
|
|
// digi->WriteRegister(DPP::MaxAggregatePerBlockTransfer, 100, -1);
|
2023-10-11 18:28:19 -04:00
|
|
|
|
2023-11-21 18:03:10 -05:00
|
|
|
// digi->SetBits(DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::Polarity, 0, -1);
|
2023-10-11 18:28:19 -04:00
|
|
|
|
2023-12-15 16:02:46 -05:00
|
|
|
/*
|
2023-10-13 18:02:19 -04:00
|
|
|
digi->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::EnableExtra2, 1, -1);
|
2023-11-21 18:03:10 -05:00
|
|
|
digi->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::RecordTrace, 0, -1);
|
2023-10-09 13:12:48 -04:00
|
|
|
|
2023-10-09 17:46:32 -04:00
|
|
|
Data * data = digi->GetData();
|
2023-10-09 13:12:48 -04:00
|
|
|
|
2023-11-21 18:03:10 -05:00
|
|
|
MultiBuilder * builder = new MultiBuilder(data, DPPType::DPP_PHA_CODE, digi->GetSerialNumber());
|
|
|
|
builder->SetTimeWindow(100);
|
|
|
|
|
|
|
|
//remove("haha_*.fsu");
|
|
|
|
//data->OpenSaveFile("haha");
|
2023-10-09 17:46:32 -04:00
|
|
|
|
2023-10-10 11:06:03 -04:00
|
|
|
digi->StartACQ();
|
2023-10-09 17:46:32 -04:00
|
|
|
|
2023-11-21 18:03:10 -05:00
|
|
|
for( int i = 0; i < 5; i ++ ){
|
2023-10-09 17:46:32 -04:00
|
|
|
usleep(1000*1000);
|
|
|
|
digi->ReadData();
|
2023-10-13 18:02:19 -04:00
|
|
|
data->DecodeBuffer(true, 0);
|
|
|
|
//data->DecodeBuffer(false, 2);
|
2023-11-21 18:03:10 -05:00
|
|
|
//data->SaveData();
|
|
|
|
//data->PrintStat();
|
|
|
|
|
|
|
|
data->PrintAllData(true);
|
2023-10-09 17:46:32 -04:00
|
|
|
|
2023-12-08 17:03:52 -05:00
|
|
|
//builder->BuildEvents(false, true, true);
|
|
|
|
builder->BuildEventsBackWard(20, true);
|
2023-10-09 17:46:32 -04:00
|
|
|
|
2023-11-21 18:03:10 -05:00
|
|
|
builder->PrintStat();
|
2023-10-09 17:46:32 -04:00
|
|
|
// int index = data->NumEventsDecoded[0];
|
|
|
|
// printf("-------------- %ld \n", data->Waveform1[0][index].size());
|
|
|
|
|
|
|
|
}
|
|
|
|
digi->StopACQ();
|
2023-10-09 17:18:38 -04:00
|
|
|
|
2023-11-21 18:03:10 -05:00
|
|
|
//data->CloseSaveFile();
|
|
|
|
builder->BuildEvents(true, true, true);
|
2023-12-08 17:03:52 -05:00
|
|
|
|
2023-10-13 18:02:19 -04:00
|
|
|
data->PrintAllData();
|
2023-10-09 17:18:38 -04:00
|
|
|
|
2023-11-21 18:03:10 -05:00
|
|
|
builder->PrintAllEvent(); // TODO
|
2023-12-15 16:02:46 -05:00
|
|
|
*/
|
2023-11-21 18:03:10 -05:00
|
|
|
|
2024-03-01 16:58:27 -05:00
|
|
|
// digi->CloseDigitizer();
|
|
|
|
// delete digi;
|
2023-04-11 11:13:23 -04:00
|
|
|
|
2023-04-11 14:23:38 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2023-04-11 11:13:23 -04:00
|
|
|
|
2023-04-11 14:23:38 -04:00
|
|
|
//*********************************
|
|
|
|
//*********************************
|
2023-04-11 11:13:23 -04:00
|
|
|
|
2023-04-11 14:23:38 -04:00
|
|
|
static void cooked(void){
|
|
|
|
tcsetattr(0, TCSANOW, &g_old_kbd_mode);
|
|
|
|
}
|
2023-04-11 11:13:23 -04:00
|
|
|
|
2023-04-11 14:23:38 -04:00
|
|
|
static void uncooked(void){
|
|
|
|
struct termios new_kbd_mode;
|
|
|
|
/** put keyboard (stdin, actually) in raw, unbuffered mode */
|
|
|
|
tcgetattr(0, &g_old_kbd_mode);
|
|
|
|
memcpy(&new_kbd_mode, &g_old_kbd_mode, sizeof(struct termios));
|
|
|
|
new_kbd_mode.c_lflag &= ~(ICANON | ECHO);
|
|
|
|
new_kbd_mode.c_cc[VTIME] = 0;
|
|
|
|
new_kbd_mode.c_cc[VMIN] = 1;
|
|
|
|
tcsetattr(0, TCSANOW, &new_kbd_mode);
|
|
|
|
}
|
2023-04-11 11:13:23 -04:00
|
|
|
|
2023-04-11 14:23:38 -04:00
|
|
|
static void raw(void){
|
2023-04-11 11:13:23 -04:00
|
|
|
|
2023-04-11 14:23:38 -04:00
|
|
|
static char init;
|
|
|
|
if(init) return;
|
|
|
|
/** put keyboard (stdin, actually) in raw, unbuffered mode */
|
|
|
|
uncooked();
|
|
|
|
/** when we exit, go back to normal, "cooked" mode */
|
|
|
|
atexit(cooked);
|
|
|
|
|
|
|
|
init = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int keyboardhit(){
|
|
|
|
|
|
|
|
struct timeval timeout;
|
|
|
|
fd_set read_handles;
|
|
|
|
int status;
|
2023-04-11 11:13:23 -04:00
|
|
|
|
2023-04-11 14:23:38 -04:00
|
|
|
raw();
|
|
|
|
/** check stdin (fd 0) for activity */
|
|
|
|
FD_ZERO(&read_handles);
|
|
|
|
FD_SET(0, &read_handles);
|
|
|
|
timeout.tv_sec = timeout.tv_usec = 0;
|
|
|
|
status = select(0 + 1, &read_handles, NULL, NULL, &timeout);
|
|
|
|
if(status < 0){
|
|
|
|
printf("select() failed in keyboardhit()\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return (status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int getch(void){
|
|
|
|
unsigned char temp;
|
|
|
|
raw();
|
|
|
|
/** stdin = fd 0 */
|
|
|
|
if(read(0, &temp, 1) != 1) return 0;
|
|
|
|
return temp;
|
2023-04-11 11:13:23 -04:00
|
|
|
}
|