Class FWCheckHelper

java.lang.Object
net.simplace.sim.check.FWCheckHelper

public class FWCheckHelper extends Object
Checks the setting of values (limits, owning component, write protection) and the configuration according to the check level of the session (see FWCheckHelper.CHECK_LEVEL). Violations are logged and written to <outputdir>/CheckResult.csv.

How the violations of the runtime checks (limits, owning component, write protection, conditions of components) are reported depends on the FWCheckHelper.CHECK_REPORT: with DETAIL every violation is logged and written (as before), with SUMMARY they are only counted per check, variable and details, and a summary (count, number of simulations, first reported occurrence, value range) is logged and written when the session ends (finalize()). Numbers in condition messages are replaced by #, so that the messages of one condition are counted together. The session uses SUMMARY for project runs unless DETAIL is requested (console option -checkreport, see FWSimEngine.setCheckReport(CHECK_REPORT)). Violations of large project runs thus no longer cost a log line, a line in CheckResult.csv and a lock shared by all parallel simulations each, but they are still reported. The check levels themselves are not changed (INTENSE still limits values, STRICT still stops). Missing resources and script parameter checks are always reported in detail.

Author:
Andreas Enders
  • Constructor Details

    • FWCheckHelper

      public FWCheckHelper(FWCheckHelper.CHECK_LEVEL aLevel, String aCustomCheckerClassName, FWSimSession aSession)
      Creates the check helper; for level CUSTOM the custom checker is instantiated.
      Parameters:
      aLevel - the check level
      aCustomCheckerClassName - class name of the custom FWChecker (level CUSTOM only)
      aSession - the session
  • Method Details

    • getCheckLevel

      public FWCheckHelper.CHECK_LEVEL getCheckLevel()
      Returns:
      the check level
    • setCheckLevel

      public void setCheckLevel(FWCheckHelper.CHECK_LEVEL aCheckLevel)
      Parameters:
      aCheckLevel - the check level
    • isSummary

      public boolean isSummary()
      Returns:
      true if violations of the runtime checks are only counted and summarized at the end
    • setSummary

      public void setSummary(boolean aSummary)
      Sets how violations of the runtime checks are reported (see FWCheckHelper.CHECK_REPORT).
      Parameters:
      aSummary - true for FWCheckHelper.CHECK_REPORT.SUMMARY, false for FWCheckHelper.CHECK_REPORT.DETAIL
    • checkLimits

      public Number checkLimits(FWSimVariable<?> aSource, Number aValue, Number aMin, Number aMax) throws SimValueOutOfRangeException
      Checks a value against its limits (null limits are ignored): LAZY reports a violation and keeps the value, INTENSE replaces it by the exceeded limit and reports it, STRICT throws an exception, CUSTOM delegates to the custom checker; OFF and ONLY do nothing. NaN is not checked.
      Parameters:
      aSource - the variable (for messages)
      aValue - the value
      aMin - lower limit, may be null
      aMax - upper limit, may be null
      Returns:
      the value to use (the limit in INTENSE mode if it was exceeded)
      Throws:
      SimValueOutOfRangeException - in STRICT mode if a limit is exceeded
    • checkSource

      public boolean checkSource(FWSimVariable<?> aTarget, FWSimFieldContainer aSimFieldContainer, FWSimFieldContainer aSource) throws SimLinkInvalidException
      Checks whether a variable is written by its owning component. Writing is always allowed by the solution and the control components. LAZY reports a violation, INTENSE reports it and returns false, STRICT throws an exception, CUSTOM delegates to the custom checker. Other errors while checking are logged and true is returned.
      Parameters:
      aTarget - the variable written
      aSimFieldContainer - the owning component of the variable
      aSource - the writing component
      Returns:
      false in INTENSE mode if the variable is written by another component, otherwise true
      Throws:
      SimLinkInvalidException - in STRICT mode if the variable is written by another component
    • checkWriteProtectionOnContentType

      public boolean checkWriteProtectionOnContentType(FWSimVariable<?> aTarget, FWSimVariable.CONTENT_TYPE aContentType, FWSimFieldContainer aSource) throws SimLinkInvalidException
      Checks whether the content type allows the writing component to write the variable: privat only by its owner; constant, dyn, input and var only by the solution, control components and simple components; mgm only by the management; sys only by the solution and control components. LAZY reports a violation and allows it, INTENSE reports it and returns false, STRICT throws an exception, CUSTOM delegates to the custom checker.
      Parameters:
      aTarget - the variable written
      aContentType - content type of the variable
      aSource - the writing component; no check if null
      Returns:
      true if writing is allowed
      Throws:
      SimLinkInvalidException - in STRICT mode if writing is not allowed
    • checkResource

      public boolean checkResource(Map<String, FWSimInputAdapter> aResourceCreators, FWSimVarMap aVarMap, Map<String, FWSimResourceCache> aResourcesCacheMap)
      Check level ONLY: reads all resources (not transformers and project data) to check them; missing or bad resources are reported.
      Parameters:
      aResourceCreators - the resource adapters by name
      aVarMap - variable map of the first simulation of the project
      aResourcesCacheMap - map the read caches are put into
      Returns:
      true for the first checked project (and the same project again), false for other projects
    • isConditionCheck

      public boolean isConditionCheck()
      Returns:
      true if conditions are checked (levels ONLY, LAZY, INTENSE, STRICT)
    • checkCondition

      public void checkCondition(Boolean aCheckResult, String aMessage, FWSimFieldContainer aInstance)
      Reports a failed condition of a component (e.g. an initialization error): if the condition result is true (i.e. the problem occurred), the message is logged as warning and written to the check result, in levels ONLY, LAZY, INTENSE and STRICT.
      Parameters:
      aCheckResult - true if the problem occurred
      aMessage - the message
      aInstance - the component reporting it
    • checkOnlyMode

      public boolean checkOnlyMode(String aSimulationID)
      Level ONLY: decides whether a simulation is run; only the first simulation (and the same one again) is run.
      Parameters:
      aSimulationID - id of the simulation
      Returns:
      true if the simulation is run; always true in other levels
    • checkParametersInScript

      public boolean checkParametersInScript(Collection<String> aAllowedFields, Collection<String> aForbiddenFields, String aJexlScript, FWSimFieldContainer aSource)
      Checks the parameters (${...}) of a script: all must be in the allowed fields (if given), none in the forbidden fields (if given). Only if the check fails, a warning is logged (LAZY, INTENSE) or an exception is thrown (STRICT).
      Parameters:
      aAllowedFields - allowed parameter names, or null
      aForbiddenFields - forbidden parameter names, or null
      aJexlScript - the script
      aSource - the component using the script (for messages)
      Returns:
      true if the check passed (always in LAZY mode)
      Throws:
      SimLinkInvalidException - in STRICT mode
    • finalize

      public void finalize()
      Writes the summary of the checks (summary mode, see FWCheckHelper.CHECK_REPORT) and closes the check result file.
      Overrides:
      finalize in class Object