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

     1  // Copyright ©2020 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 rbase
     6  
     7  import (
     8  	"fmt"
     9  	"reflect"
    10  
    11  	"go-hep.org/x/hep/groot/rbytes"
    12  	"go-hep.org/x/hep/groot/root"
    13  	"go-hep.org/x/hep/groot/rtypes"
    14  	"go-hep.org/x/hep/groot/rvers"
    15  )
    16  
    17  // ProcessID is ROOT's way to provide a process identifier object.
    18  type ProcessID struct {
    19  	named Named
    20  
    21  	objs map[uint32]root.Object
    22  }
    23  
    24  func (*ProcessID) Class() string {
    25  	return "TProcessID"
    26  }
    27  
    28  func (pid *ProcessID) UID() uint32 {
    29  	return pid.named.UID()
    30  }
    31  
    32  func (*ProcessID) RVersion() int16 {
    33  	return rvers.ProcessID
    34  }
    35  
    36  // Name returns the name of the instance
    37  func (pid *ProcessID) Name() string {
    38  	return pid.named.Name()
    39  }
    40  
    41  // Title returns the title of the instance
    42  func (pid *ProcessID) Title() string {
    43  	return pid.named.Title()
    44  }
    45  
    46  func (pid *ProcessID) SetName(name string)   { pid.named.SetName(name) }
    47  func (pid *ProcessID) SetTitle(title string) { pid.named.SetTitle(title) }
    48  
    49  func (pid *ProcessID) String() string {
    50  	return fmt.Sprintf("%s{Name: %s, Title: %s}", pid.Class(), pid.Name(), pid.Title())
    51  }
    52  
    53  func (pid *ProcessID) UnmarshalROOT(r *rbytes.RBuffer) error {
    54  	if r.Err() != nil {
    55  		return r.Err()
    56  	}
    57  
    58  	hdr := r.ReadHeader(pid.Class(), pid.RVersion())
    59  
    60  	r.ReadObject(&pid.named)
    61  
    62  	r.CheckHeader(hdr)
    63  	return r.Err()
    64  }
    65  
    66  func (pid *ProcessID) MarshalROOT(w *rbytes.WBuffer) (int, error) {
    67  	if w.Err() != nil {
    68  		return 0, w.Err()
    69  	}
    70  
    71  	hdr := w.WriteHeader(pid.Class(), pid.RVersion())
    72  	w.WriteObject(&pid.named)
    73  	return w.SetHeader(hdr)
    74  }
    75  
    76  func init() {
    77  	f := func() reflect.Value {
    78  		o := &ProcessID{
    79  			named: *NewNamed("", ""),
    80  		}
    81  		return reflect.ValueOf(o)
    82  	}
    83  	rtypes.Factory.Add("TProcessID", f)
    84  }
    85  
    86  var (
    87  	_ root.Object        = (*ProcessID)(nil)
    88  	_ root.UIDer         = (*ProcessID)(nil)
    89  	_ root.Named         = (*ProcessID)(nil)
    90  	_ rbytes.Marshaler   = (*ProcessID)(nil)
    91  	_ rbytes.Unmarshaler = (*ProcessID)(nil)
    92  )