|
1 | | -function specs = readEmbeddedSpecifications(filename, specLocation) |
| 1 | +function specs = readEmbeddedSpecifications(reader, specLocation) |
2 | 2 | % readEmbeddedSpecifications - Read embedded specs from an NWB file |
3 | 3 | % |
4 | | -% specs = io.spec.readEmbeddedSpecifications(filename, specLocation) read |
5 | | -% embedded specs from the specLocation in an NWB file |
| 4 | +% specs = io.spec.readEmbeddedSpecifications(reader, specLocation) reads |
| 5 | +% embedded specs from the specLocation in an NWB file, using reader |
| 6 | +% (an io.backend.base.Reader) to access the file. Backend-agnostic: |
| 7 | +% only uses the io.backend.base.Reader interface, so this works for |
| 8 | +% any registered storage backend, not just HDF5. |
6 | 9 | % |
7 | 10 | % Inputs: |
8 | | -% filename (string) : Absolute path of an nwb file |
9 | | -% specLocation (string) : h5 path for the location of specs inside the NWB file |
| 11 | +% reader (io.backend.base.Reader) : Reader for the NWB file |
| 12 | +% specLocation (string) : Path for the location of specs inside the NWB file |
10 | 13 | % |
11 | 14 | % Outputs |
12 | 15 | % specs cell: A cell array of structs with one element for each embedded |
|
17 | 20 | % - schemaMap (containers.Map): A set of schema specifications for the namespace |
18 | 21 |
|
19 | 22 | arguments |
20 | | - filename (1,1) string {matnwb.common.mustBeNwbFile} |
| 23 | + reader (1,1) io.backend.base.Reader |
21 | 24 | specLocation (1,1) string |
22 | 25 | end |
23 | 26 |
|
24 | | - specInfo = h5info(filename, specLocation); |
| 27 | + specInfo = reader.readNodeInfo(specLocation); |
25 | 28 | specs = deal( cell(size(specInfo.Groups)) ); |
26 | | - |
27 | | - fid = H5F.open(filename); |
28 | | - fileCleanup = onCleanup(@(id) H5F.close(fid) ); |
29 | 29 |
|
30 | 30 | for iGroup = 1:length(specInfo.Groups) |
31 | | - location = specInfo.Groups(iGroup).Groups(1); |
| 31 | + namespaceGroupInfo = specInfo.Groups(iGroup); |
| 32 | + location = namespaceGroupInfo.Groups(1); |
32 | 33 |
|
33 | | - namespaceName = split(specInfo.Groups(iGroup).Name, '/'); |
| 34 | + namespaceName = split(namespaceGroupInfo.Name, '/'); |
34 | 35 | namespaceName = namespaceName{end}; |
35 | 36 |
|
36 | | - filenames = {location.Datasets.Name}; |
37 | | - if ~any(strcmp('namespace', filenames)) |
| 37 | + datasetNames = {location.Datasets.Name}; |
| 38 | + if ~any(strcmp('namespace', datasetNames)) |
38 | 39 | warning('NWB:Read:GenerateSpec:CacheInvalid',... |
39 | 40 | 'Couldn''t find a `namespace` in namespace `%s`. Skipping cache generation.',... |
40 | 41 | namespaceName); |
41 | 42 | return; |
42 | 43 | end |
43 | | - sourceNames = {location.Datasets.Name}; |
44 | | - fileLocation = strcat(location.Name, '/', sourceNames); |
| 44 | + |
45 | 45 | schemaMap = containers.Map; |
46 | | - for iFileLocation = 1:length(fileLocation) |
47 | | - did = H5D.open(fid, fileLocation{iFileLocation}); |
48 | | - if strcmp('namespace', sourceNames{iFileLocation}) |
49 | | - namespaceText = H5D.read(did); |
| 46 | + for iDataset = 1:length(datasetNames) |
| 47 | + datasetName = datasetNames{iDataset}; |
| 48 | + datasetPath = strcat(location.Name, '/', datasetName); |
| 49 | + datasetValue = reader.readDatasetValue(location.Datasets(iDataset), datasetPath); |
| 50 | + if strcmp('namespace', datasetName) |
| 51 | + namespaceText = datasetValue; |
50 | 52 | else |
51 | | - schemaMap(sourceNames{iFileLocation}) = H5D.read(did); |
| 53 | + schemaMap(datasetName) = datasetValue; |
52 | 54 | end |
53 | | - H5D.close(did); |
54 | 55 | end |
55 | 56 |
|
56 | 57 | specs{iGroup}.namespaceName = namespaceName; |
|
0 commit comments