save data take too many time

This commit is contained in:
Ryan Tang 2023-01-09 18:22:33 -05:00
parent 27576d301d
commit 1fce22bd2b
6 changed files with 241 additions and 73 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ test
test_indep
*.o
*.sol

View File

@ -31,9 +31,11 @@ void Digitizer2Gen::Initialization(){
netMask = "";
gateway = "";
outFileIndex = 0;
}
//########################## Handles functions
//########################################### Handles functions
uint64_t Digitizer2Gen::GetHandle(const char * parameter){
uint64_t par_handle;
@ -67,10 +69,10 @@ std::string Digitizer2Gen::GetPath(uint64_t handle){
}
//############################ Read Write
//########################################### Read Write
std::string Digitizer2Gen::ReadValue(const char * parameter){
if( !isConnected ) return "not connected";
printf(" %s|%s \n", __func__, parameter);
//printf(" %s|%s \n", __func__, parameter);
ret = CAEN_FELib_GetValue(handle, parameter, retValue);
if (ret != CAEN_FELib_Success) return ErrorMsg(__func__);
return retValue;
@ -96,7 +98,7 @@ void Digitizer2Gen::SendCommand(const char * parameter){
}
}
//############################## Open digitizer
//########################################### Open digitizer
int Digitizer2Gen::OpenDigitizer(const char * url){
printf("======== %s \n",__func__);
@ -114,7 +116,6 @@ int Digitizer2Gen::OpenDigitizer(const char * url){
modelName = ReadValue("/par/ModelName");
cupVersion = ReadValue("/par/cupver");
DPPVersion = ReadValue("/par/FPGA_FwVer");
DPPType = ReadValue("/par/FwType");
@ -173,7 +174,7 @@ int Digitizer2Gen::CloseDigitizer(){
return 0;
}
//################################## DAQ
//########################################### DAQ
void Digitizer2Gen::StartACQ(){
SendCommand("/cmd/armacquisition");
@ -200,6 +201,7 @@ void Digitizer2Gen::SetPHADataFormat(){
{ \"name\" : \"CHANNEL\", \"type\" : \"U8\" }, \
{ \"name\" : \"TIMESTAMP\", \"type\" : \"U64\" }, \
{ \"name\" : \"FINE_TIMESTAMP\", \"type\" : \"U16\" }, \
{ \"name\" : \"TIMESTAMP_NS\", \"type\" : \"U64\" }, \
{ \"name\" : \"ENERGY\", \"type\" : \"U16\" }, \
{ \"name\" : \"ANALOG_PROBE_1\", \"type\" : \"I32\", \"dim\" : 1 }, \
{ \"name\" : \"ANALOG_PROBE_2\", \"type\" : \"I32\", \"dim\" : 1 }, \
@ -216,6 +218,11 @@ void Digitizer2Gen::SetPHADataFormat(){
{ \"name\" : \"WAVEFORM_SIZE\", \"type\" : \"SIZE_T\" }, \
{ \"name\" : \"FLAGS_LOW_PRIORITY\", \"type\" : \"U16\"}, \
{ \"name\" : \"FLAGS_HIGH_PRIORITY\", \"type\" : \"U16\" }, \
{ \"name\" : \"TRIGGER_THR\", \"type\" : \"U16\" }, \
{ \"name\" : \"TIME_RESOLUTION\", \"type\" : \"U8\" }, \
{ \"name\" : \"BOARD_FAIL\", \"type\" : \"BOOL\" }, \
{ \"name\" : \"FLUSH\", \"type\" : \"BOOL\" }, \
{ \"name\" : \"AGGREGATE_COUNTER\", \"type\" : \"U32\" }, \
{ \"name\" : \"EVENT_SIZE\", \"type\" : \"SIZE_T\" } \
] \
");
@ -225,68 +232,99 @@ void Digitizer2Gen::SetPHADataFormat(){
}
}
struct event {
uint8_t channel;
uint64_t timestamp;
double timestamp_us;
uint16_t fine_timestamp;
uint16_t energy;
uint16_t flags_low_priority;
uint16_t flags_high_priority;
size_t event_size;
int32_t* analog_probes[2];
uint8_t* digital_probes[4];
uint8_t analog_probes_type[2];
uint8_t digital_probes_type[4];
size_t n_allocated_samples;
size_t n_samples;
};
void Digitizer2Gen::ReadData(){
printf("========= %s \n", __func__);
event evt;
int Digitizer2Gen::ReadData(){
//printf("========= %s \n", __func__);
ret = CAEN_FELib_ReadData(ep_handle, 100,
evt.channel,
evt.timestamp,
evt.fine_timestamp,
evt.energy,
evt.analog_probes[0],
evt.analog_probes[1],
evt.digital_probes[0],
evt.digital_probes[1],
evt.digital_probes[2],
evt.digital_probes[3],
evt.analog_probes_type[0],
evt.analog_probes_type[1],
evt.digital_probes_type[0],
evt.digital_probes_type[1],
evt.digital_probes_type[2],
evt.digital_probes_type[3],
evt.n_samples,
evt.flags_low_priority,
evt.flags_high_priority,
evt.event_size
&evt.channel,
&evt.timestamp,
&evt.fine_timestamp,
&evt.timestamp_ns,
&evt.energy,
&evt.analog_probes0,
&evt.analog_probes1,
&evt.digital_probes0,
&evt.digital_probes1,
&evt.digital_probes2,
&evt.digital_probes3,
&evt.analog_probes_type[0],
&evt.analog_probes_type[1],
&evt.digital_probes_type[0],
&evt.digital_probes_type[1],
&evt.digital_probes_type[2],
&evt.digital_probes_type[3],
&evt.traceLenght,
&evt.flags_low_priority,
&evt.flags_high_priority,
&evt.trigger_threashold,
&evt.downSampling,
&evt.board_fail,
&evt.flush,
&evt.aggCounter,
&evt.event_size
);
evt.timestamp_us = (evt.timestamp*8 + evt.fine_timestamp*0.0078125)/1000.;
return ret;
if( ret != CAEN_FELib_Success) {
ErrorMsg("Set Read Data");
return;
return ret;
}
}
//##########################################
void Digitizer2Gen::ProgramPHA(){
void Digitizer2Gen::ReadDataRaw(){
}
//###########################################
void Digitizer2Gen::SaveDataToFile(std::string fileName){
char outFileName[100];
sprintf(outFileName, "%s_%03d.sol", fileName.c_str(), outFileIndex);
FILE * outFile = fopen(outFileName, "a+");
fseek(outFile, 0L, SEEK_END);
unsigned int outFileSize = ftell(outFile); // unsigned int = Max ~4GB
if( outFileSize > (unsigned int) MaxOutFileSize){
fclose(outFile);
outFileIndex ++;
sprintf(outFileName, "%s_%03d.sol", fileName.c_str(), outFileIndex);
outFile = fopen(outFileName, "a+");
}
fwrite(evt.GetWord1(), 8, 1, outFile);
fwrite(evt.GetWord2(), 8, 1, outFile);
fwrite(evt.GetWord3(), 8, 1, outFile);
fwrite(evt.GetWord4(), 8, 1, outFile);
for(int i = 0; i < evt.traceLenght; i++){
fwrite(evt.GetWordTrace(i), 8, 1, outFile);
}
fclose(outFile);
}
//###########################################
void Digitizer2Gen::ProgramPHA(bool testPulse){
if( !isConnected ) return ;
// Channel enable
WriteValue("/ch/0..63/par/ChEnable" , "true");
// Global trigger configuration
///WriteValue("/par/GlobalTriggerSource", "SwTrg");
if( testPulse ) {
WriteValue("/par/GlobalTriggerSource", "SwTrg | TestPulse");
WriteValue("/par/TestPulsePeriod" , "100000000");
}else{
WriteValue("/par/GlobalTriggerSource", "SwTrg");
}
WriteValue("/par/TestPulsePeriod" , "1000000"); // 1 msec = 1kHz
WriteValue("/par/TestPulseWidth" , "16");
// Wave configuration

View File

@ -8,6 +8,112 @@
//#include "Parameter.h"
#define MaxOutFileSize 2*1024*1024
#define MaxTraceLenght 2048
struct event {
uint8_t channel; // 6 bit
uint64_t timestamp; // 48 bit
uint64_t timestamp_ns; // 51 bit fine_timestamp not included
double timestamp_us;
uint16_t fine_timestamp; // 16 bit
uint16_t energy; // 16 bit
uint16_t flags_low_priority; // 12 bit
uint16_t flags_high_priority; // 8 bit
uint8_t analog_probes_type[2]; // 3 bit
uint8_t digital_probes_type[4]; // 4 bit
int32_t analog_probes0[MaxTraceLenght]; // 18 bit
int32_t analog_probes1[MaxTraceLenght];
uint8_t digital_probes0[MaxTraceLenght]; // 1 bit
uint8_t digital_probes1[MaxTraceLenght];
uint8_t digital_probes2[MaxTraceLenght];
uint8_t digital_probes3[MaxTraceLenght];
size_t traceLenght; // 64 bit
uint16_t trigger_threashold; // 16 bit
uint8_t downSampling; // 8 bit
bool board_fail;
size_t event_size; // 64 bit
bool flush;
uint32_t aggCounter; // 32 bit
void PrintEnergyTimeStamp(){
printf("ch: %2d, energy: %u, timestamp: %lu ch, traceLenght: %lu\n", channel, energy, timestamp, traceLenght);
}
void PrintAll(){
printf("============== ch : %2d (0x%2X), fail: %d, flush: %d\n", channel, channel, board_fail, flush);
printf("energy: %u, timestamp: %lu, fine_timestamp: %u \n", energy, timestamp, fine_timestamp);
printf("flag (high): 0x%2X, (low): 0x%3X, traceLength: %lu\n", flags_high_priority, flags_low_priority, traceLenght);
printf("Agg counter : %u, trigger : %u, downSampling: %u \n", aggCounter, trigger_threashold, downSampling);
printf("AnaProbe Type: %u, %u\n", analog_probes_type[0], analog_probes_type[1]);
printf("DigProbe Type: %u, %u, %u, %u\n", digital_probes_type[0], digital_probes_type[1], digital_probes_type[2], digital_probes_type[3]);
}
void PrintTrace(){
for(int i = 0; i < traceLenght; i++){
printf("%4d| %6d %6d %1d %1d %1d %1d\n", i, analog_probes0[i],
analog_probes1[i],
digital_probes0[i],
digital_probes1[i],
digital_probes2[i],
digital_probes3[i]);
}
}
uint64_t word;
uint64_t* GetWord1(){
word = 0;
word += timestamp;
word += ((((uint64_t)channel & 0x3F) << 48));
word += ((((uint64_t)board_fail) << 58));
word += ((((uint64_t)flush) << 59));
word += (((uint64_t) 0xA) << 60);
return &word;
}
uint64_t* GetWord2(){
word = 0;
word += energy;
word += ((((uint64_t)fine_timestamp & 0x3FF) << 16));
word += ((((uint64_t)flags_low_priority & 0xFFF) << 26));
word += ((((uint64_t)flags_high_priority & 0xFF) << 38));
word += ((((uint64_t)traceLenght) << 46));
return &word;
}
uint64_t* GetWord3(){
word = 0;
word += trigger_threashold;
word += ((((uint64_t)aggCounter) << 16));
word += ((((uint64_t)downSampling) << 48));
return &word;
}
uint64_t* GetWord4(){
word = 0;
word += analog_probes_type[0] & 0x7 ;
word += (((uint64_t)(analog_probes_type[1] & 0x7)) << 3) ;
word += (((uint64_t)(digital_probes_type[0] & 0xF)) << 6) ;
word += (((uint64_t)(digital_probes_type[1] & 0xF)) << 10) ;
word += (((uint64_t)(digital_probes_type[2] & 0xF)) << 14) ;
word += (((uint64_t)(digital_probes_type[3] & 0xF)) << 18) ;
return &word;
}
uint64_t* GetWordTrace(int i){
word = 0;
word += analog_probes0[i] & 0x7FFFF;
word += (((uint64_t)analog_probes1[i] & 0x7FFFF) << 32) ;
word += (((uint64_t)digital_probes0[i]) << 18) ;
word += (((uint64_t)digital_probes1[i]) << 19) ;
word += (((uint64_t)digital_probes2[i]) << 50) ;
word += (((uint64_t)digital_probes3[i]) << 51) ;
return &word;
}
};
class Digitizer2Gen {
private:
uint64_t handle;
@ -32,11 +138,13 @@ class Digitizer2Gen {
std::string netMask;
std::string gateway;
void Initialization();
std::string ErrorMsg(const char * funcName);
unsigned short outFileIndex;
public:
Digitizer2Gen();
~Digitizer2Gen();
@ -56,14 +164,17 @@ class Digitizer2Gen {
void StopACQ();
void SetPHADataFormat();
void ReadData();
int ReadData();
void ReadDataRaw(); //not impletmented
void ProgramPHA();
void ProgramPHA(bool testPulse = false);
unsigned short GetNChannels() {return nChannels;}
unsigned short GetCh2ns() {return ch2ns;}
uint64_t GetHandle() {return handle;}
event evt;
void SaveDataToFile(std::string fileName);
};

View File

@ -2,6 +2,8 @@ CC = g++
COPTS = -fPIC -DLINUX -O2 -std=c++17 -lpthread
CAENLIBS = -lCAEN_FELib
all: test test_indep ClassDigitizer2Gen.o
test_indep : test_indep.cpp
$(CC) $(COPTS) -o test_indep test_indep.cpp $(CAENLIBS)

View File

@ -2,6 +2,7 @@
#include <string>
#include <vector>
#include <unistd.h>
#include <time.h> // time in nano-sec
#include "ClassDigitizer2Gen.h"
@ -16,7 +17,7 @@ int main(int argc, char* argv[]){
Digitizer2Gen * digi = new Digitizer2Gen();
digi->OpenDigitizer(url);
digi->ProgramPHA();
digi->ProgramPHA(true);
//printf("%s \n", digi->ReadValue("/ch/0/par/ChRealtimeMonitor").c_str());
//printf("%s \n", digi->ReadValue("/ch/0/par/Energy_Nbit").c_str());
@ -49,16 +50,37 @@ int main(int argc, char* argv[]){
digi->SetPHADataFormat();
digi->StartACQ();
usleep(1e6);
timespec t0, t1;
//digi->ReadData();
clock_gettime(CLOCK_REALTIME, &t0);
for( int i = 0; i < 64*10; i++){
int ret = digi->ReadData();
if( ret == CAEN_FELib_Success){
//digi->evt.PrintAll();
//digi->evt.PrintTrace();
//printf("0x%016lX \n", *(digi->evt.GetWord1()));
//printf("0x%016lX \n", *(digi->evt.GetWord2()));
//printf("0x%016lX \n", *(digi->evt.GetWord3()));
//printf("0x%016lX \n", *(digi->evt.GetWord4()));
digi->SaveDataToFile("haha");
if( digi->evt.channel == 63 ) {
clock_gettime(CLOCK_REALTIME, &t1);
printf("%3d | t1-t0 : %ld\n", i, t1.tv_nsec-t0.tv_nsec);
t0 = t1;
}
}
}
digi->StopACQ();
digi->CloseDigitizer();
delete digi;

View File

@ -112,15 +112,9 @@ void RawDecorder(uint8_t * data, size_t size, int verbose = 0){
}
}
word++;
}
}
int main(){
@ -356,7 +350,7 @@ int main(){
tsum.tv_nsec = 0;
}
/*
if( ret == CAEN_FELib_Success ) {
printf("================= %ld, %d \n", event_size, count);
printf("ch : %u, energy : %u, time : %lu, fTime : %u \n", channel, energy, timestamp, fine_timestamp);
@ -378,7 +372,7 @@ int main(){
digital_probes[3][i]);
}
}*/
}
}