Commit 6f13d1dd by yiannis

Modified code so frame references are fbs frames, not 0-based index numbers.

Added missing code to look for the latest available sample of a differential
channel when the beginning frame didn't have a sample.
parent 6253ccbd
......@@ -2,7 +2,7 @@
///
// DAQ low level IO Library
//
// $Id: DaqFileIO.cxx,v 1.10 2005/03/22 20:12:17 yiannis Exp $
// $Id: DaqFileIO.cxx,v 1.11 2005/04/14 14:19:17 yiannis Exp $
// Date: March, 2005
// Author: Yiannis Papelis
//
......@@ -1556,9 +1556,8 @@ CDaqLowLevelIo::LowLevelDataCopy(
/// Finally, note that for differentially stored data, the extrapolation
/// method defaults to zero-hold.
///
/// The frm1 and frm2 arguments specify the first/last frame to read, inclusively.
/// The frm1 and frm2 arguments specify the first/last fbs frame to read, inclusively.
/// Specify -1 to read from the start or to the end of file respectively.
/// The frame numbers are 0 based, so the first frame would be 0.
///
bool
CDaqLowLevelIo::GetFullData(
......@@ -1660,29 +1659,27 @@ CDaqLowLevelIo::GetFullData(
CDaqLowLevelIo::TReadErrorCode rcode;
//
// Adjust frame numbers so they reflect fbs frames. Also, if frames are specified,
// adjust them to make sure they contain data; we look ahead for hte first frame
// and we look backwards for the last frame, that way we give the user slightly
// less than what was asked.
// Adjust frame numbers if the user specified -1. Also, if frames are specified,
// adjust them to make sure they refer to frames that contain data; we look ahead for
// the first frame and we look backwards for the last frame, that way we give
// the user slightly less than what was asked.
//
if ( frm1 < 0 ) {
frm1 = GetFirstFrame();
}
else {
frm1 += GetFirstFrame();
if ( frm1 < 0 ) frm1 = GetFirstFrame();
if ( frm2 < 0 ) frm2 = GetLastFrame();
int triesLeft = 32;
while ( m_Toc.find(frm1) == m_Toc.end() && triesLeft-- > 0 ) frm1++;
if ( frm1 < GetFirstFrame() || frm1 > GetLastFrame()
|| frm2 < GetFirstFrame() || frm2 > GetLastFrame() ) {
m_LastError = "invalid frame specification; remember frames are fbs based";
return false;
}
if ( frm2 < 0 ) {
frm2 = GetLastFrame();
}
else {
frm2 += GetFirstFrame();
int triesLeft = 32;
while ( m_Toc.find(frm2) == m_Toc.end() && triesLeft-- > 0 ) frm2--;
}
int triesLeft = 32;
while ( m_Toc.find(frm1) == m_Toc.end() && triesLeft-- > 0 ) frm1++;
assert(triesLeft>0); // shouldn't really happen
triesLeft = 32;
while ( m_Toc.find(frm2) == m_Toc.end() && triesLeft-- > 0 ) frm2--;
assert(triesLeft>0); // shouldn't really happen
//
// If the first frame to read is not the first one in the file, and if
......@@ -1690,12 +1687,25 @@ CDaqLowLevelIo::GetFullData(
// of all differential channels, otherwise we may need to output data nad
// have none
//
if ( frm1 == GetFirstFrame() ) {
if ( frm1 != GetFirstFrame() ) {
for (size_t idx=0; idx < pChnList->size(); idx++) {
if ( m_Channels[(*pChnList)[idx]].GetCapRate() < 0 ) {
// TODO: here search backwards from frame frm1 until
// Search backwards from frame frm1 until
// we find data for the specific channel. Store
// its values in latestData[idx]
bool done = false;
int candFrame = frm1;
int theChan = (*pChnList)[idx];
while ( !done && candFrame >= GetFirstFrame() ) {
ReadFrameHeader(candFrame, curFrame, numChan, bytesSkipped);
ReadChannelDataForOneFrame(numChan, theChan, latestData[idx], pTempSpace, done);
candFrame--;
}
if ( !done ) {
m_LastError = "could not find any data for var channel; possible internal error";
return false;
}
}
}
}
......@@ -1708,7 +1718,7 @@ CDaqLowLevelIo::GetFullData(
return false;
}
while ( curFrame < frm2 ) {
while ( curFrame <= frm2 ) {
bool curFrameLost = FrameDropped(curFrame);
if ( curFrameLost ) {
......@@ -1876,6 +1886,82 @@ CDaqLowLevelIo::ReadDataForOneFrame(
return eDAQ_READ_OK;
}
///////////////////////////////////////////////////////////////////////////////
//
// This function reads data for a specific channel from the current frame
//
CDaqLowLevelIo::TReadErrorCode
CDaqLowLevelIo::ReadChannelDataForOneFrame(
int numEntriesInThisRecord,
int channel,
CDaqBuffer& daqBuf,
void* pTempSpace,
bool& gotData
)
{
int idx;
char buf[256];
for (idx=0; idx<numEntriesInThisRecord; idx++) {
int chId;
if ( fread(&chId, sizeof(int), 1, m_pFile) != 1 ) return eDAQ_READ_ERROR;
if ( chId >= m_NumEntries || chId < 0 ) {
sprintf(buf, "Encountered invalid channel %d in data area", chId);
m_LastError = buf;
return eDAQ_READ_BAD_DATA;
}
CDaqChannelInfo& ch = m_Channels[chId];
int size;
if ( ch.IsVarLen() ) {
int actCount;
if ( fread(&actCount, sizeof(int), 1, m_pFile) != 1 ) {
sprintf(buf, "Could not read var size channel length; chId=%d, ofs=%d, abort",
chId, ftell(m_pFile));
m_LastError = buf;
(*m_UserErrorFunc)(m_Filename.c_str(), buf);
return eDAQ_READ_ERROR;
}
size = ch.GetItemSize() * actCount;
}
else {
size = ch.GetRecSize();
}
if ( chId == channel ) { // we only care for the particular channel
if ( size > cMaxDaqRec ) {
sprintf(buf, "Daq record size too big, increase \"cMaxDaqRec\"");
m_LastError = buf;
return eDAQ_READ_INTERNAL_ERROR;
}
if ( size > 0 ) {
size_t n = fread(pTempSpace, size, 1, m_pFile);
if ( n != 1 ) {
sprintf(buf, "read data for channel %d failed", chId);
m_LastError = buf;
return eDAQ_READ_ERROR;
}
}
int fullSize = ch.GetRecSize();
if ( fullSize != size ) {
memset(((char *)pTempSpace) + size, 0, fullSize - size);
}
daqBuf.Replace(pTempSpace, fullSize, ch.GetItemCount());
gotData = true;
return eDAQ_READ_OK;
}
else {
// skip the data
fseek(m_pFile, size, SEEK_CUR);
}
}
return eDAQ_READ_OK;
}
/////////////////////////////////////////////////////////////////////////////
//
......
......@@ -82,6 +82,7 @@ private:
bool ReadTocFile(const string& fname);
TReadErrorCode ReadFrameHeader(int, int& ,int&, int&);
TReadErrorCode ReadDataForOneFrame(int, TIntVec, TDataVec &, void *, vector<bool>&);
TReadErrorCode ReadChannelDataForOneFrame(int, int, CDaqBuffer&, void*, bool&);
string m_Filename;
string m_Version; // file version
......
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