go-hep.org/x/hep@v0.38.1/fwk/internal/fwktest/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 fwktest
     6  
     7  import (
     8  	"reflect"
     9  
    10  	"go-hep.org/x/hep/fwk"
    11  )
    12  
    13  type task1 struct {
    14  	fwk.TaskBase
    15  
    16  	i1prop string
    17  	i2prop string
    18  
    19  	i1 int64
    20  	i2 int64
    21  }
    22  
    23  func (tsk *task1) Configure(ctx fwk.Context) error {
    24  	var err error
    25  	msg := ctx.Msg()
    26  
    27  	msg.Infof("configure ...\n")
    28  
    29  	err = tsk.DeclOutPort(tsk.i1prop, reflect.TypeOf(int64(1.0)))
    30  	if err != nil {
    31  		return err
    32  	}
    33  
    34  	err = tsk.DeclOutPort(tsk.i2prop, reflect.TypeOf(int64(1.0)))
    35  	if err != nil {
    36  		return err
    37  	}
    38  
    39  	msg.Infof("configure ... [done]\n")
    40  	return err
    41  }
    42  
    43  func (tsk *task1) StartTask(ctx fwk.Context) error {
    44  	msg := ctx.Msg()
    45  	msg.Infof("start...\n")
    46  	return nil
    47  }
    48  
    49  func (tsk *task1) StopTask(ctx fwk.Context) error {
    50  	msg := ctx.Msg()
    51  	msg.Infof("stop...\n")
    52  	return nil
    53  }
    54  
    55  func (tsk *task1) Process(ctx fwk.Context) error {
    56  	var err error
    57  	msg := ctx.Msg()
    58  	msg.Infof("proc... (id=%d|%d) => [%d, %d]\n", ctx.ID(), ctx.Slot(), tsk.i1, tsk.i2)
    59  	store := ctx.Store()
    60  
    61  	err = store.Put(tsk.i1prop, tsk.i1)
    62  	if err != nil {
    63  		return err
    64  	}
    65  
    66  	err = store.Put(tsk.i2prop, tsk.i2)
    67  	if err != nil {
    68  		return err
    69  	}
    70  
    71  	return nil
    72  }
    73  
    74  func init() {
    75  	fwk.Register(reflect.TypeOf(task1{}),
    76  		func(typ, name string, mgr fwk.App) (fwk.Component, error) {
    77  			var err error
    78  			tsk := &task1{
    79  				TaskBase: fwk.NewTask(typ, name, mgr),
    80  				i1prop:   "ints1",
    81  				i2prop:   "ints2",
    82  				i1:       -1,
    83  				i2:       +2,
    84  			}
    85  
    86  			err = tsk.DeclProp("Ints1", &tsk.i1prop)
    87  			if err != nil {
    88  				return nil, err
    89  			}
    90  
    91  			err = tsk.DeclProp("Ints2", &tsk.i2prop)
    92  			if err != nil {
    93  				return nil, err
    94  			}
    95  
    96  			err = tsk.DeclProp("Int1", &tsk.i1)
    97  			if err != nil {
    98  				return nil, err
    99  			}
   100  
   101  			err = tsk.DeclProp("Int2", &tsk.i2)
   102  			if err != nil {
   103  				return nil, err
   104  			}
   105  
   106  			err = tsk.SetProp("Int1", int64(1))
   107  			if err != nil {
   108  				return nil, err
   109  			}
   110  
   111  			return tsk, err
   112  		},
   113  	)
   114  }