Functions
CountEvents.C File Reference
#include "TFile.h"
#include "TTree.h"
#include "TBranch.h"
#include "TTreeReader.h"
#include "TTreeReaderValue.h"

Go to the source code of this file.

Functions

void CountEvents ()
 

Function Documentation

void CountEvents ( )

Definition at line 7 of file CountEvents.C.

8 {
9  // Variables used to store the data
10  Int_t totalSize = 0; // Sum of data size (in bytes) of all events
11 
12  // open the file
13  TFile *f = TFile::Open("http://lcg-heppkg.web.cern.ch/lcg-heppkg/ROOT/eventdata.root");
14  if (f == 0) {
15  // if we cannot open the file, print an error message and return immediatly
16  printf("Error: cannot open http://lcg-heppkg.web.cern.ch/lcg-heppkg/ROOT/eventdata.root!\n");
17  return;
18  }
19 
20  // Create a tree reader (of type Int_t) on the branch "fEventSize"
21  TTreeReader myReader("EventTree", f);
22  TTreeReaderValue<Int_t> eventSize(myReader, "fEventSize");
23 
24  // Loop over all entries of the TTree or TChain.
25  while (myReader.Next()) {
26  // Get the data from the current TTree entry by getting
27  // the value from the connected reader (eventSize):
28  totalSize += *eventSize;
29  }
30 
31  Int_t sizeInMB = totalSize/1024/1024;
32  printf("Total size of all events: %d MB\n", sizeInMB);
33 }
FILE * f
Definition: loadlibs.C:26