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( ...@@ -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 void
NearDump(FILE* p, int ofs) NearDump(FILE* p, int ofs)
{ {
...@@ -1281,7 +1303,7 @@ CDaqLowLevelIo::LowLevelDataCopy( ...@@ -1281,7 +1303,7 @@ CDaqLowLevelIo::LowLevelDataCopy(
} }
if ( m_HaveToc == false ) { if ( m_HaveToc == false ) {
m_LastError = "need to buld table of contents first"; m_LastError = "need to build table of contents first";
return false; return false;
} }
...@@ -1457,9 +1479,15 @@ CDaqLowLevelIo::LowLevelDataCopy( ...@@ -1457,9 +1479,15 @@ CDaqLowLevelIo::LowLevelDataCopy(
/// expands differentially stored data, and fills in data for dropped frames. /// 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. /// 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 /// The pWhichChannels vector lists the identifiers for which channels to read.
/// data vector contains data buffers onto which to store the samples of the ///
/// corresponding channels. /// 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 /// Finally, note that for differentially stored data, the extrapolation
/// method defaults to zero-hold. /// method defaults to zero-hold.
...@@ -1506,6 +1534,7 @@ CDaqLowLevelIo::GetFullData( ...@@ -1506,6 +1534,7 @@ CDaqLowLevelIo::GetFullData(
// //
vector<int> needChan; vector<int> needChan;
if ( pWhichChannels ) { if ( pWhichChannels ) {
if ( pWhichChannels->size() == 0 ) return true;
needChan.resize(m_NumEntries, -1); needChan.resize(m_NumEntries, -1);
for (unsigned i=0; i<pWhichChannels->size(); i++) { for (unsigned i=0; i<pWhichChannels->size(); i++) {
if ( (*pWhichChannels)[i] < 0 || (*pWhichChannels)[i] >= m_NumEntries) { if ( (*pWhichChannels)[i] < 0 || (*pWhichChannels)[i] >= m_NumEntries) {
...@@ -1535,6 +1564,17 @@ CDaqLowLevelIo::GetFullData( ...@@ -1535,6 +1564,17 @@ CDaqLowLevelIo::GetFullData(
pChnList = &fullList; 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 // temporary storage; use a vector so we don't have to worry about
// memory leaks // memory leaks
vector<unsigned char> tempSpace; vector<unsigned char> tempSpace;
...@@ -1556,10 +1596,29 @@ CDaqLowLevelIo::GetFullData( ...@@ -1556,10 +1596,29 @@ CDaqLowLevelIo::GetFullData(
CDaqLowLevelIo::TReadErrorCode rcode; 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 ( frm1 < 0 ) {
if ( frm2 < 0 ) frm2 = GetLastFrame(); else frm2 += GetLastFrame(); 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 // If the first frame to read is not the first one in the file, and if
...@@ -1570,7 +1629,7 @@ CDaqLowLevelIo::GetFullData( ...@@ -1570,7 +1629,7 @@ CDaqLowLevelIo::GetFullData(
if ( frm1 == GetFirstFrame() ) { if ( frm1 == GetFirstFrame() ) {
for (size_t idx=0; idx < pChnList->size(); idx++) { for (size_t idx=0; idx < pChnList->size(); idx++) {
if ( m_Channels[(*pChnList)[idx]].GetCapRate() < 0 ) { 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 // we find data for the specific channel. Store
// its values in latestData[idx] // its values in latestData[idx]
} }
...@@ -1580,7 +1639,7 @@ CDaqLowLevelIo::GetFullData( ...@@ -1580,7 +1639,7 @@ CDaqLowLevelIo::GetFullData(
// Seek to the first frame we need // Seek to the first frame we need
rcode = ReadFrameHeader(frm1, curFrame, numChan, bytesSkipped); rcode = ReadFrameHeader(frm1, curFrame, numChan, bytesSkipped);
if ( rcode != eDAQ_READ_OK ) { 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; m_LastError = buf;
return false; return false;
} }
......
...@@ -313,6 +313,7 @@ public: ...@@ -313,6 +313,7 @@ public:
bool Open(const string &); bool Open(const string &);
void GetChannels(TChanInfoVec& channels) const; void GetChannels(TChanInfoVec& channels) const;
bool GetChannelInfo(int chId, CDaqChannelInfo &info) const;
int GetFirstFrame() const; int GetFirstFrame() const;
int GetLastFrame() const; int GetLastFrame() const;
int GetFrames() const; int GetFrames() const;
...@@ -397,7 +398,7 @@ private: ...@@ -397,7 +398,7 @@ private:
vector<int> m_DroppedFrames; vector<int> m_DroppedFrames;
int m_FirstFrame; int m_FirstFrame;
int m_LastFrame; int m_LastFrame;
string m_LastError; mutable string m_LastError;
TDaqEofStatus m_EofStatus; TDaqEofStatus m_EofStatus;
// These are for data integrity // 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