go-hep.org/x/hep@v0.38.1/groot/rarrow/option.go (about)

     1  // Copyright ©2019 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 rarrow // import "go-hep.org/x/hep/groot/rarrow"
     6  
     7  import (
     8  	"git.sr.ht/~sbinet/go-arrow/memory"
     9  )
    10  
    11  type config struct {
    12  	mem    memory.Allocator
    13  	chunks int64
    14  	beg    int64
    15  	end    int64
    16  }
    17  
    18  func newConfig(opts []Option) *config {
    19  	cfg := &config{
    20  		mem: memory.NewGoAllocator(),
    21  		end: -1,
    22  	}
    23  	for _, opt := range opts {
    24  		opt(cfg)
    25  	}
    26  	return cfg
    27  }
    28  
    29  // Option allows to configure how Records and Tables are constructed
    30  // from input ROOT Trees.
    31  type Option func(*config)
    32  
    33  // WithAllocator configures an Arrow value to use the specified memory allocator
    34  // instead of the default Go one.
    35  func WithAllocator(mem memory.Allocator) Option {
    36  	return func(cfg *config) {
    37  		cfg.mem = mem
    38  	}
    39  }
    40  
    41  // WithChunk specifies the number of entries to populate Records with.
    42  //
    43  // The default is to populate Records with the whole set of entries the input
    44  // ROOT Tree contains.
    45  func WithChunk(nentries int64) Option {
    46  	return func(cfg *config) {
    47  		cfg.chunks = nentries
    48  	}
    49  }
    50  
    51  // WithStart specifies the first entry to read from the input ROOT Tree.
    52  func WithStart(entry int64) Option {
    53  	return func(cfg *config) {
    54  		cfg.beg = entry
    55  	}
    56  }
    57  
    58  // WithEnd specifies the last entry (excluded) to read from the input ROOT Tree.
    59  //
    60  // The default (-1) is to read all the entries of the input ROOT Tree.
    61  func WithEnd(entry int64) Option {
    62  	return func(cfg *config) {
    63  		cfg.end = entry
    64  	}
    65  }