forked from barrywark/pldaps-importer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindEpochByUniqueNumber.m
54 lines (43 loc) · 1.68 KB
/
findEpochByUniqueNumber.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function epoch = findEpochByUniqueNumber(epochGroup, uniqueNumber, varargin)
% EntityBase.getProperty is slow. Until we can pull just getOwner()'s
% properties, we do some caching and hinting to speed up this search.
if(nargin >= 3)
uniqueNumberCache = varargin{1};
else
uniqueNumberCache = [];
end
epoch = [];
if(isempty(epochGroup))
return;
end
if(~isempty(uniqueNumberCache))
if(uniqueNumberCache.uniqueNumber.containsKey(num2str(uniqueNumber)))
epoch = uniqueNumberCache.uniqueNumber.get(num2str(uniqueNumber));
return;
elseif(uniqueNumberCache.truncatedUniqueNumber.containsKey(num2str(uniqueNumber)))
epoch = uniqueNumberCache.truncatedUniqueNumber.get(num2str(uniqueNumber));
warning('ovation:import:plx:unique_number', 'uniqueNumber appears to be 8-bit truncated');
return;
end
end
epochs = epochGroup.getEpochs();
for i = 1:length(epochs)
epoch = epochs(i);
% TODO this should use getProperty(getOwner)
vals = epoch.getProperty('uniqueNumber');
assert(length(vals) <= 1);
if(isempty(vals))
continue;
end
epochUniqueNumber = vals(1).getIntegerData()';
if(all(epochUniqueNumber == uniqueNumber))
uniqueNumberCache.put(uniqueNumber, epoch);
return;
end
if(all(mod(epochUniqueNumber,256) == uniqueNumber))
warning('ovation:import:plx:unique_number', 'uniqueNumber appears to be 8-bit truncated');
return;
end
end
epoch = [];
end