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

     1  // Copyright ©2018 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 groot
     6  
     7  //go:generate go run ./gen.rboot.go
     8  //go:generate go run ./gen.rbytes.go
     9  //go:generate go run ./gen.rcont.go
    10  //go:generate go run ./gen.rhist.go
    11  //go:generate go run ./gen.rtree.go
    12  
    13  import (
    14  	"go-hep.org/x/hep/groot/riofs"
    15  	"go-hep.org/x/hep/groot/root"
    16  	_ "go-hep.org/x/hep/groot/ztypes"
    17  )
    18  
    19  const (
    20  	Version = root.Version // ROOT version hep/groot implements
    21  )
    22  
    23  // Open opens the named ROOT file for reading. If successful, methods on the
    24  // returned file can be used for reading; the associated file descriptor
    25  // has mode os.O_RDONLY.
    26  func Open(path string) (*File, error) {
    27  	return riofs.Open(path)
    28  }
    29  
    30  // NewReader creates a new ROOT file reader.
    31  func NewReader(r Reader) (*File, error) {
    32  	return riofs.NewReader(r)
    33  }
    34  
    35  // Create creates the named ROOT file for writing.
    36  func Create(name string, opts ...FileOption) (*File, error) {
    37  	return riofs.Create(name, opts...)
    38  }
    39  
    40  type (
    41  	File       = riofs.File
    42  	FileOption = riofs.FileOption
    43  	Reader     = riofs.Reader
    44  )
    45  
    46  // Object represents a ROOT object
    47  type Object interface {
    48  	// Class returns the ROOT class of this object
    49  	Class() string
    50  }
    51  
    52  // Named represents a ROOT TNamed object
    53  type Named interface {
    54  	Object
    55  
    56  	// Name returns the name of this ROOT object
    57  	Name() string
    58  
    59  	// Title returns the title of this ROOT object
    60  	Title() string
    61  }
    62  
    63  // Collection is a collection of ROOT Objects.
    64  type Collection interface {
    65  	Object
    66  
    67  	// Name returns the name of the collection.
    68  	Name() string
    69  
    70  	// Last returns the last element index
    71  	Last() int
    72  
    73  	// At returns the element at index i
    74  	At(i int) Object
    75  
    76  	// Len returns the number of elements in the collection
    77  	Len() int
    78  }
    79  
    80  // SeqCollection is a sequential collection of ROOT Objects.
    81  type SeqCollection interface {
    82  	Collection
    83  }
    84  
    85  // List is a list of ROOT Objects.
    86  type List interface {
    87  	SeqCollection
    88  }
    89  
    90  // ObjArray is an array of ROOT Objects.
    91  type ObjArray interface {
    92  	SeqCollection
    93  	LowerBound() int
    94  }
    95  
    96  // Array describes ROOT abstract array type.
    97  type Array interface {
    98  	Len() int // number of array elements
    99  	Get(i int) any
   100  	Set(i int, v any)
   101  }
   102  
   103  // ObjString is a ROOT string that implements ROOT TObject.
   104  type ObjString interface {
   105  	Name() string
   106  	String() string
   107  }