2022-08-23 13:43:05 -04:00
|
|
|
#include "ClassData.h"
|
2022-09-28 15:09:27 -04:00
|
|
|
#include "ClassDigitizer.h"
|
|
|
|
|
|
|
|
#include "TROOT.h"
|
|
|
|
#include "TSystem.h"
|
|
|
|
#include "TApplication.h"
|
|
|
|
#include "TCanvas.h"
|
|
|
|
#include "TGraph.h"
|
|
|
|
#include "TH1.h"
|
|
|
|
|
|
|
|
#include <sys/time.h> /* struct timeval, select() */
|
|
|
|
#include <termios.h> /* tcgetattr(), tcsetattr() */
|
|
|
|
|
|
|
|
static struct termios g_old_kbd_mode;
|
|
|
|
|
|
|
|
static void cooked(void){
|
|
|
|
tcsetattr(0, TCSANOW, &g_old_kbd_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void raw(void){
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
//printf("%s", &temp);
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
long get_time(){
|
|
|
|
long time_ms;
|
|
|
|
struct timeval t1;
|
|
|
|
struct timezone tz;
|
|
|
|
gettimeofday(&t1, &tz);
|
|
|
|
time_ms = (t1.tv_sec) * 1000 + t1.tv_usec / 1000;
|
|
|
|
return time_ms;
|
|
|
|
}
|
2022-08-03 19:00:41 -04:00
|
|
|
|
|
|
|
int main(int argc, char* argv[]){
|
2022-09-26 16:47:20 -04:00
|
|
|
|
2022-09-27 17:58:14 -04:00
|
|
|
const int nBoard = 1;
|
2022-08-26 17:18:43 -04:00
|
|
|
Digitizer **dig = new Digitizer *[nBoard];
|
2022-08-03 19:00:41 -04:00
|
|
|
|
2022-08-10 18:35:13 -04:00
|
|
|
for( int i = 0 ; i < nBoard; i++){
|
|
|
|
int board = i % 3;
|
|
|
|
int port = i/3;
|
2022-09-26 16:47:20 -04:00
|
|
|
dig[i] = new Digitizer(board, port, false, true);
|
2022-09-27 17:58:14 -04:00
|
|
|
//dig[i]->CreateAndSaveSettingBinary("setting_" + to_string(dig[i]->GetSerialNumber()) + ".bin");
|
|
|
|
dig[i]->OpenSettingBinary("setting_" + to_string(dig[i]->GetSerialNumber()) + ".bin");
|
2022-08-10 18:35:13 -04:00
|
|
|
}
|
|
|
|
|
2022-09-28 15:09:27 -04:00
|
|
|
dig[0]->Reset();
|
2022-09-27 17:58:14 -04:00
|
|
|
dig[0]->ProgramPHABoard();
|
2022-09-28 15:09:27 -04:00
|
|
|
dig[0]->WriteRegister(Register::DPP::BoardConfiguration, 0x84F8115); /// enable wave form, pileup
|
|
|
|
|
|
|
|
unsigned int waveFormLength = 2000;
|
|
|
|
unsigned int ch2ns = (unsigned int) dig[0]->GetCh2ns();
|
2022-08-29 18:06:12 -04:00
|
|
|
|
2022-10-05 17:54:10 -04:00
|
|
|
//dig[0]->WriteRegister(Register::DPP::RecordLength_G, waveFormLength/ch2ns, 0);
|
|
|
|
//dig[0]->WriteRegister(Register::DPP::RecordLength_G, waveFormLength/ch2ns + 10, 3);
|
|
|
|
//dig[0]->WriteRegister(Register::DPP::DPPAlgorithmControl, 0xe30200e);
|
|
|
|
//dig[0]->WriteRegister(Register::DPP::TriggerValidationMask_G, 0x500, 1);
|
|
|
|
//dig[0]->WriteRegister(Register::DPP::TriggerValidationMask_G, 0x600, 3);
|
|
|
|
//dig[0]->WriteRegister(Register::DPP::Scratch, 0x12345678);
|
|
|
|
|
|
|
|
dig[0]->ReadRegister(Register::DPP::RecordLength_G, 0, "A0");
|
|
|
|
dig[0]->ReadRegister(Register::DPP::RecordLength_G, 3, "A0");
|
|
|
|
dig[0]->ReadRegister(Register::DPP::DPPAlgorithmControl, 0, "A1");
|
|
|
|
dig[0]->ReadRegister(Register::DPP::DPPAlgorithmControl, -1, "A1");
|
|
|
|
dig[0]->ReadRegister(Register::DPP::TriggerValidationMask_G, 1, "A3");
|
|
|
|
dig[0]->ReadRegister(Register::DPP::TriggerValidationMask_G, 3, "A3");
|
|
|
|
dig[0]->ReadRegister(Register::DPP::Scratch);
|
|
|
|
|
|
|
|
printf(" ======== %u \n", dig[0]->GetSettingFromMemory(Register::DPP::RecordLength_G, 0));
|
|
|
|
printf(" ======== %u \n", dig[0]->GetSettingFromMemory(Register::DPP::RecordLength_G, 3));
|
|
|
|
//printf(" ======== %u \n", dig[0]->GetSettingFromMemory(Register::DPP::DPPAlgorithmControl, 0));
|
|
|
|
//printf(" ======== %u \n", dig[0]->GetSettingFromMemory(Register::DPP::TriggerValidationMask_G, 1));
|
|
|
|
//printf(" ======== %u \n", dig[0]->GetSettingFromMemory(Register::DPP::TriggerValidationMask_G, 2));
|
|
|
|
//printf(" ======== %u \n", dig[0]->GetSettingFromMemory(Register::DPP::TriggerValidationMask_G, 3));
|
|
|
|
//printf(" ======== %u \n", dig[0]->GetSettingFromMemory(Register::DPP::Scratch));
|
|
|
|
|
|
|
|
dig[0]->ReadSettingFromFile(Register::DPP::RecordLength_G, 0);
|
|
|
|
dig[0]->ReadSettingFromFile(Register::DPP::RecordLength_G, 3);
|
|
|
|
//dig[0]->ReadSettingFromFile(Register::DPP::DPPAlgorithmControl, 0);
|
|
|
|
//dig[0]->ReadSettingFromFile(Register::DPP::TriggerValidationMask_G, 1);
|
|
|
|
//dig[0]->ReadSettingFromFile(Register::DPP::TriggerValidationMask_G, 2);
|
|
|
|
//dig[0]->ReadSettingFromFile(Register::DPP::TriggerValidationMask_G, 3);
|
|
|
|
//dig[0]->ReadSettingFromFile(Register::DPP::Scratch);
|
|
|
|
|
|
|
|
//dig[0]->PrintSettingFromMemory();
|
2022-09-28 15:09:27 -04:00
|
|
|
|
2022-10-05 17:54:10 -04:00
|
|
|
/**
|
|
|
|
///============================ Get Data
|
2022-09-28 15:09:27 -04:00
|
|
|
TApplication * app = new TApplication("app", &argc, argv);
|
|
|
|
TCanvas * canvas = new TCanvas("c", "haha", 1200, 400);
|
|
|
|
canvas->Divide(3, 1);
|
|
|
|
|
|
|
|
TH1F * h1 = new TH1F("h1", "count", dig[0]->GetNChannel(), 0, dig[0]->GetNChannel());
|
|
|
|
TH1F * h2 = new TH1F("h2", "energy ch-0", 400, 0, 40000);
|
|
|
|
|
|
|
|
TGraph * g1 = new TGraph();
|
|
|
|
|
|
|
|
canvas->cd(1); h1->Draw("hist");
|
|
|
|
canvas->cd(2); h2->Draw();
|
|
|
|
canvas->cd(3); g1->Draw("AP");
|
2022-08-03 19:00:41 -04:00
|
|
|
|
2022-09-27 17:58:14 -04:00
|
|
|
Data * data = dig[0]->GetData();
|
2022-08-17 16:08:49 -04:00
|
|
|
data->AllocateMemory();
|
2022-08-12 18:13:54 -04:00
|
|
|
|
2022-10-05 17:54:10 -04:00
|
|
|
remove("test.bin");
|
|
|
|
|
2022-09-27 17:58:14 -04:00
|
|
|
dig[0]->StartACQ();
|
2022-09-28 15:09:27 -04:00
|
|
|
|
|
|
|
std::vector<unsigned short> haha ;
|
2022-08-18 17:34:28 -04:00
|
|
|
|
2022-09-28 15:09:27 -04:00
|
|
|
uint32_t PreviousTime = get_time();
|
|
|
|
uint32_t CurrentTime = 0;
|
|
|
|
uint32_t ElapsedTime = 0;
|
|
|
|
|
|
|
|
while(true){
|
|
|
|
|
|
|
|
if(keyboardhit()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
usleep(50000);
|
2022-09-27 17:58:14 -04:00
|
|
|
dig[0]->ReadData();
|
2022-09-28 15:09:27 -04:00
|
|
|
|
|
|
|
if( data->nByte > 0 ){
|
2022-10-04 16:54:01 -04:00
|
|
|
data->SaveBuffer("test");
|
2022-09-28 15:09:27 -04:00
|
|
|
data->DecodeBuffer(0);
|
|
|
|
|
2022-09-29 15:26:40 -04:00
|
|
|
unsigned short nData = data->NumEvents[0]; //channel-0
|
|
|
|
haha = data->Waveform1[0][nData-1];
|
2022-09-28 15:09:27 -04:00
|
|
|
for( int i = 0; i < waveFormLength; i++) g1->SetPoint(i, i*ch2ns, haha[i]);
|
|
|
|
|
|
|
|
canvas->cd(3); g1->Draw("AP");
|
|
|
|
|
2022-09-29 15:26:40 -04:00
|
|
|
canvas->Modified();
|
2022-09-28 15:09:27 -04:00
|
|
|
canvas->Update();
|
|
|
|
gSystem->ProcessEvents();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrentTime = get_time();
|
|
|
|
ElapsedTime = CurrentTime - PreviousTime; /// milliseconds
|
|
|
|
|
|
|
|
if( ElapsedTime > 1000 ){
|
2022-09-28 17:54:33 -04:00
|
|
|
int temp = system("clear");
|
2022-09-28 15:09:27 -04:00
|
|
|
data->PrintStat();
|
2022-09-29 15:26:40 -04:00
|
|
|
|
|
|
|
for(int i = 0; i < dig[0]->GetNChannel(); i++){
|
|
|
|
h1->Fill(i, data->NumEvents[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for( int i = 0; i < data->NumEvents[0]; i++){
|
|
|
|
h2->Fill( data->Energy[0][i]);
|
|
|
|
}
|
|
|
|
data->ClearData();
|
|
|
|
|
|
|
|
canvas->cd(1); h1->Draw("hist");
|
|
|
|
canvas->cd(2); h2->Draw();
|
|
|
|
canvas->Modified();
|
|
|
|
canvas->Update();
|
|
|
|
gSystem->ProcessEvents();
|
|
|
|
|
2022-09-28 15:09:27 -04:00
|
|
|
PreviousTime = CurrentTime;
|
2022-09-29 15:26:40 -04:00
|
|
|
|
|
|
|
printf("Press any key to Stop\n");
|
2022-09-28 15:09:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-18 17:34:28 -04:00
|
|
|
}
|
2022-08-05 18:15:50 -04:00
|
|
|
|
2022-09-27 17:58:14 -04:00
|
|
|
dig[0]->StopACQ();
|
2022-08-03 19:00:41 -04:00
|
|
|
|
2022-09-28 15:09:27 -04:00
|
|
|
app->Run();
|
2022-08-18 17:34:28 -04:00
|
|
|
|
2022-09-27 17:58:14 -04:00
|
|
|
delete [] dig;
|
2022-08-03 19:00:41 -04:00
|
|
|
|
2022-08-26 17:18:43 -04:00
|
|
|
/*********************/
|
2022-08-23 13:43:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
///********************* method for using Data Class for decoding bin file
|
2022-08-26 17:18:43 -04:00
|
|
|
/**
|
2022-08-23 13:43:05 -04:00
|
|
|
FILE * haha = fopen("output.bin", "r");
|
|
|
|
fseek(haha, 0L, SEEK_END);
|
|
|
|
size_t inFileSize = ftell(haha);
|
|
|
|
printf("file size : %d Byte\n", (int) inFileSize);
|
|
|
|
fclose(haha);
|
|
|
|
|
|
|
|
Data * data = new Data();
|
2022-08-23 15:49:03 -04:00
|
|
|
data->DPPType = V1730_DPP_PHA_CODE;
|
2022-08-23 13:43:05 -04:00
|
|
|
|
2022-08-24 17:50:21 -04:00
|
|
|
haha = fopen("output.bin", "r");
|
|
|
|
printf("pos : %d \n", (int) ftell(haha));
|
|
|
|
|
|
|
|
do{
|
|
|
|
unsigned int word[1]; /// 4 bytes
|
|
|
|
size_t dump = fread(word, 4, 1, haha);
|
|
|
|
fseek(haha, -4, SEEK_CUR);
|
|
|
|
unsigned int aggSize = (word[0] & 0x0FFFFFFF) * 4; ///byte
|
|
|
|
short header = ((word[0] >> 28 ) & 0xF);
|
|
|
|
if( header != 10 ) break;
|
|
|
|
|
|
|
|
printf("-------- %d word = %d bytes\n", aggSize/4, aggSize);
|
|
|
|
char * buffer = new char[aggSize];
|
|
|
|
dump = fread(buffer, aggSize, 1, haha);
|
|
|
|
|
|
|
|
data->DecodeBuffer(buffer, 1);
|
|
|
|
|
|
|
|
if( ftell(haha) >= inFileSize ) break;
|
|
|
|
|
|
|
|
}while(!feof(haha) );
|
|
|
|
|
2022-09-28 15:09:27 -04:00
|
|
|
|
2022-08-24 17:50:21 -04:00
|
|
|
fclose(haha);
|
2022-09-28 15:09:27 -04:00
|
|
|
*/
|
2022-08-23 13:43:05 -04:00
|
|
|
|
|
|
|
|
2022-10-05 17:54:10 -04:00
|
|
|
dig[0]->CloseDigitizer();
|
2022-08-23 13:43:05 -04:00
|
|
|
|
2022-08-03 19:00:41 -04:00
|
|
|
return 0;
|
|
|
|
}
|