go-hep.org/x/hep@v0.38.1/fwk/examples/fwk-ex-tuto-5-read-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: "go-hep.org/x/hep/fwk/hbooksvc.hsvc",
    71  		Name: "histsvc",
    72  		Props: job.P{
    73  			"Streams": map[string]hbooksvc.Stream{
    74  				"/my-hist": {
    75  					Name: "hist.rio",
    76  					Mode: hbooksvc.Read,
    77  				},
    78  			},
    79  		},
    80  	})
    81  
    82  	app.Run()
    83  	fmt.Printf("::: %s... [done] (cpu=%v)\n", os.Args[0], time.Since(start))
    84  }
    85  
    86  /*
    87  output:
    88  
    89  $ fwk-ex-tuto-5-read-histo
    90  ::: fwk-ex-tuto-5-read-histo...
    91  app                  INFO workers done: 1/2
    92  app                  INFO workers done: 2/2
    93  t-01                 INFO histo[h1d-t-01]: entries=100 mean=4.5 RMS=2.8722813232690143
    94  t-02                 INFO histo[h1d-t-02]: entries=100 mean=4.5 RMS=2.8722813232690143
    95  app                  INFO cpu: 8.414409ms
    96  app                  INFO mem: alloc:             89 kB
    97  app                  INFO mem: tot-alloc:        710 kB
    98  app                  INFO mem: n-mallocs:      11009
    99  app                  INFO mem: n-frees:         9783
   100  app                  INFO mem: gc-pauses:          1 ms
   101  ::: fwk-ex-tuto-5-read-histo... [done] (cpu=8.634269ms)
   102  */