Esempio n. 1
0
        private SpectrumPeaksInfo.MI[] ReadSpectrum(BiblioSpectrumInfo info)
        {
            const int lenPair = sizeof(float) + sizeof(float);

            byte[] peaks = new byte[info.NumPeaks * lenPair];
            lock (ReadStream)
            {
                Stream fs = ReadStream.Stream;

                // Seek to stored location
                fs.Seek(info.Location, SeekOrigin.Begin);

                // Single read to get all the peaks
                if (fs.Read(peaks, 0, peaks.Length) < peaks.Length)
                {
                    throw new IOException(Resources.BiblioSpecLibrary_ReadSpectrum_Failure_trying_to_read_peaks);
                }
            }

            // Build the list
            var arrayMI = new SpectrumPeaksInfo.MI[info.NumPeaks];

            for (int i = 0, iNext = 0; i < peaks.Length; i += lenPair)
            {
                arrayMI[iNext].Intensity = BitConverter.ToSingle(peaks, i + sizeof(Single));
                arrayMI[iNext++].Mz      = BitConverter.ToSingle(peaks, i);
            }

            return(arrayMI);
        }
Esempio n. 2
0
        private SpectrumPeaksInfo.MI[] ReadSpectrum(BiblioSpectrumInfo info)
        {
            const int lenPair = sizeof(float) + sizeof(float);

            byte[] peaks = new byte[info.NumPeaks * lenPair];
            lock (ReadStream)
            {
                try
                {
                    Stream fs = ReadStream.Stream;

                    // Seek to stored location
                    fs.Seek(info.Location, SeekOrigin.Begin);

                    // Single read to get all the peaks
                    if (fs.Read(peaks, 0, peaks.Length) < peaks.Length)
                    {
                        throw new IOException(Resources.BiblioSpecLibrary_ReadSpectrum_Failure_trying_to_read_peaks);
                    }
                }
                catch (Exception)
                {
                    // If an exception is thrown, close the stream in case the failure is something
                    // like a network failure that can be remedied by re-opening the stream.
                    ReadStream.CloseStream();
                    throw;
                }
            }

            // Build the list
            var arrayMI = new SpectrumPeaksInfo.MI[info.NumPeaks];

            for (int i = 0, iNext = 0; i < peaks.Length; i += lenPair)
            {
                arrayMI[iNext].Intensity = BitConverter.ToSingle(peaks, i + sizeof(Single));
                arrayMI[iNext++].Mz      = BitConverter.ToSingle(peaks, i);
            }

            return(arrayMI);
        }
Esempio n. 3
0
        private SpectrumPeaksInfo.MI[] ReadSpectrum(BiblioSpectrumInfo info)
        {
            const int lenPair = sizeof(float) + sizeof(float);
            byte[] peaks = new byte[info.NumPeaks * lenPair];
            lock (ReadStream)
            {
                Stream fs = ReadStream.Stream;

                // Seek to stored location
                fs.Seek(info.Location, SeekOrigin.Begin);

                // Single read to get all the peaks
                if (fs.Read(peaks, 0, peaks.Length) < peaks.Length)
                    throw new IOException(Resources.BiblioSpecLibrary_ReadSpectrum_Failure_trying_to_read_peaks);
            }

            // Build the list
            var arrayMI = new SpectrumPeaksInfo.MI[info.NumPeaks];

            for (int i = 0, iNext = 0; i < peaks.Length; i += lenPair)
            {
                arrayMI[iNext].Intensity = BitConverter.ToSingle(peaks, i + sizeof (Single));
                arrayMI[iNext++].Mz = BitConverter.ToSingle(peaks, i);
            }

            return arrayMI;
        }