go-hep.org/x/hep@v0.38.1/groot/riofs/gendata/gen-base.go (about) 1 // Copyright ©2022 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-base.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 <stdint.h> 32 33 class Base { 34 public: 35 int32_t I32; 36 }; 37 38 class D1 : public Base { 39 public: 40 int32_t D32; 41 }; 42 43 class D2 : public Base { 44 public: 45 int32_t I32; 46 }; 47 48 void gentree(const char* fname, int splitlvl = 99) { 49 int bufsize = 32000; 50 int evtmax = 2; 51 52 auto f = TFile::Open(fname, "RECREATE"); 53 auto t = new TTree("tree", "my tree title"); 54 55 D1 d1; 56 D2 d2; 57 58 t->Branch("d1", &d1, bufsize, splitlvl); 59 t->Branch("d2", &d2, bufsize, splitlvl); 60 61 for (int i = 0; i != evtmax; i++) { 62 d1.I32 = i+1; 63 d1.D32 = i+2; 64 ((Base*)&d2)->I32 = i+3; 65 d2.I32 = i+4; 66 67 t->Fill(); 68 } 69 70 f->Write(); 71 f->Close(); 72 73 exit(0); 74 } 75 `