Commit 30ef1473 by yiannis

Fixed a bug related to the frame numbers. Something is still not quite right.

Added function to provide the information about a single channel.
parent 4eb7c23c
......@@ -70,6 +70,28 @@ CDaqLowLevelIo::SetCallbacks(
}
bool
CDaqLowLevelIo::GetChannelInfo(
int chId,
CDaqChannelInfo& info) const
{
if ( m_pFile == 0 ) {
m_LastError = "uninitialized class instance (call Open first)";
return false;
}
if ( chId < 0 || chId >= m_Channels.size() ) {
m_LastError = "invalid channel";
return false;
}
info = m_Channels[chId];
m_LastError = "";
return true;
}
void
NearDump(FILE* p, int ofs)
{
......@@ -1281,7 +1303,7 @@ CDaqLowLevelIo::LowLevelDataCopy(
}
if ( m_HaveToc == false ) {
m_LastError = "need to buld table of contents first";
m_LastError = "need to build table of contents first";
return false;
}
......@@ -1457,9 +1479,15 @@ CDaqLowLevelIo::LowLevelDataCopy(
/// expands differentially stored data, and fills in data for dropped frames.
/// If specified, it can read a subset of the data based on a start and end frame.
///
/// The chans vector lists the identifiers for which channels to read. The
/// data vector contains data buffers onto which to store the samples of the
/// corresponding channels.
/// The pWhichChannels vector lists the identifiers for which channels to read.
///
/// The userDataStorage argument is a vector of CDaqBuffer classes, each of which
/// will contain the data for a channel. The vector can be empty, in which case
/// the function will expand it to be equal to the number of requested channels.
/// If the vector is already properly sized, the function will simply put
/// the data on the corresponding entry. For example, the first requested channel will
/// be stored in userDataStorage[0], the second requested channel will be stored
/// in userDataStorage[1] etc.
///
/// Finally, note that for differentially stored data, the extrapolation
/// method defaults to zero-hold.
......@@ -1506,6 +1534,7 @@ CDaqLowLevelIo::GetFullData(
//
vector<int> needChan;
if ( pWhichChannels ) {
if ( pWhichChannels->size() == 0 ) return true;
needChan.resize(m_NumEntries, -1);
for (unsigned i=0; i<pWhichChannels->size(); i++) {
if ( (*pWhichChannels)[i] < 0 || (*pWhichChannels)[i] >= m_NumEntries) {
......@@ -1535,6 +1564,17 @@ CDaqLowLevelIo::GetFullData(
pChnList = &fullList;
}
// clear any buffers that the user has provided
for (unsigned ii=0; ii<userDataStorage.size(); ii++) {
userDataStorage[ii].Clear();
}
// make sure the storage vectory is properly dimensioned and initialized
if ( pChnList->size() > userDataStorage.size() ) {
CDaqBuffer empty;
userDataStorage.resize(pChnList->size(), empty);
}
// temporary storage; use a vector so we don't have to worry about
// memory leaks
vector<unsigned char> tempSpace;
......@@ -1556,10 +1596,29 @@ CDaqLowLevelIo::GetFullData(
CDaqLowLevelIo::TReadErrorCode rcode;
//
// Adjust frame numbers so they reflect fbs frames
// 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.
//
if ( frm1 < 0 ) frm1 = GetFirstFrame(); else frm1 += GetFirstFrame();
if ( frm2 < 0 ) frm2 = GetLastFrame(); else frm2 += GetLastFrame();
if ( frm1 < 0 ) {
frm1 = GetFirstFrame();
}
else {
frm1 += GetFirstFrame();
int triesLeft = 32;
while ( m_Toc.find(frm1) == m_Toc.end() && triesLeft-- > 0 ) frm1++;
}
if ( frm2 < 0 ) {
frm2 = GetLastFrame();
}
else {
frm2 += GetLastFrame();
int triesLeft = 32;
while ( m_Toc.find(frm2) == m_Toc.end() && triesLeft-- > 0 ) frm2--;
}
//
// If the first frame to read is not the first one in the file, and if
......@@ -1570,7 +1629,7 @@ CDaqLowLevelIo::GetFullData(
if ( frm1 == GetFirstFrame() ) {
for (size_t idx=0; idx < pChnList->size(); idx++) {
if ( m_Channels[(*pChnList)[idx]].GetCapRate() < 0 ) {
// here search backwards from frame frm1 until
// TODO: here search backwards from frame frm1 until
// we find data for the specific channel. Store
// its values in latestData[idx]
}
......@@ -1580,7 +1639,7 @@ CDaqLowLevelIo::GetFullData(
// Seek to the first frame we need
rcode = ReadFrameHeader(frm1, curFrame, numChan, bytesSkipped);
if ( rcode != eDAQ_READ_OK ) {
sprintf(buf, "First ReadFrameHeader() returned %d", rcode);
sprintf(buf, "First ReadFrameHeader(frm1=%d) returned %d", frm1, rcode);
m_LastError = buf;
return false;
}
......
......@@ -313,6 +313,7 @@ public:
bool Open(const string &);
void GetChannels(TChanInfoVec& channels) const;
bool GetChannelInfo(int chId, CDaqChannelInfo &info) const;
int GetFirstFrame() const;
int GetLastFrame() const;
int GetFrames() const;
......@@ -397,7 +398,7 @@ private:
vector<int> m_DroppedFrames;
int m_FirstFrame;
int m_LastFrame;
string m_LastError;
mutable string m_LastError;
TDaqEofStatus m_EofStatus;
// These are for data integrity
......
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