Beispiel #1
0
        /// <summary>
        /// This method converts the given array of time series values (array of double precision
        /// floats) to a BLOB (byte array).  It also sets the computes the checksum from the resultant
        /// BLOB, and then sets the Checksum and ValueBlob properties of the given ITimeSeriesTrace
        /// object accordingly.
        /// </summary>
        /// <param name="valueArray">The array of time series values to convert into a BLOB</param>
        /// <param name="compressionCode">a generation number that indicates what compression technique to use</param>
        /// <param name="traceObject">object whose TraceNumber property will be used to compute the checksum,
        /// and whose properties will be assigned by this method</param>
        /// <returns>The BLOB that is created from valueArray</returns>
        public static unsafe byte[] ConvertArrayToBlobRegular(
            double[] valueArray, int compressionCode, ITimeSeriesTrace traceObject)
        {
            // The number of bytes required for the BLOB
            int nBin = traceObject.TimeStepCount * sizeof(double);

            // Allocate an array for the BLOB
            Byte[] blobData = new Byte[nBin];
            // Copy the array of doubles that was passed to the method into the byte array.
            // The byte array becomes the BLOB.
            Buffer.BlockCopy(valueArray, 0, blobData, 0, nBin);

            // Compute the checksum using the uncompressed BLOB.  During development, it was
            // demonstrated that the checksum would be computed faster on the compressed BLOB.
            // However, this could make it difficult to upgrade the compression algorithm in the
            // future, because the checksum value would be dependent on the compression algorithm.
            Byte[]  checksum = ComputeTraceChecksum(traceObject.TraceNumber, blobData);
            Boolean checksumChanged
                = (MurmurHash.ByteArraysAreEqual(traceObject.Checksum, checksum) == false);

            // If the checksum did not change, then we will not assign any properties to the traceObject.
            // The result will be that we will return the original ValueBlob.  If the checksum did change,
            // then we compute a new compressed ValueBlob and assign the new values.
            if (checksumChanged)
            {
                traceObject.Checksum = checksum;
                // the BLOB is stored in a compressed form, so our last step is to compress it
                traceObject.ValueBlob = CompressBlob(blobData, compressionCode);
            }
            return(traceObject.ValueBlob);
        }
Beispiel #2
0
        /// <summary>
        /// This method converts the given array of time series values (date/value pairs stored in
        /// TSDateValueStruct) to a BLOB (byte array).  It also sets the computes the checksum from the
        /// resultant BLOB, and then sets the Checksum and ValueBlob properties of the given
        /// ITimeSeriesTrace object accordingly.
        /// </summary>
        /// <param name="dateValueArray">The array of time series values to convert into a BLOB</param>
        /// <param name="compressionCode">a generation number that indicates what compression technique to use</param>
        /// <param name="traceObject">object whose TraceNumber property will be used to compute the checksum,
        /// and whose properties will be assigned by this method</param>
        /// <returns>The BLOB that is created from dateValueArray</returns>
        public static unsafe byte[] ConvertArrayToBlobIrregular(
            TSDateValueStruct[] dateValueArray, int compressionCode, ITimeSeriesTrace traceObject)
        {
            // The number of bytes required for the BLOB
            int nBin = traceObject.TimeStepCount * sizeof(TSDateValueStruct);

            // Allocate an array for the BLOB
            Byte[] blobData = new Byte[nBin];

            // MemoryStream and BinaryWriter objects enable copying of data to the BLOB
            using (MemoryStream blobStream = new MemoryStream(blobData))
                using (BinaryWriter blobWriter = new BinaryWriter(blobStream))
                {
                    // Loop through the entire array
                    for (int i = 0; i < traceObject.TimeStepCount; i++)
                    {
                        // write the value to the BLOB as DATE followed by VALUE
                        blobWriter.Write(dateValueArray[i].Date.ToBinary());
                        blobWriter.Write(dateValueArray[i].Value);
                    }
                }

            // Compute the checksum using the uncompressed BLOB.  During development, it was
            // demonstrated that the checksum would be computed faster on the compressed BLOB.
            // However, this could make it difficult to upgrade the compression algorithm in the
            // future, because the checksum value would be dependent on the compression algorithm.
            Byte[]  checksum = ComputeTraceChecksum(traceObject.TraceNumber, blobData);
            Boolean checksumChanged
                = (MurmurHash.ByteArraysAreEqual(traceObject.Checksum, checksum) == false);

            // If the checksum did not change, then we will not assign any properties to the traceObject.
            // The result will be that we will return the original ValueBlob.  If the checksum did change,
            // then we compute a new compressed ValueBlob and assign the new values.
            if (checksumChanged)
            {
                traceObject.Checksum = checksum;
                // the BLOB is stored in a compressed form, so our last step is to compress it
                traceObject.ValueBlob = CompressBlob(blobData, compressionCode);
            }
            return(traceObject.ValueBlob);
        }