fix BinReader.h for no header data format
This commit is contained in:
parent
84851051f7
commit
5ae7c256f2
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
|||
*.o
|
||||
*.fsu
|
||||
*.root
|
||||
*.BIN
|
||||
|
||||
data
|
||||
|
||||
|
|
|
@ -106,8 +106,7 @@ int main(int argc, char **argv) {
|
|||
printf(" %s 100 0 '\\ls -1 *001*.bin' (event build with 100 ns, no trace, no verbose)\n", argv[0]);
|
||||
printf("\n");
|
||||
printf(" Time offset file format :\n");
|
||||
printf("[n, sn appears between the n-th - (n+1)-th underscore of the fileName] 0\n");
|
||||
printf("[digi sn] [time offset(int64_t)]\n");
|
||||
printf("[board SN] [time offset(int64_t)]\n");
|
||||
printf("\n");
|
||||
printf(" file name should be this format CH0@V1725_324_Data_run_196.bin\n");
|
||||
printf(" so that the serial number is between the 1st and 2nd underscore\n");
|
||||
|
@ -160,8 +159,8 @@ int main(int argc, char **argv) {
|
|||
if( timeOffsetFile != "0" ) {
|
||||
printf(" Time Offset File = %s\n", timeOffsetFile.c_str());
|
||||
timeOffsetList = readFileAndExtractData(timeOffsetFile);
|
||||
for (size_t i = 0 ; timeOffsetList.size(); i++) {
|
||||
printf("Digi-%4d %16llu ps\n", timeOffsetList[i].first, timeOffsetList[i].second);
|
||||
for (size_t i = 0 ; i < timeOffsetList.size(); i++) {
|
||||
printf("Board-%4d %16llu ps\n", timeOffsetList[i].first, timeOffsetList[i].second);
|
||||
}
|
||||
}
|
||||
printf("========================================= Number of Files : %d \n", nFile);
|
||||
|
|
51
BinReader.h
51
BinReader.h
|
@ -60,7 +60,7 @@ struct Data{
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
//^################################################
|
||||
class BinReader{
|
||||
public:
|
||||
Data data;
|
||||
|
@ -83,16 +83,18 @@ class BinReader{
|
|||
|
||||
bool isHeaderOK;
|
||||
bool isOldFormat;
|
||||
bool isNoHeaderFormat;
|
||||
|
||||
template <typename T> int FillData(T * dataItem); // if successful, return 1, else 0; cannot fill Trace
|
||||
|
||||
///============================================ Methods
|
||||
public:
|
||||
BinReader();
|
||||
BinReader(TString inFileName);
|
||||
BinReader(TString inFileName, int64_t timeOffset = 0, bool noHeader = false);
|
||||
~BinReader();
|
||||
|
||||
void OpenFile(TString inFileName, int64_t timeOffset = 0);
|
||||
void OpenFile(TString inFileName, int64_t timeOffset = 0, bool noHeader = false);
|
||||
// void SetDataFormat(bool has );
|
||||
void CloseFile();
|
||||
void UpdateFileSize();
|
||||
bool IsEndOfFile();
|
||||
|
@ -128,6 +130,7 @@ BinReader::BinReader(){
|
|||
|
||||
isHeaderOK = false;
|
||||
isOldFormat = false;
|
||||
isNoHeaderFormat = false;
|
||||
|
||||
}
|
||||
|
||||
|
@ -135,8 +138,7 @@ BinReader::~BinReader(){
|
|||
fclose(inFile); /// fclose already delete inFile;
|
||||
}
|
||||
|
||||
|
||||
BinReader::BinReader(TString inFileName){
|
||||
BinReader::BinReader(TString inFileName, int64_t timeOffset, bool noHeader){
|
||||
inFile = 0;
|
||||
data.Clear();
|
||||
|
||||
|
@ -146,11 +148,11 @@ BinReader::BinReader(TString inFileName){
|
|||
hitID = -1;
|
||||
endOfFile = false;
|
||||
isOpened = false;
|
||||
|
||||
OpenFile(inFileName);
|
||||
|
||||
OpenFile(inFileName, timeOffset, noHeader);
|
||||
}
|
||||
|
||||
void BinReader::OpenFile(TString inFileName, int64_t timeOffset){
|
||||
void BinReader::OpenFile(TString inFileName, int64_t timeOffset, bool noHeader){
|
||||
inFile = fopen(inFileName, "r");
|
||||
this->timeOffset = timeOffset;
|
||||
if( inFile == NULL ){
|
||||
|
@ -166,6 +168,14 @@ void BinReader::OpenFile(TString inFileName, int64_t timeOffset){
|
|||
|
||||
isOpened = true;
|
||||
|
||||
if( noHeader ){
|
||||
data.Header = 0x0;
|
||||
isOldFormat = false;
|
||||
isHeaderOK = false;
|
||||
isNoHeaderFormat = true;
|
||||
return;
|
||||
}
|
||||
|
||||
///============= Read the Header,
|
||||
/// the header only at the beginning of a file
|
||||
isHeaderOK = FillData(&data.Header);
|
||||
|
@ -179,13 +189,16 @@ void BinReader::OpenFile(TString inFileName, int64_t timeOffset){
|
|||
printf(" Old format of CoMPASS, 0x%04x\n", data.Header);
|
||||
isHeaderOK = true;
|
||||
isOldFormat = true;
|
||||
isNoHeaderFormat = false;
|
||||
data.Header = 0xCAE5; // only with energy and energy short
|
||||
return;
|
||||
}
|
||||
|
||||
if( (data.Header >> 4 ) != 0xCAE ) {
|
||||
printf(" Header format not right. 0x%04x\n", data.Header);
|
||||
isOldFormat = false;
|
||||
isHeaderOK = false;
|
||||
isNoHeaderFormat = false;
|
||||
return ;
|
||||
}
|
||||
|
||||
|
@ -230,10 +243,27 @@ int BinReader::ReadBlock(int skipTrace){
|
|||
if( inFile == nullptr ) return -1;
|
||||
if( feof(inFile) ) return -1;
|
||||
if( endOfFile ) return -1;
|
||||
|
||||
|
||||
if( isNoHeaderFormat ) {
|
||||
FillData(&data.BoardID);
|
||||
FillData(&data.Channel);
|
||||
FillData(&data.TimeStamp);
|
||||
if( timeOffset != 0 ) data.TimeStamp += timeOffset;
|
||||
FillData(&data.Energy);
|
||||
FillData(&data.Flags);
|
||||
|
||||
hitID ++;
|
||||
|
||||
inFilePos = ftell(inFile);
|
||||
if( inFilePos >= inFileSize ) endOfFile = true;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if( !isHeaderOK ) return -2;
|
||||
|
||||
/// see the CoMPASS manual v19, P.67
|
||||
|
||||
FillData(&data.BoardID);
|
||||
FillData(&data.Channel);
|
||||
FillData(&data.TimeStamp);
|
||||
|
@ -280,6 +310,7 @@ int BinReader::ReadBlock(int skipTrace){
|
|||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void BinReader::ScanNumHit(){
|
||||
|
||||
numHit = 0;
|
||||
|
@ -300,7 +331,7 @@ void BinReader::ScanNumHit(){
|
|||
printf("scan complete: number of data Block : %ld\n", numHit);
|
||||
|
||||
rewind(inFile); ///back to the File begining
|
||||
if( !isOldFormat ){
|
||||
if( !isOldFormat && isHeaderOK ){
|
||||
FillData(&data.Header);
|
||||
}
|
||||
inFilePos = 0;
|
||||
|
|
5
test.C
5
test.C
|
@ -18,7 +18,8 @@ TH1I * he[NChannel];
|
|||
|
||||
// BinReader * reader = new BinReader("/home/ryan/ExpData/fsu_testing/testing_014_single.bin");
|
||||
// BinReader * reader = new BinReader("data/run_123/UNFILTERED/Data_CH9@V1725S_19555_run_123.BIN");
|
||||
BinReader * reader = new BinReader("run_268/CH0@V1725_324_Data_run_268.bin");
|
||||
// BinReader * reader = new BinReader("run_268/CH0@V1725_324_Data_run_268.bin");
|
||||
BinReader * reader = new BinReader("DataR_run_34_108.BIN", 0, true);
|
||||
|
||||
void test(){
|
||||
|
||||
|
@ -35,7 +36,7 @@ void test(){
|
|||
reader->data.Print();
|
||||
count ++;
|
||||
|
||||
// if( count > 10 ) break;
|
||||
if( count > 10 ) break;
|
||||
|
||||
}while( !reader->IsEndOfFile() );
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
1 0
|
||||
123 456
|
||||
86 49
|
||||
19267 0
|
Loading…
Reference in New Issue
Block a user