added ScanBlockNumber in evtReader.h

This commit is contained in:
Ryan Tang 2022-02-14 16:06:34 -05:00
parent 92573e6251
commit 4e569c1f9e

View File

@ -36,12 +36,43 @@ private:
bool isOpened;
Long64_t blockID;
TBenchmark gClock;
unsigned int extraHeader[14];
unsigned int traceBlock[4000];
long int nBlock;
TBenchmark gClock;
///============================================ Methods
public:
evtReader(){
evtReader();
evtReader(TString inFileName);
~evtReader();
void OpenFile(TString inFileName);
void UpdateFileSize();
bool IsOpen() { return isOpened;}
bool IsEndOfFile();
long int GetFilePos() {return inFilePos;}
long int GetFileSize() {return inFileSize;}
Long64_t GetBlockID() { return blockID;}
int ReadBlock(int opt = 0); /// 0 = default, fill data
/// 1 = no fill data
void ScanNumberOfBlock();
Long64_t GetNumberOfBlock() {return nBlock;}
void PrintStatus(int mod);
};
//========================== implementation
evtReader::evtReader(){
inFile = 0;
data = new DataBlock();
@ -51,18 +82,34 @@ public:
blockID = -1;
endOfFile = false;
isOpened = false;
}
evtReader(TString inFileName){
OpenFile(inFileName);
nBlock = 0;
}
~evtReader(){
evtReader::~evtReader(){
fclose(inFile);
delete inFile;
delete data;
}
void OpenFile(TString inFileName){
evtReader::evtReader(TString inFileName){
inFile = 0;
data = new DataBlock();
inFileSize = 0;
inFilePos = 0;
blockID = -1;
endOfFile = false;
isOpened = false;
nBlock = 0;
OpenFile(inFileName);
}
void evtReader::OpenFile(TString inFileName){
inFile = fopen(inFileName, "r");
if( inFile == NULL ){
printf("Cannot read file : %s \n", inFileName.Data());
@ -82,33 +129,28 @@ public:
gClock.Start("timer");
}
}
};
void UpdateFileSize(){
void evtReader::UpdateFileSize(){
if( inFile == NULL ) return;
fseek(inFile, 0L, SEEK_END);
inFileSize = ftell(inFile);
fseek(inFile, inFilePos, SEEK_SET);
}
bool IsOpen(){ return isOpened;}
bool IsEndOfFile() {
bool evtReader::IsEndOfFile() {
int haha = feof(inFile);
return haha > 0 ? true: false;
}
long int GetFilePos(){return inFilePos;}
long int GetFileSize(){return inFileSize;}
Long64_t GetBlockID(){ return blockID;}
int ReadBlock(){
int evtReader::ReadBlock(int opt = 0){
if( feof(inFile) ) return -1;
if( endOfFile ) return -1;
unsigned int header[4]; //read 4 header, unsigned int = 4 byte = 32 bits.
unsigned int header[4]; ///read 4 header, unsigned int = 4 byte = 32 bits.
if ( fread(header, sizeof(header), 1, inFile) != 1 ) {
endOfFile = true;
@ -116,6 +158,8 @@ public:
}
blockID ++;
if( opt == 0 ){
/// see the Pixie-16 user manual, Table4-2
data->eventID = blockID;
data->ch = header[0] & 0xF ;
@ -137,8 +181,7 @@ public:
///======== read QDCsum
if( data->headerLength >= 4 ){
unsigned int extraHeader[data->headerLength-4];
fread(extraHeader, sizeof(extraHeader), 1, inFile);
fread(extraHeader, sizeof(unsigned int) * (data->headerLength-4), 1, inFile);
if( data->headerLength == 8 || data->headerLength == 16){
data->trailing = extraHeader[0];
data->leading = extraHeader[1];
@ -161,8 +204,7 @@ public:
}
///====== read trace
if( data->eventLength > data->headerLength ){
unsigned int traceBlock[data->trace_length / 2];
fread(traceBlock, sizeof(traceBlock), 1, inFile);
fread(traceBlock, sizeof(unsigned int) * ( data->trace_length / 2 ), 1, inFile);
for( int i = 0; i < data->trace_length/2 ; i++){
data->trace[2*i+0] = traceBlock[i] & 0xFFFF ;
@ -184,6 +226,21 @@ public:
}
}
}
}
if( opt == 1 ){
data->headerLength = (header[0] >> 12) & 0x1F;
data->eventLength = (header[0] >> 17) & 0x3FFF;
data->trace_length = (header[3] >> 16) & 0x7FFF;
if( data->headerLength >= 4 ){
fread(extraHeader, sizeof(unsigned int) * (data->headerLength-4), 1, inFile);
}
if( data->eventLength > data->headerLength ){
fread(traceBlock, sizeof(unsigned int) * ( data->trace_length / 2 ), 1, inFile);
}
}
inFilePos = ftell(inFile);
@ -191,10 +248,30 @@ public:
}
void PrintStatus(int id){
void evtReader::ScanNumberOfBlock(){
nBlock = 0;
while( ReadBlock(1) != -1 ){
nBlock ++;
PrintStatus(10000);
}
printf("\n\n\n");
printf("scan complete: number of data Block : %ld\n", nBlock);
inFilePos = 0;
blockID = -1;
rewind(inFile); ///back to the File begining
endOfFile = false;
}
void evtReader::PrintStatus(int mod){
///==== event stats, print status every 10000 events
if ( blockID % id == 0 ) {
if ( blockID % mod == 0 ) {
UpdateFileSize();
gClock.Stop("timer");
double time = gClock.GetRealTime("timer");
@ -205,6 +282,4 @@ public:
}
};
#endif