2023-08-28 15:19:50 -04:00
|
|
|
/*************
|
|
|
|
|
|
|
|
This can be loaded to root and run the DataReader()
|
|
|
|
|
|
|
|
***********/
|
|
|
|
|
2023-11-16 19:20:29 -05:00
|
|
|
#include "../ClassData.h"
|
|
|
|
#include "../MultiBuilder.h"
|
2023-06-19 12:48:17 -04:00
|
|
|
|
2023-08-28 15:19:50 -04:00
|
|
|
void DataReader(std::string fileName, int DPPType){
|
2023-05-16 11:26:22 -04:00
|
|
|
|
2023-10-09 13:12:48 -04:00
|
|
|
Data * data = new Data(64);
|
2023-08-28 15:19:50 -04:00
|
|
|
data->DPPType = DPPType;
|
2023-05-16 11:26:22 -04:00
|
|
|
|
|
|
|
FILE * haha = fopen(fileName.c_str(), "r");
|
|
|
|
fseek(haha, 0L, SEEK_END);
|
|
|
|
const long inFileSize = ftell(haha);
|
|
|
|
printf("%s | file size : %ld Byte = %.2f MB\n", fileName.c_str() , inFileSize, inFileSize/1024./1024.);
|
|
|
|
|
|
|
|
|
|
|
|
fseek(haha, 0, SEEK_SET);
|
|
|
|
|
2023-10-05 13:13:15 -04:00
|
|
|
MultiBuilder * mb = new MultiBuilder(data, DPPType, 0);
|
2023-09-05 14:23:52 -04:00
|
|
|
mb->SetTimeWindow(0);
|
2023-06-19 12:48:17 -04:00
|
|
|
|
2023-05-16 11:26:22 -04:00
|
|
|
char * buffer = nullptr;
|
|
|
|
int countBdAgg = 0;
|
|
|
|
|
|
|
|
do{
|
|
|
|
|
2023-08-28 15:19:50 -04:00
|
|
|
//long fPos1 = ftell(haha);
|
2023-05-16 11:26:22 -04:00
|
|
|
|
|
|
|
unsigned int word[1]; /// 4 bytes
|
2023-06-19 12:48:17 -04:00
|
|
|
size_t dummy = fread(word, 4, 1, haha);
|
2023-08-28 15:19:50 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-05-16 11:26:22 -04:00
|
|
|
fseek(haha, -4, SEEK_CUR);
|
|
|
|
short header = ((word[0] >> 28 ) & 0xF);
|
|
|
|
if( header != 0xA ) break;
|
|
|
|
|
|
|
|
unsigned int aggSize = (word[0] & 0x0FFFFFFF) * 4; ///byte
|
|
|
|
buffer = new char[aggSize];
|
2023-06-19 12:48:17 -04:00
|
|
|
dummy = fread(buffer, aggSize, 1, haha);
|
2023-08-28 15:19:50 -04:00
|
|
|
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;
|
|
|
|
}
|
2023-06-19 12:48:17 -04:00
|
|
|
|
2023-08-28 15:19:50 -04:00
|
|
|
//long fPos2 = ftell(haha);
|
2023-05-16 11:26:22 -04:00
|
|
|
|
|
|
|
countBdAgg ++;
|
2023-08-28 15:19:50 -04:00
|
|
|
// printf("Board Agg. has %d word = %d bytes | %ld - %ld\n", aggSize/4, aggSize, fPos1, fPos2);
|
|
|
|
// printf("==================== %d Agg\n", countBdAgg);
|
2023-06-14 15:20:15 -04:00
|
|
|
|
2023-05-16 11:26:22 -04:00
|
|
|
data->DecodeBuffer(buffer, aggSize, false, 0); // data own the buffer
|
|
|
|
data->ClearBuffer(); // this will clear the buffer.
|
|
|
|
|
2023-06-14 15:20:15 -04:00
|
|
|
//if( countBdAgg % 100 == 0) data->PrintStat();
|
2023-05-16 11:26:22 -04:00
|
|
|
//data->ClearData();
|
2023-05-17 17:05:27 -04:00
|
|
|
|
2023-09-06 09:59:06 -04:00
|
|
|
//if( countBdAgg > 10 ){
|
2023-09-05 14:23:52 -04:00
|
|
|
//data->PrintAllData();
|
|
|
|
|
2023-09-06 09:59:06 -04:00
|
|
|
//mb->BuildEvents(false, true, false);
|
2023-09-05 14:23:52 -04:00
|
|
|
//mb->BuildEventsBackWard(false);
|
2023-09-06 09:59:06 -04:00
|
|
|
//}
|
2023-06-19 12:48:17 -04:00
|
|
|
|
2023-05-16 11:26:22 -04:00
|
|
|
|
|
|
|
}while(!feof(haha) && ftell(haha) < inFileSize);
|
2023-08-28 15:19:50 -04:00
|
|
|
fclose(haha);
|
2023-05-16 11:26:22 -04:00
|
|
|
|
2023-08-28 15:19:50 -04:00
|
|
|
printf("============================ done | Total Agg. %d\n", countBdAgg);
|
2023-06-15 11:48:18 -04:00
|
|
|
data->PrintStat();
|
2023-08-28 15:19:50 -04:00
|
|
|
//data->PrintAllData();
|
2023-05-16 11:26:22 -04:00
|
|
|
|
2023-09-05 14:23:52 -04:00
|
|
|
mb->BuildEvents(true, true, false);
|
2023-05-16 11:26:22 -04:00
|
|
|
|
2023-09-05 14:23:52 -04:00
|
|
|
mb->PrintStat();
|
2023-06-19 12:48:17 -04:00
|
|
|
|
|
|
|
delete mb;
|
2023-05-16 11:26:22 -04:00
|
|
|
delete data;
|
|
|
|
|
2023-06-19 12:48:17 -04:00
|
|
|
}
|
|
|
|
|
2023-08-28 15:19:50 -04:00
|
|
|
int main(int argc, char **argv){
|
|
|
|
|
|
|
|
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]);
|
2023-10-05 13:19:45 -04:00
|
|
|
printf(" +-- PHA = %d\n", DPPType::DPP_PHA_CODE);
|
|
|
|
printf(" +-- PSD = %d\n", DPPType::DPP_PSD_CODE);
|
2023-10-13 18:02:19 -04:00
|
|
|
printf(" +-- QDC = %d\n", DPPType::DPP_QDC_CODE);
|
2023-08-28 15:19:50 -04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-06-19 12:48:17 -04:00
|
|
|
|
2023-08-28 15:19:50 -04:00
|
|
|
DataReader(argv[1], atoi(argv[2]));
|
2023-06-19 12:48:17 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2023-05-16 11:26:22 -04:00
|
|
|
}
|