--- myst: substitutions: bloc: python: 1,4,15-16,20 cpp: 1-2,4,12-13 --- (dataserver_data_import_from_ascii)= # Import data from an ASCII file An example of import of the data file `"geyser.dat"` (available in the {{uranie}}-macros folder) is shown below leading to a 2D scatterplot of the variable **x2** versus the variable **x1** {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/dataserver/data/" + language + "/draw_geyser_scatterplot." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc[language] + "\n" + "```" }} **Description of the import of an ASCII file** 1. Setting the namespace. This instruction is useless when the provided rootlogon has been loaded as all {{uranie}}-namespaces have been loaded as well. 2. Defining a pointer *tdsGeyser* to an object of type `TDataServer` whose name is *"tdsgeyser"* and whose title is *"Geyser database"*. These information are used by the `export` or `printLog` methods. 3. Loading data contained in an ASCII file `$URANIESYS/share/uranie/macros/geyser.dat`. 4. Plot of the scatterplot of the variable **x2** versus the variable **x1** The obtained graph is the following: {{ "```{" "figure" "} " + parent_dir + "/roottest/build/uranie/doc/dataserver/data/" + language + "/geyser_2/geyser_scatterplot.png\n" ":align: center\n" ":name: dataserver_geyser_scatterplot\n" + figure_scale + "\n" "\n" 'Import data from an ASCII file\n' "```" }} Various examples of macros loading data in a {{tds}} with different treatment applied on, are provided in the {{usecase}} chapter of this user manual, between [](#use_cases_macro_dataserver_load_ascii_file_pasture) and [](#use_cases_macro_dataserver_load_ascii_file_cornell). ```{admonition} Summary: Loading data ( ASCII file ) - `fileDataRead` ( **TString** filename, **bool** saveTuple=true, **bool** preAddReload=false) Loads the data contained in the ASCII file ("Salome-table" format). The possible arguments are: - The name of the file (compulsory) - A boolean to state whether the file should be saved as root-ntuple once the reading is complete (not mandatory, set to true by default) - A boolean to allow pre-adding or reloading a database (advanced, not recommended for beginners). This allows - Pre-adding variables: very technical. It should not be used unless discussed with developers. - Reloading database: Allow to reload a database file without complaining, AS long AS the provided file exactly matches the list of attribute in the {{tds}} object - `fileDataReadJSon` ( **TString** filename, **bool** saveTuple=true) Loads the data contained in the ASCII file (JSON format). The possible arguments are: - The name of the file (compulsory) - A boolean to state whether the file should be saved as root-ntuple once the reading is complete (not mandatory, set to true by default) ```