Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
DaqIOLib
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
NADS-Public
DaqIOLib
Commits
76ef08ce
Commit
76ef08ce
authored
Mar 12, 2020
by
IOWA\dheitbri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upgraded to 64bit
parent
39e4aadf
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
76 deletions
+90
-76
DaqBuffer.h
DaqBuffer.h
+5
-5
DaqFileIO.cxx
DaqFileIO.cxx
+77
-65
DaqIo.h
DaqIo.h
+6
-5
DaqIoLibDefines.h
DaqIoLibDefines.h
+2
-1
No files found.
DaqBuffer.h
View file @
76ef08ce
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
///
///
/// $Id: DaqBuffer.h,v 1.
5 2013/04/30 00:59:10 IOWA\vhorosewsk
i Exp $
/// $Id: DaqBuffer.h,v 1.
6 2020/03/12 00:43:37 IOWA\dheitbr
i Exp $
///
///
/// Date: December 2004
/// Date: December 2004
///
///
...
@@ -32,8 +32,8 @@ public:
...
@@ -32,8 +32,8 @@ public:
std
::
vector
<
TDaqByte
>::
const_pointer
GetDataPtr
()
const
;
///< Return faw pointer to data
std
::
vector
<
TDaqByte
>::
const_pointer
GetDataPtr
()
const
;
///< Return faw pointer to data
int
GetCount
()
const
;
///< Return number of typed elements in buffer
size_t
GetCount
()
const
;
///< Return number of typed elements in buffer
int
GetSize
()
const
;
///< Return buffer size in bytes
size_t
GetSize
()
const
;
///< Return buffer size in bytes
char
*
GetChar
(
int
ind
=
0
);
///< Return char type pointer to data
char
*
GetChar
(
int
ind
=
0
);
///< Return char type pointer to data
int
*
GetInt
(
int
ind
=
0
);
///< Return int type pointer to data
int
*
GetInt
(
int
ind
=
0
);
///< Return int type pointer to data
float
*
GetFloat
(
int
ind
=
0
);
///< Return float type pointer to data
float
*
GetFloat
(
int
ind
=
0
);
///< Return float type pointer to data
...
@@ -55,7 +55,7 @@ protected:
...
@@ -55,7 +55,7 @@ protected:
///
///
/// This function ...
/// This function ...
//
//
inline
in
t
inline
size_
t
CDaqBuffer
::
GetSize
()
const
CDaqBuffer
::
GetSize
()
const
{
{
return
(
int
)
m_Data
.
size
();
return
(
int
)
m_Data
.
size
();
...
@@ -63,7 +63,7 @@ CDaqBuffer::GetSize() const
...
@@ -63,7 +63,7 @@ CDaqBuffer::GetSize() const
///
///
/// This function ...
/// This function ...
inline
in
t
inline
size_
t
CDaqBuffer
::
GetCount
()
const
CDaqBuffer
::
GetCount
()
const
{
{
return
m_Count
;
return
m_Count
;
...
...
DaqFileIO.cxx
View file @
76ef08ce
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
///
///
// DAQ low level IO Library
// DAQ low level IO Library
//
//
// $Id: DaqFileIO.cxx,v 1.2
6 2019/07/10 17:05:56
IOWA\dheitbri Exp $
// $Id: DaqFileIO.cxx,v 1.2
7 2020/03/12 00:43:37
IOWA\dheitbri Exp $
// Date: March, 2005
// Date: March, 2005
// Author: Yiannis Papelis
// Author: Yiannis Papelis
//
//
...
@@ -30,7 +30,7 @@ static void DefaultErrorFunc(const char *, const char *) {}
...
@@ -30,7 +30,7 @@ static void DefaultErrorFunc(const char *, const char *) {}
static
void
DefaultProgressFunc
(
const
char
*
,
int
,
int
)
{}
static
void
DefaultProgressFunc
(
const
char
*
,
int
,
int
)
{}
struct
TFrameInfo
{
struct
TFrameInfo
{
int
ofs
;
long
long
ofs
;
int
numChan
;
int
numChan
;
};
};
//Intel says 8k (2006) is the ideal buffer size for streaming from the HD,
//Intel says 8k (2006) is the ideal buffer size for streaming from the HD,
...
@@ -119,10 +119,10 @@ CDaqLowLevelIo::GetChannelInfo(
...
@@ -119,10 +119,10 @@ CDaqLowLevelIo::GetChannelInfo(
void
void
NearDump
(
FILE
*
p
,
int
ofs
)
NearDump
(
FILE
*
p
,
int
ofs
)
{
{
int
origOfs
=
ftell
(
p
);
auto
origOfs
=
_ftelli64
(
p
);
printf
(
"
\n
Data dump near unrecoverable read at offset %d
\n
"
,
ofs
);
printf
(
"
\n
Data dump near unrecoverable read at offset %d
\n
"
,
ofs
);
fseek
(
p
,
-
8
*
4
,
SEEK_CUR
);
_fseeki64
(
p
,
-
8
*
4
,
SEEK_CUR
);
int
d
;
int
d
;
for
(
int
i
=
0
;
i
<
96
;
i
++
)
{
for
(
int
i
=
0
;
i
<
96
;
i
++
)
{
...
@@ -134,7 +134,7 @@ NearDump(FILE* p, int ofs)
...
@@ -134,7 +134,7 @@ NearDump(FILE* p, int ofs)
printf
(
"Read at ofs %-d failed.
\n
"
,
int
(
ftell
(
p
)
-
sizeof
(
d
)));
printf
(
"Read at ofs %-d failed.
\n
"
,
int
(
ftell
(
p
)
-
sizeof
(
d
)));
}
}
}
}
fseek
(
p
,
origOfs
,
SEEK_SET
);
_fseeki64
(
p
,
origOfs
,
SEEK_SET
);
}
}
...
@@ -221,7 +221,7 @@ int CDaqLowLevelIo::GetDroppedFrames() const {
...
@@ -221,7 +221,7 @@ int CDaqLowLevelIo::GetDroppedFrames() const {
bool
bool
CDaqLowLevelIo
::
FrameHasData
(
int
frm
)
CDaqLowLevelIo
::
FrameHasData
(
int
frm
)
{
{
map
<
int
,
int
>::
const_iterator
p
;
map
<
int
,
long
long
>::
const_iterator
p
;
p
=
m_Toc
.
find
(
frm
);
p
=
m_Toc
.
find
(
frm
);
return
p
!=
m_Toc
.
end
();
return
p
!=
m_Toc
.
end
();
...
@@ -365,7 +365,7 @@ bool
...
@@ -365,7 +365,7 @@ bool
CDaqLowLevelIo
::
DetectFrameHeader
(
CDaqLowLevelIo
::
DetectFrameHeader
(
int
recentFrame
)
int
recentFrame
)
{
{
int
origOfs
=
ftell
(
m_pFile
);
auto
origOfs
=
_ftelli64
(
m_pFile
);
int
header
[
3
];
int
header
[
3
];
if
(
fread
(
header
,
sizeof
(
int
),
3
,
m_pFile
)
!=
3
)
return
false
;
if
(
fread
(
header
,
sizeof
(
int
),
3
,
m_pFile
)
!=
3
)
return
false
;
...
@@ -375,7 +375,7 @@ CDaqLowLevelIo::DetectFrameHeader(
...
@@ -375,7 +375,7 @@ CDaqLowLevelIo::DetectFrameHeader(
bool
reasonableFrame
=
header
[
1
]
-
recentFrame
<
200000
;
bool
reasonableFrame
=
header
[
1
]
-
recentFrame
<
200000
;
bool
reasonableChCount
=
header
[
2
]
>=
0
&&
header
[
2
]
<
m_NumEntries
;
bool
reasonableChCount
=
header
[
2
]
>=
0
&&
header
[
2
]
<
m_NumEntries
;
fseek
(
m_pFile
,
origOfs
,
SEEK_SET
);
_fseeki64
(
m_pFile
,
origOfs
,
SEEK_SET
);
if
(
header
[
0
]
==
-
1
&&
reasonableFrame
&&
reasonableChCount
)
{
if
(
header
[
0
]
==
-
1
&&
reasonableFrame
&&
reasonableChCount
)
{
return
true
;
return
true
;
...
@@ -394,18 +394,18 @@ CDaqLowLevelIo::DetectFrameHeader(
...
@@ -394,18 +394,18 @@ CDaqLowLevelIo::DetectFrameHeader(
CDaqLowLevelIo
::
TResyncOutcome
CDaqLowLevelIo
::
TResyncOutcome
CDaqLowLevelIo
::
ResyncChannel
(
CDaqLowLevelIo
::
ResyncChannel
(
int
recentFrame
,
int
recentFrame
,
int
&
skip
)
long
long
&
skip
)
{
{
int
data
;
int
data
;
int
cch1
;
// candidate channels
int
cch1
;
// candidate channels
int
tries
=
0
;
int
tries
=
0
;
int
startingOffset
=
ftell
(
m_pFile
);
auto
startingOffset
=
_ftelli64
(
m_pFile
);
skip
=
0
;
skip
=
0
;
while
(
!
feof
(
m_pFile
)
&&
tries
++
<
cMaxChannResyncLookahead
)
{
while
(
!
feof
(
m_pFile
)
&&
tries
++
<
cMaxChannResyncLookahead
)
{
int
mostRecentGoodOfs
;
long
long
mostRecentGoodOfs
;
mostRecentGoodOfs
=
ftell
(
m_pFile
);
mostRecentGoodOfs
=
_ftelli64
(
m_pFile
);
if
(
fread
(
&
data
,
sizeof
(
int
),
1
,
m_pFile
)
!=
1
)
return
eRESYNC_NONE
;
if
(
fread
(
&
data
,
sizeof
(
int
),
1
,
m_pFile
)
!=
1
)
return
eRESYNC_NONE
;
// possible channel definition; read at least two more things to be sure
// possible channel definition; read at least two more things to be sure
...
@@ -413,9 +413,9 @@ CDaqLowLevelIo::ResyncChannel(
...
@@ -413,9 +413,9 @@ CDaqLowLevelIo::ResyncChannel(
if
(
data
>=
0
&&
data
<
m_NumEntries
)
{
if
(
data
>=
0
&&
data
<
m_NumEntries
)
{
cch1
=
data
;
cch1
=
data
;
CDaqChannelInfo
&
ch
=
m_Channels
[
cch1
];
CDaqChannelInfo
&
ch
=
m_Channels
[
cch1
];
int
skipDataPortion
=
ch
.
GetRecSize
();
long
long
skipDataPortion
=
ch
.
GetRecSize
();
fseek
(
m_pFile
,
skipDataPortion
,
SEEK_CUR
);
_fseeki64
(
m_pFile
,
skipDataPortion
,
SEEK_CUR
);
if
(
fread
(
&
data
,
sizeof
(
int
),
1
,
m_pFile
)
!=
1
)
return
eRESYNC_NONE
;
if
(
fread
(
&
data
,
sizeof
(
int
),
1
,
m_pFile
)
!=
1
)
return
eRESYNC_NONE
;
...
@@ -423,9 +423,9 @@ CDaqLowLevelIo::ResyncChannel(
...
@@ -423,9 +423,9 @@ CDaqLowLevelIo::ResyncChannel(
// it seems as if we are back in sync, we re-wind and return
// it seems as if we are back in sync, we re-wind and return
while
(
data
>=
0
&&
data
<
m_NumEntries
&&
data
>
cch1
)
{
while
(
data
>=
0
&&
data
<
m_NumEntries
&&
data
>
cch1
)
{
CDaqChannelInfo
&
ch
=
m_Channels
[
data
];
CDaqChannelInfo
&
ch
=
m_Channels
[
data
];
int
skipDataPortion
=
ch
.
GetRecSize
();
long
long
skipDataPortion
=
ch
.
GetRecSize
();
fseek
(
m_pFile
,
skipDataPortion
,
SEEK_CUR
);
_fseeki64
(
m_pFile
,
skipDataPortion
,
SEEK_CUR
);
if
(
fread
(
&
data
,
sizeof
(
int
),
1
,
m_pFile
)
!=
1
)
return
eRESYNC_NONE
;
if
(
fread
(
&
data
,
sizeof
(
int
),
1
,
m_pFile
)
!=
1
)
return
eRESYNC_NONE
;
}
}
}
}
...
@@ -433,7 +433,7 @@ CDaqLowLevelIo::ResyncChannel(
...
@@ -433,7 +433,7 @@ CDaqLowLevelIo::ResyncChannel(
if
(
data
==
-
1
)
{
if
(
data
==
-
1
)
{
fseek
(
m_pFile
,
-
4
,
SEEK_CUR
);
fseek
(
m_pFile
,
-
4
,
SEEK_CUR
);
if
(
DetectFrameHeader
(
recentFrame
))
{
if
(
DetectFrameHeader
(
recentFrame
))
{
skip
=
ftell
(
m_pFile
)
-
startingOffset
;
skip
=
_ftelli64
(
m_pFile
)
-
startingOffset
;
return
eRESYNC_FRAME
;
return
eRESYNC_FRAME
;
}
}
fseek
(
m_pFile
,
4
,
SEEK_CUR
);
fseek
(
m_pFile
,
4
,
SEEK_CUR
);
...
@@ -442,7 +442,7 @@ CDaqLowLevelIo::ResyncChannel(
...
@@ -442,7 +442,7 @@ CDaqLowLevelIo::ResyncChannel(
else
if
(
data
==
-
1
)
{
else
if
(
data
==
-
1
)
{
fseek
(
m_pFile
,
-
4
,
SEEK_CUR
);
fseek
(
m_pFile
,
-
4
,
SEEK_CUR
);
if
(
DetectFrameHeader
(
recentFrame
))
{
if
(
DetectFrameHeader
(
recentFrame
))
{
skip
=
ftell
(
m_pFile
)
-
startingOffset
;
skip
=
_ftelli64
(
m_pFile
)
-
startingOffset
;
return
eRESYNC_FRAME
;
return
eRESYNC_FRAME
;
}
}
fseek
(
m_pFile
,
4
,
SEEK_CUR
);
fseek
(
m_pFile
,
4
,
SEEK_CUR
);
...
@@ -460,7 +460,7 @@ CDaqLowLevelIo::ResyncChannel(
...
@@ -460,7 +460,7 @@ CDaqLowLevelIo::ResyncChannel(
bool
bool
CDaqLowLevelIo
::
ResyncFrame
(
CDaqLowLevelIo
::
ResyncFrame
(
int
curFrame
,
// last known frame, if -1 then we have no info
int
curFrame
,
// last known frame, if -1 then we have no info
int
&
bytesSkipped
)
long
long
&
bytesSkipped
)
{
{
int
head
[
3
];
int
head
[
3
];
...
@@ -476,7 +476,7 @@ CDaqLowLevelIo::ResyncFrame(
...
@@ -476,7 +476,7 @@ CDaqLowLevelIo::ResyncFrame(
bool
reasonableCount
=
head
[
2
]
>=
0
&&
head
[
2
]
<
m_NumEntries
;
bool
reasonableCount
=
head
[
2
]
>=
0
&&
head
[
2
]
<
m_NumEntries
;
if
(
reasonableFrame
&&
reasonableCount
)
{
if
(
reasonableFrame
&&
reasonableCount
)
{
fseek
(
m_pFile
,
-
3
*
(
signed
int
)
sizeof
(
int
),
SEEK_CUR
);
_fseeki64
(
m_pFile
,
-
3
*
(
signed
int
)
sizeof
(
int
),
SEEK_CUR
);
return
true
;
return
true
;
}
}
}
}
...
@@ -491,7 +491,7 @@ CDaqLowLevelIo::ResyncFrame(
...
@@ -491,7 +491,7 @@ CDaqLowLevelIo::ResyncFrame(
// Since we've lost allignment, we can't keep reading, we have to
// Since we've lost allignment, we can't keep reading, we have to
// keep looking for a frame header one byte at a time
// keep looking for a frame header one byte at a time
else
{
else
{
fseek
(
m_pFile
,
1
-
3
*
sizeof
(
int
),
SEEK_CUR
);
_fseeki64
(
m_pFile
,
1
-
3
*
sizeof
(
int
),
SEEK_CUR
);
bytesSkipped
++
;
bytesSkipped
++
;
}
}
}
}
...
@@ -563,7 +563,7 @@ CDaqLowLevelIo::Open(
...
@@ -563,7 +563,7 @@ CDaqLowLevelIo::Open(
return
false
;
return
false
;
}
}
m_DataOffset
=
ftell
(
m_pFile
);
m_DataOffset
=
_ftelli64
(
m_pFile
);
// find the first frame
// find the first frame
int
maxTries
=
2000
;
int
maxTries
=
2000
;
...
@@ -609,7 +609,7 @@ CDaqLowLevelIo::Open(
...
@@ -609,7 +609,7 @@ CDaqLowLevelIo::Open(
// No matter what happened with the last frame search, we seek ready to
// No matter what happened with the last frame search, we seek ready to
// read data
// read data
//
//
fseek
(
m_pFile
,
m_DataOffset
,
SEEK_SET
);
_fseeki64
(
m_pFile
,
m_DataOffset
,
SEEK_SET
);
//
//
// Now look for the TOC file, if one exists read it
// Now look for the TOC file, if one exists read it
...
@@ -655,10 +655,10 @@ CDaqLowLevelIo::WriteTocFile(
...
@@ -655,10 +655,10 @@ CDaqLowLevelIo::WriteTocFile(
FILE
*
p
=
fopen
(
fname
.
c_str
(),
"wb"
);
FILE
*
p
=
fopen
(
fname
.
c_str
(),
"wb"
);
if
(
p
==
0
)
return
false
;
if
(
p
==
0
)
return
false
;
int
d1
,
d2
;
int
d1
;
int
tblOfs
;
long
long
tblOfs
,
d2
;
d1
=
DAQ_TOC_MAGIC_NUM
;
d1
=
DAQ_TOC_MAGIC_NUM
64
;
if
(
fwrite
(
&
d1
,
sizeof
(
int
),
1
,
p
)
!=
1
)
return
false
;
if
(
fwrite
(
&
d1
,
sizeof
(
int
),
1
,
p
)
!=
1
)
return
false
;
// again, leave space for table offset
// again, leave space for table offset
...
@@ -677,7 +677,7 @@ CDaqLowLevelIo::WriteTocFile(
...
@@ -677,7 +677,7 @@ CDaqLowLevelIo::WriteTocFile(
if
(
fwrite
(
&
d1
,
sizeof
(
int
),
1
,
p
)
!=
1
)
return
false
;
if
(
fwrite
(
&
d1
,
sizeof
(
int
),
1
,
p
)
!=
1
)
return
false
;
TIntVec
::
iterator
vi
;
TIntVec
::
iterator
vi
;
map
<
int
,
int
>::
iterator
mi
;
map
<
int
,
long
long
>::
iterator
mi
;
// num frame drops
// num frame drops
d1
=
(
int
)
m_FrameDrops
.
size
();
d1
=
(
int
)
m_FrameDrops
.
size
();
...
@@ -709,13 +709,13 @@ CDaqLowLevelIo::WriteTocFile(
...
@@ -709,13 +709,13 @@ CDaqLowLevelIo::WriteTocFile(
if
(
fwrite
(
&
d1
,
sizeof
(
int
),
1
,
p
)
!=
1
)
return
false
;
if
(
fwrite
(
&
d1
,
sizeof
(
int
),
1
,
p
)
!=
1
)
return
false
;
}
}
tblOfs
=
ftell
(
p
);
tblOfs
=
_ftelli64
(
p
);
for
(
mi
=
m_Toc
.
begin
();
mi
!=
m_Toc
.
end
();
mi
++
)
{
for
(
mi
=
m_Toc
.
begin
();
mi
!=
m_Toc
.
end
();
mi
++
)
{
d1
=
mi
->
first
;
d1
=
mi
->
first
;
d2
=
mi
->
second
;
d2
=
mi
->
second
;
if
(
fwrite
(
&
d1
,
sizeof
(
int
),
1
,
p
)
!=
1
)
return
false
;
if
(
fwrite
(
&
d1
,
sizeof
(
int
),
1
,
p
)
!=
1
)
return
false
;
if
(
fwrite
(
&
d2
,
sizeof
(
int
),
1
,
p
)
!=
1
)
return
false
;
if
(
fwrite
(
&
d2
,
sizeof
(
long
long
),
1
,
p
)
!=
1
)
return
false
;
}
}
fseek
(
p
,
4
,
SEEK_SET
);
fseek
(
p
,
4
,
SEEK_SET
);
...
@@ -743,7 +743,8 @@ CDaqLowLevelIo::ReadTocFile(
...
@@ -743,7 +743,8 @@ CDaqLowLevelIo::ReadTocFile(
TIntVec
DroppedFrames
;
TIntVec
DroppedFrames
;
TIntVec
Skips
;
TIntVec
Skips
;
int
numEntries
;
int
numEntries
;
int
i
,
count
,
d1
,
d2
;
int
i
,
count
,
d1
;
long
long
d2
;
//
//
// Cannot read the TOC for a file which we have not yet opened
// Cannot read the TOC for a file which we have not yet opened
...
@@ -758,8 +759,12 @@ CDaqLowLevelIo::ReadTocFile(
...
@@ -758,8 +759,12 @@ CDaqLowLevelIo::ReadTocFile(
}
}
if
(
fread
(
&
d1
,
sizeof
(
int
),
1
,
p
)
!=
1
)
return
false
;
if
(
fread
(
&
d1
,
sizeof
(
int
),
1
,
p
)
!=
1
)
return
false
;
if
(
d1
!=
DAQ_TOC_MAGIC_NUM
)
return
false
;
if
(
d1
!=
DAQ_TOC_MAGIC_NUM
&&
d1
!=
DAQ_TOC_MAGIC_NUM64
)
return
false
;
size_t
refSize
=
4
;
if
(
d1
==
DAQ_TOC_MAGIC_NUM64
)
{
refSize
=
8
;
}
// we don't need the offset now, it's for future compatibility
// we don't need the offset now, it's for future compatibility
if
(
fread
(
&
d1
,
sizeof
(
int
),
1
,
p
)
!=
1
)
return
false
;
if
(
fread
(
&
d1
,
sizeof
(
int
),
1
,
p
)
!=
1
)
return
false
;
...
@@ -796,10 +801,17 @@ CDaqLowLevelIo::ReadTocFile(
...
@@ -796,10 +801,17 @@ CDaqLowLevelIo::ReadTocFile(
map
<
int
,
int
>
Toc
;
map
<
int
,
int
>
Toc
;
vector
<
int
>
frame
;
vector
<
int
>
frame
;
vector
<
int
>
offset
;
vector
<
long
long
>
offset
;
for
(
i
=
0
;
i
<
numEntries
;
i
++
)
{
for
(
i
=
0
;
i
<
numEntries
;
i
++
)
{
if
(
fread
(
&
d1
,
sizeof
(
int
),
1
,
p
)
!=
1
)
return
false
;
if
(
fread
(
&
d1
,
sizeof
(
int
),
1
,
p
)
!=
1
)
return
false
;
if
(
fread
(
&
d2
,
sizeof
(
int
),
1
,
p
)
!=
1
)
return
false
;
if
(
refSize
==
4
)
{
int
tempVal
;
if
(
fread
(
&
tempVal
,
refSize
,
1
,
p
)
!=
1
)
return
false
;
d2
=
tempVal
;
}
else
{
if
(
fread
(
&
d2
,
refSize
,
1
,
p
)
!=
1
)
return
false
;
}
frame
.
push_back
(
d1
);
frame
.
push_back
(
d1
);
offset
.
push_back
(
d2
);
offset
.
push_back
(
d2
);
}
}
...
@@ -905,8 +917,8 @@ CDaqLowLevelIo::CheckIntegrity(
...
@@ -905,8 +917,8 @@ CDaqLowLevelIo::CheckIntegrity(
while
(
!
done
)
{
while
(
!
done
)
{
int
curFrame
=
-
1
;
// frame for current record
int
curFrame
=
-
1
;
// frame for current record
int
numChan
;
// number of channels in current record
int
numChan
;
// number of channels in current record
int
skip
=
0
;
long
long
skip
=
0
;
int
frameOffset
;
long
long
frameOffset
;
CDaqLowLevelIo
::
TReadErrorCode
rcode
;
CDaqLowLevelIo
::
TReadErrorCode
rcode
;
...
@@ -919,7 +931,7 @@ CDaqLowLevelIo::CheckIntegrity(
...
@@ -919,7 +931,7 @@ CDaqLowLevelIo::CheckIntegrity(
if
(
curFrame
>
largestFrame
)
largestFrame
=
curFrame
;
if
(
curFrame
>
largestFrame
)
largestFrame
=
curFrame
;
frameOffset
=
ftell
(
m_pFile
)
-
12
;
frameOffset
=
_ftelli64
(
m_pFile
)
-
12
;
numFrames
++
;
numFrames
++
;
if
(
rcode
==
eDAQ_READ_EOF
)
{
if
(
rcode
==
eDAQ_READ_EOF
)
{
...
@@ -957,7 +969,7 @@ CDaqLowLevelIo::CheckIntegrity(
...
@@ -957,7 +969,7 @@ CDaqLowLevelIo::CheckIntegrity(
ch
=
0
;
ch
=
0
;
while
(
ch
<
numChan
)
{
while
(
ch
<
numChan
)
{
int
chId
;
int
chId
;
int
ofs
=
ftell
(
m_pFile
);
// to keep track of where errors may occur
long
long
ofs
=
_ftelli64
(
m_pFile
);
// to keep track of where errors may occur
if
(
fread
(
&
chId
,
sizeof
(
int
),
1
,
m_pFile
)
!=
1
)
{
if
(
fread
(
&
chId
,
sizeof
(
int
),
1
,
m_pFile
)
!=
1
)
{
if
(
m_EofStatus
==
eDAQ_EOF_NOTFOUND
)
{
// OK, we had no end of file
if
(
m_EofStatus
==
eDAQ_EOF_NOTFOUND
)
{
// OK, we had no end of file
...
@@ -1003,8 +1015,8 @@ CDaqLowLevelIo::CheckIntegrity(
...
@@ -1003,8 +1015,8 @@ CDaqLowLevelIo::CheckIntegrity(
int
actCount
;
int
actCount
;
if
(
fread
(
&
actCount
,
sizeof
(
int
),
1
,
m_pFile
)
!=
1
)
{
if
(
fread
(
&
actCount
,
sizeof
(
int
),
1
,
m_pFile
)
!=
1
)
{
sprintf
(
buf
,
"Could not read var size channel length; chId=%d, ofs=%d, abort"
,
sprintf
(
buf
,
"Could not read var size channel length; chId=%d, ofs=%
I64
d, abort"
,
chId
,
ftell
(
m_pFile
));
chId
,
_ftelli64
(
m_pFile
));
m_LastError
=
buf
;
m_LastError
=
buf
;
(
*
m_UserErrorFunc
)(
m_Filename
.
c_str
(),
buf
);
(
*
m_UserErrorFunc
)(
m_Filename
.
c_str
(),
buf
);
return
false
;
return
false
;
...
@@ -1191,7 +1203,7 @@ CDaqLowLevelIo::LowLevelDataRead(
...
@@ -1191,7 +1203,7 @@ CDaqLowLevelIo::LowLevelDataRead(
//
//
int
numFrames
=
0
;
int
numFrames
=
0
;
int
curFrame
=
-
1
;
// frame for current record
int
curFrame
=
-
1
;
// frame for current record
fseek
(
m_pFile
,
m_DataOffset
,
SEEK_SET
);
_fseeki64
(
m_pFile
,
m_DataOffset
,
SEEK_SET
);
while
(
1
)
{
while
(
1
)
{
int
recHead
[
3
];
// (Code, Frame, Count)
int
recHead
[
3
];
// (Code, Frame, Count)
int
numChan
;
// number of channels in current record
int
numChan
;
// number of channels in current record
...
@@ -1229,14 +1241,14 @@ CDaqLowLevelIo::LowLevelDataRead(
...
@@ -1229,14 +1241,14 @@ CDaqLowLevelIo::LowLevelDataRead(
}
}
}
}
else
{
else
{
sprintf
(
buf
,
"Unexpected header code %d at file offset %d"
,
sprintf
(
buf
,
"Unexpected header code %d at file offset %
I64
d"
,
recHead
[
0
],
ftell
(
m_pFile
));
recHead
[
0
],
_ftelli64
(
m_pFile
));
(
*
m_UserErrorFunc
)(
m_Filename
.
c_str
(),
buf
);
(
*
m_UserErrorFunc
)(
m_Filename
.
c_str
(),
buf
);
int
skip
;
long
long
skip
;
int
ofs
=
ftell
(
m_pFile
);
long
long
ofs
=
_ftelli64
(
m_pFile
);
if
(
ResyncFrame
(
curFrame
,
skip
)
==
false
)
{
if
(
ResyncFrame
(
curFrame
,
skip
)
==
false
)
{
sprintf
(
buf
,
"Could not recover after error at file offset %d"
,
ofs
);
sprintf
(
buf
,
"Could not recover after error at file offset %
I64
d"
,
ofs
);
m_LastError
=
buf
;
m_LastError
=
buf
;
return
false
;
return
false
;
}
}
...
@@ -1256,7 +1268,7 @@ CDaqLowLevelIo::LowLevelDataRead(
...
@@ -1256,7 +1268,7 @@ CDaqLowLevelIo::LowLevelDataRead(
return
false
;
return
false
;
}
}
if
(
chId
>=
m_NumEntries
||
chId
<
0
)
{
if
(
chId
>=
m_NumEntries
||
chId
<
0
)
{
int
dummy
;
long
long
dummy
;
int
rcode
=
ResyncChannel
(
curFrame
,
dummy
);
int
rcode
=
ResyncChannel
(
curFrame
,
dummy
);
if
(
rcode
==
eRESYNC_CHANNEL
||
rcode
==
eRESYNC_FRAME
)
{
if
(
rcode
==
eRESYNC_CHANNEL
||
rcode
==
eRESYNC_FRAME
)
{
printf
(
"ERROR, ofs %d
\n
"
,
ftell
(
m_pFile
));
printf
(
"ERROR, ofs %d
\n
"
,
ftell
(
m_pFile
));
...
@@ -1273,8 +1285,8 @@ CDaqLowLevelIo::LowLevelDataRead(
...
@@ -1273,8 +1285,8 @@ CDaqLowLevelIo::LowLevelDataRead(
int
actCount
;
int
actCount
;
if
(
fread
(
&
actCount
,
sizeof
(
int
),
1
,
m_pFile
)
!=
1
)
{
if
(
fread
(
&
actCount
,
sizeof
(
int
),
1
,
m_pFile
)
!=
1
)
{
sprintf
(
buf
,
"Could not read var size channel length; chId=%d, ofs=%d, abort"
,
sprintf
(
buf
,
"Could not read var size channel length; chId=%d, ofs=%
I64
d, abort"
,
chId
,
ftell
(
m_pFile
));
chId
,
_ftelli64
(
m_pFile
));
m_LastError
=
buf
;
m_LastError
=
buf
;
(
*
m_UserErrorFunc
)(
m_Filename
.
c_str
(),
buf
);
(
*
m_UserErrorFunc
)(
m_Filename
.
c_str
(),
buf
);
return
false
;
return
false
;
...
@@ -1439,7 +1451,7 @@ CDaqLowLevelIo::LowLevelDataCopy(
...
@@ -1439,7 +1451,7 @@ CDaqLowLevelIo::LowLevelDataCopy(
gotData
.
resize
(
m_NumEntries
,
false
);
gotData
.
resize
(
m_NumEntries
,
false
);
while
(
frm
<=
m_LastFrame
)
{
while
(
frm
<=
m_LastFrame
)
{
map
<
int
,
int
>::
const_iterator
pTocEn
;
// iterates list of frames for which we have data
TTocMap
::
const_iterator
pTocEn
;
// iterates list of frames for which we have data
vector
<
int
>::
const_iterator
pDrpFrm
;
// iterates list of dropped frames
vector
<
int
>::
const_iterator
pDrpFrm
;
// iterates list of dropped frames
bool
curFrameLost
=
false
;
bool
curFrameLost
=
false
;
int
numChan
;
int
numChan
;
...
@@ -1460,7 +1472,7 @@ CDaqLowLevelIo::LowLevelDataCopy(
...
@@ -1460,7 +1472,7 @@ CDaqLowLevelIo::LowLevelDataCopy(
}
}
else
{
else
{
int
actualFrameRead
;
int
actualFrameRead
;
int
dummy
;
long
long
dummy
;
TReadErrorCode
rcode
;
TReadErrorCode
rcode
;
rcode
=
ReadFrameHeader
(
frm
,
actualFrameRead
,
numChan
,
dummy
);
rcode
=
ReadFrameHeader
(
frm
,
actualFrameRead
,
numChan
,
dummy
);
...
@@ -1666,7 +1678,7 @@ CDaqLowLevelIo::GetFullData(
...
@@ -1666,7 +1678,7 @@ CDaqLowLevelIo::GetFullData(
CDaqBuffer
temBuf
;
// empty buffer to be used as template for latestData
CDaqBuffer
temBuf
;
// empty buffer to be used as template for latestData
int
curFrame
;
int
curFrame
;
int
numChan
;
// number of channels in current record
int
numChan
;
// number of channels in current record
int
bytesSkipped
;
long
long
bytesSkipped
;
TIntVec
empty
;
TIntVec
empty
;
if
(
pFrmList
)
pFrmList
->
resize
(
userDataStorage
.
size
(),
empty
);
if
(
pFrmList
)
pFrmList
->
resize
(
userDataStorage
.
size
(),
empty
);
...
@@ -1866,13 +1878,13 @@ CDaqLowLevelIo::ReadDataForOneFrame(
...
@@ -1866,13 +1878,13 @@ CDaqLowLevelIo::ReadDataForOneFrame(
}
}
CDaqChannelInfo
&
ch
=
m_Channels
[
chId
];
CDaqChannelInfo
&
ch
=
m_Channels
[
chId
];
int
size
;
size_t
size
;
if
(
ch
.
IsVarLen
()
)
{
if
(
ch
.
IsVarLen
()
)
{
int
actCount
;
int
actCount
;
if
(
fread
(
&
actCount
,
sizeof
(
int
),
1
,
m_pFile
)
!=
1
)
{
if
(
fread
(
&
actCount
,
sizeof
(
int
),
1
,
m_pFile
)
!=
1
)
{
sprintf
(
buf
,
"Could not read var size channel length; chId=%d, ofs=%d, abort"
,
sprintf
(
buf
,
"Could not read var size channel length; chId=%d, ofs=%
I64
d, abort"
,
chId
,
ftell
(
m_pFile
));
chId
,
_ftelli64
(
m_pFile
));
m_LastError
=
buf
;
m_LastError
=
buf
;
(
*
m_UserErrorFunc
)(
m_Filename
.
c_str
(),
buf
);
(
*
m_UserErrorFunc
)(
m_Filename
.
c_str
(),
buf
);
return
eDAQ_READ_ERROR
;
return
eDAQ_READ_ERROR
;
...
@@ -1913,7 +1925,7 @@ CDaqLowLevelIo::ReadDataForOneFrame(
...
@@ -1913,7 +1925,7 @@ CDaqLowLevelIo::ReadDataForOneFrame(
}
}
else
{
else
{
// skip the data
// skip the data
fseek
(
m_pFile
,
size
,
SEEK_CUR
);
_fseeki64
(
m_pFile
,
size
,
SEEK_CUR
);
}
}
}
}
return
eDAQ_READ_OK
;
return
eDAQ_READ_OK
;
...
@@ -1951,8 +1963,8 @@ CDaqLowLevelIo::ReadChannelDataForOneFrame(
...
@@ -1951,8 +1963,8 @@ CDaqLowLevelIo::ReadChannelDataForOneFrame(
if
(
ch
.
IsVarLen
()
)
{
if
(
ch
.
IsVarLen
()
)
{
int
actCount
;
int
actCount
;
if
(
fread
(
&
actCount
,
sizeof
(
int
),
1
,
m_pFile
)
!=
1
)
{
if
(
fread
(
&
actCount
,
sizeof
(
int
),
1
,
m_pFile
)
!=
1
)
{
sprintf
(
buf
,
"Could not read var size channel length; chId=%d, ofs=%d, abort"
,
sprintf
(
buf
,
"Could not read var size channel length; chId=%d, ofs=%
I64
d, abort"
,
chId
,
ftell
(
m_pFile
));
chId
,
_ftelli64
(
m_pFile
));
m_LastError
=
buf
;
m_LastError
=
buf
;
(
*
m_UserErrorFunc
)(
m_Filename
.
c_str
(),
buf
);
(
*
m_UserErrorFunc
)(
m_Filename
.
c_str
(),
buf
);
return
eDAQ_READ_ERROR
;
return
eDAQ_READ_ERROR
;
...
@@ -2021,7 +2033,7 @@ CDaqLowLevelIo::ReadFrameHeader(
...
@@ -2021,7 +2033,7 @@ CDaqLowLevelIo::ReadFrameHeader(
int
frameToRead
,
// which frame we anticipate reading, use -1 to read next available
int
frameToRead
,
// which frame we anticipate reading, use -1 to read next available
int
&
curFrame
,
// which frame was read
int
&
curFrame
,
// which frame was read
int
&
numChan
,
// number of channels in this frame
int
&
numChan
,
// number of channels in this frame
int
&
skip
// how many bytes were skipped (if >0 indicates some corruption)
long
long
&
skip
// how many bytes were skipped (if >0 indicates some corruption)
)
)
{
{
int
recHead
[
3
];
// (Code, Frame, Count)
int
recHead
[
3
];
// (Code, Frame, Count)
...
@@ -2033,15 +2045,15 @@ CDaqLowLevelIo::ReadFrameHeader(
...
@@ -2033,15 +2045,15 @@ CDaqLowLevelIo::ReadFrameHeader(
// drops or other file corruption
// drops or other file corruption
for
(
;
;
)
{
for
(
;
;
)
{
if
(
frameToRead
>=
0
)
{
if
(
frameToRead
>=
0
)
{
int
startOfs
;
long
long
startOfs
;
map
<
int
,
int
>
::
const_iterator
mapIter
;
TTocMap
::
const_iterator
mapIter
;
mapIter
=
m_Toc
.
find
(
frameToRead
);
mapIter
=
m_Toc
.
find
(
frameToRead
);
if
(
mapIter
==
m_Toc
.
end
()
)
{
if
(
mapIter
==
m_Toc
.
end
()
)
{
return
eDAQ_NO_SUCH_FRAME
;
return
eDAQ_NO_SUCH_FRAME
;
}
}
startOfs
=
mapIter
->
second
;
startOfs
=
mapIter
->
second
;
fseek
(
m_pFile
,
startOfs
,
SEEK_SET
);
_fseeki64
(
m_pFile
,
startOfs
,
SEEK_SET
);
}
}
// Read the frame header; if this fails, we are really in trouble
// Read the frame header; if this fails, we are really in trouble
...
@@ -2082,13 +2094,13 @@ CDaqLowLevelIo::ReadFrameHeader(
...
@@ -2082,13 +2094,13 @@ CDaqLowLevelIo::ReadFrameHeader(
// Most likely some data didn't make it and we are out of sync with
// Most likely some data didn't make it and we are out of sync with
// where things are. We will try to resynchronize by looking for
// where things are. We will try to resynchronize by looking for
// a reasonable frame marker at some point ahead
// a reasonable frame marker at some point ahead
sprintf
(
buf
,
"Expected header code (-1) but found %d at fileofs %d"
,
sprintf
(
buf
,
"Expected header code (-1) but found %d at fileofs %
I64
d"
,
recHead
[
0
],
ftell
(
m_pFile
));
recHead
[
0
],
_ftelli64
(
m_pFile
));
(
*
m_UserErrorFunc
)(
m_Filename
.
c_str
(),
buf
);
(
*
m_UserErrorFunc
)(
m_Filename
.
c_str
(),
buf
);
int
ofs
=
ftell
(
m_pFile
);
auto
ofs
=
_ftelli64
(
m_pFile
);
if
(
ResyncFrame
(
curFrame
,
skip
)
==
false
)
{
if
(
ResyncFrame
(
curFrame
,
skip
)
==
false
)
{
sprintf
(
buf
,
"Could not recover after error at file offset %d"
,
ofs
);
sprintf
(
buf
,
"Could not recover after error at file offset %
I64
d"
,
ofs
);
m_LastError
=
buf
;
m_LastError
=
buf
;
return
eDAQ_READ_FAILED
;
return
eDAQ_READ_FAILED
;
}
}
...
...
DaqIo.h
View file @
76ef08ce
...
@@ -83,11 +83,11 @@ private:
...
@@ -83,11 +83,11 @@ private:
bool
ReadHeader
(
FILE
*
);
bool
ReadHeader
(
FILE
*
);
bool
ReadChannelInfo
(
FILE
*
);
bool
ReadChannelInfo
(
FILE
*
);
bool
DetectFrameHeader
(
int
recFrame
);
bool
DetectFrameHeader
(
int
recFrame
);
bool
ResyncFrame
(
int
curFrame
,
int
&
skipCount
);
bool
ResyncFrame
(
int
curFrame
,
long
long
&
skipCount
);
TResyncOutcome
ResyncChannel
(
int
recFrame
,
int
&
skipCount
);
TResyncOutcome
ResyncChannel
(
int
recFrame
,
long
long
&
skipCount
);
bool
WriteTocFile
(
const
std
::
string
&
fname
);
bool
WriteTocFile
(
const
std
::
string
&
fname
);
bool
ReadTocFile
(
const
std
::
string
&
fname
);
bool
ReadTocFile
(
const
std
::
string
&
fname
);
TReadErrorCode
ReadFrameHeader
(
int
,
int
&
,
int
&
,
int
&
);
TReadErrorCode
ReadFrameHeader
(
int
,
int
&
,
int
&
,
long
long
&
);
TReadErrorCode
ReadDataForOneFrame
(
int
,
TIntVec
,
TDataVec
&
,
void
*
,
std
::
vector
<
bool
>&
);
TReadErrorCode
ReadDataForOneFrame
(
int
,
TIntVec
,
TDataVec
&
,
void
*
,
std
::
vector
<
bool
>&
);
TReadErrorCode
ReadChannelDataForOneFrame
(
int
,
int
,
CDaqBuffer
&
,
void
*
,
bool
&
);
TReadErrorCode
ReadChannelDataForOneFrame
(
int
,
int
,
CDaqBuffer
&
,
void
*
,
bool
&
);
...
@@ -109,8 +109,9 @@ private:
...
@@ -109,8 +109,9 @@ private:
bool
m_TocExists
;
///< Indicates a TOC exists in a file
bool
m_TocExists
;
///< Indicates a TOC exists in a file
bool
m_HaveToc
;
///< Indicates if we have TOC in memory
bool
m_HaveToc
;
///< Indicates if we have TOC in memory
TChanInfoVec
m_Channels
;
///< Channel information
TChanInfoVec
m_Channels
;
///< Channel information
long
m_DataOffset
;
///< where data starts in the file
long
long
m_DataOffset
;
///< where data starts in the file
std
::
map
<
int
,
int
>
m_Toc
;
///< given a sim frame, gives the offset in the file
typedef
std
::
map
<
int
,
long
long
>
TTocMap
;
TTocMap
m_Toc
;
///< given a sim frame, gives the offset in the file
std
::
vector
<
int
>
m_DroppedFrames
;
std
::
vector
<
int
>
m_DroppedFrames
;
int
m_FirstFrame
;
int
m_FirstFrame
;
int
m_LastFrame
;
int
m_LastFrame
;
...
...
DaqIoLibDefines.h
View file @
76ef08ce
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
//
// $Id: DaqIoLibDefines.h,v 1.
4 2019/07/09 14:33:59
IOWA\dheitbri Exp $
// $Id: DaqIoLibDefines.h,v 1.
5 2020/03/12 00:43:37
IOWA\dheitbri Exp $
// Date: March, 2005
// Date: March, 2005
// Author: Yiannis Papelis
// Author: Yiannis Papelis
//
//
...
@@ -18,6 +18,7 @@ class CDaqChannelInfo;
...
@@ -18,6 +18,7 @@ class CDaqChannelInfo;
#define DAQ_MAGIC_NUM_VER_2_2 0x2C3D4E7F
#define DAQ_MAGIC_NUM_VER_2_2 0x2C3D4E7F
#define DAQ_END_MARK 0x1A2B2C3D
#define DAQ_END_MARK 0x1A2B2C3D
#define DAQ_TOC_MAGIC_NUM 0x2C3ABCDE
#define DAQ_TOC_MAGIC_NUM 0x2C3ABCDE
#define DAQ_TOC_MAGIC_NUM64 0x123ABCDE
typedef
unsigned
char
TDaqByte
;
typedef
unsigned
char
TDaqByte
;
typedef
std
::
vector
<
int
>
TIntVec
;
typedef
std
::
vector
<
int
>
TIntVec
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment