public unsafe override object GetValue() { int elementSize; byte * sourcePtr; DataPort dataPort; dataPort = this.AssociatedDataInput; if (this.AssociatedDataInput != null) { sourcePtr = (byte *)dataPort.DataPtr.ToPointer(); elementSize = OneDasUtilities.SizeOf(typeof(T)); byte *targetPtr = stackalloc byte[elementSize]; if (dataPort.DataType == OneDasDataType.BOOLEAN && dataPort.BitOffset > -1) // special handling for boolean { // from bit to byte bool value; value = (*sourcePtr & (1 << dataPort.BitOffset)) > 0; targetPtr[0] = *(byte *)&value; } else { switch (dataPort.Endianness) { case Endianness.LittleEndian: for (int i = 0; i < elementSize; i++) { targetPtr[i] = sourcePtr[i]; } break; case Endianness.BigEndian: for (int i = 0; i < elementSize; i++) { targetPtr[i] = sourcePtr[elementSize - i - 1]; } break; default: throw new ArgumentException(); } } return(new Span <T>(targetPtr, 1)[0]); } else { return(null); } }
public unsafe DataStorageBase(Type type, int elementCount) { this.ElementSize = OneDasUtilities.SizeOf(type); _byteCount = this.ElementSize * elementCount; this.DataBufferPtr = Marshal.AllocHGlobal(_byteCount); this.DataBuffer.Clear(); }
protected virtual int SetDataPortBufferOffset(KeyValuePair <OneDasModule, List <DataPort> > moduleEntry, int bufferOffsetBase, DataDirection dataDirection) { int dataPortOffset; dataPortOffset = 0; moduleEntry.Value.ForEach(dataPort => { dataPort.DataPtr = new IntPtr(bufferOffsetBase + dataPortOffset); dataPortOffset += OneDasUtilities.SizeOf(dataPort.DataType); }); return(moduleEntry.Key.GetByteCount()); }
public Task <string> GetData(DateTime dateTimeBegin, DateTime dateTimeEnd, string sampleRateDescription, FileFormat fileFormat, FileGranularity fileGranularity, Dictionary <string, Dictionary <string, List <string> > > campaignInfoSet) { long fileId = -1; long datasetId = -1; ulong start; ulong stride; ulong block; ulong count; ulong segmentLength; ulong segmentSize; ulong bytesPerRow; double sampleRate; DateTime epochStart; DateTime epochEnd; string zipFilePath; // task return(Task.Run(() => { this.CheckState(); if (!campaignInfoSet.Any()) { return string.Empty; } // zip file zipFilePath = Path.Combine(_options.SupportDirectoryPath, "EXPORT", $"OneDAS_{ dateTimeBegin.ToString("yyyy-MM-ddTHH-mm") }_{ sampleRateDescription }_{ Guid.NewGuid().ToString() }.zip"); // sampleRate sampleRate = sampleRateDescription.ToSampleRate(); // epoch & hyperslab epochStart = new DateTime(2000, 01, 01); epochEnd = new DateTime(2030, 01, 01); if (!(epochStart <= dateTimeBegin && dateTimeBegin <= dateTimeEnd && dateTimeEnd <= epochEnd)) { throw new Exception("requirement >> epochStart <= dateTimeBegin && dateTimeBegin <= dateTimeEnd && dateTimeBegin <= epochEnd << is not matched"); } start = (ulong)(Math.Floor((dateTimeBegin - epochStart).TotalSeconds * sampleRate)); stride = 1; block = (ulong)(Math.Ceiling((dateTimeEnd - dateTimeBegin).TotalSeconds * sampleRate)); count = 1; try { // open file fileId = H5F.open(_options.VdsFilePath, H5F.ACC_RDONLY); // byte count bytesPerRow = 0; foreach (var campaignInfo in campaignInfoSet) { foreach (var variableInfo in campaignInfo.Value) { foreach (string datasetInfo in variableInfo.Value) { try { datasetId = H5D.open(fileId, $"{ campaignInfo.Key }/{ variableInfo.Key }/{ datasetInfo }"); bytesPerRow += (ulong)OneDasUtilities.SizeOf(TypeConversionHelper.GetTypeFromHdfTypeId(H5D.get_type(datasetId))); } finally { if (H5I.is_valid(datasetId) > 0) { H5D.close(datasetId); } } } } } this.GetClient().SendByteCount(bytesPerRow * block); segmentSize = (50 * 1024 * 1024) / bytesPerRow * bytesPerRow; segmentLength = segmentSize / bytesPerRow; // ensure that dataset length is multiple of 1 minute if ((segmentLength / sampleRate) % 60 != 0) { segmentLength = (ulong)((ulong)(segmentLength / sampleRate / 60) * 60 * sampleRate); } // start _stateManager.SetState(this.Context.ConnectionId, HdfExplorerState.Loading); using (ZipArchive zipArchive = ZipFile.Open(zipFilePath, ZipArchiveMode.Create)) { foreach (var campaignInfo in campaignInfoSet) { HdfDataLoader hdfDataLoader; hdfDataLoader = new HdfDataLoader(_stateManager.GetToken(this.Context.ConnectionId)); hdfDataLoader.ProgressUpdated += this.OnProgressUpdated; if (!hdfDataLoader.WriteZipFileCampaignEntry(zipArchive, fileGranularity, fileFormat, new ZipSettings(dateTimeBegin, campaignInfo, fileId, sampleRate, start, stride, block, count, segmentLength))) { return string.Empty; } } } } catch (Exception ex) { this.WriteLogEntry(ex.Message, true); throw; } finally { _stateManager.SetState(this.Context.ConnectionId, HdfExplorerState.Idle); if (H5I.is_valid(fileId) > 0) { H5F.close(fileId); } } this.WriteLogEntry($"{ this.Context.GetHttpContext().Connection.RemoteIpAddress } requested data: { dateTimeBegin.ToString("yyyy-MM-dd HH:mm:ss") } to { dateTimeEnd.ToString("yyyy-MM-dd HH:mm:ss") }", false); return $"download/{ Path.GetFileName(zipFilePath) }"; }, _stateManager.GetToken(this.Context.ConnectionId))); }