Skip to content

Instantly share code, notes, and snippets.

@sbinet
Created April 30, 2018 13:15
Show Gist options
  • Save sbinet/f79eb6a28f572b82c35e8c450813bcd1 to your computer and use it in GitHub Desktop.
Save sbinet/f79eb6a28f572b82c35e8c450813bcd1 to your computer and use it in GitHub Desktop.
ROOT I/O

Reading ROOT data benchmarks

  • write a benchmark for reading ROOT files (with the Scanner types)
  • input file generated with the attached C++ program
    • /data/f64s-scalar.root on clrmastergo

ROOT I/O main classes

ROOT output implementation

  • Creation of a simple ROOT file readable by ROOT C++ and Go-HEP/rootio
    • write a ROOT file that is empty (but contains the needed information(s) to be interpretable and readable by C++ and Go)
    • write a ROOT file that contains a TObjString of name "foo" and title "bar"
    • write a ROOT file that only contains a TH1D (a 1-dimension histogram filled with Doubles)
#include <string>
#include "TTree.h"
#include "TFile.h"
#include "TRandom.h"
#include "TString.h"
int main(int argc, char **argv) {
auto f = TFile::Open("f64s.root", "recreate");
f->SetCompressionLevel(0);
auto t = new TTree("tree","tree");
const Long_t EVTMAX = 1000000;
const Long_t BRANCHES = 1;
const std::string fname = "f64s.root";
Double_t v[BRANCHES];
for (int i = 0; i < BRANCHES; i++) {
auto n = TString::Format("Scalar_%d", i);
auto b = TString::Format("Scalar_%d/D", i);
t->Branch(n, &v[i], b);
}
for ( Long_t i = 0; i <EVTMAX;i++) {
for (int j = 0; j < BRANCHES; j++) {
v[j]=gRandom->Gaus();
}
t->Fill();
}
f->Write();
f->Close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment