2.3.7. Export to an ASCII file
In the same way as the data are imported from an ASCII file, we can also save the data of a TDataServer
in an ASCII file. Currently, four methods of export are available in Uranie:
using the same format as that observed during import (“Salome Table”);
using a C file containing the data vectors that can be inserted in a C program.
using the NeMo format: the generated file is useful for the NeMo tool for constructing neural response surface developed at STMF.
using the JSON format: the generated file is easily transferable to any other program that include the JSON protocol. This file can also be read through the
fileDataReadJSonmethod of aTDataServerobject.
tdsGeyser = DataServer.TDataServer("tdsgeyser", "geyser database")
tdsGeyser.fileDataRead("geyser.dat")
tdsGeyser.addAttribute("y", "sqrt(x2) * x1")
tdsGeyser.exportData("newfile.dat") # (1)
tdsGeyser.exportDataHeader("newfile.C", "x1:x2:y") # (2)
tdsGeyser.exportDataNeMo("newfile.nemo", "x1:x2", "y", "x2<75.0") # (3)
tdsGeyser.exportDataJSon("newfile.json") # (4)
Data export from a TDataServer in an ASCII file
Export the data of the
TDataServertdsGeyser in an ASCII file"newfile.dat":#NAME: tdsgeyser #TITLE: Database of the geyser #DATE: Tue Oct 9 15:41:29 2007 #COLUMN_NAMES: x1| x2| y| n__iter__ 3.600000000e+00 7.900000000e+01 3.199749990e+01 1 1.800000000e+00 5.400000000e+01 1.322724461e+01 2 3.333000000e+00 7.400000000e+01 2.867155012e+01 3 2.283000000e+00 6.200000000e+01 1.797635998e+01 4 4.533000000e+00 8.500000000e+01 4.179219502e+01 5 ... 2.150000000e+00 4.600000000e+01 1.458200946e+01 269 4.417000000e+00 9.000000000e+01 4.190334127e+01 270 1.817000000e+00 4.600000000e+01 1.232349358e+01 271 4.467000000e+00 7.400000000e+01 3.842658697e+01 272
Exports the data of attributes x1, x2 and y of the
TDataServertdsGeyser in the ASCII file"newfile.C"A format “Header”.// File "newfile.C" generated by ROOT v5.17/04 // DateTime Tue Oct 9 15:41:30 2007 // DataServer: Name="tdsgeyser" Title="Database of the geyser" Select="" #define essai_nPattern 272 // Attribute Name="x1" Title=" x_{1}" Double_t x1[essai_nPattern] = { 3.600000000e+00, 1.800000000e+00, ... 1.817000000e+00, 4.467000000e+00, }; // End of attribute x1 // Attribute Name="x2" Title=" #delta x_{2}" Double_t x2[essai_nPattern] = { 7.900000000e+01, 5.400000000e+01, ... 1.232349358e+01, 3.842658697e+01, }; // End of attribute y // End of File newfile.CExports the data of the
TDataServertdsGeyser in an ASCII filenewfile.nemowith format NeMo with x1:x2 as input vector, “y” as output and applying a filter “x2<75.0”#NombreExemples 126 #NombreEntrees 2 #NombreSorties 1 1.800000000e+00 5.400000000e+01 1.322724461e+01 3.333000000e+00 7.400000000e+01 2.867155012e+01 2.283000000e+00 6.200000000e+01 1.797635998e+01 2.883000000e+00 5.500000000e+01 2.138090024e+01 ... 2.150000000e+00 4.600000000e+01 1.458200946e+01 1.817000000e+00 4.600000000e+01 1.232349358e+01 4.467000000e+00 7.400000000e+01 3.842658697e+01
Exports the data of the
TDataServertdsGeyser in an ASCII filenewfile.jsonwith format JSON.{ "_metadata" : { "_comment" : "CurrentComment", "date" : "Fri Oct 28 10:41:44 2016", "short_names" : [ "x1", "x2", "geyser__n__iter__" ], "table_description" : "Les donnees du geyser", "table_name" : "geyser", "types" : [ "D", "D", "D" ], "units" : [ "Sec", "", "" ] }, "items" : [ { "geyser__n__iter__" : 1.0, "x1" : 3.60, "x2" : 79.0 }, { "geyser__n__iter__" : 2.0, "x1" : 1.80, "x2" : 54.0 }, { "geyser__n__iter__" : 272.0, "x1" : 4.4670, "x2" : 74.0 } ] }
Summary: Exportation of a TDataServer to ASCII format
exportData( const char* filename, const char * varexp=”*”, const char * select=”” )Exportation of the data of attributes “varexp” of the
TDataServerin the file “filename” in ASCII format, “Salome table” type, applying the filter contained in “select”. The filter “select” is added to the permanent selection (c.f. Pattern selection) of theTDataServer.exportDataJSon( const char* filename, const char * varexp=”*”, const char * select=”” )Exportation of the data of attributes “varexp” of the
TDataServerin the file “filename” in JSON format, applying the filter contained in “select”. The filter “select” is added to the permanent selection (c.f. Pattern selection) of theTDataServer.exportDataHeader( const char* filename, const char * varexp=”*”, const char * select=”” )Exportation of the data of attributes “varexp” of the
TDataServerin the file “filename” in ASCII format for the use of a C/C++ program. The “select” filter is added to the permanent selection (c.f. Pattern selection) of theTDataServer.exportDataNeMo( const char* filename, const char * varexpinput, const char * varexpoutput, const char * select=”” )Exportation of the
TDataServerdata in the file “filename”TDataServerin ASCII format NeMo with attributes “varexpinput” as inputs (separated by the character “:”) and attributes “varexpoutput” as outputs (separated by the character “:”) and applying the filter contained in option. The “select” filter is added to the the permanent selection (c.f. Pattern selection) of theTDataServer