Class CSVOutputAdapter

All Implemented Interfaces:
FWSimFieldContainer

public class CSVOutputAdapter extends FWSimOutputAdapter
Output adapter writing the output of an FWSimOutput to a CSV file (CSVInterface). The file name may contain tokens (e.g. ${projectid}); the file is determined again for each project (see updateFile(FWSimVarMap, long)). The header line is written before the first data line.
Author:
Andreas Enders
  • Constructor Details

    • CSVOutputAdapter

      public CSVOutputAdapter(org.jdom2.Element aResourceElement, int aOrderNumber, FWSimVarMap aVarMap)
      Creates the adapter from an output element.
      Parameters:
      aResourceElement - the output element
      aOrderNumber - order number of the adapter
      aVarMap - template variable map of the solution
    • CSVOutputAdapter

      public CSVOutputAdapter(String aFile, String aName, String aDivider, int aOrderNumber, FWSimIOAdapter.FREQUENCE aFrequence, String aCacheSize, ProcessTime aProcessTime, FWSimSession aSession)
      Creates the adapter from the graph panel with its own CSV interface (column mode).
      Parameters:
      aFile - output file
      aName - name of the adapter; the interface is named <name>_INTERFACE
      aDivider - column divider
      aOrderNumber - order number of the adapter
      aFrequence - frequency of the output
      aCacheSize - capacity of the queue
      aProcessTime - runtime statistics of the adapter
      aSession - the session
    • CSVOutputAdapter

      public CSVOutputAdapter(FWSimOutputAdapter aOldAdapter, CSVInterface aInterface)
      Copy constructor used when the interface is replaced.
      Parameters:
      aOldAdapter - the adapter to copy
      aInterface - the new interface
  • Method Details

    • init

      protected void init(FWSimVarMap aVarMap)
      Registers the output file and builds the header line: one column per header variable, optionally with its unit in brackets. In array mode with column layout, an array variable gets one column per selected element (_1, _2, ..., _LAST for the last element: count 99999, stored 0-based as 99998, or last, stored as 99999 - like in FWSimOutputCache).
      Specified by:
      init in class FWSimOutputAdapter
      Parameters:
      aVarMap - variable map used for replacing tokens
    • writeData

      protected void writeData(FWSimQueueObjectMap aObjectToWrite)
      Writes an output line to the CSV file (in the writer thread); the header line is written first if necessary.
      Specified by:
      writeData in class FWSimOutputAdapter
      Parameters:
      aObjectToWrite - the output line
      See Also:
    • finalize

      public void finalize() throws Exception
      Closes the files of the file pool.
      Overrides:
      finalize in class FWSimIOAdapter
      Throws:
      Exception - if closing fails
      See Also:
    • updateFile

      public boolean updateFile(FWSimVarMap aVarMap, long aSkipAboveSize)
      Determines the output file for the current project; if it differs from the current file, the adapter is initialized for the new file.
      Parameters:
      aVarMap - variable map of the first simulation of the project
      aSkipAboveSize - size limit in bytes, or 0 for no limit
      Returns:
      true if the file changed and already exists with a size above the limit (the project can be skipped)