go-hep.org/x/hep@v0.38.1/fwk/examples/fwk-ex-tuto-1/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 "time" 12 13 // job is the scripting interface to 'fwk' 14 "go-hep.org/x/hep/fwk/job" 15 16 // side-effect import 'fwktest'. 17 // merely importing it will register the components defined in this package 18 // with the fwk components' factory. 19 _ "go-hep.org/x/hep/fwk/internal/fwktest" 20 ) 21 22 var ( 23 lvl = flag.String("l", "INFO", "message level (DEBUG|INFO|WARN|ERROR)") 24 evtmax = flag.Int64("evtmax", 10, "number of events to process") 25 nprocs = flag.Int("nprocs", -1, "number of events to process concurrently") 26 ) 27 28 func main() { 29 flag.Usage = func() { 30 fmt.Fprintf(os.Stderr, `Usage: %[1]s [options] 31 32 ex: 33 $ %[1]s -l=INFO -evtmax=-1 34 35 options: 36 `, 37 os.Args[0], 38 ) 39 flag.PrintDefaults() 40 } 41 42 flag.Parse() 43 44 start := time.Now() 45 fmt.Printf("::: %s...\n", os.Args[0]) 46 47 // create a default fwk application, with some properties 48 // extracted from the CLI 49 app := job.New(job.P{ 50 "EvtMax": *evtmax, 51 "NProcs": *nprocs, 52 "MsgLevel": job.MsgLevel(*lvl), 53 }) 54 55 // create a task that reads integers from some location 56 // and publish the square of these integers under some other location 57 app.Create(job.C{ 58 Type: "go-hep.org/x/hep/fwk/internal/fwktest.task2", 59 Name: "t2", 60 Props: job.P{ 61 "Input": "t1-ints1", 62 "Output": "t1-ints1-massaged", 63 }, 64 }) 65 66 // create a task that publish integers to some location(s) 67 // note we create it after the one that consumes these integers 68 // to exercize the automatic data-flow scheduling. 69 app.Create(job.C{ 70 Type: "go-hep.org/x/hep/fwk/internal/fwktest.task1", 71 Name: "t1", 72 Props: job.P{ 73 "Ints1": "t1-ints1", 74 "Ints2": "t2-ints2", 75 "Int1": int64(10), // value for the Ints1 76 "Int2": int64(20), // value for the Ints2 77 }, 78 }) 79 80 // run the application 81 app.Run() 82 83 fmt.Printf("::: %s... [done] (cpu=%v)\n", os.Args[0], time.Since(start)) 84 } 85 86 /* 87 output: 88 89 $ fwk-ex-tuto-1 90 ::: fwk-ex-tuto-1... 91 t2 INFO configure... 92 t2 INFO configure... [done] 93 t1 INFO configure ... 94 t1 INFO configure ... [done] 95 t2 INFO start... 96 t1 INFO start... 97 app INFO >>> running evt=0... 98 t1 INFO proc... (id=0|0) => [10, 20] 99 t2 INFO proc... (id=0|0) => [10 -> 100] 100 app INFO >>> running evt=1... 101 t1 INFO proc... (id=1|0) => [10, 20] 102 t2 INFO proc... (id=1|0) => [10 -> 100] 103 app INFO >>> running evt=2... 104 t1 INFO proc... (id=2|0) => [10, 20] 105 t2 INFO proc... (id=2|0) => [10 -> 100] 106 app INFO >>> running evt=3... 107 t1 INFO proc... (id=3|0) => [10, 20] 108 t2 INFO proc... (id=3|0) => [10 -> 100] 109 app INFO >>> running evt=4... 110 t1 INFO proc... (id=4|0) => [10, 20] 111 t2 INFO proc... (id=4|0) => [10 -> 100] 112 app INFO >>> running evt=5... 113 t1 INFO proc... (id=5|0) => [10, 20] 114 t2 INFO proc... (id=5|0) => [10 -> 100] 115 app INFO >>> running evt=6... 116 t1 INFO proc... (id=6|0) => [10, 20] 117 t2 INFO proc... (id=6|0) => [10 -> 100] 118 app INFO >>> running evt=7... 119 t1 INFO proc... (id=7|0) => [10, 20] 120 t2 INFO proc... (id=7|0) => [10 -> 100] 121 app INFO >>> running evt=8... 122 t1 INFO proc... (id=8|0) => [10, 20] 123 t2 INFO proc... (id=8|0) => [10 -> 100] 124 app INFO >>> running evt=9... 125 t1 INFO proc... (id=9|0) => [10, 20] 126 t2 INFO proc... (id=9|0) => [10 -> 100] 127 t2 INFO stop... 128 t1 INFO stop... 129 ::: fwk-ex-tuto-1... [done] (cpu=5.482751ms) 130 131 */