go-hep.org/x/hep@v0.38.1/lcio/trackerrawdata.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 "fmt" 9 "strings" 10 11 "go-hep.org/x/hep/sio" 12 ) 13 14 type TrackerRawDataContainer struct { 15 Flags Flags // bits 0-15 are user/detector specific 16 Params Params 17 Data []TrackerRawData 18 } 19 20 type TrackerRawData struct { 21 CellID0 int32 22 CellID1 int32 23 Time int32 24 ADCs []uint16 25 } 26 27 func (data *TrackerRawData) GetCellID0() int32 { return data.CellID0 } 28 func (data *TrackerRawData) GetCellID1() int32 { return data.CellID1 } 29 30 func (tds *TrackerRawDataContainer) String() string { 31 o := new(strings.Builder) 32 fmt.Fprintf(o, "%[1]s print out of TrackerData collection %[1]s\n\n", strings.Repeat("-", 15)) 33 fmt.Fprintf(o, " flag: 0x%x\n", tds.Flags) 34 fmt.Fprintf(o, " LCIO::TRAWBIT_ID1 : %v\n", tds.Flags.Test(BitsTRawID1)) 35 36 fmt.Fprintf(o, "%v\n", tds.Params) 37 38 const ( 39 head = " [ id ] | cellid0 | cellid1 | time | cellid-fields \n" 40 tail = "------------|----------|----------|----------|----------------\n" 41 ) 42 o.WriteString(head) 43 o.WriteString(tail) 44 for i := range tds.Data { 45 data := &tds.Data[i] 46 fmt.Fprintf(o, 47 "[%09d] | %08d | %08d | %+8d | unknown/default ADCs: %v\n", 48 ID(data), 49 data.CellID0, data.CellID1, 50 data.Time, 51 data.ADCs, 52 ) 53 } 54 return o.String() 55 } 56 57 func (*TrackerRawDataContainer) VersionSio() uint32 { 58 return Version 59 } 60 61 func (trs *TrackerRawDataContainer) MarshalSio(w sio.Writer) error { 62 enc := sio.NewEncoder(w) 63 enc.Encode(&trs.Flags) 64 enc.Encode(&trs.Params) 65 enc.Encode(int32(len(trs.Data))) 66 for i := range trs.Data { 67 data := &trs.Data[i] 68 enc.Encode(&data.CellID0) 69 if trs.Flags.Test(BitsTRawID1) { 70 enc.Encode(&data.CellID1) 71 } 72 enc.Encode(&data.Time) 73 nADCs := int32(len(data.ADCs)) 74 enc.Encode(&nADCs) 75 for _, value := range data.ADCs { 76 enc.Encode(&value) 77 } 78 if nADCs%2 == 1 { 79 pad := uint16(0) 80 enc.Encode(&pad) 81 } 82 enc.Tag(data) 83 } 84 return enc.Err() 85 } 86 87 func (trs *TrackerRawDataContainer) UnmarshalSio(r sio.Reader) error { 88 dec := sio.NewDecoder(r) 89 dec.Decode(&trs.Flags) 90 dec.Decode(&trs.Params) 91 var n int32 92 dec.Decode(&n) 93 trs.Data = make([]TrackerRawData, int(n)) 94 for i := range trs.Data { 95 data := &trs.Data[i] 96 dec.Decode(&data.CellID0) 97 if trs.Flags.Test(BitsTRawID1) { 98 dec.Decode(&data.CellID1) 99 } 100 dec.Decode(&data.Time) 101 var nADCs int32 102 dec.Decode(&nADCs) 103 data.ADCs = make([]uint16, nADCs) 104 for j := range data.ADCs { 105 dec.Decode(&data.ADCs[j]) 106 } 107 if nADCs%2 == 1 { 108 var pad uint16 109 dec.Decode(&pad) 110 } 111 dec.Tag(data) 112 } 113 return dec.Err() 114 } 115 116 var ( 117 _ sio.Versioner = (*TrackerRawDataContainer)(nil) 118 _ sio.Codec = (*TrackerRawDataContainer)(nil) 119 )