Skip to content

Commit

Permalink
Fix for issue #12 Data missing when reading from channels
Browse files Browse the repository at this point in the history
* fixed EndOfStreamException for files with incremental metadata

* Fixed Issue #12 Data missing when reading from channels

* Improved the fix for EndOfStreamException
  • Loading branch information
tommyja authored and mikeobrien committed Apr 1, 2016
1 parent 341c3c9 commit cbeda5b
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/TDMSReader/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,9 @@ private static void LoadChannels(IDictionary<string, Group> groups, IEnumerable<

private static IEnumerable<Reader.Metadata> LoadMetadata(Reader reader)
{

var segments = GetSegments(reader).ToList();

var segmentMetadata = new List<Tuple<Reader.Segment, List<Reader.Metadata>>>();

Tuple<Reader.Segment, List<Reader.Metadata>> prevSegment = null;
var prevMetaDataLookup = new Dictionary<string, Dictionary<string, Reader.Metadata>>();
foreach (var segment in segments)
{
var metadatas = reader.ReadMetadata(segment);
Expand All @@ -87,13 +84,13 @@ private static void LoadChannels(IDictionary<string, Group> groups, IEnumerable<

foreach (var m in metadatas)
{
if (m.RawData.Count == 0 && prevSegment != null && m.Path.Length > 1)
if (m.RawData.Count == 0 && m.Path.Length > 1)
{
// apply previous metadata if available
var prevMetaData = prevSegment.Item2.FirstOrDefault(md => md.Path.Length > 1 && md.Path[1] == m.Path[1]);
var prevMetaData = prevMetaDataLookup[m.Path[0]][m.Path[1]];
if (prevMetaData != null)
{
m.RawData.Count = prevMetaData.RawData.Count;
m.RawData.Count = segment.TableOfContents.HasRawData ? prevMetaData.RawData.Count : 0;
m.RawData.DataType = prevMetaData.RawData.DataType;
m.RawData.ClrDataType = prevMetaData.RawData.ClrDataType;
m.RawData.Offset = segment.RawDataOffset + rawDataSize;
Expand All @@ -110,7 +107,6 @@ private static void LoadChannels(IDictionary<string, Group> groups, IEnumerable<
m.RawData.InterleaveStride
: (reader.FileSize - m.RawData.Offset + m.RawData.InterleaveStride - 1)/
m.RawData.InterleaveStride;

}
if (m.Path.Length > 1)
{
Expand Down Expand Up @@ -152,11 +148,19 @@ private static void LoadChannels(IDictionary<string, Group> groups, IEnumerable<
}
}
var metadataWithImplicit = metadatas.Concat(implicitMetadatas).ToList();
prevSegment = Tuple.Create(segment, metadataWithImplicit);
segmentMetadata.Add(prevSegment);
foreach (var metadata in metadataWithImplicit)
{
if (metadata.Path.Length == 2)
{
if (!prevMetaDataLookup.ContainsKey(metadata.Path[0]))
{
prevMetaDataLookup[metadata.Path[0]] = new Dictionary<string, Reader.Metadata>();
}
prevMetaDataLookup[metadata.Path[0]][metadata.Path[1]] = metadata;
}
yield return metadata;
}
}

return segmentMetadata.SelectMany(st => st.Item2);
}

private static IEnumerable<Reader.Segment> GetSegments(Reader reader)
Expand Down

1 comment on commit cbeda5b

@mikeobrien
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity TDMS Reader :: Deploy Build 3.0.19.0 outcome was SUCCESS
Summary: Tests passed: 42, ignored: 2 Build time: 00:00:47

Please sign in to comment.