Jpp  master_rocky-37-gf0c5bc59d
the software that should make you happy
Functions
readEvtFile.cc File Reference
#include "km3net-dataformat/offline/Evt.hh"
#include "km3net-dataformat/definitions/root.hh"
#include "TFile.h"
#include "TTree.h"
#include <iostream>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 7 of file readEvtFile.cc.

7  {
8 using 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 }
const JPolynome f1(1.0, 2.0, 3.0)
Function.
Definition: JSTDTypes.hh:14
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