Commit 449ff090 authored by Jérémie Dudouet's avatar Jérémie Dudouet
Browse files

Add possibility to read binary ts files

parent 9f3ee326
...@@ -11,8 +11,9 @@ TstampFilter::TstampFilter() ...@@ -11,8 +11,9 @@ TstampFilter::TstampFilter()
} }
TstampFilter::TstampFilter(const std::string& tstampFile, int tolerance, int id) TstampFilter::TstampFilter(const std::string& tstampFile, int tolerance, int id, bool binary)
{ {
fBinaryFormat = binary;
Reset(); Reset();
Initialize(tstampFile, tolerance, id); Initialize(tstampFile, tolerance, id);
} }
...@@ -48,6 +49,14 @@ bool TstampFilter::Initialize(std::string tstampFile, int tolerance, int id) ...@@ -48,6 +49,14 @@ bool TstampFilter::Initialize(std::string tstampFile, int tolerance, int id)
fTstampFile = tstampFile; fTstampFile = tstampFile;
//fTstampFile = GetConfPath() + fTstampFile; //fTstampFile = GetConfPath() + fTstampFile;
if(fBinaryFormat) {
if( (fTstampFILE = fopen(fTstampFile.c_str(),"rb")) == NULL) {
cout << "Error opening " << fTstampFile << endl;
//*error_code = 133;
//Log << dolog;
return false;
}
}
if( (fTstampFILE = fopen(fTstampFile.c_str(),"r")) == NULL) { if( (fTstampFILE = fopen(fTstampFile.c_str(),"r")) == NULL) {
cout << "Error opening " << fTstampFile << endl; cout << "Error opening " << fTstampFile << endl;
//*error_code = 133; //*error_code = 133;
...@@ -58,7 +67,9 @@ bool TstampFilter::Initialize(std::string tstampFile, int tolerance, int id) ...@@ -58,7 +67,9 @@ bool TstampFilter::Initialize(std::string tstampFile, int tolerance, int id)
fTimestamp = 0x0FFFFFFFFFFFFFFFULL; fTimestamp = 0x0FFFFFFFFFFFFFFFULL;
fMyId = id; fMyId = id;
if(fMyId < 0) { // only tstamp present in file if(fMyId < 0) { // only tstamp present in file
int nn = fscanf(fTstampFILE, "%lld", &fTimestamp); int nn;
if(fBinaryFormat) nn = fread (&fTimestamp,1,sizeof (fTimestamp),fTstampFILE);
else nn = fscanf(fTstampFILE, "%lld", &fTimestamp);
if(nn != 1) { if(nn != 1) {
cout << "Error reading " << fTstampFile << endl; cout << "Error reading " << fTstampFile << endl;
//*error_code = 134; //*error_code = 134;
...@@ -71,7 +82,12 @@ bool TstampFilter::Initialize(std::string tstampFile, int tolerance, int id) ...@@ -71,7 +82,12 @@ bool TstampFilter::Initialize(std::string tstampFile, int tolerance, int id)
id = -1; id = -1;
int nnr = 0; int nnr = 0;
while(true) { while(true) {
int nn = fscanf(fTstampFILE, "%d %lld", & id, &fTimestamp); int nn;
if(fBinaryFormat) {
nn = fread (&fTimestamp,1,sizeof (fTimestamp),fTstampFILE);
nn += fread (&id,1,sizeof (id),fTstampFILE);
}
else nn = fscanf(fTstampFILE, "%d %lld", & id, &fTimestamp);
if(nn != 2) { if(nn != 2) {
cout << "Error reading " << fTstampFile << endl; cout << "Error reading " << fTstampFile << endl;
//*error_code = 134; //*error_code = 134;
...@@ -97,8 +113,10 @@ void TstampFilter::NextTstamp() ...@@ -97,8 +113,10 @@ void TstampFilter::NextTstamp()
if(fMyId < 0) { if(fMyId < 0) {
// timestamp only // timestamp only
while(true) { while(true) {
int nn = fscanf(fTstampFILE, "%lld", &fTimestamp); int nn;
if(nn != 1) { if(fBinaryFormat) nn = fread (&fTimestamp,1,sizeof (fTimestamp),fTstampFILE);
else nn = fscanf(fTstampFILE, "%lld", &fTimestamp);
if(nn != 1) {
cout << "Error reading " << fTstampFile << endl; cout << "Error reading " << fTstampFile << endl;
fTimestamp = 0xFFFFFFFFFFFFFFFFULL; fTimestamp = 0xFFFFFFFFFFFFFFFFULL;
return; return;
...@@ -114,8 +132,13 @@ void TstampFilter::NextTstamp() ...@@ -114,8 +132,13 @@ void TstampFilter::NextTstamp()
int id = -1; int id = -1;
while(true) { while(true) {
while(true) { while(true) {
int nn = fscanf(fTstampFILE, "%d %lld", &id, &fTimestamp); int nn;
if(nn != 2) { if(fBinaryFormat) {
nn = fread (&fTimestamp,1,sizeof (fTimestamp),fTstampFILE);
nn += fread (&id,1,sizeof (id),fTstampFILE);
}
else nn = fscanf(fTstampFILE, "%d %lld", & id, &fTimestamp);
if(nn != 2) {
cout << "Error reading " << fTstampFile << endl; cout << "Error reading " << fTstampFile << endl;
fTimestamp = 0xFFFFFFFFFFFFFFFFULL; fTimestamp = 0xFFFFFFFFFFFFFFFFULL;
return; return;
......
...@@ -21,8 +21,10 @@ public: ...@@ -21,8 +21,10 @@ public:
UInt_t fCount; UInt_t fCount;
//UInt_t fStats[1000]; //UInt_t fStats[1000];
Bool_t fBinaryFormat = false;
TstampFilter(); TstampFilter();
TstampFilter(const std::string& tstampFile, int tolerance, int id = -1); TstampFilter(const std::string& tstampFile, int tolerance, int id = -1, bool binary = false);
virtual ~TstampFilter(); virtual ~TstampFilter();
void Reset(); void Reset();
bool Initialize(std::string tstampFile, int tolerance, int id = -1); bool Initialize(std::string tstampFile, int tolerance, int id = -1);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment