only tangentially relevant but, in Go:
import (
"io"
"os"
"net/http"
)
resp, err := http.Get("https://example.org/somefile.csv")
if err != nil { panic(err) }
defer resp.Body.Close()
f, err := os.Create("out.csv")
if err != nil { panic(err) }
defer f.Close()
_, err = io.Copy(f, resp.Body)
if err != nil { panic(err) }
alternatively, to directly process the CSV file, without going through the creation of a temporary file:
import (
"encoding/csv"
"fmt"
)
r := csv.NewReader(resp.Body)
r.Comma = ','
records, err := r.ReadAll()
if err != nil { panic(err) }
for _, record := range records {
fmt.Printf("%v\n", record)
}
and, if you were to use go-hep
:
import (
"fmt"
"go-hep.org/x/hep/hbook/ntup/ntcsv"
)
nt, err := ntcsv.Open("https://someserver.org/file.csv", ntcsv.Comma(','))
if err != nil { panic(err) }
defer nt.DB().Close()
for _, col := range nt.Cols() {
fmt.Printf("%s: %v", col.Name(), col.Type())
}
and, eventually, when go-hep/rootio gets support for writing ROOT files:
import (
"fmt"
"go-hep.org/x/hep/hbook/ntup"
"go-hep.org/x/hep/hbook/ntup/ntcsv"
"go-hep.org/x/hep/rootio/ntroot"
)
nt, err := ntcsv.Open("http://someserver.org/file.csv", ntcsv.Comma(','))
if err != nil { panic(err) }
defer nt.DB().Close()
for _, col := range nt.Cols() {
fmt.Printf("%s: %v", col.Name(), col.Type())
}
out, err := ntroot.Create("out.root")
if err != nil { panic(err) }
err = ntup.Copy(out, nt)
if err != nil { panic(err) }
the last snippet is pure science-fiction for the moment 