go-hep.org/x/hep@v0.38.1/fwk/examples/fwk-ex-tuto-7-read-data/main.go (about) 1 // Copyright ©2017 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "flag" 9 "fmt" 10 "os" 11 "reflect" 12 "time" 13 14 "go-hep.org/x/hep/fwk" 15 16 // job is the scripting interface to 'fwk' 17 "go-hep.org/x/hep/fwk/job" 18 19 // for persistency 20 "go-hep.org/x/hep/fwk/rio" 21 22 // we need to access some tools defined in fwktest 23 // so we need to directly import that package 24 _ "go-hep.org/x/hep/fwk/internal/fwktest" 25 ) 26 27 var ( 28 lvl = flag.String("l", "INFO", "message level (DEBUG|INFO|WARN|ERROR)") 29 evtmax = flag.Int64("evtmax", -1, "number of events to process") 30 nprocs = flag.Int("nprocs", -1, "number of events to process concurrently") 31 ) 32 33 func main() { 34 flag.Usage = func() { 35 fmt.Fprintf(os.Stderr, `Usage: %[1]s [options] <input-file> <output-file> 36 37 ex: 38 $ %[1]s -l=INFO -evtmax=100 ./input.rio ./output.rio 39 40 options: 41 `, 42 os.Args[0], 43 ) 44 flag.PrintDefaults() 45 } 46 47 flag.Parse() 48 49 input := "input.rio" 50 if flag.NArg() > 0 { 51 input = flag.Arg(0) 52 } 53 54 output := "output.rio" 55 if flag.NArg() > 1 { 56 output = flag.Arg(1) 57 } 58 59 start := time.Now() 60 fmt.Printf("::: %s...\n", os.Args[0]) 61 62 // create a default fwk application, with some properties 63 // extracted from the CLI 64 app := job.New(job.P{ 65 "EvtMax": *evtmax, 66 "NProcs": *nprocs, 67 "MsgLevel": job.MsgLevel(*lvl), 68 }) 69 70 // create a task that reads integers from some location 71 // and publish the square of these integers under some other location 72 app.Create(job.C{ 73 Type: "go-hep.org/x/hep/fwk/internal/fwktest.task2", 74 Name: "t2", 75 Props: job.P{ 76 "Input": "t1-ints1-massaged", 77 "Output": "t1-ints1-massaged-new", 78 }, 79 }) 80 81 // create an input-stream, reading from some io.Reader 82 // note we create it after the one that consumes these integers 83 // to exercize the automatic data-flow scheduling. 84 app.Create(job.C{ 85 Type: "go-hep.org/x/hep/fwk.InputStream", 86 Name: "input", 87 Props: job.P{ 88 "Ports": []fwk.Port{ 89 { 90 Name: "t1-ints1-massaged", // location where to publish our data 91 Type: reflect.TypeOf(int64(0)), // type of that data 92 }, 93 }, 94 "Streamer": &rio.InputStreamer{ 95 Names: []string{input}, 96 }, 97 }, 98 }) 99 100 // output 101 app.Create(job.C{ 102 Type: "go-hep.org/x/hep/fwk.OutputStream", 103 Name: "rio-output", 104 Props: job.P{ 105 "Ports": []fwk.Port{ 106 { 107 Name: "t1-ints1-massaged-new", // location of data to write out 108 Type: reflect.TypeOf(int64(0)), // type of that data 109 }, 110 }, 111 "Streamer": &rio.OutputStreamer{ 112 Name: output, 113 }, 114 }, 115 }) 116 117 // run the application 118 app.Run() 119 120 fmt.Printf("::: %s... [done] (cpu=%v)\n", os.Args[0], time.Since(start)) 121 } 122 123 /* 124 output: 125 126 $ fwk-ex-tuto-7-read-data 127 ::: fwk-ex-tuto-7-read-data... 128 t2 INFO configure... 129 t2 INFO configure... [done] 130 t2 INFO start... 131 t2 INFO proc... (id=0|1) => [1 -> 1] 132 t2 INFO proc... (id=1|0) => [0 -> 0] 133 t2 INFO proc... (id=2|1) => [4 -> 16] 134 t2 INFO proc... (id=3|0) => [9 -> 81] 135 t2 INFO proc... (id=4|1) => [16 -> 256] 136 t2 INFO proc... (id=5|0) => [25 -> 625] 137 t2 INFO proc... (id=6|1) => [36 -> 1296] 138 t2 INFO proc... (id=7|0) => [49 -> 2401] 139 t2 INFO proc... (id=8|1) => [81 -> 6561] 140 t2 INFO proc... (id=9|0) => [64 -> 4096] 141 t2 INFO proc... (id=10|1) => [121 -> 14641] 142 t2 INFO proc... (id=11|0) => [100 -> 10000] 143 t2 INFO proc... (id=12|1) => [169 -> 28561] 144 t2 INFO proc... (id=13|0) => [144 -> 20736] 145 t2 INFO proc... (id=14|1) => [196 -> 38416] 146 t2 INFO proc... (id=15|0) => [225 -> 50625] 147 t2 INFO proc... (id=16|1) => [256 -> 65536] 148 t2 INFO proc... (id=17|0) => [289 -> 83521] 149 t2 INFO proc... (id=18|1) => [324 -> 104976] 150 t2 INFO proc... (id=19|0) => [361 -> 130321] 151 app INFO workers done: 1/2 152 app INFO workers done: 2/2 153 t2 INFO stop... 154 app INFO cpu: 7.033018ms 155 app INFO mem: alloc: 197 kB 156 app INFO mem: tot-alloc: 1058 kB 157 app INFO mem: n-mallocs: 2953 158 app INFO mem: n-frees: 2332 159 app INFO mem: gc-pauses: 1 ms 160 ::: fwk-ex-tuto-7-read-data... [done] (cpu=7.271177ms) 161 */