File MIES_Cache.ipf

CA This file holds functions related to caching of waves.

The cache allows to store waves using a unique key for later retrieval. The stored waves are kept until they are explicitly removed.

Usage:

  • Write a key generator function returning a string The parameters to CA_GenKey() must completely determine the wave you will later store. The appended version string to the key allows you to invalidate old keys if the algorithm creating the wave changes, but all input stays the same.

Function/S CA_GenKey(input)
    variable input

    return stringCRC(0, num2str(input)) + "Version 1"
End

  • Write your main function as in the following example. The first time MyFancyCalculation(input) is called you get a cache miss and result has to be created from scratch, but all subsequent calls are fast as the entry is fetched from the cache.

Function/WAVE MyFancyCalculation(input)
    variable input

    string key = CA_GenKey(input)

    WAVE/Z result = CA_TryFetchingEntryFromCache(key)

    if(WaveExists(result))
        return result
    endif

    // create result from scratch
    // ...

    CA_StoreEntryIntoCache(key, result)

    return result
End

  • Deleting cache entries has to be done manually via CA_DeleteCacheEntry(). The cache is also stored in a packed experiment.

  • The entries in the cache are stored as free wave copies of what you feed into CA_StoreEntryIntoCache(). Similiary you get a free wave copy from CA_TryFetchingEntryFromCache().

  • Storing 1D wave reference waves is supported, they are by default deep copied.

Cache key generators

string CA_KeyRecreatedEpochs(wave numericalValues, WaveText textualValues, dfref sweepDFR, variable sweepNo)

Cache key generator for recreated epochs wave.

string CA_DistDAQCreateCacheKey(OOdDAQParams *params)

Cache key generator for oodDAQ offset waves.

string CA_PulseTimes(wave wv, string fullPath, variable channelNumber, variable totalOnsetDelay)

Cache key generator for FindLevel in PA_CalculatePulseTimes()

string CA_SmoothDeconv(wave wv, variable smoothingFactor, variable range_pnts)

Cache key generator for PA_SmoothDeconv()

Parameters:
  • wv – input wave (average)

  • smoothingFactor – smoothing factor

  • range_pnts – number of points (p) the smoothing was performed

string CA_Deconv(wave wv, variable tau)

Cache key generator for PA_Deconvolution()

Parameters:
  • wv – input wave (smoothed average)

  • tau – convolution time

string CA_GenKeyGetActiveChannels(wave numericalValues, wave textualValues, variable sweepNo, variable channelType, variable TTLmode)

Cache key generator for GetActiveChannels.

string CA_GenKeyLogbookSortedKeys(wave keys)

Cache key generator for Logbook sortedKeyWave.

string CA_ArtefactRemovalRangesKey(dfref singleSweepDFR, variable sweepNo)

Cache key generator for artefact removal ranges.

string CA_AveragingKey(WaveRefWave waveRefs)

Cache key generator for averaging.

string CA_AveragingWaveModKey(wave wv)

Cache key generator for averaging info from non-free waves.

string CA_PSXEventGoodTauRange(wave wv)

Cache key generator for the tau range calculation of psx events.

static variable CA_RecursiveWavemodCRC(WaveOrNull wv, variable prevCRC = defaultValue)

Calculated a CRC from non wave reference waves using modification data, wave modification count and wave location. If the given wave is a wave reference wave, then the CRC is calculated recursively from all non wave reference waves and null wave references found.

static variable CA_GetWaveModCRC(wave wv, variable crc)
static variable CA_WaveScalingCRC(variable crc, wave wv, variable dimension = defaultValue)

Calculate the CRC of all metadata of all or the given dimension.

static string CA_WaveCRCs(WaveRefWave waveRefs, variable crcMode = defaultValue, variable includeWaveScalingAndUnits = defaultValue, variable dims = defaultValue)

Calculate all CRC values of the waves referenced in waveRefs.

Parameters:
  • waveRefs – wave reference wave

  • crcMode – [optional] parameter to WaveCRC

  • includeWaveScalingAndUnits – [optional] include the wave scaling and units of filled dimensions

  • dims – [optional] number of dimensions to include wave scaling and units in crc

string CA_SamplingIntervalKey(wave lut, ActiveChannels *s)

Calculate the cache key for SI_FindMatchingTableEntry.

We are deliberatly not using a WaveCRC here as know that the wave is not changed in IP once loaded. Therefore using its name and ModDate is enough.

string CA_TemporaryWaveKey(wave dims)

Generic key generator for storing throw away waves used for Multithread assignments.

Only the size is relevant, the rest is undefined.

string CA_HWDeviceInfoKey(string device, variable hardwareType, variable deviceID)

Calculate the cache key for the hardware device info wave.

string CA_HardwareDataTPKey(HardwareDataTPInput *s)

Generate a key for the DAQDataWave in TEST_PULSE_MODE.

Properties which influence the Testpulse:

  • hardwareType

  • numDA (filled columns)

  • numActiveChannels (number of columns)

  • number of rows, return from DC_CalculateDAQDataWaveLength(device, TEST_PULSE_MODE)

  • samplingInterval

  • DAGain

  • DACAmp[][TPAmp] column

  • testPulseLength, baselineFrac

string CA_PSXKernelOperationKey(variable riseTau, variable decayTau, variable amp, variable numPoints, variable dt, wave range)
static string CA_PSXBaseKey(string comboKey, string psxParameters)
string CA_PSXEventsKey(string comboKey, string psxParameters)

Generate the key for the cache and the results wave for psxEvent data of the psx SweepFormula operation.

Parameters:
  • comboKey – combination key, see PSX_GenerateComboKey()

  • psxParameters – JSON dump of the psx/psxKernel operation parameters

string CA_PSXOperationKey(string comboKey, string psxParameters)
string CA_PSXAnalyzePeaks(string comboKey, string psxParameters)
string CA_IgorInfoKey(variable selector)

Return the key for the igor info entries.

string CA_GetLabnotebookNamesKey(WaveTextOrNull textualValues, WaveTextOrNull numericalValues)

Return the key for the filled labnotebook parameter names.

Functions

static variable CA_MakeSpaceForNewEntry()

Make space for one new entry in the cache waves.

Returns:

index into cache waves

variable CA_StoreEntryIntoCache(string key, wave val, variable options = defaultValue)

Add a new entry into the cache.

Existing entries with the same key are overwritten.

Parameters:
  • key – string which uniquely identifies the cached wave

  • val – wave to store

  • options – [optional, defaults to none] One or multiple constants from CacheFetchOptions

static variable CA_GetCacheIndex(wave keys, string key)

Return the index of the entry key

UTF_NOINSTRUMENTATION

Returns:

non-negative number or NaN if it could not be found.

wave CA_TryFetchingEntryFromCache(string key, variable options = defaultValue)

Try to fetch the wave stored under key from the cache.

Parameters:
  • key – string which uniquely identifies the cached wave

  • options – [optional, defaults to none] One or multiple constants from CacheFetchOptions

Returns:

A wave reference with the stored data or a invalid wave reference if nothing could be found.

variable CA_DeleteCacheEntry(string key)

Try to delete a cache entry.

Returns:

One if it could be found and deleted, zero otherwise

variable CA_FlushCache()

Remove all entries from the wave cache.

variable CA_OutputCacheStatistics()

Output cache statistics.