go-hep.org/x/hep@v0.38.1/groot/riofs/gendata/gen-bufevt-tree.go (about) 1 // Copyright ©2025 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 //go:build ignore 6 7 package main 8 9 import ( 10 "flag" 11 "log" 12 13 "go-hep.org/x/hep/groot/internal/rtests" 14 ) 15 16 var ( 17 root = flag.String("f", "test-bufevt.root", "output ROOT file") 18 split = flag.Int("split", 0, "default split-level for TTree") 19 ) 20 21 func main() { 22 flag.Parse() 23 24 out, err := rtests.RunCxxROOT("gentree", []byte(script), *root, *split) 25 if err != nil { 26 log.Fatalf("could not run ROOT macro:\noutput:\n%v\nerror: %+v", string(out), err) 27 } 28 } 29 30 const script = ` 31 #include <string.h> 32 #include <stdio.h> 33 34 const int ARRAYSZ = 10; 35 const int MAXSLICE = 20; 36 const int MAXSTR = 32; 37 38 #define OFFSET 0 39 40 struct __attribute__((packed)) Event { 41 bool Bool; 42 char Str[6]; 43 int8_t I8; 44 int16_t I16; 45 int32_t I32; 46 int64_t I64; 47 int64_t G64; 48 uint8_t U8; 49 uint16_t U16; 50 uint32_t U32; 51 uint64_t U64; 52 uint64_t UGG; 53 float F32; 54 double F64; 55 56 bool ArrayBs[ARRAYSZ]; 57 int8_t ArrayI8[ARRAYSZ]; 58 int16_t ArrayI16[ARRAYSZ]; 59 int32_t ArrayI32[ARRAYSZ]; 60 int64_t ArrayI64[ARRAYSZ]; 61 int64_t ArrayG64[ARRAYSZ]; 62 uint8_t ArrayU8[ARRAYSZ]; 63 uint16_t ArrayU16[ARRAYSZ]; 64 uint32_t ArrayU32[ARRAYSZ]; 65 uint64_t ArrayU64[ARRAYSZ]; 66 uint64_t ArrayUGG[ARRAYSZ]; 67 float ArrayF32[ARRAYSZ]; 68 double ArrayF64[ARRAYSZ]; 69 70 }; 71 72 void gentree(const char* fname, int splitlvl = 99) { 73 int bufsize = 32000; 74 int evtmax = 10; 75 76 auto f = TFile::Open(fname, "RECREATE"); 77 auto t = new TTree("tree", "my tree title"); 78 79 Event e; 80 t->Branch("Event",&e, 81 "B/O" 82 ":Str[6]/C" 83 ":I8/B:I16/S:I32/I:I64/L:G64/G" 84 ":U8/b:U16/s:U32/i:U64/l:UGG/g" 85 ":F32/F:F64/D" 86 87 // static arrays 88 ":ArrBs[10]/O" 89 ":ArrI8[10]/B:ArrI16[10]/S:ArrI32[10]/I:ArrI64[10]/L:ArrG64[10]/G" 90 ":ArrU8[10]/b:ArrU16[10]/s:ArrU32[10]/i:ArrU64[10]/l:ArrUGG[10]/g" 91 ":ArrF32[10]/F:ArrF64[10]/D" 92 ); 93 94 for (int j = 0; j != evtmax; j++) { 95 int i = j + OFFSET; 96 e.Bool = (i % 2) == 0; 97 strncpy(e.Str, TString::Format("str-%d\0", i).Data(), 32); 98 e.I8 = -i; 99 e.I16 = -i; 100 e.I32 = -i; 101 e.I64 = -i; 102 e.G64 = -i; 103 e.U8 = i; 104 e.U16 = i; 105 e.U32 = i; 106 e.U64 = i; 107 e.UGG = i; 108 e.F32 = float(i); 109 e.F64 = double(i); 110 111 for (int ii = 0; ii != ARRAYSZ; ii++) { 112 e.ArrayBs[ii] = ii == i; 113 e.ArrayI8[ii] = -i; 114 e.ArrayI16[ii] = -i; 115 e.ArrayI32[ii] = -i; 116 e.ArrayI64[ii] = -i; 117 e.ArrayG64[ii] = -i; 118 e.ArrayU8[ii] = i; 119 e.ArrayU16[ii] = i; 120 e.ArrayU32[ii] = i; 121 e.ArrayU64[ii] = i; 122 e.ArrayUGG[ii] = i; 123 e.ArrayF32[ii] = float(i); 124 e.ArrayF64[ii] = double(i); 125 } 126 127 t->Fill(); 128 } 129 130 f->Write(); 131 f->Close(); 132 133 exit(0); 134 } 135 `