This commit is contained in:
Ryan Tang 2023-01-13 17:35:37 -05:00
parent 82623988ab
commit 2c0dc7d625
5 changed files with 61 additions and 48 deletions

View File

@ -82,7 +82,7 @@ std::string Digitizer2Gen::ReadValue(const char * parameter, bool verbose = fals
if (ret != CAEN_FELib_Success) {
return ErrorMsg(__func__);
}else{
if( verbose ) printf("%s : %s\n", parameter, retValue.c_str());
if( verbose ) printf("%-45s : %s\n", parameter, retValue);
}
return retValue;
}
@ -152,6 +152,10 @@ int Digitizer2Gen::OpenDigitizer(const char * url){
printf(" ADC rate : %d Msps, ch2ns : %d ns\n", adcRate, ch2ns);
printf(" Channels : %d\n", nChannels);
ReadValue("/par/InputRange", true);
ReadValue("/par/InputType", true);
ReadValue("/par/Zin", true);
///SendCommand("/cmd/reset");
return 0;
@ -218,7 +222,6 @@ void Digitizer2Gen::SetPHADataFormat(unsigned short dataFormat){
{ \"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 }, \
@ -357,7 +360,6 @@ int Digitizer2Gen::ReadData(){
&evt->channel,
&evt->timestamp,
&evt->fine_timestamp,
&evt->timestamp_ns,
&evt->energy,
evt->analog_probes[0],
evt->analog_probes[1],
@ -521,8 +523,21 @@ void Digitizer2Gen::SaveDataToFile(){
void Digitizer2Gen::ProgramPHA(bool testPulse){
if( !isConnected ) return ;
// Channel enable
WriteValue("/ch/0..63/par/ChEnable" , "true");
// Acquistion
WriteValue("/par/StartSource" , "SWcmd | SINedge");
WriteValue("/par/TrgOutMode", "Disabled");
WriteValue("/par/GPIOMode", "Disabled");
WriteValue("/par/SyncOutMode", "Disabled");
WriteValue("/par/RunDelay", "0"); // ns, that is for sync time with multi board
WriteValue("/par/IOlevel", "NIM");
WriteValue("/par/EnStatEvents", "1");
// Channel setting
//WriteValue("/ch/0..63/par/EventTriggerSource", "GlobalTriggerSource");
WriteValue("/ch/0..63/par/EventTriggerSource", "ChSelfTrigger");
WriteValue("/ch/0..63/par/ChEnable" , "true");
WriteValue("/ch/0..63/par/DCOffset" , "10"); /// 10%
WriteValue("/ch/0..63/par/WaveSaving" , "Always");
// Global trigger configuration
if( testPulse ) {
@ -536,13 +551,12 @@ void Digitizer2Gen::ProgramPHA(bool testPulse){
}
// Wave configuration
WriteValue("/ch/0..63/par/WaveTriggerSource" , "ChSelfTrigger");
//WriteValue("/ch/0..63/par/WaveTriggerSource" , "ChSelfTrigger"); // EventTriggerSource enought
WriteValue("/ch/0..63/par/ChRecordLengthS" , "512"); /// 4096 ns
WriteValue("/ch/0..63/par/ChPreTriggerS" , "125"); /// 1000 ns
WriteValue("/ch/0..63/par/WaveResolution" , "RES8"); /// 8 ns
WriteValue("/ch/0..63/par/DCOffset" , "10"); /// 10%
WriteValue("/ch/0..63/par/WaveAnalogProbe0" , "ADCInput");
WriteValue("/ch/0..63/par/WaveAnalogProbe1" , "EnergyFilterMinusBaseline");
WriteValue("/ch/0..63/par/WaveDigitalProbe0" , "Trigger");
@ -550,9 +564,6 @@ void Digitizer2Gen::ProgramPHA(bool testPulse){
WriteValue("/ch/0..63/par/WaveDigitalProbe2" , "TimeFilterArmed");
WriteValue("/ch/0..63/par/WaveDigitalProbe3" , "EnergyFilterPeakReady");
// Event configuration
//WriteValue("/ch/0..63/par/EventTriggerSource", "GlobalTriggerSource");
WriteValue("/ch/0..63/par/EventTriggerSource", "ChSelfTrigger");
// Filter parameters
WriteValue("/ch/0..63/par/TimeFilterRiseTimeS" , "10"); // 80 ns
@ -573,15 +584,6 @@ void Digitizer2Gen::ProgramPHA(bool testPulse){
WriteValue("/ch/0..63/par/EnergyFilterLFLimitation" , "Off");
// Other Setting
WriteValue("/par/TrgOutMode", "SwTrg");
WriteValue("/par/IOlevel", "NIM");
ret = CAEN_FELib_SetValue(handle, "/par/EnStatEvents", "true");
if( ret != CAEN_FELib_Success){
ErrorMsg("Enable stats");
}
}
void Digitizer2Gen::ReadDigitizerSettings(){

17
Event.h
View File

@ -17,7 +17,6 @@ class Event {
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
uint16_t flags_low_priority; // 12 bit
uint16_t flags_high_priority; // 8 bit
size_t traceLenght; // 64 bit
@ -38,6 +37,18 @@ class Event {
uint32_t n_events;
Event(){
Init();
}
~Event(){
ClearMemory();
}
void Init(){
channel = 0;
energy = 0;
timestamp = 0;
fine_timestamp = 0;
analog_probes[0] = NULL;
analog_probes[1] = NULL;
digital_probes[0] = NULL;
@ -47,10 +58,6 @@ class Event {
data = NULL;
}
~Event(){
ClearMemory();
}
void ClearMemory(){
if( data != NULL ) delete data;

View File

@ -32,7 +32,10 @@ class SolReader {
void ScanNumBlock();
unsigned int GetNumBlock(){return numBlock;}
unsigned int GetNumBlock() {return numBlock;}
unsigned int GetTotalNumBlock() {return totNumBlock;}
unsigned int GetFilePos() {return filePos;}
unsigned int GetFileSize() {return inFileSize;}
Event * evt;
@ -73,7 +76,7 @@ inline void SolReader::OpenFile(std::string fileName){
inline int SolReader::ReadBlock(int opt = 0){
if( inFile == NULL ) return -1;
if( feof(inFile) ) return -1;
if( inFileSize < filePos) return -1;
if( filePos >= inFileSize) return -1;
fread(&blockStart, 2, 1, inFile);
@ -173,6 +176,8 @@ void SolReader::ScanNumBlock(){
if( inFile == NULL ) return;
if( feof(inFile) ) return;
numBlock = 0;
while( ReadBlock(1) == 0){
//printf("%u, traceLen %lu, %u/%u\n", numBlock, evt->traceLenght, filePos, inFileSize);
}

View File

@ -5,14 +5,18 @@ void script(){
SolReader * reader = new SolReader("haha_000.sol");
Event * evt = reader->evt;
printf("----------file size: %u Byte\n", reader->GetFileSize());
reader->ScanNumBlock();
for( int i = 0; i < 2; i++){
printf("########### nBlock : %u\n", reader->GetNumBlock());
for( int i = 0; i < reader->GetTotalNumBlock() ; i++){
printf("########################## nBlock : %u, %u/%u\n", reader->GetNumBlock(),
reader->GetFilePos(),
reader->GetFileSize());
reader->ReadBlock();
evt->PrintAll();
reader->evt->PrintAllTrace();
//evt->PrintAllTrace();
}

View File

@ -49,7 +49,7 @@ int main(int argc, char* argv[]){
printf("%s\n", digi->GetPath(parHandle).c_str());
*/
//digi->ReadDigitizerSettings();
digi->ReadDigitizerSettings();
digi->SetPHADataFormat(0);
@ -60,37 +60,31 @@ int main(int argc, char* argv[]){
digi->StartACQ();
timespec t0, t1;
clock_gettime(CLOCK_REALTIME, &t0);
for( int i = 0; i < 20; i++){
usleep(100000);
for( int i = 0; i < 30; i++){
//usleep(100000);
int ret = digi->ReadData();
//digi->ReadValue("/ch/4/par/SelfTrgRate", true);
//if( i% 2 == 0 ) printf("0x%X \n", atoi(digi->ReadValue("/par/AcquisitionStatus").c_str()) & 0x3F );
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 ) {
//if( i % 10 == 0 ) {
//if( digi->evt->channel == 63 ) {
//if( i % 63 == 0 ) {
clock_gettime(CLOCK_REALTIME, &t1);
printf("%5d | t1-t0 : %10ld\n", i, t1.tv_nsec-t0.tv_nsec);
t0 = t1;
//digi->ReadStat();
//digi->PrintStat();
}
// //digi->ReadStat();
// //digi->PrintStat();
//}
}else{
printf("something wrong when ReadData() | ret = %d \n", ret);
digi->ErrorMsg("ReadData()");
@ -99,7 +93,8 @@ int main(int argc, char* argv[]){
}
digi->StopACQ();
//digi->ReadStat();
digi->ReadStat();
digi->PrintStat();