> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/holoscan/sdk-user-guide/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/holoscan/sdk-user-guide/_mcp/server.

# holoscan::CsvDataExporter

> A class to support exporting Holoscan application data in CSV format for Holoscan Federated Analytics.

A class to support exporting Holoscan application data in CSV format for Holoscan Federated Analytics.

The directory will be created with the app name in the data root directory if it is not present already. Inside the application directory, a directory with the current timestamp will be created.

The output file name can be specified using the environment variable `HOLOSCAN_ANALYTICS_DATA_FILE_NAME`. If not specified, the output file named `data.csv` will be created inside the timestamp directory. The column names are added to the output file as a first row.

Using this class mainly involves two steps:

* Create `CsvDataExporter` object specifying app name and columns.
* Call `export_data()` method to add a single row to the output file.

Example:

```cpp showLineNumbers={false}
#include <holoscan/csv_data_exporter.hpp>
```

## Example

```cpp showLineNumbers={false}
#include <holoscan/core/analytics/csv_data_exporter.hpp>

void export_data() {
const std::string app_name = "sample_app";
const std::vector<std::string> columns = {"column1", "column2", "column3"};
CsvDataExporter data_exporter(app_name, columns);

const std::vector<std::string> data = {"1", "2", "3"};
data_exporter.export_data(data);
...
}
```

**Inherits from:** `holoscan::DataExporter` (public)

***

## Constructors

### CsvDataExporter \[#csvdataexporter]

```cpp showLineNumbers={false}
holoscan::CsvDataExporter::CsvDataExporter(
    const std::string &app_name,
    const std::vector<std::string> &columns
)
```

The constructor creates required directories and CSV file with the specified names.

**Parameters**

The application name.

The column names list which will be added to the CSV file as a first row.

### Destructor \[#destructor]

### \~CsvDataExporter

```cpp showLineNumbers={false}
holoscan::CsvDataExporter::~CsvDataExporter()
```

***

## Methods

### export\_data \[#exportdata]

```cpp showLineNumbers={false}
void holoscan::CsvDataExporter::export_data(
    const std::vector<std::string> &data
) override
```

Exports given data to a CSV file.

Each call to the function will add one more row to the csv file.

**Parameters**

The data to be written to the CSV file.

### output\_file\_name \[#outputfilename]

```cpp showLineNumbers={false}
const std::string & holoscan::CsvDataExporter::output_file_name() const
```

Returns output file name.

### columns \[#columns]

```cpp showLineNumbers={false}
const std::vector<std::string> & holoscan::CsvDataExporter::columns() const
```

Returns the column names.

### app\_name \[#appname]

```cpp showLineNumbers={false}
const std::string & holoscan::CsvDataExporter::app_name() const
```

Return the application name.

### data\_directory \[#datadirectory]

```cpp showLineNumbers={false}
const std::string & holoscan::CsvDataExporter::data_directory() const
```

Returns a data directory name.

### cleanup\_data\_directory \[#cleanupdatadirectory]

```cpp showLineNumbers={false}
void holoscan::CsvDataExporter::cleanup_data_directory()
```

Remove the data directory and its contents.

### write\_row \[#writerow]

```cpp showLineNumbers={false}
void holoscan::CsvDataExporter::write_row(
    const std::vector<std::string> &data
)
```

Write one row to a CSV file.

Each call to the function will just add one more row to the csv file.

**Parameters**

The data to be written to the CSV file. The number of strings passed should be same as the number of columns in CSV file.

***

## Static methods

### get\_analytics\_data\_file\_name\_env \[#getanalyticsdatafilenameenv]

```cpp showLineNumbers={false}
static expected<std::string, ErrorCode> holoscan::CsvDataExporter::get_analytics_data_file_name_env()
```

Get the value of analytics output file name environment variable `HOLOSCAN_ANALYTICS_DATA_FILE_NAME`.

**Returns:** A string if the environment variable is set else it returns error code.

### get\_analytics\_data\_directory\_env \[#getanalyticsdatadirectoryenv]

```cpp showLineNumbers={false}
static expected<std::string, ErrorCode> holoscan::CsvDataExporter::get_analytics_data_directory_env()
```

Get the value of analytics data directory environment variable `HOLOSCAN_ANALYTICS_DATA_DIRECTORY`.

**Returns:** A string if the environment variable is set else it returns error code.

***

## Member variables

| Name              | Type                         | Description |
| ----------------- | ---------------------------- | ----------- |
| `file_name_`      | `std::string`                |             |
| `columns_`        | `std::vector< std::string >` |             |
| `file_`           | `std::ofstream`              |             |
| `app_name_`       | `std::string`                |             |
| `directory_name_` | `std::string`                |             |