예제 #1
0
 private H5File(H5Context context,
                NamedReference reference,
                ObjectHeader header,
                string absoluteFilePath,
                bool deleteOnClose)
     : base(context, reference, header)
 {
     this.Path      = absoluteFilePath;
     _deleteOnClose = deleteOnClose;
 }
 internal H5CommitedDatatype(H5Context context, ObjectHeader header, NamedReference reference)
     : base(context, reference, header)
 {
     this.Datatype = header.GetMessage <DatatypeMessage>();
 }
예제 #3
0
 internal H5Group(H5File file, H5Context context, NamedReference reference, ObjectHeader header)
     : base(context, reference, header)
 {
     _file = file;
 }
예제 #4
0
        internal H5Dataset(H5File file, H5Context context, NamedReference reference, ObjectHeader header)
            : base(context, reference, header)
        {
            this.File = file;

            foreach (var message in this.Header.HeaderMessages)
            {
                var type = message.Data.GetType();

                if (typeof(DataLayoutMessage).IsAssignableFrom(type))
                {
                    this.InternalDataLayout = (DataLayoutMessage)message.Data;
                }

                else if (type == typeof(DataspaceMessage))
                {
                    this.InternalDataspace = (DataspaceMessage)message.Data;
                }

                else if (type == typeof(DatatypeMessage))
                {
                    this.InternalDataType = (DatatypeMessage)message.Data;
                }

                else if (type == typeof(FillValueMessage))
                {
                    this.InternalFillValue = (FillValueMessage)message.Data;
                }

                else if (type == typeof(FilterPipelineMessage))
                {
                    this.InternalFilterPipeline = (FilterPipelineMessage)message.Data;
                }

                else if (type == typeof(ObjectModificationMessage))
                {
                    this.InternalObjectModification = (ObjectModificationMessage)message.Data;
                }

                else if (type == typeof(ExternalFileListMessage))
                {
                    this.InternalExternalFileList = (ExternalFileListMessage)message.Data;
                }
            }

            // check that required fields are set
            if (this.InternalDataLayout is null)
            {
                throw new Exception("The data layout message is missing.");
            }

            if (this.InternalDataspace is null)
            {
                throw new Exception("The dataspace message is missing.");
            }

            if (this.InternalDataType is null)
            {
                throw new Exception("The data type message is missing.");
            }

            if (this.InternalFillValue is null)
            {
                throw new Exception("The fill value message is missing.");
            }
        }
