go-hep.org/x/hep@v0.38.1/groot/riofs/gendata/gen-tdatime.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", "tdatime.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(class+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 class = ` 31 #ifndef EVENT_H 32 #define EVENT_H 1 33 34 #include "TObject.h" 35 #include "TDatime.h" 36 37 class TFoo : public TObject { 38 public: 39 TDatime d; 40 ClassDef(TFoo, 1) 41 }; 42 43 class TBar : public TObject { 44 public: 45 TDatime d; 46 47 // pad object to increase its size to fit version header that 48 // TDatime doesn't stream. 49 char pad[6] = "12345"; 50 ClassDef(TBar, 1); 51 }; 52 53 class Date { 54 public: 55 TDatime d; 56 57 // pad object to increase its size to fit version header that 58 // TDatime doesn't stream. 59 char pad[6] = "12345"; 60 ClassDef(Date, 1); 61 }; 62 63 #endif // EVENT_H 64 ` 65 66 const script = ` 67 #include "TFile.h" 68 #include "TTree.h" 69 70 void gentree(const char* fname, int splitlvl = 99) { 71 int bufsize = 32000; 72 int evtmax = 2; 73 74 auto f = TFile::Open(fname, "RECREATE"); 75 auto t = new TTree("tree", "my tree title"); 76 77 auto tda = TDatime(2006, 1, 2, 15, 4, 5); 78 TFoo foo; foo.d = tda; 79 TBar bar; bar.d = tda; 80 Date dat; dat.d = tda; 81 82 f->WriteObjectAny(&tda, "TDatime", "tda"); 83 f->WriteTObject(&foo, "foo"); 84 f->WriteTObject(&bar, "bar"); 85 f->WriteObjectAny(&dat, "Date", "dat"); 86 87 t->Branch("b0", &tda, bufsize, splitlvl); 88 t->Branch("b1", &foo, bufsize, splitlvl); 89 t->Branch("b2", &bar, bufsize, splitlvl); 90 t->Branch("b3", &dat, bufsize, splitlvl); 91 92 for (int i = 0; i != evtmax; i++) { 93 tda.Set(2006, 1, 2+i, 15, 4, 5); 94 foo.d.Set(2006, 1, 2+i, 15, 4, 5); 95 bar.d.Set(2006, 1, 2+i, 15, 4, 5); 96 dat.d.Set(2006, 1, 2+i, 15, 4, 5); 97 t->Fill(); 98 } 99 100 f->Write(); 101 f->Close(); 102 103 exit(0); 104 } 105 `