Class FWSimPostProcessManager

java.lang.Object
net.simplace.sim.io.postprocess.FWSimPostProcessManager

public class FWSimPostProcessManager extends Object
Post-processing of a session: after the run, the CSV output files are loaded into a temporary in-memory database (H2), SQL statements summarize them, and query results are written to files.

Declaration, like the outputs: element postprocess after outputs in the solution or in the project file. Without project file the one of the solution is run; with project file only the one of the project file (none if the project file has none).

<postprocess>
  <sql>CREATE TABLE yearly AS SELECT simulationid, YEAR("CURRENT.DATE") AS year, SUM(rain) AS rain
       FROM daily GROUP BY simulationid, YEAR("CURRENT.DATE")</sql>
  <write interface="summaryfile">SELECT * FROM yearly ORDER BY simulationid, year</write>
</postprocess>
Steps, in the order of the file:
  • sql: one or more SQL statements separated by ; (H2 syntax), e.g. CREATE TABLE ... AS SELECT, UPDATE, DELETE
  • write: a query whose result is written to the file of the CSV interface named by interface (interfaces of the solution or the project file), see ResultFileWriter
The texts may contain ${...} tokens of the solution (e.g. ${_OUTPUTDIR_}), as the file name of the interface. Tables: one per CSV output, named like the output, see OutputTableLoader. Identifiers are case-insensitive and keep their case (an alias AS year is written as year in the header line); column names with special characters (e.g. "CURRENT.DATE") have to be quoted. YEAR, MONTH, DAY, HOUR, MINUTE, SECOND and VALUE are usable as column names without quotes.

Runs: automatically at the end of a session (FWSimSession.finalize()) if the run has written output files, once per session; again without simulation with FWSimSession.postprocess() (console command postprocess), which loads the files on disk matching the output file names. An error stops the post-processing and is thrown with the step and statement.

Author:
Andreas Enders, Claude (Anthropic), co-author
  • Constructor Details

    • FWSimPostProcessManager

      public FWSimPostProcessManager()
  • Method Details

    • setProjectPostProcess

      public void setProjectPostProcess(org.jdom2.Element aPostProcessElement)
      Parameters:
      aPostProcessElement - the postprocess element of the project file, or null
    • getPostProcess

      public org.jdom2.Element getPostProcess(FWSimSession aSession)
      Parameters:
      aSession - the session
      Returns:
      the post-processing to run: of the project file if the session has one, otherwise of the solution; null if there is none
    • processAfterRun

      public void processAfterRun(FWSimSession aSession) throws Exception
      Runs the post-processing at the end of a session (called by FWSimSession.finalize()), once, and only if the session has one and the run has written CSV output files.
      Parameters:
      aSession - the session; its output files have to be closed
      Throws:
      Exception - if a step fails
    • process

      public void process(FWSimSession aSession) throws Exception
      Runs the post-processing on the output files on disk, without simulation (console command postprocess).
      Parameters:
      aSession - the prepared session
      Throws:
      Exception - if a step fails