Skip to content

Commit c6aa414

Browse files
committed
GetLBRowCache/GetLBIndexCache: Make them work across experiments
Since 8be5388 (NewExperiment: Keep the cache waves across NewExperiment calls, 2025-10-02) we allow to keep the cache across experiments. For the labnotebook row and index cache keeping the cache across experiments is equivalent to deleting the logbook waves and then restarting over. But the upgrade path for both cases did not work as expected as we only did a full upgrade if the labnotebook was empty i.e. the GetLastSweepWithSetting call did not succeed. But if we added an entry for the first sweep, that would pass but then we would not overwrite entries from later sweeps from the previous labnotebook.
1 parent 3ecf2cd commit c6aa414

File tree

2 files changed

+93
-44
lines changed

2 files changed

+93
-44
lines changed

Packages/MIES/MIES_WaveDataFolderGetters.ipf

Lines changed: 58 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,7 @@ End
21912191
/// - One for each entrySourceType, mapped via EntrySourceTypeMapper()
21922192
threadsafe Function/WAVE GetLBRowCache(WAVE values)
21932193

2194-
variable actual, sweepNo, first, last
2194+
variable actual, sweepNo, first, last, expected
21952195
string key
21962196

21972197
variable versionOfNewWave = 6
@@ -2202,32 +2202,39 @@ threadsafe Function/WAVE GetLBRowCache(WAVE values)
22022202
WAVE/Z/D wv = CA_TryFetchingEntryFromCache(key, options = CA_OPTS_NO_DUPLICATE)
22032203

22042204
if(ExistsWithCorrectLayoutVersion(wv, versionOfNewWave))
2205-
if(actual == GetNumberFromWaveNote(wv, LABNOTEBOOK_MOD_COUNT))
2205+
expected = GetNumberFromWaveNote(wv, LABNOTEBOOK_MOD_COUNT)
2206+
2207+
if(actual == expected)
22062208
return wv
22072209
elseif(!MU_RunningInMainThread() && GetLockState(values) == 1)
22082210
return wv
22092211
else
2210-
// new entries were added so we need to propagate all entries to LABNOTEBOOK_GET_RANGE
2211-
// for sweep numbers >= than the currently acquired sweep
2212-
// this is required as the `last` element of the range can be changed if you add labnotebook
2213-
// entries and then query them and then add again.
2214-
2215-
if(IsNumericWave(values))
2216-
WAVE/Z sweeps = GetLastSweepWithSetting(values, "SweepNum", sweepNo)
2217-
elseif(IsTextWave(values))
2218-
WAVE/Z sweeps = GetLastSweepWithSettingText(values, "SweepNum", sweepNo)
2219-
endif
2220-
2221-
if(IsFinite(sweepNo))
2222-
EnsureLargeEnoughWave(wv, indexShouldExist = sweepNo, dimension = ROWS, initialValue = LABNOTEBOOK_GET_RANGE)
2223-
first = limit(sweepNo - 1, 0, Inf)
2224-
last = sweepNo
2225-
Multithread wv[first, last][][] = LABNOTEBOOK_GET_RANGE
2226-
2227-
// now we are up to date
2228-
SetNumberInWaveNote(wv, LABNOTEBOOK_MOD_COUNT, actual)
2229-
2230-
return wv
2212+
if(actual > expected)
2213+
// new entries were added so we need to propagate all entries to LABNOTEBOOK_GET_RANGE
2214+
// for sweep numbers >= than the currently acquired sweep
2215+
// this is required as the `last` element of the range can be changed if you add labnotebook
2216+
// entries and then query them and then add again.
2217+
2218+
if(IsNumericWave(values))
2219+
WAVE/Z sweeps = GetLastSweepWithSetting(values, "SweepNum", sweepNo)
2220+
elseif(IsTextWave(values))
2221+
WAVE/Z sweeps = GetLastSweepWithSettingText(values, "SweepNum", sweepNo)
2222+
endif
2223+
2224+
if(IsFinite(sweepNo))
2225+
EnsureLargeEnoughWave(wv, indexShouldExist = sweepNo, dimension = ROWS, initialValue = LABNOTEBOOK_GET_RANGE)
2226+
first = limit(sweepNo - 1, 0, Inf)
2227+
last = sweepNo
2228+
Multithread wv[first, last][][] = LABNOTEBOOK_GET_RANGE
2229+
2230+
// now we are up to date
2231+
SetNumberInWaveNote(wv, LABNOTEBOOK_MOD_COUNT, actual)
2232+
2233+
return wv
2234+
endif
2235+
else
2236+
// cache across experiments, so the stored wave modification is
2237+
// larger than the last labnotebook we cached, go for a full reset
22312238
endif
22322239
endif
22332240
else
@@ -2266,7 +2273,7 @@ End
22662273
/// could not be found, and #LABNOTEBOOK_UNCACHED_VALUE if the cache is empty.
22672274
threadsafe Function/WAVE GetLBIndexCache(WAVE values)
22682275

2269-
variable actual, sweepNo, first, last
2276+
variable actual, sweepNo, first, last, expected
22702277
string key
22712278

