Compare commits

..

3 Commits

6 changed files with 542 additions and 161 deletions

1
.gitignore vendored
View File

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

View File

@ -31,9 +31,14 @@ void Digitizer2Gen::Initialization(){
netMask = "";
gateway = "";
outFileIndex = 0;
dataStartIndetifier = 0xA345;
outFile = NULL;
outFileSize = 0;
}
//########################## Handles functions
//########################################### Handles functions
uint64_t Digitizer2Gen::GetHandle(const char * parameter){
uint64_t par_handle;
@ -67,10 +72,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 +101,7 @@ void Digitizer2Gen::SendCommand(const char * parameter){
}
}
//############################## Open digitizer
//########################################### Open digitizer
int Digitizer2Gen::OpenDigitizer(const char * url){
printf("======== %s \n",__func__);
@ -114,7 +119,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 +177,7 @@ int Digitizer2Gen::CloseDigitizer(){
return 0;
}
//################################## DAQ
//########################################### DAQ
void Digitizer2Gen::StartACQ(){
SendCommand("/cmd/armacquisition");
@ -187,7 +191,7 @@ void Digitizer2Gen::StopACQ(){
}
void Digitizer2Gen::SetPHADataFormat(){
void Digitizer2Gen::SetPHADataFormat(unsigned dataFormat){
ret = CAEN_FELib_SetValue(ep_folder_handle, "/par/activeendpoint", "dpppha");
if (ret != CAEN_FELib_Success) {
@ -195,98 +199,280 @@ void Digitizer2Gen::SetPHADataFormat(){
return;
}
ret = CAEN_FELib_SetReadDataFormat(ep_handle, " \
[ \
{ \"name\" : \"CHANNEL\", \"type\" : \"U8\" }, \
{ \"name\" : \"TIMESTAMP\", \"type\" : \"U64\" }, \
{ \"name\" : \"FINE_TIMESTAMP\", \"type\" : \"U16\" }, \
{ \"name\" : \"ENERGY\", \"type\" : \"U16\" }, \
{ \"name\" : \"ANALOG_PROBE_1\", \"type\" : \"I32\", \"dim\" : 1 }, \
{ \"name\" : \"ANALOG_PROBE_2\", \"type\" : \"I32\", \"dim\" : 1 }, \
{ \"name\" : \"DIGITAL_PROBE_1\", \"type\" : \"U8\", \"dim\" : 1 }, \
{ \"name\" : \"DIGITAL_PROBE_2\", \"type\" : \"U8\", \"dim\" : 1 }, \
{ \"name\" : \"DIGITAL_PROBE_3\", \"type\" : \"U8\", \"dim\" : 1 }, \
{ \"name\" : \"DIGITAL_PROBE_4\", \"type\" : \"U8\", \"dim\" : 1 }, \
{ \"name\" : \"ANALOG_PROBE_1_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"ANALOG_PROBE_2_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"DIGITAL_PROBE_1_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"DIGITAL_PROBE_2_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"DIGITAL_PROBE_3_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"DIGITAL_PROBE_4_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"WAVEFORM_SIZE\", \"type\" : \"SIZE_T\" }, \
{ \"name\" : \"FLAGS_LOW_PRIORITY\", \"type\" : \"U16\"}, \
{ \"name\" : \"FLAGS_HIGH_PRIORITY\", \"type\" : \"U16\" }, \
{ \"name\" : \"EVENT_SIZE\", \"type\" : \"SIZE_T\" } \
] \
");
dataFormatID = dataFormat;
if( dataFormatID == 0 ){
ret = CAEN_FELib_SetReadDataFormat(ep_handle, " \
[ \
{ \"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 }, \
{ \"name\" : \"DIGITAL_PROBE_1\", \"type\" : \"U8\", \"dim\" : 1 }, \
{ \"name\" : \"DIGITAL_PROBE_2\", \"type\" : \"U8\", \"dim\" : 1 }, \
{ \"name\" : \"DIGITAL_PROBE_3\", \"type\" : \"U8\", \"dim\" : 1 }, \
{ \"name\" : \"DIGITAL_PROBE_4\", \"type\" : \"U8\", \"dim\" : 1 }, \
{ \"name\" : \"ANALOG_PROBE_1_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"ANALOG_PROBE_2_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"DIGITAL_PROBE_1_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"DIGITAL_PROBE_2_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"DIGITAL_PROBE_3_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"DIGITAL_PROBE_4_TYPE\", \"type\" : \"U8\" }, \
{ \"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\" } \
] \
");
}
if( dataFormatID == 1 ){
ret = CAEN_FELib_SetReadDataFormat(ep_handle, " \
[ \
{ \"name\" : \"CHANNEL\", \"type\" : \"U8\" }, \
{ \"name\" : \"TIMESTAMP\", \"type\" : \"U64\" }, \
{ \"name\" : \"FINE_TIMESTAMP\", \"type\" : \"U16\" }, \
{ \"name\" : \"ENERGY\", \"type\" : \"U16\" }, \
{ \"name\" : \"ANALOG_PROBE_1\", \"type\" : \"I32\", \"dim\" : 1 }, \
{ \"name\" : \"ANALOG_PROBE_1_TYPE\", \"type\" : \"U8\" }, \
{ \"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\" } \
] \
");
}
if( dataFormatID == 2 ){
ret = CAEN_FELib_SetReadDataFormat(ep_handle, " \
[ \
{ \"name\" : \"CHANNEL\", \"type\" : \"U8\" }, \
{ \"name\" : \"TIMESTAMP\", \"type\" : \"U64\" }, \
{ \"name\" : \"FINE_TIMESTAMP\", \"type\" : \"U16\" }, \
{ \"name\" : \"ENERGY\", \"type\" : \"U16\" }, \
{ \"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\" } \
] \
");
}
if( dataFormatID == 3 ){
ret = CAEN_FELib_SetReadDataFormat(ep_handle, " \
[ \
{ \"name\" : \"CHANNEL\", \"type\" : \"U8\" }, \
{ \"name\" : \"TIMESTAMP\", \"type\" : \"U64\" }, \
{ \"name\" : \"ENERGY\", \"type\" : \"U16\" } \
] \
");
}
if (ret != CAEN_FELib_Success) {
ErrorMsg("Set Read Data Format");
return;
}
}
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;
};
int Digitizer2Gen::ReadData(){
//printf("========= %s \n", __func__);
if( dataFormatID == 0){
ret = CAEN_FELib_ReadData(ep_handle, 100,
&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.;
}else if( dataFormatID == 1){
ret = CAEN_FELib_ReadData(ep_handle, 100,
&evt.channel,
&evt.timestamp,
&evt.fine_timestamp,
&evt.energy,
&evt.analog_probes0,
&evt.analog_probes_type[0],
&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
);
}else if( dataFormatID == 2){
ret = CAEN_FELib_ReadData(ep_handle, 100,
&evt.channel,
&evt.timestamp,
&evt.fine_timestamp,
&evt.energy,
&evt.flags_low_priority,
&evt.flags_high_priority,
&evt.trigger_threashold,
&evt.downSampling,
&evt.board_fail,
&evt.flush,
&evt.aggCounter,
&evt.event_size
);
}else if( dataFormatID == 3){
ret = CAEN_FELib_ReadData(ep_handle, 100,
&evt.channel,
&evt.timestamp,
&evt.energy
);
}else{
return CAEN_FELib_UNKNOWN;
}
return ret;
void Digitizer2Gen::ReadData(){
printf("========= %s \n", __func__);
event evt;
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
);
if( ret != CAEN_FELib_Success) {
ErrorMsg("Set Read Data");
return;
return ret;
}
}
//##########################################
void Digitizer2Gen::ProgramPHA(){
void Digitizer2Gen::ReadDataRaw(){
}
//###########################################
void Digitizer2Gen::OpenOutFile(std::string fileName){
outFileNameBase = fileName;
sprintf(outFileName, "%s_%03d.sol", fileName.c_str(), outFileIndex);
outFile = fopen(outFileName, "a+");
fseek(outFile, 0L, SEEK_END);
outFileSize = ftell(outFile); // unsigned int = Max ~4GB
}
void Digitizer2Gen::CloseOutFile(){
fclose(outFile);
}
void Digitizer2Gen::SaveDataToFile(){
if( outFileSize > (unsigned int) MaxOutFileSize){
fclose(outFile);
outFileIndex ++;
sprintf(outFileName, "%s_%03d.sol", outFileNameBase.c_str(), outFileIndex);
outFile = fopen(outFileName, "a+");
}
if( dataFormatID == 0){
fwrite(&dataStartIndetifier, 2, 1, outFile);
fwrite(&evt.channel, 1, 1, outFile);
fwrite(&evt.energy, 2, 1, outFile);
fwrite(&evt.timestamp, 6, 1, outFile);
fwrite(&evt.fine_timestamp, 2, 1, outFile);
fwrite(&evt.flags_high_priority, 1, 1, outFile);
fwrite(&evt.flags_low_priority, 2, 1, outFile);
fwrite(&evt.traceLenght, 8, 1, outFile);
fwrite(&evt.analog_probes_type[0], 1, 1, outFile);
fwrite(evt.analog_probes0, evt.traceLenght*4, 1, outFile);
}else if( dataFormatID == 1){
fwrite(&dataStartIndetifier, 2, 1, outFile);
fwrite(&evt.channel, 1, 1, outFile);
fwrite(&evt.energy, 2, 1, outFile);
fwrite(&evt.timestamp, 6, 1, outFile);
fwrite(&evt.fine_timestamp, 2, 1, outFile);
fwrite(&evt.flags_high_priority, 1, 1, outFile);
fwrite(&evt.flags_low_priority, 2, 1, outFile);
fwrite(&evt.traceLenght, 8, 1, outFile);
fwrite(&evt.analog_probes_type[0], 1, 1, outFile);
fwrite(evt.analog_probes0, evt.traceLenght*4, 1, outFile);
}else if( dataFormatID == 2){
fwrite(&dataStartIndetifier, 2, 1, outFile);
fwrite(&evt.channel, 1, 1, outFile);
fwrite(&evt.energy, 2, 1, outFile);
fwrite(&evt.timestamp, 6, 1, outFile);
fwrite(&evt.fine_timestamp, 2, 1, outFile);
fwrite(&evt.flags_high_priority, 1, 1, outFile);
fwrite(&evt.flags_low_priority, 2, 1, outFile);
}else if( dataFormatID == 3){
//fwrite(&dataStartIndetifier, 2, 1, outFile);
fwrite(&evt.channel, 1, 1, outFile);
fwrite(&evt.energy, 2, 1, outFile);
fwrite(&evt.timestamp, 6, 1, outFile);
}
// tested speed, 64 readout and save cost ~ 200 us. ~ 5 kHz;
//fwrite(evt.digital_probes_type, sizeof(evt.digital_probes_type), 1, outFile);
//fwrite(evt.analog_probes1, evt.traceLenght*4, 1, outFile);
//fwrite(evt.digital_probes0, evt.traceLenght, 1, outFile);
//fwrite(evt.digital_probes1, evt.traceLenght, 1, outFile);
//fwrite(evt.digital_probes2, evt.traceLenght, 1, outFile);
//fwrite(evt.digital_probes3, evt.traceLenght, 1, outFile);
//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);
//}
outFileSize = ftell(outFile); // unsigned int = Max ~4GB
}
//###########################################
void Digitizer2Gen::ProgramPHA(bool testPulse){
if( !isConnected ) return ;
// Channel enable
WriteValue("/ch/0..63/par/ChEnable" , "true");
// Global trigger configuration
///WriteValue("/par/GlobalTriggerSource", "SwTrg");
WriteValue("/par/GlobalTriggerSource", "SwTrg | TestPulse");
WriteValue("/par/TestPulsePeriod" , "100000000");
if( testPulse ) {
WriteValue("/par/GlobalTriggerSource", "SwTrg | TestPulse");
}else{
WriteValue("/par/GlobalTriggerSource", "SwTrg");
}
WriteValue("/par/TestPulsePeriod" , "25000"); // 0.05 msec = 20kHz
WriteValue("/par/TestPulseWidth" , "16");
// Wave configuration

View File

@ -8,6 +8,61 @@
//#include "Parameter.h"
#define MaxOutFileSize 2*1024*1024*1024
#define MaxTraceLenght 2048
#define DataStartIndetifier 0xA345
struct event {
uint8_t channel; // 6 bit
uint16_t energy; // 16 bit
uint64_t timestamp; // 48 bit
uint16_t fine_timestamp; // 16 bit
uint64_t timestamp_ns; // 51 bit fine_timestamp not included
double timestamp_us;
uint16_t flags_low_priority; // 12 bit
uint16_t flags_high_priority; // 8 bit
size_t traceLenght; // 64 bit
uint8_t downSampling; // 8 bit
bool board_fail;
bool flush;
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];
uint16_t trigger_threashold; // 16 bit
size_t event_size; // 64 bit
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]);
}
}
};
class Digitizer2Gen {
private:
uint64_t handle;
@ -32,10 +87,23 @@ class Digitizer2Gen {
std::string netMask;
std::string gateway;
void Initialization();
std::string ErrorMsg(const char * funcName);
unsigned int dataFormatID; // 0 = all data,
// 1 = analog trace-0 only + flags
// 2 = no trace, only ch, energy, timestamp, fine_timestamp + flags
// 3 = only ch, energy, timestamp, minimum
unsigned short outFileIndex;
unsigned short dataStartIndetifier;
std::string outFileNameBase;
char outFileName[100];
FILE * outFile;
unsigned int outFileSize;
public:
Digitizer2Gen();
@ -55,16 +123,21 @@ class Digitizer2Gen {
void StartACQ();
void StopACQ();
void SetPHADataFormat();
void ReadData();
void ProgramPHA();
void SetPHADataFormat(unsigned dataFormat);
int ReadData();
void ReadDataRaw(); //not impletmented
void ProgramPHA(bool testPulse = false);
unsigned short GetNChannels() {return nChannels;}
unsigned short GetCh2ns() {return ch2ns;}
uint64_t GetHandle() {return handle;}
event evt;
void OpenOutFile(std::string fileName);
void CloseOutFile();
void SaveDataToFile();
};
#endif

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());
@ -48,16 +49,42 @@ int main(int argc, char* argv[]){
digi->SetPHADataFormat();
digi->SetPHADataFormat(1);
digi->OpenOutFile("haha");
digi->StartACQ();
usleep(1e6);
//digi->ReadData();
timespec t0, t1;
clock_gettime(CLOCK_REALTIME, &t0);
for( int i = 0; i < 64*20; 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();
if( digi->evt.channel == 63 ) {
clock_gettime(CLOCK_REALTIME, &t1);
printf("%5d | t1-t0 : %10ld\n", i, t1.tv_nsec-t0.tv_nsec);
t0 = t1;
}
}
}
digi->StopACQ();
digi->CloseOutFile();
digi->CloseDigitizer();

View File

@ -4,10 +4,123 @@
#include <cstdio>
#include <unistd.h>
#include <cmath>
#include <time.h> // time in nano-sec
void RawDecorder(uint8_t * data, size_t size, int verbose = 0){
uint64_t haha ;
unsigned short dataType;
int word = 0;
int traceWord = -2;
for( int i =0 ; i < ((int)size / 8) ; i++){
///the data is array of 1 byte.
/// by get the point of the data[8*i]
/// cast it into uint64_t pointer, that will get 8 bytes all togteher
/// get this point value, and bit swap it.
haha = __builtin_bswap64(*(uint64_t *)&(data[8*i]));
if (verbose > 0 ) printf("%7d | %3d | %3d | 0x%016lX \n", i, word, traceWord, haha);
if ( word == 0 ){ /// aggregation header, or start header, or end header
dataType = ( haha >> 56 ) & 0xFF ;
if ( verbose> 0 & dataType == 0x30 ) printf("====== start Run data\n");
if ( verbose> 0 & dataType == 0x32 ) printf("====== Stop Run data\n");
if ( verbose> 0 & (dataType >> 4) == 0x2 ) printf("====== data aggregation start\n");
}else{
if( dataType == 0x30 ){
if( word == 1){
if( (haha & 0xFFFFFFFF) != 0x2000000) printf("*** something wrong.\n");
}
uint64_t channelMask;
if( word == 2){
channelMask = ( haha & 0xFFFFFFFF );
}
if( word == 3){
channelMask += (( haha & 0xFFFFFFFF ) << 32);
if (verbose > 0 ) printf("Channel mask : 0x%016lX\n", channelMask);
}
}
if( (dataType >> 4 ) == 0x2 ) {
unsigned short chID ;
uint64_t timestamp ;
bool hasTrace;
unsigned short fl ; // flag low
unsigned short fh ; // flog hight
unsigned short energy ;
unsigned short fTime ;
unsigned short traceLength;
unsigned short anaProb0[512];
unsigned short anaProb1[512];
bool digProb0[512];
bool digProb1[512];
bool digProb2[512];
bool digProb3[512];
if( word == 1){
chID = ((haha >> 56) & 0x7F);
timestamp = (haha & 0xFFFFFFFFFFFF);
}else if( word == 2){
hasTrace = ((haha >> 62) & 0x1);
fl = (( haha >> 50) & 0x1FFF);
fh = (( haha >> 41) & 0xFF);
energy = (haha & 0xFFFF);
fTime = ((haha >> 15) & 0x7FF);
}else{
if( ((haha >> 63) & 0x1 ) == 1 && traceWord == -2) {
//printf("=====last word of header\n");
traceWord = 0;
if (verbose > 0 ) printf("ch %2d, energy %5u, time %10lu, fTime %5u %10.2f ms 0x%X, 0x%X, %u\n",
chID, energy, timestamp, fTime, (timestamp*8 + fTime*0.0078125) / 1e+6 , fl, fh, hasTrace);
word ++;
continue;
}
if( hasTrace) {
if( traceWord == 0) {
traceLength = (haha & 0xFFF );
word ++;
traceWord ++;
continue;
}
if( traceWord > 0 ){
anaProb0[traceWord-1] = (haha & 0x3FFF);
anaProb1[traceWord-1] = ((haha >> 16) & 0x3FFF);
digProb0[traceWord-1] = ((haha >> 14) & 0x1);
digProb1[traceWord-1] = ((haha >> 15) & 0x1);
digProb2[traceWord-1] = ((haha >> 30) & 0x1);
digProb3[traceWord-1] = ((haha >> 31) & 0x1);
traceWord ++;
if( traceWord - 1 == traceLength ){
//printf("============= end of one data, traceLength = %d\n", traceLength);
word = 0;
traceWord = -2;
}
}
}
}
}
}
word++;
}
}
int main(){
int ret;
timespec t0, t1, t2;
//#################################### Open digitizer
uint64_t dev_handle;
@ -31,20 +144,20 @@ int main(){
/// Global trigger configuration
ret = CAEN_FELib_SetValue(dev_handle, "/par/GlobalTriggerSource", "SwTrg | TestPulse"); // use test Pulse
ret = CAEN_FELib_SetValue(dev_handle, "/par/TestPulsePeriod", "100000000"); /// ns
ret = CAEN_FELib_SetValue(dev_handle, "/par/TestPulsePeriod", "1000000"); /// ns, 1 msec
ret = CAEN_FELib_SetValue(dev_handle, "/par/TestPulseWidth", "16"); ///ns
/// Wave configuration
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/ChRecordLengthS", "512");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/ChRecordLengthS", "512"); // when setting sample, the ChRecordLengthT will not set. vice versa
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveTriggerSource", "GlobalTriggerSource");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveResolution", "RES8");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveResolution", "RES8"); // 8 ns
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveAnalogProbe0", "ADCInput");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveAnalogProbe1", "TimeFilter");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveDigitalProbe0", "Trigger");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveDigitalProbe1", "TimeFilterArmed");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveDigitalProbe2", "EnergyFilterBaselineFreeze");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveDigitalProbe3", "EnergyFilterPeakReady");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/ChPreTriggerS", "200");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/ChPreTriggerS", "100");
/// Event configuration
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EventTriggerSource", "GlobalTriggerSource");
@ -65,8 +178,17 @@ int main(){
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterFineGain", "1.0");
//#################################### Set the end point for data
if( ret != CAEN_FELib_Success) printf("errro in set value\n");
//#################################### setting readout
ret = CAEN_FELib_GetValue(dev_handle, "/ch/10/par/ChRecordLengthS", value);
if( ret != CAEN_FELib_Success) printf("errro in get value\n");
printf("trace length : %s sample\n", value);
//#################################### Set the end point for data
/*
{//----------------------- RAW
uint64_t ep_handle;
ret = CAEN_FELib_GetHandle(dev_handle, "/endpoint/raw", &ep_handle);
@ -85,7 +207,7 @@ int main(){
);
uint8_t* data = new uint8_t[200000];
size_t size; /// number of byte of the data
size_t size; /// number of byte of the data, size/8 = word [64 bits]
uint32_t n_events;
printf("Starting ACQ\n");
@ -93,70 +215,25 @@ int main(){
ret = CAEN_FELib_SendCommand(dev_handle, "/cmd/swstartacquisition");
int count = 0;
for( int i = 0; i < 2; i++){
for( int i = 0; i < 10; i++){
usleep(10000);
//usleep(1000000);
clock_gettime(CLOCK_REALTIME, &t0);
ret = CAEN_FELib_ReadData(ep_handle, 100, data, &size, &n_events );
count ++;
clock_gettime(CLOCK_REALTIME, &t1);
if( ret == CAEN_FELib_Success ) {
printf("================= %u, %ld, %d \n", n_events, size, count);
uint64_t haha ;
unsigned short dataType;
int word = 0;
for( int i =0 ; i < std::min((int)size / 8, 100) ; i++){
///the data is array of 1 byte.
/// by get the point of the data[8*i]
/// cast it into uint64_t pointer, that will get 8 bytes all togteher
/// get this point value, and bit swap it.
haha = __builtin_bswap64(*(uint64_t *)&(data[8*i]));
printf("%7d | 0x%016lX \n", i, haha);
if ( word == 0 ){ /// aggregation header, or start header, or end header
dataType = ( haha >> 55 ) & 0xFF ;
if ( dataType == 0x30 ){ /// start Run data
}
if ( dataType == 0x32 ){ /// stop Run data
}
if ( (dataType >> 4) == 0x2 ){ /// data aggregation
}
}
if ( word == 1 ){
unsigned short channel = ((haha >> 56) & 0x7F);
unsigned short SE = ((haha >> 55) & 0x1);
uint64_t timestamp = (haha & 0xFFFFFFFFFFFF);
printf("ch %u, SE %u, %llu \n", channel, SE, timestamp);
}
if ( word == 2 ){
unsigned short W = ((haha >> 62) & 0x1);
unsigned short fl = (( haha >> 50) & 0x1FFF);
unsigned short fh = (( haha >> 41) & 0xFF);
unsigned short energy = (haha & 0xFFFF);
unsigned short fTime = ((haha >> 15) & 7FF);
printf("energy %u, fTiem %u, fl %u, fh %u, W %u\n", energy, fTime, fl, fh, W);
}*/
word++;
}
printf("================= %u, %ld byte, %d \n", n_events, size, count);
RawDecorder(data, size);
clock_gettime(CLOCK_REALTIME, &t2);
printf("t2-t1 : %ld\n", t2.tv_nsec-t1.tv_nsec);
}
printf("t1-t0 : %ld\n", t1.tv_nsec-t0.tv_nsec);
}
@ -164,8 +241,8 @@ int main(){
ret = CAEN_FELib_SendCommand(dev_handle, "/cmd/disarmacquisition");
}
/**/
/**
{//------------------------ DPPPHA
uint64_t ep_handle;
ret = CAEN_FELib_GetHandle(dev_handle, "/endpoint/dpppha", &ep_handle);
@ -231,11 +308,14 @@ int main(){
ret = CAEN_FELib_SendCommand(dev_handle, "/cmd/armacquisition");
ret = CAEN_FELib_SendCommand(dev_handle, "/cmd/swstartacquisition");
timespec tsum;
int count = 0;
for( int i = 0; i < 10; i++){
for( int i = 0; i < 64*5; i++){
usleep(10000);
//usleep(10000);
clock_gettime(CLOCK_REALTIME, &t0);
ret = CAEN_FELib_ReadData(ep_handle, 100,
&channel,
&timestamp,
@ -259,6 +339,18 @@ int main(){
&event_size
);
count ++;
clock_gettime(CLOCK_REALTIME, &t1);
printf("%3d | t1-t0 : %ld\n", i, t1.tv_nsec-t0.tv_nsec);
tsum.tv_nsec += t1.tv_nsec-t0.tv_nsec;
if( channel == 63) {
printf("================###################=== tsum : %ld\n", tsum.tv_nsec);
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);