Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
readEvtFile.cc
Go to the documentation of this file.
3#include "TFile.h"
4#include "TTree.h"
5#include <iostream>
6
7int main(int argc, char* argv[]){
8using namespace std;
9 if (argc != 2) {
10 cout << "usage: readEvtFile file.root" << endl;
11 return 1;
12 }
13 //TFile::Open works with local and remote files (xrootd)
14 TFile *f1 = TFile::Open(argv[1]);
15 //check that file is open
16 if (f1 == nullptr) {
17 cerr << "File can't be open." << endl;
18 return 1;
19 }
20 //TTree *EvtTree = (TTree*)f1->Get("E");
21 TTree *EvtTree = (TTree*)f1->Get(TTREE_OFFLINE_EVENT); // TTREE_OFFLINE_EVENT is in km3net-dataformat/definitions/root.hh
22 if (EvtTree == 0) {
23 cerr << "File has no " << TTREE_OFFLINE_EVENT << " tree." << endl;
24 return 1;
25 }
26 Evt *evt = nullptr;
27 EvtTree->SetBranchAddress("Evt",&evt);
28 Long64_t nentries = EvtTree->GetEntries();
29 for (Long64_t i=0; i<nentries; i++) {
30 EvtTree->GetEntry(i);
31 cout << "Event ID: " << evt->id << endl; //an example of accessing Evt struct object
32 evt->print(); //an example of using Evt struct function
33 }
34 f1->Close();
35 return 0;
36}
int main(int argc, char *argv[])
Definition readEvtFile.cc:7
static const char *const TTREE_OFFLINE_EVENT
ROOT TTree name.
Definition root.hh:19
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
void print(std::ostream &out=std::cout) const
Print event.
Definition Evt.hh:74
int id
offline event identifier
Definition Evt.hh:22