File Output Generator

The File Output Generator is a tool which gives you the opportunity to log specific Eclipse MOSAIC interaction types. For each interaction the File Output receives, one line (or more in case of an iteration object) is added to a CSV output file. This allows to track the movements of vehicles or to monitor the V2X message exchange.

One example output could be the following:


Configuring the FileOutput

  • The main configuration file is located at <mosaic-root>/scenarios/<scenarioName>/output/output_config.xml

Basic configuration

The following listing shows a basic example for the configuration of the FileOutput:

<?xml version="1.0" encoding="UTF-8"?>
<output id="fileoutput" enabled="true" update="5" loader="org.eclipse.mosaic.fed.output.generator.file.FileOutputLoader">
        <subscription id="...">

Note: The <decimalSeparator>-element is an optional parameter defining how floating-point numbers will be written. Be careful not to use the same characters for <separator> and <decimalSeparator> as it will break the output.

Basic configuration parameters for FileOutput

The usage of the parameters is described in the following table:

Parameter Usage
id Sets the id for the output
enabled If set to “false”, output is not used (default value is “true”)
update Sets the update interval in seconds for the output
start Sets the start time in seconds for output generation. This has nothing to do with the run time of the actual simulation
end Sets the end time in seconds for output generation. This has nothing to do with the run time of the actual simulation
loader Sets where the output is loaded from using the Java-class (see previous listing)

Interaction record

Each interaction record is derived from a certain interaction type and composed of several entries,which are separated by Element separator.

The configuration of the file output is explained at the example of the VehicleUpdates interaction:

<subscription id="VehicleUpdates" enabled="true">

Specific Configuration for interaction

  • Attribute id indicates the interaction type, namely the class name of the interaction.
  • The element entries defines the format and content of the handled subscription record.
  • The element entries is composed of several sub-elements entry, which correspond to columns of a subscription record and the sequence of the columns is the same as that of sub-elements entry.

In total, there are three basic types of entries:


Every quoted entry is defined as a constant. The content inside the quotation will be directly written into each corresponding interaction record.


An example for constant type entry

Basic method

The Basic method type accesses values of the interaction object by using the appropriate getXXX() methods. For an entry, the root object for method invoking is the corresponding interaction class, here VehicleUpdates. As this object provides the simulation time by calling the getter method getTime(), the entry Time retrieves the requested value. If a null object is returned before the last method of cascaded methods is invoked, then null will be written to the corresponding field.


An example for constant type entry



An example for method type entry with iteration

The first part of this example is Updated , which means to invoke the getUpdated method of class VehicleUpdates. Then a list of VehicleInfo objects is returned. The character : indicates the iteration, which means that for each of the VehicleInfo objects in the returned list the getId method is invoked.



An example for method type entry with iteration and cascading

In this example, there is a dot operation, which is a cascade operation. Here getPosition method of VehicleInfo class is called and a GlobalPosition object is returned. Then we continuously invoke the getLatitude method of this GlobalPosition object.

Extended Method

All the methods involved above are the basic methods. There also is some functionality, which we cannot extract from these existing methods. So an extended method set is offered to meet these requirements and also as an extension point in the future.


An example for simple extended method type entry

With existing methods of VehicleUpdates and its super class Interaction, we cannot get the timestamp of a interaction in second. (only Interaction.getTime, which returns a time in ns, is available). Here, getTimeInSec is a method extension for Interaction class. The extended method set will be listed later.

Further details

The method type of entry definition supports cascaded iteration as follows:


An example for cascaded iteration

It is possible to handle several different iterating operations, coming from the entry definition:


An example for multi-level iteration

getSenders() and getReceivers() are two different iterations. In this case, a combination of both Ids from the lists will be generated. The result may look like this:

sender1, receiver1
sender1, receiver2
sender2, receiver1
sender2, receiver2

Output result of the above listing

Note: the longest matched prefix will be considered as the same iterating operation, which means they are in the same level of iteration structure.

Additional features

Limit output on time frame

You can configure the File Output Generator to write out interactions within a specific frame of simulation time. This can be configured by setting the start and end attributes accordingly:

<?xml version="1.0" encoding="UTF-8"?>
<output id="fileoutput" enabled="true" 
            start="300" end="1000" update="5" 

An example for restricting output generation of interactions within a time frame

Compress Output

The tag <write>file+compress</write> can be added to the output configuration, in order to compress the output using gzip compression. This feature is suitable for large-scale scenarios with many outputs.

<output id="output" loader="org.eclipse.mosaic.fed.output.generator.file.FileOutputLoader">