#include "TString.h" #include "TTree.h" #include "TBranch.h" #include "TFile.h" #include "MyEventClass.hh" using namespace std; int CreateSimpleEventTree(void) { TString name = "MyEventTree"; TString title = "MyEventTree"; TTree *tree = new TTree(name, title); MyEventClass event; MyEventClass::Class()->IgnoreTObjectStreamer(); //this is to remove the TObject branch with fUniqueID and fBits leaves. TBranch *branch = tree->Branch("event.", &event, 32000, 2); branch = branch; // get rid of the "warning: unused variable ‘branch’" for (int i=0;i<10;i++) { event.test_var_01 = i*100 + 1; event.test_var_02 = i*1000 + 2; event.test_string.Form("-> %d <-", i*10 + 3); tree->Fill(); } TFile *OutputFile = new TFile("MyEventTree.root","RECREATE"); tree->Write(); delete tree; delete OutputFile; return 0; }