179 lines
6.1 KiB
C++
179 lines
6.1 KiB
C++
#ifndef DATA_H
|
|
#define DATA_H
|
|
|
|
#include <stdio.h>
|
|
#include <string>
|
|
#include <sstream>
|
|
#include <cmath>
|
|
#include <cstring> ///memset
|
|
#include <iostream> ///cout
|
|
#include <bitset>
|
|
|
|
#include "CAENDigitizer.h"
|
|
#include "CAENDigitizerType.h"
|
|
|
|
#include "macro.h"
|
|
|
|
class Data{
|
|
|
|
public:
|
|
|
|
unsigned int nByte; /// number of byte
|
|
char *buffer; /// readout buffer
|
|
uint32_t NumEvents[MaxNChannels];
|
|
uint32_t AllocatedSize;
|
|
uint32_t BufferSize;
|
|
CAEN_DGTZ_DPP_PHA_Event_t *Events[MaxNChannels]; /// events buffer
|
|
CAEN_DGTZ_DPP_PHA_Waveforms_t *Waveform[MaxNChannels]; /// waveforms buffer
|
|
|
|
public:
|
|
Data(){
|
|
nByte = 0;
|
|
buffer = NULL;
|
|
AllocatedSize = 0;
|
|
BufferSize = 0;
|
|
for( int i = 0 ; i < MaxNChannels; i++){
|
|
NumEvents[i] = 0;
|
|
Events[i] = NULL;
|
|
Waveform[i] = NULL;
|
|
}
|
|
}
|
|
|
|
~Data(){
|
|
delete buffer;
|
|
for( int i = 0 ; i < MaxNChannels; i++){
|
|
delete Events [i];
|
|
delete Waveform [i];
|
|
}
|
|
}
|
|
|
|
void AllocateMemory(){
|
|
|
|
BufferSize = 100000; /// byte
|
|
buffer = (char *) malloc( BufferSize);
|
|
printf("Allocated %d byte for buffer \n", BufferSize);
|
|
|
|
for( int i = 0 ; i < MaxNChannels ; i++ ) Events[i] = (CAEN_DGTZ_DPP_PHA_Event_t *) malloc( BufferSize);
|
|
printf("Allocated %d byte for Events for each channel \n", BufferSize);
|
|
|
|
}
|
|
|
|
void FreeMemory(){
|
|
printf("======= Free memory, not impletment yet \n");
|
|
}
|
|
|
|
void ReadAllBuffer(){
|
|
if( buffer == NULL ) return;
|
|
|
|
unsigned int nw = 0;
|
|
|
|
do{
|
|
printf("#########################################\n");
|
|
unsigned int word = ReadBuffer(nw);
|
|
if( ( (word >> 28) & 0xF ) == 0xA ) { /// start of Board Agg
|
|
unsigned int nWord = word & 0x0FFFFFFF ;
|
|
printf(" number of words in this Agg : %d \n", nWord);
|
|
|
|
nw = nw + 1; word = ReadBuffer(nw);
|
|
unsigned int BoardID = ((word >> 27) & 0x1F);
|
|
bool BoardFailFlag = ((word >> 26) & 0x1 );
|
|
unsigned int ChannelMask = ( word & 0xFF ) ;
|
|
printf("Board ID : %d, FailFlag = %d, ChannelMask = 0x%x\n", BoardID, BoardFailFlag, ChannelMask);
|
|
|
|
nw = nw + 2;
|
|
unsigned int AggCounter = ReadBuffer(nw);
|
|
printf("Agg Counter : %d \n", AggCounter);
|
|
|
|
printf("----------------------\n");
|
|
|
|
nw = nw + 1;
|
|
do{
|
|
word = ReadBuffer(nw);
|
|
bool hasFormatInfo = ((word >> 31) & 0x1);
|
|
unsigned int aggSize = ( word & 0x3FFFFFF ) ;
|
|
printf(" size : %d \n", aggSize);
|
|
unsigned int nSample = 0; /// wave form;
|
|
unsigned int nEvents = 0;
|
|
if( hasFormatInfo ){
|
|
nw = nw + 1; word = ReadBuffer(nw);
|
|
nSample = ( word & 0xFFFF ) * 8;
|
|
unsigned int digitalProbe = ( (word >> 16 ) & 0xF );
|
|
unsigned int analogProbe2 = ( (word >> 20 ) & 0x3 );
|
|
unsigned int analogProbe1 = ( (word >> 22 ) & 0x3 );
|
|
unsigned int extra2Option = ( (word >> 24 ) & 0x7 );
|
|
bool hasWaveForm = ( (word >> 27 ) & 0x1 );
|
|
bool hasExtra2 = ( (word >> 28 ) & 0x1 );
|
|
bool hasTimeStamp = ( (word >> 29 ) & 0x1 );
|
|
bool hasEnergy = ( (word >> 30 ) & 0x1 );
|
|
bool hasDualTrace = ( (word >> 31 ) & 0x1 );
|
|
|
|
printf("dualTrace : %d, Energy : %d, Time: %d, Wave : %d, Extra2: %d, Extra2Option: %d \n",
|
|
hasDualTrace, hasEnergy, hasTimeStamp, hasWaveForm, hasExtra2, extra2Option);
|
|
printf("Ana Probe 1 & 2: %d %d , Digi Probe: %d, nSample : %d \n",
|
|
analogProbe1, analogProbe2, digitalProbe, nSample);
|
|
|
|
nEvents = aggSize / (nSample/2 + 2 + hasExtra2 );
|
|
printf("=========== nEvents : %d \n", nEvents);
|
|
}else{
|
|
printf("does not has format info. unable to read buffer.\n");
|
|
break;
|
|
}
|
|
|
|
for( int ev = 0; ev < nEvents ; ev++){
|
|
printf("=================================== event : %d\n", ev);
|
|
nw = nw +1 ; word = ReadBuffer(nw);
|
|
bool channelTag = ((word >> 31) & 0x1);
|
|
unsigned int timeStamp = (word & 0x7FFFFFFF);
|
|
int channel = log(ChannelMask)/log(2) *2 + channelTag;
|
|
printf("ch : %d, timeStamp %u \n", channel, timeStamp);
|
|
|
|
///===== read waveform
|
|
for( int wi = 0; wi < nSample/2; wi++){
|
|
nw = nw +1 ; word = ReadBuffer(nw, false);
|
|
bool isTrigger1 = (( word >> 31 ) & 0x1 );
|
|
unsigned int wave1 = (( word >> 16) & 0x3FFF);
|
|
|
|
bool isTrigger0 = (( word >> 15 ) & 0x1 );
|
|
unsigned int wave0 = ( word & 0x3FFF);
|
|
|
|
if( ev == 0 ){
|
|
printf(" %5d, %d \n", wave0, isTrigger0);
|
|
printf(" %5d, %d \n", wave1, isTrigger1);
|
|
}
|
|
}
|
|
|
|
nw = nw +1 ; word = ReadBuffer(nw);
|
|
unsigned int extra2 = word;
|
|
|
|
nw = nw +1 ; word = ReadBuffer(nw);
|
|
unsigned int extra = (( word >> 16) & 0x3FF);
|
|
unsigned int energy = (word & 0x7FFF);
|
|
bool pileUp = ((word >> 15) & 0x1);
|
|
|
|
printf("PileUp : %d , extra : 0x%4x, energy : %d \n", pileUp, extra, energy);
|
|
|
|
}
|
|
|
|
nw ++;
|
|
}while( nw < nWord);
|
|
}else{
|
|
printf("incorrect buffer header. \n");
|
|
break;
|
|
}
|
|
}while(true);
|
|
}
|
|
|
|
unsigned int ReadBuffer(unsigned int nWord, bool verbose = true){
|
|
if( buffer == NULL ) return 0;
|
|
|
|
unsigned int word = 0;
|
|
for( int i = 0 ; i < 4 ; i++) word += ((buffer[i + 4 * nWord] & 0xFF) << 8*i);
|
|
if( verbose) printf("%d | 0x%08x\n", nWord, word);
|
|
return word;
|
|
}
|
|
|
|
};
|
|
|
|
|
|
#endif
|