added ScanBlockNumber in evtReader.h
This commit is contained in:
parent
92573e6251
commit
4e569c1f9e
|
@ -24,98 +24,142 @@
|
||||||
|
|
||||||
class evtReader{
|
class evtReader{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DataBlock * data;
|
DataBlock * data;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FILE * inFile;
|
FILE * inFile;
|
||||||
|
|
||||||
long int inFileSize;
|
long int inFileSize;
|
||||||
long int inFilePos;
|
long int inFilePos;
|
||||||
bool endOfFile;
|
bool endOfFile;
|
||||||
bool isOpened;
|
bool isOpened;
|
||||||
Long64_t blockID;
|
Long64_t blockID;
|
||||||
|
|
||||||
TBenchmark gClock;
|
unsigned int extraHeader[14];
|
||||||
|
unsigned int traceBlock[4000];
|
||||||
|
|
||||||
|
long int nBlock;
|
||||||
|
|
||||||
|
TBenchmark gClock;
|
||||||
|
|
||||||
|
///============================================ Methods
|
||||||
|
public:
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
///============================================ Methods
|
//========================== implementation
|
||||||
public:
|
|
||||||
evtReader(){
|
|
||||||
inFile = 0;
|
|
||||||
data = new DataBlock();
|
|
||||||
|
|
||||||
inFileSize = 0;
|
evtReader::evtReader(){
|
||||||
inFilePos = 0;
|
inFile = 0;
|
||||||
|
data = new DataBlock();
|
||||||
|
|
||||||
blockID = -1;
|
inFileSize = 0;
|
||||||
endOfFile = false;
|
inFilePos = 0;
|
||||||
isOpened = false;
|
|
||||||
}
|
|
||||||
evtReader(TString inFileName){
|
|
||||||
OpenFile(inFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
~evtReader(){
|
blockID = -1;
|
||||||
fclose(inFile);
|
endOfFile = false;
|
||||||
delete inFile;
|
isOpened = false;
|
||||||
delete data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenFile(TString inFileName){
|
nBlock = 0;
|
||||||
inFile = fopen(inFileName, "r");
|
}
|
||||||
if( inFile == NULL ){
|
|
||||||
printf("Cannot read file : %s \n", inFileName.Data());
|
|
||||||
}else{
|
|
||||||
fseek(inFile, 0L, SEEK_END);
|
|
||||||
inFileSize = ftell(inFile);
|
|
||||||
inFilePos = 0;
|
|
||||||
rewind(inFile); ///back to the File begining
|
|
||||||
|
|
||||||
data->Clear();
|
|
||||||
blockID = -1;
|
|
||||||
|
|
||||||
endOfFile = false;
|
evtReader::~evtReader(){
|
||||||
isOpened = true;
|
fclose(inFile);
|
||||||
|
delete inFile;
|
||||||
|
delete data;
|
||||||
|
}
|
||||||
|
|
||||||
gClock.Reset();
|
|
||||||
gClock.Start("timer");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
evtReader::evtReader(TString inFileName){
|
||||||
|
inFile = 0;
|
||||||
|
data = new DataBlock();
|
||||||
|
|
||||||
void UpdateFileSize(){
|
inFileSize = 0;
|
||||||
if( inFile == NULL ) return;
|
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());
|
||||||
|
}else{
|
||||||
fseek(inFile, 0L, SEEK_END);
|
fseek(inFile, 0L, SEEK_END);
|
||||||
inFileSize = ftell(inFile);
|
inFileSize = ftell(inFile);
|
||||||
fseek(inFile, inFilePos, SEEK_SET);
|
inFilePos = 0;
|
||||||
|
rewind(inFile); ///back to the File begining
|
||||||
|
|
||||||
|
data->Clear();
|
||||||
|
blockID = -1;
|
||||||
|
|
||||||
|
endOfFile = false;
|
||||||
|
isOpened = true;
|
||||||
|
|
||||||
|
gClock.Reset();
|
||||||
|
gClock.Start("timer");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsOpen(){ return isOpened;}
|
};
|
||||||
|
|
||||||
bool IsEndOfFile() {
|
|
||||||
int haha = feof(inFile);
|
void evtReader::UpdateFileSize(){
|
||||||
return haha > 0 ? true: false;
|
if( inFile == NULL ) return;
|
||||||
|
fseek(inFile, 0L, SEEK_END);
|
||||||
|
inFileSize = ftell(inFile);
|
||||||
|
fseek(inFile, inFilePos, SEEK_SET);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool evtReader::IsEndOfFile() {
|
||||||
|
int haha = feof(inFile);
|
||||||
|
return haha > 0 ? true: false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
if ( fread(header, sizeof(header), 1, inFile) != 1 ) {
|
||||||
|
endOfFile = true;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
blockID ++;
|
||||||
|
|
||||||
long int GetFilePos(){return inFilePos;}
|
|
||||||
long int GetFileSize(){return inFileSize;}
|
|
||||||
|
|
||||||
Long64_t GetBlockID(){ return blockID;}
|
|
||||||
|
|
||||||
int ReadBlock(){
|
|
||||||
|
|
||||||
if( feof(inFile) ) return -1;
|
|
||||||
if( endOfFile ) return -1;
|
|
||||||
|
|
||||||
unsigned int header[4]; //read 4 header, unsigned int = 4 byte = 32 bits.
|
|
||||||
|
|
||||||
if ( fread(header, sizeof(header), 1, inFile) != 1 ) {
|
|
||||||
endOfFile = true;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
blockID ++;
|
|
||||||
|
|
||||||
|
if( opt == 0 ){
|
||||||
/// see the Pixie-16 user manual, Table4-2
|
/// see the Pixie-16 user manual, Table4-2
|
||||||
data->eventID = blockID;
|
data->eventID = blockID;
|
||||||
data->ch = header[0] & 0xF ;
|
data->ch = header[0] & 0xF ;
|
||||||
|
@ -137,8 +181,7 @@ public:
|
||||||
|
|
||||||
///======== read QDCsum
|
///======== read QDCsum
|
||||||
if( data->headerLength >= 4 ){
|
if( data->headerLength >= 4 ){
|
||||||
unsigned int extraHeader[data->headerLength-4];
|
fread(extraHeader, sizeof(unsigned int) * (data->headerLength-4), 1, inFile);
|
||||||
fread(extraHeader, sizeof(extraHeader), 1, inFile);
|
|
||||||
if( data->headerLength == 8 || data->headerLength == 16){
|
if( data->headerLength == 8 || data->headerLength == 16){
|
||||||
data->trailing = extraHeader[0];
|
data->trailing = extraHeader[0];
|
||||||
data->leading = extraHeader[1];
|
data->leading = extraHeader[1];
|
||||||
|
@ -161,8 +204,7 @@ public:
|
||||||
}
|
}
|
||||||
///====== read trace
|
///====== read trace
|
||||||
if( data->eventLength > data->headerLength ){
|
if( data->eventLength > data->headerLength ){
|
||||||
unsigned int traceBlock[data->trace_length / 2];
|
fread(traceBlock, sizeof(unsigned int) * ( data->trace_length / 2 ), 1, inFile);
|
||||||
fread(traceBlock, sizeof(traceBlock), 1, inFile);
|
|
||||||
|
|
||||||
for( int i = 0; i < data->trace_length/2 ; i++){
|
for( int i = 0; i < data->trace_length/2 ; i++){
|
||||||
data->trace[2*i+0] = traceBlock[i] & 0xFFFF ;
|
data->trace[2*i+0] = traceBlock[i] & 0xFFFF ;
|
||||||
|
@ -184,27 +226,60 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inFilePos = ftell(inFile);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( opt == 1 ){
|
||||||
|
|
||||||
void PrintStatus(int id){
|
data->headerLength = (header[0] >> 12) & 0x1F;
|
||||||
|
data->eventLength = (header[0] >> 17) & 0x3FFF;
|
||||||
|
data->trace_length = (header[3] >> 16) & 0x7FFF;
|
||||||
|
|
||||||
///==== event stats, print status every 10000 events
|
if( data->headerLength >= 4 ){
|
||||||
if ( blockID % id == 0 ) {
|
fread(extraHeader, sizeof(unsigned int) * (data->headerLength-4), 1, inFile);
|
||||||
UpdateFileSize();
|
}
|
||||||
gClock.Stop("timer");
|
if( data->eventLength > data->headerLength ){
|
||||||
double time = gClock.GetRealTime("timer");
|
fread(traceBlock, sizeof(unsigned int) * ( data->trace_length / 2 ), 1, inFile);
|
||||||
gClock.Start("timer");
|
|
||||||
printf("Total measurements: \x1B[32m%llu \x1B[0m\nReading Pos: \x1B[32m %.3f/%.3f GB\x1B[0m\nTime used:%3.0f min %5.2f sec\033[A\033[A\r",
|
|
||||||
blockID, inFilePos/(1024.*1024.*1024.), inFileSize/1024./1024./1024, TMath::Floor(time/60.), time - TMath::Floor(time/60.)*60.);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
inFilePos = ftell(inFile);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 % mod == 0 ) {
|
||||||
|
UpdateFileSize();
|
||||||
|
gClock.Stop("timer");
|
||||||
|
double time = gClock.GetRealTime("timer");
|
||||||
|
gClock.Start("timer");
|
||||||
|
printf("Total measurements: \x1B[32m%llu \x1B[0m\nReading Pos: \x1B[32m %.3f/%.3f GB\x1B[0m\nTime used:%3.0f min %5.2f sec\033[A\033[A\r",
|
||||||
|
blockID, inFilePos/(1024.*1024.*1024.), inFileSize/1024./1024./1024, TMath::Floor(time/60.), time - TMath::Floor(time/60.)*60.);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user