diff --git a/.gitignore b/.gitignore index 38d240f..963e446 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ EventKenshikushi EventBuilder DataGenerator DataReaderScript +DataReader pid.dat DAQLock.dat diff --git a/DataReaderScript.cpp b/DataReaderScript.cpp index 18fe1b2..aa1b2b7 100644 --- a/DataReaderScript.cpp +++ b/DataReaderScript.cpp @@ -1,13 +1,16 @@ +/************* + +This can be loaded to root and run the DataReader() + +***********/ + #include "ClassData.h" #include "MultiBuilder.h" - -void DataReaderScript(){ +void DataReader(std::string fileName, int DPPType){ Data * data = new Data(); - data->DPPType = V1730_DPP_PSD_CODE; - - std::string fileName = "data/temp_046_325_PHA_000.fsu"; + data->DPPType = DPPType; FILE * haha = fopen(fileName.c_str(), "r"); fseek(haha, 0L, SEEK_END); @@ -17,17 +20,22 @@ void DataReaderScript(){ fseek(haha, 0, SEEK_SET); - MultiBuilder * mb = new MultiBuilder(data, V1730_DPP_PSD_CODE); + MultiBuilder * mb = new MultiBuilder(data, DPPType); char * buffer = nullptr; int countBdAgg = 0; do{ - long fPos1 = ftell(haha); + //long fPos1 = ftell(haha); unsigned int word[1]; /// 4 bytes size_t dummy = fread(word, 4, 1, haha); + if( dummy != 1) { + printf("fread error, should read 4 bytes, but read %ld x 4 byte, file pos: %ld byte\n", dummy, ftell(haha)); + break; + } + fseek(haha, -4, SEEK_CUR); short header = ((word[0] >> 28 ) & 0xF); if( header != 0xA ) break; @@ -35,13 +43,16 @@ void DataReaderScript(){ unsigned int aggSize = (word[0] & 0x0FFFFFFF) * 4; ///byte buffer = new char[aggSize]; dummy = fread(buffer, aggSize, 1, haha); - if( dummy != 1) printf("fread error, should read 4 bytes, but read %ld x 4 byte\n", dummy); + if( dummy != 1) { + printf("fread error, should read %d bytes, but read %ld x %d byte, file pos: %ld byte \n", aggSize, dummy, aggSize, ftell(haha)); + break; + } - long fPos2 = ftell(haha); + //long fPos2 = ftell(haha); countBdAgg ++; - printf("Board Agg. has %d word = %d bytes | %ld - %ld\n", aggSize/4, aggSize, fPos1, fPos2); - printf("==================== %d Agg\n", countBdAgg); + // printf("Board Agg. has %d word = %d bytes | %ld - %ld\n", aggSize/4, aggSize, fPos1, fPos2); + // printf("==================== %d Agg\n", countBdAgg); data->DecodeBuffer(buffer, aggSize, false, 0); // data own the buffer data->ClearBuffer(); // this will clear the buffer. @@ -57,22 +68,35 @@ void DataReaderScript(){ }while(!feof(haha) && ftell(haha) < inFileSize); - - data->PrintStat(); - data->PrintAllData(); - fclose(haha); - mb->PrintStat(); + printf("============================ done | Total Agg. %d\n", countBdAgg); + data->PrintStat(); + //data->PrintAllData(); + + + //mb->PrintStat(); delete mb; delete data; } -int main(){ +int main(int argc, char **argv){ - DataReaderScript(); + printf("=========================================\n"); + printf("=== *.fsu data reader ===\n"); + printf("=========================================\n"); + if (argc <= 1) { + printf("Incorrect number of arguments:\n"); + printf("%s [inFile] [DPPType] \n", argv[0]); + printf(" +-- PHA = %d\n", V1730_DPP_PHA_CODE); + printf(" +-- PSD = %d\n", V1730_DPP_PSD_CODE); + return 1; + } + + + DataReader(argv[1], atoi(argv[2])); return 0; diff --git a/EventBuilder.cpp b/EventBuilder.cpp index 9ebfd96..2cee8ed 100644 --- a/EventBuilder.cpp +++ b/EventBuilder.cpp @@ -238,7 +238,7 @@ int main(int argc, char **argv) { } aggCount++; - }while(aggCount < 10); // get 10 agg + }while(aggCount < 10); // get 10 agg should be enough for events building mb->BuildEvents(0, 0, debug); diff --git a/Makefile_test b/Makefile_test deleted file mode 100644 index d82003d..0000000 --- a/Makefile_test +++ /dev/null @@ -1,50 +0,0 @@ -######################################################################## -# -# -######################################################################### - -CC = g++ - -#COPTS = -fPIC -DLINUX -O2 -std=c++17 -lpthread -COPTS = -fPIC -DLINUX -g -O2 -Wall -std=c++17 -lpthread - -CAENLIBS = -lCAENDigitizer - -ROOTLIBS = `root-config --cflags --glibs` - -OBJS = ClassDigitizer.o MultiBuilder.o - -ALL = test test_indep DataGenerator EventBuilder DataReaderScript - -######################################################################### - -all : $(ALL) - -clean : - /bin/rm -f $(OBJS) $(ALL) - -MultiBuilder.o : MultiBuilder.cpp MultiBuilder.h - $(CC) $(COPTS) -c MultiBuilder.cpp - -ClassDigitizer.o : ClassDigitizer.cpp ClassDigitizer.h RegisterAddress.h macro.h ClassData.h - $(CC) $(COPTS) -c ClassDigitizer.cpp - -test : test.cpp ClassDigitizer.o - @echo "--------- making test" - $(CC) $(COPTS) -o test test.cpp ClassDigitizer.o $(CAENLIBS) $(ROOTLIBS) - -test_indep : test_indep.cpp RegisterAddress.h macro.h - @echo "--------- making test_indep" - $(CC) $(COPTS) -o test_indep test_indep.cpp $(CAENLIBS) - -DataGenerator : DataGenerator.cpp ClassDigitizer.o - @echo "--------- making DataGenerator" - $(CC) $(COPTS) -o DataGenerator DataGenerator.cpp ClassDigitizer.o $(CAENLIBS) - -DataReaderScript : DataReaderScript.cpp ClassData.h MultiBuilder.o - @echo "--------- making DataReaderScript" - $(CC) $(COPTS) -o DataReaderScript DataReaderScript.cpp ClassData.h MultiBuilder.o $(CAENLIBS) - -EventBuilder : EventBuilder.cpp ClassData.h MultiBuilder.o - @echo "--------- making EventBuilder" - $(CC) $(COPTS) -o EventBuilder EventBuilder.cpp MultiBuilder.o $(CAENLIBS) $(ROOTLIBS) \ No newline at end of file