func (tsk *CPUCruncher) Configure(ctx fwk.Context) error { var err error for _, input := range tsk.inputs { if input == "" { continue } err = tsk.DeclInPort(input, reflect.TypeOf(int64(0))) if err != nil { return err } } for _, output := range tsk.outputs { if output == "" { continue } err = tsk.DeclOutPort(output, reflect.TypeOf(int64(0))) if err != nil { return err } } if len(tsk.cpus) <= 0 { msg := ctx.Msg() msg.Errorf("invalid cpu-timings list: %v\n", tsk.cpus) return fwk.Errorf("invalid cpu-timings") } return err }
func (o *OutputStreamer) Write(ctx fwk.Context) error { var err error store := ctx.Store() for i, rec := range o.recs { port := o.ports[i] n := rec.Name() blk := rec.Block(n) obj, err := store.Get(n) if err != nil { return err } rt := reflect.TypeOf(obj) if rt != port.Type { return fwk.Errorf("record[%s]: got type=%q. want type=%q.", rec.Name(), rt.Name(), port.Type, ) } err = blk.Write(obj) if err != nil { return err } err = rec.Write() if err != nil { return err } } return err }
func (tsk *testhsvc) StopTask(ctx fwk.Context) error { var err error h := tsk.h1d.Hist if h.Entries() != *evtmax { return fwk.Errorf("expected %d entries. got=%d", *evtmax, h.Entries()) } mean := h.Mean() if mean != 4.5 { return fwk.Errorf("expected mean=%v. got=%v", 4.5, mean) } rms := h.RMS() if rms != 2.8722813232690143 { return fwk.Errorf("expected RMS=%v. got=%v", 2.8722813232690143, rms) } msg := ctx.Msg() msg.Infof("histo[%s]: entries=%v mean=%v RMS=%v\n", tsk.h1d.ID, h.Entries(), h.Mean(), h.RMS(), ) return err }
func (input *InputStreamer) Read(ctx fwk.Context) error { var err error store := ctx.Store() recs := make(map[string]struct{}, len(input.ports)) for i := 0; i < len(input.ports); i++ { if !input.scan.Scan() { err = input.scan.Err() if err == nil { return io.EOF } } rec := input.scan.Record() blk := rec.Block(rec.Name()) obj := reflect.New(input.ports[rec.Name()].Type).Elem() err := blk.Read(obj.Addr().Interface()) if err != nil { return fwk.Errorf("block-read error: %v", err) } err = store.Put(rec.Name(), obj.Interface()) if err != nil { return fwk.Errorf("store-put error: %v", err) } recs[rec.Name()] = struct{}{} } if len(recs) != len(input.ports) { return fwk.Errorf("fwk.rio: expected inputs: %d. got: %d.", len(input.ports), len(recs)) } return err }
func (tsk *task3) Process(ctx fwk.Context) error { msg := ctx.Msg() msg.Infof("proc...\n") store := ctx.Store() parts := make([]int, 0) err := store.Put(tsk.parts, parts) if err != nil { return err } return nil }
func (tsk *task3) Configure(ctx fwk.Context) error { var err error msg := ctx.Msg() msg.Infof("configure...\n") err = tsk.DeclOutPort(tsk.parts, reflect.TypeOf([]int{})) if err != nil { return err } msg.Infof("configure... [done]\n") return err }
func (out *OutputStream) Write(ctx fwk.Context) error { var err error store := ctx.Store() v, err := store.Get(out.input) if err != nil { return err } data := v.(int64) _, err = out.W.Write([]byte(fmt.Sprintf("%d\n", data))) if err != nil { return err } return err }
func (stream *InputStream) Read(ctx fwk.Context) error { var err error store := ctx.Store() var data int64 _, err = fmt.Fscanf(stream.R, "%d\n", &data) if err != nil { return err } err = store.Put(stream.output, data) if err != nil { return err } return err }
func (tsk *reducer) StopTask(ctx fwk.Context) error { var err error tsk.mux.RLock() sum := tsk.sum nevts := tsk.nevts tsk.mux.RUnlock() msg := ctx.Msg() if sum != tsk.exp { msg.Errorf("expected sum=%v. got=%v (nevts=%d)\n", tsk.exp, sum, nevts) return fwk.Errorf("%s: expected sum=%v. got=%v (nevts=%d)", tsk.Name(), tsk.exp, sum, nevts) } msg.Debugf("expected sum=%v. got=%v (all GOOD) (nevts=%d)\n", tsk.exp, sum, nevts) return err }
func (tsk *testhsvc) Configure(ctx fwk.Context) error { var err error svc, err := ctx.Svc("histsvc") if err != nil { return err } tsk.hsvc = svc.(fwk.HistSvc) tsk.h1d, err = tsk.hsvc.BookH1D("h1d-"+tsk.Name(), 100, -10, 10) if err != nil { return err } return err }
func (tsk *task2) Configure(ctx fwk.Context) error { var err error msg := ctx.Msg() msg.Infof("configure...\n") err = tsk.DeclInPort(tsk.input, reflect.TypeOf(int64(1))) if err != nil { return err } err = tsk.DeclOutPort(tsk.output, reflect.TypeOf(int64(1))) if err != nil { return err } msg.Infof("configure... [done]\n") return err }
func (tsk *CPUCruncher) Process(ctx fwk.Context) error { var err error store := ctx.Store() for _, input := range tsk.inputs { _, err = store.Get(input) if err != nil { return err } } cpu := <-tsk.cpuch time.Sleep(time.Duration(cpu) * time.Microsecond) for _, output := range tsk.outputs { err = store.Put(output, cpu) if err != nil { return err } } return err }
func (tsk *task2) Process(ctx fwk.Context) error { store := ctx.Store() msg := ctx.Msg() v, err := store.Get(tsk.input) if err != nil { return err } i := v.(int64) o := tsk.fct(i) err = store.Put(tsk.output, o) if err != nil { return err } msg.Infof("proc... (id=%d|%d) => [%d -> %d]\n", ctx.ID(), ctx.Slot(), i, o) return nil }
func (tsk *testhsvc) StartTask(ctx fwk.Context) error { var err error svc, err := ctx.Svc("histsvc") if err != nil { return err } tsk.hsvc = svc.(fwk.HistSvc) if !strings.HasPrefix(tsk.stream, "/") { tsk.stream = "/" + tsk.stream } if strings.HasSuffix(tsk.stream, "/") { tsk.stream = tsk.stream[:len(tsk.stream)-1] } tsk.h1d, err = tsk.hsvc.BookH1D(tsk.stream+"/h1d-"+tsk.Name(), 100, -10, 10) if err != nil { return err } return err }
func (tsk *task1) Process(ctx fwk.Context) error { var err error msg := ctx.Msg() msg.Infof("proc... (id=%d|%d) => [%d, %d]\n", ctx.ID(), ctx.Slot(), tsk.i1, tsk.i2) store := ctx.Store() err = store.Put(tsk.i1prop, tsk.i1) if err != nil { return err } err = store.Put(tsk.i2prop, tsk.i2) if err != nil { return err } return nil }
func (tsk *reducer) Process(ctx fwk.Context) error { var err error tsk.mux.Lock() tsk.nevts += 1 tsk.mux.Unlock() store := ctx.Store() v, err := store.Get(tsk.input) if err != nil { return err } val := v.(int64) tsk.mux.Lock() tsk.sum += val sum := tsk.sum tsk.mux.Unlock() msg := ctx.Msg() msg.Infof("sum=%d (id=%d|%d)\n", sum, ctx.ID(), ctx.Slot()) return err }
func (tsk *task3) StartTask(ctx fwk.Context) error { msg := ctx.Msg() msg.Infof("start...\n") return nil }
func (tsk *task2) StopTask(ctx fwk.Context) error { msg := ctx.Msg() msg.Infof("stop...\n") return nil }
func (tsk *testhsvc) Process(ctx fwk.Context) error { var err error id := ctx.ID() tsk.hsvc.FillH1D(tsk.h1d.ID, float64(id), 1) return err }
func (svc *svc1) StopSvc(ctx fwk.Context) error { var err error msg := ctx.Msg() msg.Infof("-- stop svc --\n") return err }