go-hep.org/x/hep@v0.38.1/fastjet/plugin.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 fastjet
     6  
     7  import (
     8  	"fmt"
     9  )
    10  
    11  type Plugin interface {
    12  	Description() string
    13  	RunClustering(builder Builder) error
    14  	R() float64
    15  }
    16  
    17  var (
    18  	g_plugins = make(map[string]Plugin)
    19  )
    20  
    21  func Register(name string, plugin Plugin) {
    22  	_, dup := g_plugins[name]
    23  	if dup {
    24  		panic(fmt.Errorf("fastjet.Register: duplicate plugin [%s] (%s)", name, plugin.Description()))
    25  	}
    26  	g_plugins[name] = plugin
    27  }
    28  
    29  func GetPlugin(name string) (Plugin, error) {
    30  	plugin, ok := g_plugins[name]
    31  	if !ok {
    32  		return nil, fmt.Errorf("fastjet.JetPlugin: no such plugin [%s]", name)
    33  	}
    34  
    35  	return plugin, nil
    36  }