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()
}
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();
Initialize(tstampFile, tolerance, id);
}
......@@ -48,6 +49,14 @@ bool TstampFilter::Initialize(std::string tstampFile, int tolerance, int id)
fTstampFile = tstampFile;
//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) {
cout << "Error opening " << fTstampFile << endl;
//*error_code = 133;
......@@ -58,7 +67,9 @@ bool TstampFilter::Initialize(std::string tstampFile, int tolerance, int id)
fTimestamp = 0x0FFFFFFFFFFFFFFFULL;
fMyId = id;
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) {
cout << "Error reading " << fTstampFile << endl;
//*error_code = 134;
......@@ -71,7 +82,12 @@ bool TstampFilter::Initialize(std::string tstampFile, int tolerance, int id)
id = -1;
int nnr = 0;
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) {
cout << "Error reading " << fTstampFile << endl;
//*error_code = 134;
......@@ -97,8 +113,10 @@ void TstampFilter::NextTstamp()
if(fMyId < 0) {
// timestamp only
while(true) {
int nn = fscanf(fTstampFILE, "%lld", &fTimestamp);
if(nn != 1) {
int nn;
if(fBinaryFormat) nn = fread (&fTimestamp,1,sizeof (fTimestamp),fTstampFILE);
else nn = fscanf(fTstampFILE, "%lld", &fTimestamp);
if(nn != 1) {
cout << "Error reading " << fTstampFile << endl;
fTimestamp = 0xFFFFFFFFFFFFFFFFULL;
return;
......@@ -114,8 +132,13 @@ void TstampFilter::NextTstamp()
int id = -1;
while(true) {
while(true) {
int nn = fscanf(fTstampFILE, "%d %lld", &id, &fTimestamp);
if(nn != 2) {
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) {
cout << "Error reading " << fTstampFile << endl;
fTimestamp = 0xFFFFFFFFFFFFFFFFULL;
return;
......
......@@ -21,8 +21,10 @@ public:
UInt_t fCount;
//UInt_t fStats[1000];
Bool_t fBinaryFormat = false;
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();
void Reset();
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