Skip to content

Commit

Permalink
AB_AddMapEntry: Fix overwriting previous entries
Browse files Browse the repository at this point in the history
The performance improvement in c2268c0 (AB: Allow AB_AddMapEntry to use
empty rows as well, 2023-05-09) allowed to reuse empty rows which were in
the range from 0 to index - 1.

But the final SetNumberInWaveNote then wrote this index into the map wave
as next free index. Which overwrote previous entries.

By distinguishing the nex free index from the write index we can fix the
issue.
  • Loading branch information
t-b committed Mar 7, 2024
1 parent ac3a438 commit 825c14e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
29 changes: 16 additions & 13 deletions Packages/MIES/MIES_AnalysisBrowser.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ End
static Function AB_AddMapEntry(baseFolder, discLocation)
string baseFolder, discLocation

variable index, fileID, nwbVersion, dim
variable nextFreeIndex, fileID, nwbVersion, dim, writeIndex
string dataFolder, fileType, relativePath, extension
WAVE/T map = GetAnalysisBrowserMap()

Expand All @@ -99,21 +99,22 @@ static Function AB_AddMapEntry(baseFolder, discLocation)
return -1
endif

index = GetNumberFromWaveNote(map, NOTE_INDEX)
nextFreeIndex = GetNumberFromWaveNote(map, NOTE_INDEX)
dim = FindDimLabel(map, COLS, "DiscLocation")
FindValue/TEXT=""/TXOP=4/RMD=[][dim] map
if(V_row < index)
index = V_row
FindValue/TEXT=""/TXOP=4/RMD=[0, nextFreeIndex - 1][dim] map
if(V_row >= 0)
writeIndex = V_row
else
EnsureLargeEnoughWave(map, indexShouldExist=index, dimension=ROWS)
writeIndex = nextFreeIndex
EnsureLargeEnoughWave(map, indexShouldExist=writeIndex, dimension=ROWS)
endif

// %DiscLocation = full path to file
map[index][%DiscLocation] = discLocation
map[writeIndex][%DiscLocation] = discLocation

// %FileName = filename + extension
relativePath = RemovePrefix(discLocation, start = baseFolder)
map[index][%FileName] = relativePath
map[writeIndex][%FileName] = relativePath

extension = "." + GetFileSuffix(discLocation)

Expand Down Expand Up @@ -141,19 +142,21 @@ static Function AB_AddMapEntry(baseFolder, discLocation)
default:
ASSERT(0, "invalid file type")
endswitch
map[index][%FileType] = fileType
map[writeIndex][%FileType] = fileType

DFREF dfrAB = GetAnalysisFolder()
DFREF dfr = dfrAB:$AB_GetUserData(AB_UDATA_WORKINGDF)
DFREF expFolder = UniqueDataFolder(dfr, RemoveEnding(relativePath, extension))
dataFolder = RemovePrefix(GetDataFolder(1, expFolder), start = GetDataFolder(1, dfrAB))
map[index][%DataFolder] = RemoveEnding(dataFolder, ":")
map[writeIndex][%DataFolder] = RemoveEnding(dataFolder, ":")
RefCounterDFIncrease(expFolder)

index += 1
SetNumberInWaveNote(map, NOTE_INDEX, index)
if(writeIndex == nextFreeIndex)
nextFreeIndex += 1
SetNumberInWaveNote(map, NOTE_INDEX, nextFreeIndex)
endif

return index - 1
return writeIndex
End

static Function AB_RemoveMapEntry(variable index)
Expand Down
26 changes: 26 additions & 0 deletions Packages/tests/HistoricData/UTF_HistoricDashboard.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,29 @@ Function TestDashboardWithHistoricData([string str])
bsPanel = BSP_GetPanel(sbWin)
PGC_SetAndActivateControl(bsPanel, "check_BrowserSettings_DS", val = 1)
End

Function TestAnalysisBrowserAddingFiles()

string abWin, sweepBrowsers, fileToReadd
variable holeIndex

WAVE/T files = GetHistoricDataFiles()
files[] = "input:" + files[p]

[abWin, sweepBrowsers] = OpenAnalysisBrowser(files)

PGC_SetAndActivateControl(abWin, "button_collapse_all")

WAVE/T map = GetAnalysisBrowserMap()
CHECK_EQUAL_VAR(GetNumberFromWaveNote(map, NOTE_INDEX), DimSize(files, ROWS))

holeIndex = 1
fileToReadd = map[holeIndex]

SetListBoxSelection(abWin, "listbox_AB_Folders", LISTBOX_SELECTED, holeIndex)
PGC_SetAndActivateControl(abWin, "button_AB_Remove")
CHECK_EQUAL_VAR(GetNumberFromWaveNote(map, NOTE_INDEX), DimSize(files, ROWS))

MIES_AB#AB_AddFiles(abWin, {fileToReadd})
CHECK_EQUAL_VAR(GetNumberFromWaveNote(map, NOTE_INDEX), DimSize(files, ROWS))
End

0 comments on commit 825c14e

Please sign in to comment.