go-hep.org/x/hep@v0.38.1/fwk/examples/fwk-ex-tuto-4-write-histo/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 // for hsbooksvc.Stream 17 "go-hep.org/x/hep/fwk/hbooksvc" 18 ) 19 20 var ( 21 lvl = flag.String("l", "INFO", "message level (DEBUG|INFO|WARN|ERROR)") 22 evtmax = flag.Int64("evtmax", 100, "number of events to process") 23 nprocs = flag.Int("nprocs", -1, "number of events to process concurrently") 24 ) 25 26 func main() { 27 flag.Usage = func() { 28 fmt.Fprintf(os.Stderr, `Usage: %[1]s [options] <input-file> <output-file> 29 30 ex: 31 $ %[1]s -l=INFO -evtmax=-1 ./input.ascii ./output.ascii 32 33 options: 34 `, 35 os.Args[0], 36 ) 37 flag.PrintDefaults() 38 } 39 40 flag.Parse() 41 42 start := time.Now() 43 fmt.Printf("::: %s...\n", os.Args[0]) 44 45 // create a default fwk application, with some properties 46 // extracted from the CLI 47 app := job.NewJob(nil, job.P{ 48 "EvtMax": *evtmax, 49 "NProcs": *nprocs, 50 "MsgLevel": job.MsgLevel(*lvl), 51 }) 52 53 app.Create(job.C{ 54 Type: "main.testhsvc", 55 Name: "t-01", 56 Props: job.P{ 57 "Stream": "/my-hist", 58 }, 59 }) 60 61 app.Create(job.C{ 62 Type: "main.testhsvc", 63 Name: "t-02", 64 Props: job.P{ 65 "Stream": "/my-hist", 66 }, 67 }) 68 69 app.Create(job.C{ 70 Type: "main.testhsvc", 71 Name: "t-03", 72 Props: job.P{ 73 "Stream": "", // in-memory temporary hist. 74 }, 75 }) 76 77 app.Create(job.C{ 78 Type: "go-hep.org/x/hep/fwk/hbooksvc.hsvc", 79 Name: "histsvc", 80 Props: job.P{ 81 "Streams": map[string]hbooksvc.Stream{ 82 "/my-hist": { 83 Name: "hist.rio", 84 Mode: hbooksvc.Write, 85 }, 86 }, 87 }, 88 }) 89 90 app.Run() 91 fmt.Printf("::: %s... [done] (cpu=%v)\n", os.Args[0], time.Since(start)) 92 } 93 94 /* 95 output: 96 97 $ fwk-ex-tuto-4-write-histo 98 ::: fwk-ex-tuto-4-write-histo... 99 app INFO workers done: 1/2 100 app INFO workers done: 2/2 101 t-01 INFO histo[h1d-t-01]: entries=100 mean=4.5 RMS=2.8722813232690143 102 t-02 INFO histo[h1d-t-02]: entries=100 mean=4.5 RMS=2.8722813232690143 103 t-03 INFO histo[h1d-t-03]: entries=100 mean=4.5 RMS=2.8722813232690143 104 app INFO cpu: 6.827126ms 105 app INFO mem: alloc: 237 kB 106 app INFO mem: tot-alloc: 555 kB 107 app INFO mem: n-mallocs: 6540 108 app INFO mem: n-frees: 5597 109 app INFO mem: gc-pauses: 1 ms 110 ::: fwk-ex-tuto-4-write-histo... [done] (cpu=7.094478ms) 111 112 */