go-hep.org/x/hep@v0.38.1/groot/internal/rdatatest/event.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 rdatatest
     6  
     7  import (
     8  	"go-hep.org/x/hep/groot/rbase"
     9  	"go-hep.org/x/hep/groot/rbytes"
    10  	"go-hep.org/x/hep/groot/rcont"
    11  	"go-hep.org/x/hep/groot/root"
    12  )
    13  
    14  // Event is a simple type to exercize streamers generation.
    15  type Event struct {
    16  	name string `groot:"Name"`
    17  	u8   uint8
    18  	u16  uint16
    19  	u32  uint32
    20  	u64  uint64
    21  	i8   int8
    22  	i16  int16
    23  	i32  int32
    24  	i64  int64
    25  	f32  float32
    26  	f64  float64
    27  
    28  	b  bool
    29  	bb byte
    30  
    31  	u8s  []uint8
    32  	u16s []uint16
    33  	u32s []uint32
    34  	u64s []uint64
    35  	i8s  []int8
    36  	i16s []int16
    37  	i32s []int32
    38  	i64s []int64
    39  	f32s []float32
    40  	f64s []float64
    41  	bs   []bool
    42  	bbs  []byte
    43  
    44  	arru8s  [10]uint8
    45  	arru16s [10]uint16
    46  	arru32s [10]uint32
    47  	arru64s [10]uint64
    48  	arri8s  [10]int8
    49  	arri16s [10]int16
    50  	arri32s [10]int32
    51  	arri64s [10]int64
    52  	arrf32s [10]float32
    53  	arrf64s [10]float64
    54  	arrbs   [10]bool
    55  	arrbbs  [10]byte
    56  
    57  	SliF64 []float64   `groot:"SliceF64"`
    58  	SliStr []string    `groot:"SliceStr"`
    59  	SliHLV []HLV       `groot:"SliceHLV"`
    60  	ArrF64 [10]float64 `groot:"ArrF64"`
    61  }
    62  
    63  func NewEvent(
    64  	name string,
    65  	u8 uint8,
    66  	u16 uint16,
    67  	u32 uint32,
    68  	u64 uint64,
    69  	i8 int8,
    70  	i16 int16,
    71  	i32 int32,
    72  	i64 int64,
    73  	f32 float32,
    74  	f64 float64,
    75  
    76  	b bool,
    77  	bb byte,
    78  
    79  	u8s []uint8,
    80  	u16s []uint16,
    81  	u32s []uint32,
    82  	u64s []uint64,
    83  	i8s []int8,
    84  	i16s []int16,
    85  	i32s []int32,
    86  	i64s []int64,
    87  	f32s []float32,
    88  	f64s []float64,
    89  	bs []bool,
    90  	bbs []byte,
    91  
    92  	arru8s [10]uint8,
    93  	arru16s [10]uint16,
    94  	arru32s [10]uint32,
    95  	arru64s [10]uint64,
    96  	arri8s [10]int8,
    97  	arri16s [10]int16,
    98  	arri32s [10]int32,
    99  	arri64s [10]int64,
   100  	arrf32s [10]float32,
   101  	arrf64s [10]float64,
   102  	arrbs [10]bool,
   103  	arrbbs [10]byte,
   104  
   105  	SliF64 []float64,
   106  	SliStr []string,
   107  	SliHLV []HLV,
   108  	ArrF64 [10]float64,
   109  ) *Event {
   110  	return &Event{
   111  		name: name,
   112  		u8:   u8,
   113  		u16:  u16,
   114  		u32:  u32,
   115  		u64:  u64,
   116  		i8:   i8,
   117  		i16:  i16,
   118  		i32:  i32,
   119  		i64:  i64,
   120  		f32:  f32,
   121  		f64:  f64,
   122  
   123  		b:  b,
   124  		bb: bb,
   125  
   126  		u8s:  u8s,
   127  		u16s: u16s,
   128  		u32s: u32s,
   129  		u64s: u64s,
   130  		i8s:  i8s,
   131  		i16s: i16s,
   132  		i32s: i32s,
   133  		i64s: i64s,
   134  		f32s: f32s,
   135  		f64s: f64s,
   136  		bs:   bs,
   137  		bbs:  bbs,
   138  
   139  		arru8s:  arru8s,
   140  		arru16s: arru16s,
   141  		arru32s: arru32s,
   142  		arru64s: arru64s,
   143  		arri8s:  arri8s,
   144  		arri16s: arri16s,
   145  		arri32s: arri32s,
   146  		arri64s: arri64s,
   147  		arrf32s: arrf32s,
   148  		arrf64s: arrf64s,
   149  		arrbs:   arrbs,
   150  		arrbbs:  arrbbs,
   151  
   152  		SliF64: SliF64,
   153  		SliStr: SliStr,
   154  		SliHLV: SliHLV,
   155  		ArrF64: ArrF64,
   156  	}
   157  }
   158  
   159  func (*Event) RVersion() int16 { return 1 }
   160  func (*Event) Class() string   { return "go-hep.org/x/hep/groot/internal/rdatatest.Event" }
   161  
   162  // Particle is a simple type to exercize streamers generation.
   163  type Particle struct {
   164  	name string
   165  	pid  int
   166  	mom  HLV
   167  }
   168  
   169  func NewParticle(name string, pid int, mom HLV) *Particle {
   170  	return &Particle{
   171  		name: name,
   172  		pid:  pid,
   173  		mom:  mom,
   174  	}
   175  }
   176  
   177  func (*Particle) RVersion() int16 { return 1 }
   178  func (*Particle) Class() string   { return "go-hep.org/x/hep/groot/internal/rdatatest.Particle" }
   179  
   180  // HLV is a simple type to exercize streamers generation.
   181  type HLV struct {
   182  	px, py, pz, e float64
   183  }
   184  
   185  func (*HLV) RVersion() int16 { return 1 }
   186  func (*HLV) Class() string   { return "go-hep.org/x/hep/groot/internal/rdatatest.HLV" }
   187  
   188  // Builtins exercizes all simple builtins.
   189  type Builtins struct {
   190  	b bool
   191  
   192  	u8  uint8
   193  	u16 uint16
   194  	u32 uint32
   195  	u64 uint64
   196  
   197  	i8  int8
   198  	i16 int16
   199  	i32 int32
   200  	i64 int64
   201  
   202  	f32 float32
   203  	f64 float64
   204  
   205  	// c64  complex64  // FIXME(sbinet)
   206  	// c128 complex128 // FIXME(sbinet)
   207  
   208  	name string `groot:"Name"`
   209  }
   210  
   211  func (*Builtins) RVersion() int16 { return 1 }
   212  func (*Builtins) Class() string   { return "go-hep.org/x/hep/groot/internal/rdatatest.Builtins" }
   213  
   214  func NewBuiltins() *Builtins {
   215  	return &Builtins{
   216  		b: true,
   217  
   218  		u8:  8,
   219  		u16: 16,
   220  		u32: 32,
   221  		u64: 64,
   222  
   223  		i8:  -8,
   224  		i16: -16,
   225  		i32: -32,
   226  		i64: -64,
   227  
   228  		f32: 32.32,
   229  		f64: 64.64,
   230  
   231  		// c64:  complex(float32(-1), float32(+2)), // FIXME(sbinet)
   232  		// c128: complex(-2, +3),                   // FIXME(sbinet)
   233  
   234  		name: "builtins",
   235  	}
   236  }
   237  
   238  // ArrBuiltins exercizes all arrays of simple builtins.
   239  type ArrBuiltins struct {
   240  	b [2]bool
   241  
   242  	u8  [2]uint8
   243  	u16 [2]uint16
   244  	u32 [2]uint32
   245  	u64 [2]uint64
   246  
   247  	i8  [2]int8
   248  	i16 [2]int16
   249  	i32 [2]int32
   250  	i64 [2]int64
   251  
   252  	f32 [2]float32
   253  	f64 [2]float64
   254  
   255  	// c64  [2]complex64  // FIXME(sbinet)
   256  	// c128 [2]complex128 // FIXME(sbinet)
   257  
   258  	name [2]string `groot:"Name"`
   259  }
   260  
   261  func (*ArrBuiltins) RVersion() int16 { return 1 }
   262  func (*ArrBuiltins) Class() string   { return "go-hep.org/x/hep/groot/internal/rdatatest.ArrBuiltins" }
   263  
   264  func NewArrBuiltins() *ArrBuiltins {
   265  	return &ArrBuiltins{
   266  		b: [2]bool{true, false},
   267  
   268  		u8:  [2]uint8{8, 88},
   269  		u16: [2]uint16{16, 1616},
   270  		u32: [2]uint32{32, 3232},
   271  		u64: [2]uint64{64, 6464},
   272  
   273  		i8:  [2]int8{-8, -88},
   274  		i16: [2]int16{-16, -1616},
   275  		i32: [2]int32{-32, -3232},
   276  		i64: [2]int64{-64, -6464},
   277  
   278  		f32: [2]float32{32.32, -32.32},
   279  		f64: [2]float64{64.64, +64.64},
   280  
   281  		// c64:  complex(float32(-1), float32(+2)), // FIXME(sbinet)
   282  		// c128: complex(-2, +3),                   // FIXME(sbinet)
   283  
   284  		name: [2]string{"builtins", "arrays"},
   285  	}
   286  }
   287  
   288  // T1 exercizes a user type containing another user-type.
   289  type T1 struct {
   290  	name string `groot:"Name"`
   291  	hlv  HLV    `groot:"MyHLV"`
   292  }
   293  
   294  func (*T1) RVersion() int16 { return 1 }
   295  func (*T1) Class() string   { return "go-hep.org/x/hep/groot/internal/rdatatest.T1" }
   296  
   297  func NewT1() *T1 {
   298  	return &T1{
   299  		name: "hello",
   300  		hlv:  HLV{1, 2, 3, 4},
   301  	}
   302  }
   303  
   304  // T2 exercizes a user type containing an array of another user-type.
   305  type T2 struct {
   306  	name string `groot:"Name"`
   307  	hlvs [2]HLV `groot:"MyHLVs"`
   308  }
   309  
   310  func (*T2) RVersion() int16 { return 1 }
   311  func (*T2) Class() string   { return "go-hep.org/x/hep/groot/internal/rdatatest.T2" }
   312  
   313  func NewT2() *T2 {
   314  	return &T2{
   315  		name: "hello",
   316  		hlvs: [2]HLV{{1, 2, 3, 4}, {-1, -2, -3, -4}},
   317  	}
   318  }
   319  
   320  // FIXME(sbinet)
   321  //  - support types that "inherit" from TObject
   322  //  - support types that contain a TList
   323  //  - support types that contain a pointer to TObject
   324  //  - support types that contain a pointer to any-object
   325  
   326  type TObject struct {
   327  	rbase.Object
   328  	name string
   329  }
   330  
   331  func NewTObject(o rbase.Object, name string) TObject {
   332  	return TObject{Object: o, name: name}
   333  }
   334  
   335  type TList struct {
   336  	rbase.Object
   337  	objs []root.Object
   338  	list rcont.List
   339  }
   340  
   341  func NewTList(o rbase.Object, objs []root.Object, list rcont.List) TList {
   342  	return TList{
   343  		Object: o,
   344  		objs:   objs,
   345  		list:   list,
   346  	}
   347  }
   348  
   349  type TClonesArray struct {
   350  	rbase.Object
   351  	//	clones rcont.ClonesArray // FIXME(sbinet)
   352  }
   353  
   354  var (
   355  	_ rbytes.RVersioner = (*Event)(nil)
   356  	_ rbytes.RVersioner = (*HLV)(nil)
   357  	_ rbytes.RVersioner = (*Particle)(nil)
   358  
   359  	_ rbytes.RVersioner = (*Builtins)(nil)
   360  	_ rbytes.RVersioner = (*ArrBuiltins)(nil)
   361  	_ rbytes.RVersioner = (*T1)(nil)
   362  	_ rbytes.RVersioner = (*T2)(nil)
   363  )