go-hep.org/x/hep@v0.38.1/fads/cmd/fads-app/task1.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 "reflect" 9 10 "go-hep.org/x/hep/fwk" 11 ) 12 13 type task1 struct { 14 fwk.TaskBase 15 16 f1 float64 17 f2 float64 18 } 19 20 func (tsk *task1) Configure(ctx fwk.Context) error { 21 var err error 22 msg := ctx.Msg() 23 24 msg.Infof("configure ...\n") 25 26 msg.Infof("configure ... [done]\n") 27 return err 28 } 29 30 func (tsk *task1) StartTask(ctx fwk.Context) error { 31 msg := ctx.Msg() 32 msg.Infof("start...\n") 33 return nil 34 } 35 36 func (tsk *task1) StopTask(ctx fwk.Context) error { 37 msg := ctx.Msg() 38 msg.Infof("stop...\n") 39 return nil 40 } 41 42 func (tsk *task1) Process(ctx fwk.Context) error { 43 var err error 44 msg := ctx.Msg() 45 msg.Infof("proc...\n") 46 store := ctx.Store() 47 48 err = store.Put("floats1", tsk.f1) 49 if err != nil { 50 return err 51 } 52 53 err = store.Put("floats2", tsk.f2) 54 if err != nil { 55 return err 56 } 57 58 return nil 59 } 60 61 func init() { 62 fwk.Register(reflect.TypeOf(task1{}), 63 func(typ, name string, mgr fwk.App) (fwk.Component, error) { 64 var err error 65 tsk := &task1{ 66 TaskBase: fwk.NewTask(typ, name, mgr), 67 f1: -1, 68 f2: +2, 69 } 70 71 err = tsk.DeclProp("Float1", &tsk.f1) 72 if err != nil { 73 return nil, err 74 } 75 76 err = tsk.DeclProp("Float2", &tsk.f2) 77 if err != nil { 78 return nil, err 79 } 80 81 err = tsk.SetProp("Float1", 1.) 82 if err != nil { 83 return nil, err 84 } 85 86 err = tsk.DeclOutPort("floats1", reflect.TypeOf(float64(1.0))) 87 if err != nil { 88 return nil, err 89 } 90 91 err = tsk.DeclOutPort("floats2", reflect.TypeOf(float64(1.0))) 92 if err != nil { 93 return nil, err 94 } 95 return tsk, err 96 }, 97 ) 98 }