go-hep.org/x/hep@v0.38.1/groot/cmd/root-split/main.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  // root-split splits an input file+tree into multiple output ROOT files,
     6  // each containing N entries.
     7  //
     8  // Usage: root-split [options] file.root
     9  //
    10  // ex:
    11  //
    12  //	$> root-split -o out.root -n 10 ./testdata/chain.flat.1.root
    13  //
    14  // options:
    15  //
    16  //	-n int
    17  //	  	number of events to split into (default 100)
    18  //	-o string
    19  //	  	path to output ROOT files (default "out.root")
    20  //	-t string
    21  //	  	input tree name to split (default "tree")
    22  //	-v	enable verbose mode
    23  package main // import "go-hep.org/x/hep/groot/cmd/root-split"
    24  
    25  import (
    26  	"flag"
    27  	"fmt"
    28  	"log"
    29  	"os"
    30  
    31  	"go-hep.org/x/hep/groot/rcmd"
    32  	_ "go-hep.org/x/hep/groot/riofs/plugin/http"
    33  	_ "go-hep.org/x/hep/groot/riofs/plugin/xrootd"
    34  )
    35  
    36  func main() {
    37  	log.SetPrefix("root-split: ")
    38  	log.SetFlags(0)
    39  
    40  	var (
    41  		oname   = flag.String("o", "out.root", "path to output ROOT files")
    42  		tname   = flag.String("t", "tree", "input tree name to split")
    43  		verbose = flag.Bool("v", false, "enable verbose mode")
    44  		nevts   = flag.Int64("n", 100, "number of events to split into")
    45  	)
    46  
    47  	flag.Usage = func() {
    48  		fmt.Fprintf(
    49  			os.Stderr,
    50  			`Usage: root-split [options] file.root
    51  
    52  ex:
    53   $> root-split -o out.root -n 10 ./testdata/chain.flat.1.root
    54  
    55  options:
    56  `,
    57  		)
    58  		flag.PrintDefaults()
    59  	}
    60  
    61  	flag.Parse()
    62  
    63  	if flag.NArg() != 1 {
    64  		flag.Usage()
    65  		log.Fatalf("missing input file")
    66  	}
    67  
    68  	fname := flag.Arg(0)
    69  
    70  	_, err := rcmd.Split(*oname, fname, *tname, *nevts, *verbose)
    71  	if err != nil {
    72  		log.Fatalf("could not split ROOT file: %+v", err)
    73  	}
    74  }