Skip to content

Commit

Permalink
Analysis Functions: Remove PRE_SWEEP_EVENT and repurpose as PRE_SWEEP…
Browse files Browse the repository at this point in the history
…_CONFIG_EVENT

Experience has shown that the current PRE_SWEEP_EVENT, which happens
after the sweep is configured and immediately before DAQ starts, is off
very limited use.

In all PSQ/MSQ analysis functions it is never used.

The reason is that as it is called after the sweep is configured, the
analysis function can not change anything relevant anymore.

Instead of now adding a new event which is called before the sweep is
configured, the existing one PRE_SWEEP_EVENT is repurposed as
PRE_SWEEP_CONFIG_EVENT.
  • Loading branch information
t-b committed Jul 13, 2021
1 parent 9aa2b3b commit 20b6ccc
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 113 deletions.
4 changes: 2 additions & 2 deletions Packages/MIES/MIES_AcquisitionStateHandling.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ Function AS_HandlePossibleTransition(string panelTitle, variable newAcqState, [v
return AFM_CallAnalysisFunctions(panelTitle, PRE_DAQ_EVENT)
break
case AS_PRE_SWEEP_CONFIG:
// do nothing
return AFM_CallAnalysisFunctions(panelTitle, PRE_SWEEP_CONFIG_EVENT)
break
case AS_PRE_SWEEP:
return AFM_CallAnalysisFunctions(panelTitle, PRE_SWEEP_EVENT)
// nothing to do
break
case AS_MID_SWEEP:
if(oldAcqState == AS_MID_SWEEP)
Expand Down
8 changes: 4 additions & 4 deletions Packages/MIES/MIES_AnalysisFunctionManagement.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ Function AFM_CallAnalysisFunctions(panelTitle, eventType)

WAVE/T analysisFunctions = GetAnalysisFunctionStorage(panelTitle)

if(eventType == PRE_DAQ_EVENT || eventType == PRE_SET_EVENT)
if(eventType == PRE_DAQ_EVENT || eventType == PRE_SET_EVENT || eventType == PRE_SWEEP_CONFIG_EVENT)
realDataLength = NaN
else
realDataLength = stopCollectionPoint
endif

// use safe defaults
if(eventType == PRE_DAQ_EVENT || eventType == PRE_SET_EVENT || eventType == PRE_SWEEP_EVENT)
if(eventType == PRE_DAQ_EVENT || eventType == PRE_SET_EVENT || eventType == PRE_SWEEP_CONFIG_EVENT)
fifoPosition = NaN
endif

Expand Down Expand Up @@ -79,7 +79,7 @@ Function AFM_CallAnalysisFunctions(panelTitle, eventType)
// @todo Use AS_GetSweepNumber once acquisition state handling supports PRE/POST SET_EVENTS
switch(eventType)
case PRE_DAQ_EVENT:
case PRE_SWEEP_EVENT:
case PRE_SWEEP_CONFIG_EVENT:
case PRE_SET_EVENT:
case MID_SWEEP_EVENT: // fallthrough-by-design
sweepNo = DAG_GetNumericalValue(panelTitle, "SetVar_Sweep")
Expand Down Expand Up @@ -152,7 +152,7 @@ Function AFM_CallAnalysisFunctions(panelTitle, eventType)
sprintf msg, "Calling analysis function \"%s\" for event \"%s\" on headstage %d returned ret %g", func, StringFromList(eventType, EVENT_NAME_LIST), i, ret
DEBUGPRINT(msg)

if((eventType == PRE_DAQ_EVENT || eventType == PRE_SET_EVENT) && ret == 1)
if((eventType == PRE_DAQ_EVENT || eventType == PRE_SET_EVENT || eventType == PRE_SWEEP_CONFIG_EVENT) && ret == 1)
return ret
elseif(eventType == MID_SWEEP_EVENT && (ret == ANALYSIS_FUNC_RET_REPURP_TIME || ret == ANALYSIS_FUNC_RET_EARLY_STOP))
return ret
Expand Down
62 changes: 32 additions & 30 deletions Packages/MIES/MIES_AnalysisFunctions.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@
/// :width: 300 px
/// :align: center
///
/// =========== ============================================== ===============================================================
/// Event Description Specialities
/// =========== ============================================== ===============================================================
/// Pre DAQ Before any DAQ occurs Called before the settings are validated completely, only the
/// analysis parameters are validated if present. With Indexing ON,
/// only the analysis function of the first stimset will receive
/// that event.
/// Mid Sweep Each time when new data is polled Available for background DAQ only.
/// Will always be called at least once and
/// also with the full stimset acquired.
/// Pre Sweep Immediately before the sweep starts None
/// Pre Set Before a new set starts None
/// Post Sweep After each sweep (before possible ITI pause) None
/// Post Set After a *full* set has been acquired This event is not always reached as the user might not acquire
/// all steps of a set. With indexing, locked and unlocked, only
/// the post set events for fully acquired stimsets are reached.
/// Post DAQ After DAQ has finished and before potential None
/// "TP after DAQ"
/// =========== ============================================== ===============================================================
/// =================== ============================================== ===============================================================
/// Event Description Specialities
/// =================== ============================================== ===============================================================
/// Pre DAQ Before any DAQ occurs Called before the settings are validated completely, only the
/// analysis parameters are validated if present. With Indexing ON,
/// only the analysis function of the first stimset will receive
/// that event.
/// Mid Sweep Each time when new data is polled Available for background DAQ only.
/// Will always be called at least once and
/// also with the full stimset acquired.
/// Pre Sweep Config Before the sweep is configured None
/// Pre Set Before a new set starts None
/// Post Sweep After each sweep (before possible ITI pause) None
/// Post Set After a *full* set has been acquired This event is not always reached as the user might not acquire
/// all steps of a set. With indexing, locked and unlocked, only
/// the post set events for fully acquired stimsets are reached.
/// Post DAQ After DAQ has finished and before potential None
/// "TP after DAQ"
/// =================== ============================================== ===============================================================
///
/// \endrst
///
Expand All @@ -60,16 +60,17 @@
///
/// \rst
///
/// ======================================== ============= ============================================================================================
/// Value Event Types Action
/// ======================================== ============= ============================================================================================
/// NaN All Nothing
/// 0 All Nothing
/// 1 Pre DAQ DAQ is prevented to start
/// 1 Pre Set DAQ is stopped
/// :cpp:var:`ANALYSIS_FUNC_RET_REPURP_TIME` Mid Sweep Current sweep is immediately stopped. Left over time is repurposed for ITI.
/// :cpp:var:`ANALYSIS_FUNC_RET_EARLY_STOP` Mid Sweep Current sweep is immediately stopped without honouring the left over time in a special way.
/// ======================================== ============= ============================================================================================
/// ======================================== ================= ============================================================================================
/// Value Event Types Action
/// ======================================== ================= ============================================================================================
/// NaN All Nothing
/// 0 All Nothing
/// 1 Pre DAQ DAQ is prevented to start
/// 1 Pre Set DAQ is stopped
/// 1 Pre Sweep Config DAQ is stopped
/// :cpp:var:`ANALYSIS_FUNC_RET_REPURP_TIME` Mid Sweep Current sweep is immediately stopped. Left over time is repurposed for ITI.
/// :cpp:var:`ANALYSIS_FUNC_RET_EARLY_STOP` Mid Sweep Current sweep is immediately stopped without honouring the left over time in a special way.
/// ======================================== ================= ============================================================================================
///
/// \endrst
///
Expand Down Expand Up @@ -237,8 +238,9 @@ Function TestAnalysisFunction_V3(panelTitle, s)
// code
// can also return with != 0, see @ref AnalysisFunction_V3DescriptionTable
break
case PRE_SWEEP_EVENT:
case PRE_SWEEP_CONFIG_EVENT:
// code
// can also return with != 0, see @ref AnalysisFunction_V3DescriptionTable
break
case PRE_SET_EVENT:
// code
Expand Down
18 changes: 9 additions & 9 deletions Packages/MIES/MIES_Constants.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,13 @@ Constant AS_NUM_STATES = 9
/// @name Event types for analysis functions
/// @anchor EVENT_TYPE_ANALYSIS_FUNCTIONS
/// @{
Constant PRE_DAQ_EVENT = 0
Constant MID_SWEEP_EVENT = 1
Constant POST_SWEEP_EVENT = 2
Constant POST_SET_EVENT = 3
Constant POST_DAQ_EVENT = 4
Constant PRE_SWEEP_EVENT = 5
Constant PRE_SET_EVENT = 7
Constant PRE_DAQ_EVENT = 0
Constant MID_SWEEP_EVENT = 1
Constant POST_SWEEP_EVENT = 2
Constant POST_SET_EVENT = 3
Constant POST_DAQ_EVENT = 4
Constant PRE_SWEEP_CONFIG_EVENT = 5
Constant PRE_SET_EVENT = 7
/// @}

Constant GENERIC_EVENT = 6 ///< Only used for internal bookkeeping. Never
Expand All @@ -562,10 +562,10 @@ StrConstant ANALYSIS_FUNCTION_PARAMS_LBN = "Function params (encoded)"
StrConstant ANALYSIS_FUNCTION_PARAMS_STIMSET = "Function params (encoded)"

/// Human readable names for @ref EVENT_TYPE_ANALYSIS_FUNCTIONS
StrConstant EVENT_NAME_LIST = "Pre DAQ;Mid Sweep;Post Sweep;Post Set;Post DAQ;Pre Sweep;Generic;Pre Set"
StrConstant EVENT_NAME_LIST = "Pre DAQ;Mid Sweep;Post Sweep;Post Set;Post DAQ;Pre Sweep Config;Generic;Pre Set"

/// Labnotebook entries
StrConstant EVENT_NAME_LIST_LBN = "Pre DAQ function;Mid Sweep function;Post Sweep function;Post Set function;Post DAQ function;Pre Sweep function;Generic function;Pre Set function"
StrConstant EVENT_NAME_LIST_LBN = "Pre DAQ function;Mid Sweep function;Post Sweep function;Post Set function;Post DAQ function;Pre Sweep Config function;Generic function;Pre Set function"

/// List of valid analysis function types
/// @anchor AnalysisFunctionParameterTypes
Expand Down
6 changes: 3 additions & 3 deletions Packages/MIES/MIES_StimsetAPI.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ End

/// @brief Set the given stimset parameter
///
/// If you use this function in analysis functions be sure to use an event
/// which happens *before* the stimset is read. So only `PRE_DAQ_EVENT` or `PRE_SET_EVENT` work
/// for the current sweep.
/// If you use this function in analysis functions be sure to use an event which happens *before* the stimset is read,
/// for example `PRE_DAQ_EVENT`, `PRE_SET_EVENT` or `PRE_SWEEP_CONFIG_EVENT`. The last one is always called for each
/// sweep before it is configured.
///
/// @param setName name of the stimset
/// @param entry name of the parameter, can be global or epoch
Expand Down
2 changes: 1 addition & 1 deletion Packages/MIES/MIES_Structures.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ Structure AnalysisFunction_V3

/// last written row index in `rawDACWave`/`scaledDACWave` with already acquired data
///
/// Always `NaN` for #PRE_DAQ_EVENT/#PRE_SET_EVENT/#PRE_SWEEP_EVENT.
/// Always `NaN` for #PRE_DAQ_EVENT/#PRE_SET_EVENT/#PRE_SWEEP_CONFIG_EVENT.
variable lastKnownRowIndex

/// Potential *future* number of the sweep. Once the sweep is finished it will be
Expand Down
2 changes: 1 addition & 1 deletion Packages/MIES/MIES_WaveBuilder.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ static Function/WAVE WB_MakeWaveBuilderWave(WP, WPT, SegWvType, stepCount, numEp
AddEntryIntoWaveNoteAsList(WaveBuilderWave, StringFromList(POST_SWEEP_EVENT, EVENT_NAME_LIST), str=WPT[3][%Set][INDEP_EPOCH_TYPE])
AddEntryIntoWaveNoteAsList(WaveBuilderWave, StringFromList(POST_SET_EVENT, EVENT_NAME_LIST), str=WPT[4][%Set][INDEP_EPOCH_TYPE])
AddEntryIntoWaveNoteAsList(WaveBuilderWave, StringFromList(POST_DAQ_EVENT, EVENT_NAME_LIST), str=WPT[5][%Set][INDEP_EPOCH_TYPE])
AddEntryIntoWaveNoteAsList(WaveBuilderWave, StringFromList(PRE_SWEEP_EVENT, EVENT_NAME_LIST), str=WPT[8][%Set][INDEP_EPOCH_TYPE])
AddEntryIntoWaveNoteAsList(WaveBuilderWave, StringFromList(PRE_SWEEP_CONFIG_EVENT, EVENT_NAME_LIST), str=WPT[8][%Set][INDEP_EPOCH_TYPE])
AddEntryIntoWaveNoteAsList(WaveBuilderWave, StringFromList(GENERIC_EVENT, EVENT_NAME_LIST), str=WPT[9][%Set][INDEP_EPOCH_TYPE])
AddEntryIntoWaveNoteAsList(WaveBuilderWave, StringFromList(PRE_SET_EVENT, EVENT_NAME_LIST), str=WPT[27][%Set][INDEP_EPOCH_TYPE])
AddEntryIntoWaveNoteAsList(WaveBuilderWave, ANALYSIS_FUNCTION_PARAMS_STIMSET, str=WPT[%$"Analysis function params (encoded)"][%Set][INDEP_EPOCH_TYPE])
Expand Down
3 changes: 2 additions & 1 deletion Packages/MIES/MIES_WaveDataFolderGetters.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,7 @@ Function/Wave GetSweepSettingsTextKeyWave(panelTitle)
wv[0][7] = StringFromList(POST_SWEEP_EVENT, EVENT_NAME_LIST_LBN)
wv[0][8] = StringFromList(POST_SET_EVENT, EVENT_NAME_LIST_LBN)
wv[0][9] = StringFromList(POST_DAQ_EVENT, EVENT_NAME_LIST_LBN)
wv[0][10] = StringFromList(PRE_SWEEP_EVENT, EVENT_NAME_LIST_LBN)
wv[0][10] = StringFromList(PRE_SWEEP_CONFIG_EVENT, EVENT_NAME_LIST_LBN)
wv[0][11] = StringFromList(GENERIC_EVENT, EVENT_NAME_LIST_LBN)
wv[0][12] = StringFromList(PRE_SET_EVENT, EVENT_NAME_LIST_LBN)
wv[0][13] = ANALYSIS_FUNCTION_PARAMS_LBN
Expand Down Expand Up @@ -3575,6 +3575,7 @@ static Function AddDimLabelsToWPT(wv)
SetDimLabel ROWS, 5 , $("Analysis post DAQ function") , wv
SetDimLabel ROWS, 6 , $("Combine epoch formula") , wv
SetDimLabel ROWS, 7 , $("Combine epoch formula version") , wv
// not renamed as this is v1/v2 only and therefore deprecated already
SetDimLabel ROWS, 8 , $("Analysis pre sweep function") , wv
SetDimLabel ROWS, 9 , $("Analysis function (generic)") , wv
// empty: was "Analysis function params"
Expand Down
Loading

0 comments on commit 20b6ccc

Please sign in to comment.