예제 #5
0
        internal bool TryGetReference(H5ObjectReference reference, HashSet <ulong> alreadyVisited, H5LinkAccess linkAccess, int recursionLevel, out NamedReference namedReference)
        {
            // similar to H5Gint.c (H5G_visit)
            if (recursionLevel >= 100)
            {
                throw new Exception("Too much recursion.");
            }

            bool skip = false;

            namedReference = default;

            /* If its ref count is > 1, we add it to the list of visited objects
             * (because it could come up again during traversal) */
            if (this.ReferenceCount > 1)
            {
                if (alreadyVisited.Contains(this.Reference.Value))
                {
                    skip = true;
                }
                else
                {
                    alreadyVisited.Add(this.Reference.Value);
                }
            }

            if (!skip)
            {
                var references = this
                                 .EnumerateReferences(linkAccess)
                                 .ToList();

                namedReference = references
                                 .FirstOrDefault(current => current.Value == reference.Value);

                if (namedReference.Name is not null /* if struct value is not equal to default */)
                {
                    return(true);
                }
                else
                {
                    // search childs for reference
                    foreach (var childReference in references)
                    {
                        var group = childReference.Dereference() as H5Group;

                        if (group is not null)
                        {
                            if (group.TryGetReference(reference, alreadyVisited, linkAccess, recursionLevel + 1, out namedReference))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
예제 #6
0
 internal H5Group(H5File file, H5Context context, NamedReference reference)
     : base(context, reference)
 {
     _file       = file;
     _scratchPad = reference.ScratchPad;
 }
예제 #7
0
        private bool TryGetReference(string name, H5LinkAccess linkAccess, out NamedReference namedReference)
        {
            namedReference = default;

            /* cached data */
            if (_scratchPad is not null)
            {
                var localHeap = _scratchPad.LocalHeap;

                this.Context.Reader.Seek((long)_scratchPad.BTree1Address, SeekOrigin.Begin);
                var tree = new BTree1Node <BTree1GroupKey>(this.Context.Reader, this.Context.Superblock, this.DecodeGroupKey);
                var b    = tree.EnumerateNodes().ToList();

                this.Context.Reader.Seek((long)_scratchPad.NameHeapAddress, SeekOrigin.Begin);
                var heap = new LocalHeap(this.Context.Reader, this.Context.Superblock);
                var c    = heap.GetObjectName(0);


                var success = _scratchPad
                              .GetBTree1(this.DecodeGroupKey)
                              .TryFindUserData(out var userData,
                                               (leftKey, rightKey) => this.NodeCompare3(localHeap, name, leftKey, rightKey),
                                               (ulong address, BTree1GroupKey _, out BTree1SymbolTableUserData userData)
                                               => this.NodeFound(localHeap, name, address, out userData));

                if (success)
                {
                    namedReference = this.GetObjectReferencesForSymbolTableEntry(localHeap, userData.SymbolTableEntry, linkAccess);
                    return(true);
                }
            }
            else
            {
                var symbolTableHeaderMessages = this.Header.GetMessages <SymbolTableMessage>();

                if (symbolTableHeaderMessages.Any())
                {
                    /* Original approach.
                     * IV.A.2.r.: The Symbol Table Message
                     * Required for "old style" groups; may not be repeated. */

                    if (symbolTableHeaderMessages.Count() != 1)
                    {
                        throw new Exception("There may be only a single symbol table header message.");
                    }

                    var smessage  = symbolTableHeaderMessages.First();
                    var localHeap = smessage.LocalHeap;

                    var success = smessage
                                  .GetBTree1(this.DecodeGroupKey)
                                  .TryFindUserData(out var userData,
                                                   (leftKey, rightKey) => this.NodeCompare3(localHeap, name, leftKey, rightKey),
                                                   (ulong address, BTree1GroupKey _, out BTree1SymbolTableUserData userData)
                                                   => this.NodeFound(localHeap, name, address, out userData));

                    if (success)
                    {
                        namedReference = this.GetObjectReferencesForSymbolTableEntry(localHeap, userData.SymbolTableEntry, linkAccess);
                        return(true);
                    }
                }
                else
                {
                    var linkInfoMessages = this.Header.GetMessages <LinkInfoMessage>();

                    if (linkInfoMessages.Any())
                    {
                        if (linkInfoMessages.Count() != 1)
                        {
                            throw new Exception("There may be only a single link info message.");
                        }

                        var lmessage = linkInfoMessages.First();

                        /* New (1.8) indexed format (in combination with Group Info Message)
                         * IV.A.2.c. The Link Info Message
                         * Optional; may not be repeated. */
                        if (!this.Context.Superblock.IsUndefinedAddress(lmessage.BTree2NameIndexAddress))
                        {
                            if (this.TryGetLinkMessageFromLinkInfoMessage(lmessage, name, out var linkMessage))
                            {
                                namedReference = this.GetObjectReference(linkMessage, linkAccess);
                                return(true);
                            }
                        }

                        /* New (1.8) compact format
                         * IV.A.2.g. The Link Message
                         * A group is storing its links compactly when the fractal heap address
                         * in the Link Info Message is set to the "undefined address" value. */
                        else
                        {
                            var linkMessage = this.Header
                                              .GetMessages <LinkMessage>()
                                              .FirstOrDefault(message => message.LinkName == name);

                            if (linkMessage is not null)
                            {
                                namedReference = this.GetObjectReference(linkMessage, linkAccess);
                                return(true);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("No link information found in object header.");
                    }
                }
            }

            return(false);
        }
예제 #8
0
 // Only for H5File constructor
 internal H5Group(H5Context context, NamedReference reference, ObjectHeader header)
     : base(context, reference, header)
 {
     //
 }
 internal H5AttributableObject(H5Context context, NamedReference reference)
     : base(context, reference)
 {
     //
 }
 internal H5AttributableObject(H5Context context, NamedReference reference, ObjectHeader header)
     : base(context, reference, header)
 {
     //
 }
예제 #11
0
 internal H5Object(H5Context context, NamedReference reference, ObjectHeader header)
 {
     this.Context   = context;
     this.Reference = reference;
     _header        = header;
 }
예제 #12
0
 internal H5Object(H5Context context, NamedReference reference)
 {
     this.Context   = context;
     this.Reference = reference;
 }
 internal H5UnresolvedLink(NamedReference reference)
     : base(default, reference)
 {
     this.Reason = reference.Exception;
 }