go-hep.org/x/hep@v0.38.1/groot/riofs/gendata/gen-tntupled.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-tntupled.root", "output ROOT file")
    18  )
    19  
    20  func main() {
    21  	flag.Parse()
    22  
    23  	out, err := rtests.RunCxxROOT("gentntuple", []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  void gentntuple(const char* fname) {
    31  	int bufsize = 32000;
    32  	int evtmax = 10;
    33  
    34  	auto f = TFile::Open(fname, "RECREATE");
    35  	auto t = new TNtupleD("ntup", "my ntuple title", "x:y");
    36  
    37  	for (int i = 0; i != evtmax; i++) {
    38  		t->Fill(i, i+0.5);
    39  	}
    40  	f->Write();
    41  	f->Close();
    42  
    43  	exit(0);
    44  }
    45  `