22722279
variable versionOfNewWave = 5
@@ -2277,30 +2284,37 @@ threadsafe Function/WAVE GetLBIndexCache(WAVE values)
22772284
WAVE/Z/D wv = CA_TryFetchingEntryFromCache(key, options = CA_OPTS_NO_DUPLICATE)
22782285

22792286
if(ExistsWithCorrectLayoutVersion(wv, versionOfNewWave))
2280-
if(actual == GetNumberFromWaveNote(wv, LABNOTEBOOK_MOD_COUNT))
2287+
expected = GetNumberFromWaveNote(wv, LABNOTEBOOK_MOD_COUNT)
2288+
2289+
if(actual == expected)
22812290
return wv
22822291
elseif(!MU_RunningInMainThread() && GetLockState(values) == 1)
22832292
return wv
22842293
else
2285-
// new entries were added so we need to propagate all entries to uncached values
2286-
// for sweep numbers >= than the currently acquired sweep
2287-
2288-
if(IsNumericWave(values))
2289-
WAVE/Z sweeps = GetLastSweepWithSetting(values, "SweepNum", sweepNo)
2290-
elseif(IsTextWave(values))
2291-
WAVE/Z sweeps = GetLastSweepWithSettingText(values, "SweepNum", sweepNo)
2292-
endif
2293-
2294-
if(IsFinite(sweepNo))
2295-
EnsureLargeEnoughWave(wv, indexShouldExist = sweepNo, dimension = ROWS, initialValue = LABNOTEBOOK_UNCACHED_VALUE)
2296-
first = limit(sweepNo - 1, 0, Inf)
2297-
last = sweepNo
2298-
Multithread wv[first, last][][] = LABNOTEBOOK_UNCACHED_VALUE
2299-
2300-
// now we are up to date
2301-
SetNumberInWaveNote(wv, LABNOTEBOOK_MOD_COUNT, actual)
2302-
2303-
return wv
2294+
if(actual > expected)
2295+
// new entries were added so we need to propagate all entries to uncached values
2296+
// for sweep numbers >= than the currently acquired sweep
2297+
2298+
if(IsNumericWave(values))
2299+
WAVE/Z sweeps = GetLastSweepWithSetting(values, "SweepNum", sweepNo)
2300+
elseif(IsTextWave(values))
2301+
WAVE/Z sweeps = GetLastSweepWithSettingText(values, "SweepNum", sweepNo)
2302+
endif
2303+
2304+
if(IsFinite(sweepNo))
2305+
EnsureLargeEnoughWave(wv, indexShouldExist = sweepNo, dimension = ROWS, initialValue = LABNOTEBOOK_UNCACHED_VALUE)
2306+
first = limit(sweepNo - 1, 0, Inf)
2307+
last = sweepNo
2308+
Multithread wv[first, last][][] = LABNOTEBOOK_UNCACHED_VALUE
2309+
2310+
// now we are up to date
2311+
SetNumberInWaveNote(wv, LABNOTEBOOK_MOD_COUNT, actual)
2312+
2313+
return wv
2314+
endif
2315+
else
2316+
// cache across experiments, so the stored wave modification is
2317+
// larger than the last labnotebook we cached, go for a full reset
23042318
endif
23052319
endif
23062320
else

Packages/tests/HardwareAnalysisFunctions/UTF_PatchSeqDAScale_Sub.ipf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,3 +2349,38 @@ static Function PS_DS_Sub11_REENTRY([string str])
23492349
CommonAnalysisFunctionChecks(str, sweepNo, setPassed)
23502350
CheckPSQChunkTimes(str, {20, 520, 2020, 2520})
23512351
End
2352+
2353+
static Function PS_DS_Sub12_preAcq(string device)
2354+
2355+
Make/FREE asyncChannels = {2, 3}
2356+
AFH_AddAnalysisParameter("PSQ_DaScale_Sub_DA_0", "AsyncQCChannels", wv = asyncChannels)
2357+
2358+
SetAsyncChannelProperties(device, asyncChannels, -1e6, +1e6)
2359+
End
2360+
2361+
// UTF_TD_GENERATOR DataGenerators#DeviceNameGeneratorMD1
2362+
static Function PS_DS_Sub12([string str])
2363+
2364+
PS_DS_Sub2(str = str)
2365+
End
2366+
2367+
static Function PS_DS_Sub12_REENTRY([string str])
2368+
2369+
PS_DS_Sub2_REENTRY(str = str)
2370+
2371+
BackupCacheWaves()
2372+
End
2373+
2374+
// UTF_TD_GENERATOR DataGenerators#DeviceNameGeneratorMD1
2375+
static Function PS_DS_Sub13([string str])
2376+
2377+
CA_FLushCache()
2378+
RestoreCacheWaves()
2379+
2380+
PS_DS_Sub2(str = str)
2381+
End
2382+
2383+
static Function PS_DS_Sub13_REENTRY([string str])
2384+
2385+
PS_DS_Sub2_REENTRY(str = str)
2386+
End

0 commit comments

Comments
 (0)