go-hep.org/x/hep@v0.38.1/groot/riofs/gendata/gen-multi-leaves-tree.go (about)

     1  // Copyright ©2020 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", "padding-struct.root", "output ROOT file")
    18  )
    19  
    20  func main() {
    21  	flag.Parse()
    22  
    23  	out, err := rtests.RunCxxROOT("gentree", []byte(script), *root)
    24  	if err != nil {
    25  		log.Fatalf("could not run ROOT macro:\noutput:\n%v\nerror: %+v", string(out), err)
    26  	}
    27  }
    28  
    29  const script = `
    30  #include <string.h>
    31  #include <stdio.h>
    32  
    33  struct Pad {
    34  	int8_t  x1;
    35  	int64_t x2;
    36  	int8_t  x3;
    37  };
    38  
    39  struct Nop {
    40  	int64_t x1;
    41  	int8_t  x2;
    42  	int8_t  x3;
    43  };
    44  
    45  void gentree(const char* fname, int splitlvl = 99) {
    46  	int bufsize = 32000;
    47  	int evtmax = 5;
    48  
    49  	auto f = TFile::Open(fname, "RECREATE");
    50  	auto t = new TTree("tree", "tree w/ & w/o padding");
    51  
    52  	Pad pad;
    53  	Nop nop;
    54  
    55  	t->Branch("pad", &pad, "x1/B:x2/L:x3/B");
    56  	t->Branch("nop", &nop, "x1/L:x2/B:x3/B");
    57  
    58  	for (int j = 0; j != evtmax; j++) {
    59  		pad.x1 = j;
    60  		pad.x2 = j;
    61  		pad.x3 = j;
    62  
    63  		nop.x1 = j;
    64  		nop.x2 = j;
    65  		nop.x3 = j;
    66  
    67  		t->Fill();
    68  	}
    69  
    70  	f->Write();
    71  	f->Close();
    72  
    73  	exit(0);
    74  }
    75  `