go-hep.org/x/hep@v0.38.1/fads/cmd/fads-app/task3.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/fads"
    11  	"go-hep.org/x/hep/fwk"
    12  )
    13  
    14  type task3 struct {
    15  	fwk.TaskBase
    16  
    17  	parts string
    18  }
    19  
    20  func (tsk *task3) Configure(ctx fwk.Context) error {
    21  	var err error
    22  	msg := ctx.Msg()
    23  	msg.Infof("configure...\n")
    24  
    25  	msg.Infof("configure... [done]\n")
    26  	return err
    27  }
    28  
    29  func (tsk *task3) StartTask(ctx fwk.Context) error {
    30  	msg := ctx.Msg()
    31  	msg.Infof("start...\n")
    32  	return nil
    33  }
    34  
    35  func (tsk *task3) StopTask(ctx fwk.Context) error {
    36  	msg := ctx.Msg()
    37  	msg.Infof("stop...\n")
    38  	return nil
    39  }
    40  
    41  func (tsk *task3) Process(ctx fwk.Context) error {
    42  	msg := ctx.Msg()
    43  	msg.Infof("proc...\n")
    44  	store := ctx.Store()
    45  
    46  	parts := make([]fads.Candidate, 0)
    47  	err := store.Put(tsk.parts, parts)
    48  	if err != nil {
    49  		return err
    50  	}
    51  
    52  	return nil
    53  }
    54  
    55  func init() {
    56  	fwk.Register(reflect.TypeOf(task3{}),
    57  		func(typ, name string, mgr fwk.App) (fwk.Component, error) {
    58  			var err error
    59  			tsk := &task3{
    60  				TaskBase: fwk.NewTask(typ, name, mgr),
    61  				parts:    "/fads/test/StableParticles",
    62  			}
    63  			err = tsk.DeclProp("Output", &tsk.parts)
    64  			if err != nil {
    65  				return nil, err
    66  			}
    67  
    68  			err = tsk.DeclOutPort(tsk.parts, reflect.TypeOf([]fads.Candidate{}))
    69  			if err != nil {
    70  				return nil, err
    71  			}
    72  
    73  			return tsk, err
    74  		},
    75  	)
    76  }