has the decode.C for decoding the saved data
This commit is contained in:
parent
e556977729
commit
7e24189527
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -3,6 +3,8 @@
|
|||
*.cxx
|
||||
|
||||
*.bin
|
||||
*.txt
|
||||
*.fsu
|
||||
|
||||
test
|
||||
FSUDAQ
|
||||
|
|
46
ClassData.h
46
ClassData.h
|
@ -56,7 +56,7 @@ class Data{
|
|||
|
||||
void PrintBuffer(); //Incorrect
|
||||
void DecodeBuffer(bool fastDecode, int verbose = 0);
|
||||
void DecodeBuffer(char * buffer, bool fastDecode, int verbose = 0); // for outside data
|
||||
void DecodeBuffer(char * buffer, unsigned int size, bool fastDecode, int verbose = 0); // for outside data
|
||||
|
||||
void PrintStat();
|
||||
|
||||
|
@ -107,13 +107,11 @@ inline void Data::AllocateMemory(){
|
|||
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);
|
||||
|
||||
}
|
||||
|
||||
inline void Data::ClearTriggerRate(){ for( int i = 0 ; i < MaxNChannels; i++) TriggerRate[i] = 0.0; }
|
||||
|
||||
inline void Data::ClearData(){
|
||||
|
||||
nByte = 0;
|
||||
AllocatedSize = 0;
|
||||
BufferSize = 0;
|
||||
|
@ -138,16 +136,6 @@ inline void Data::ClearData(){
|
|||
tempDigiWaveform2.clear();
|
||||
}
|
||||
|
||||
|
||||
inline unsigned int Data::ReadBuffer(unsigned int nWord, int verbose){
|
||||
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 >= 2) printf("%d | 0x%08x\n", nWord, word);
|
||||
return word;
|
||||
}
|
||||
|
||||
inline void Data::SaveBuffer(const char * fileName){
|
||||
|
||||
char saveFileName[100];
|
||||
|
@ -192,8 +180,18 @@ inline void Data::PrintBuffer(){
|
|||
}
|
||||
|
||||
//####################################################### Decode
|
||||
inline void Data::DecodeBuffer(char * buffer, bool fastDecode, int verbose){
|
||||
inline unsigned int Data::ReadBuffer(unsigned int nWord, int verbose){
|
||||
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 >= 2) printf("%6d | 0x%08X | ", nWord, word);
|
||||
return word;
|
||||
}
|
||||
|
||||
inline void Data::DecodeBuffer(char * buffer, unsigned int size, bool fastDecode, int verbose){
|
||||
this->buffer = buffer;
|
||||
this->nByte = size;
|
||||
DecodeBuffer(fastDecode, verbose);
|
||||
}
|
||||
|
||||
|
@ -212,25 +210,25 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
|
|||
nw = 0;
|
||||
|
||||
do{
|
||||
if( verbose >= 2 ) printf("######################################### Board Agg.\n");
|
||||
if( verbose >= 1 ) printf("######################################### Board Agg.\n");
|
||||
unsigned int word = ReadBuffer(nw, verbose);
|
||||
if( ( (word >> 28) & 0xF ) == 0xA ) { /// start of Board Agg
|
||||
unsigned int nWord = word & 0x0FFFFFFF ;
|
||||
if( verbose >= 2 ) printf(" number of words in this Agg : %d \n", nWord);
|
||||
if( verbose >= 1 ) printf("Number of words in this Agg : %u \n", nWord);
|
||||
|
||||
nw = nw + 1; word = ReadBuffer(nw, verbose);
|
||||
unsigned int BoardID = ((word >> 27) & 0x1F);
|
||||
bool BoardFailFlag = ((word >> 26) & 0x1 );
|
||||
unsigned int ChannelMask = ( word & 0xFF ) ;
|
||||
if( verbose >= 2 ) printf("Board ID : %d, FailFlag = %d, ChannelMask = 0x%x\n", BoardID, BoardFailFlag, ChannelMask);
|
||||
if( verbose >= 1 ) printf("Board ID : %d, FailFlag = %d, ChannelMask = 0x%X\n", BoardID, BoardFailFlag, ChannelMask);
|
||||
|
||||
nw = nw + 2;
|
||||
unsigned int AggCounter = ReadBuffer(nw, verbose);
|
||||
if( verbose >= 2 ) printf("Agg Counter : %d \n", AggCounter);
|
||||
if( verbose >= 2 ) printf("Agg Counter : %u \n", AggCounter);
|
||||
|
||||
for( int chMask = 0; chMask < MaxNChannels/2 ; chMask ++ ){
|
||||
if( ((ChannelMask >> chMask) & 0x1 ) == 0 ) continue;
|
||||
if( verbose >= 2 ) printf("---------------------- Dual Channel Block : %d, nw : %d\n", chMask *2, nw);
|
||||
if( verbose >= 2 ) printf("---------------------- Dual Channel Block, ch Mask : %d, nw : %d\n", chMask *2, nw);
|
||||
|
||||
if( DPPType == V1730_DPP_PHA_CODE ) {
|
||||
if ( DecodePHADualChannelBlock(chMask, fastDecode, verbose) < 0 ) break;
|
||||
|
@ -263,7 +261,7 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe
|
|||
|
||||
bool hasFormatInfo = ((word >> 31) & 0x1);
|
||||
unsigned int aggSize = ( word & 0x7FFFFFFF ) ;
|
||||
if( verbose >= 2 ) printf(" size : %d \n", aggSize);
|
||||
if( verbose >= 2 ) printf("Dual Channel size : %d \n", aggSize);
|
||||
unsigned int nSample = 0; /// wave form;
|
||||
unsigned int nEvents = 0;
|
||||
unsigned int extra2Option = 0;
|
||||
|
@ -284,8 +282,11 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe
|
|||
hasDualTrace = ( (word >> 31 ) & 0x1 );
|
||||
|
||||
if( verbose >= 2 ) {
|
||||
printf("dualTrace : %d, Energy : %d, Time: %d, Wave : %d, Extra2: %d \n",
|
||||
printf("DualTrace : %d, Energy : %d, Time: %d, Wave : %d, Extra2: %d \n",
|
||||
hasDualTrace, hasEnergy, hasTimeStamp, hasWaveForm, hasExtra2);
|
||||
}
|
||||
|
||||
if( verbose >= 3){
|
||||
if( hasExtra2 ){
|
||||
printf("...... extra 2 : ");
|
||||
switch (extra2Option){
|
||||
|
@ -404,6 +405,7 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe
|
|||
unsigned long long timeStamp = (extTimeStamp << 30) ;
|
||||
timeStamp = timeStamp + timeStamp0;
|
||||
|
||||
if( verbose >= 2) printf("TimeStamp : %llu\n", timeStamp);
|
||||
nw = nw +1 ; word = ReadBuffer(nw, verbose);
|
||||
unsigned int extra = (( word >> 16) & 0x3FF);
|
||||
unsigned int energy = (word & 0x7FFF);
|
||||
|
@ -411,7 +413,7 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe
|
|||
bool pileUp = (extra & 0x200);
|
||||
bool rollOver = (extra & 0x002);
|
||||
|
||||
if( verbose >= 2 ) {
|
||||
if( verbose >= 3 ) {
|
||||
printf("PileUp : %d , extra : 0x%03x, energy : %d \n", pileUp, extra, energy);
|
||||
|
||||
printf(" lost event : %d \n", ((extra >> 0) & 0x1) );
|
||||
|
|
39
decode.C
Normal file
39
decode.C
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include "ClassData.h"
|
||||
|
||||
void decode() {
|
||||
|
||||
FILE * haha = fopen("ExpName_run000_323_000.fsu", "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();
|
||||
data->DPPType = V1730_DPP_PHA_CODE;
|
||||
|
||||
haha = fopen("ExpName_run000_323_000.fsu", "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("-------- %7d word = %d bytes\n", aggSize/4, aggSize);
|
||||
char * buffer = new char[aggSize];
|
||||
dump = fread(buffer, aggSize, 1, haha);
|
||||
|
||||
data->DecodeBuffer(buffer, aggSize, 0, 2);
|
||||
|
||||
if( ftell(haha) >= 12046*10 ) break;
|
||||
|
||||
}while(!feof(haha) );
|
||||
|
||||
|
||||
fclose(haha);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user