go-hep.org/x/hep@v0.38.1/lcio/meta.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 lcio
     6  
     7  import (
     8  	"go-hep.org/x/hep/sio"
     9  )
    10  
    11  const (
    12  	MajorVersion uint32 = 2
    13  	MinorVersion uint32 = 8
    14  	Version      uint32 = (MajorVersion << 16) + MinorVersion
    15  )
    16  
    17  var Records = struct {
    18  	Index        string
    19  	RandomAccess string
    20  	RunHeader    string
    21  	EventHeader  string
    22  	Event        string
    23  }{
    24  	Index:        "LCIOIndex",
    25  	RandomAccess: "LCIORandomAccess",
    26  	RunHeader:    "LCRunHeader",
    27  	EventHeader:  "LCEventHeader",
    28  	Event:        "LCEvent",
    29  }
    30  
    31  var Blocks = struct {
    32  	Index        string
    33  	RandomAccess string
    34  	RunHeader    string
    35  	EventHeader  string
    36  }{
    37  	Index:        "LCIOndex",
    38  	RandomAccess: "LCIORandomAccess",
    39  	RunHeader:    "RunHeader",
    40  	EventHeader:  "EventHeader",
    41  }
    42  
    43  type RandomAccess struct {
    44  	RunMin         int32
    45  	EventMin       int32
    46  	RunMax         int32
    47  	EventMax       int32
    48  	RunHeaders     int32
    49  	Events         int32
    50  	RecordsInOrder int32
    51  	IndexLoc       int64
    52  	PrevLoc        int64
    53  	NextLoc        int64
    54  	FirstRecordLoc int64
    55  	RecordSize     int32
    56  }
    57  
    58  type Index struct {
    59  	// Bit 0 = single run.
    60  	// Bit 1 = int64 offset required
    61  	// Bit 2 = Params included (not yet implemented)
    62  	ControlWord uint32
    63  	RunMin      int32
    64  	BaseOffset  int64
    65  	Offsets     []Offset
    66  }
    67  
    68  func (idx *Index) MarshalSio(w sio.Writer) error {
    69  	panic("not implemented")
    70  }
    71  
    72  func (idx *Index) UnmarshalSio(r sio.Reader) error {
    73  	dec := sio.NewDecoder(r)
    74  	dec.Decode(&idx.ControlWord)
    75  	dec.Decode(&idx.RunMin)
    76  	dec.Decode(&idx.BaseOffset)
    77  	var n int32
    78  	dec.Decode(&n)
    79  	idx.Offsets = make([]Offset, int(n))
    80  	for i := range idx.Offsets {
    81  		v := &idx.Offsets[i]
    82  		if idx.ControlWord&1 == 0 {
    83  			dec.Decode(&v.RunOffset)
    84  		}
    85  
    86  		dec.Decode(&v.EventNumber)
    87  		switch {
    88  		case idx.ControlWord&2 == 1:
    89  			dec.Decode(&v.Location)
    90  		default:
    91  			var loc int32
    92  			dec.Decode(&loc)
    93  			v.Location = int64(loc)
    94  		}
    95  		if idx.ControlWord&4 == 1 {
    96  			dec.Decode(&v.Ints)
    97  			dec.Decode(&v.Floats)
    98  			dec.Decode(&v.Strings)
    99  		}
   100  	}
   101  	return dec.Err()
   102  }
   103  
   104  type Offset struct {
   105  	RunOffset   int32 // run offset relative to Index.RunMin
   106  	EventNumber int32 // event number or -1 for run header records
   107  	Location    int64 // location offset relative to Index.BaseOffset
   108  	Ints        []int32
   109  	Floats      []float32
   110  	Strings     []string
   111  }
   112  
   113  var _ sio.Codec = (*Index)(nil)