BmnRoot 26.10.0-210-gc52d34b0
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
count_events.C
Go to the documentation of this file.
1/*
2 BM@N alignment routine
3 BM@N experiment at NICA complex, JINR, 2025
4
5 Department: Math & Soft Group of HEP lab
6 Author: Igor Polev, polev@jinr.int
7
8 Count number of events in a ROOT file
9*/
10
11// headers below are for IDE syntax to work and they will be
12// turned off during execution in ROOT macro mode
13#ifndef __CLING__
14#include "TCollection.h"
15#include "TFile.h"
16#include "TKey.h"
17#include "TObject.h"
18#include "TTree.h"
19#endif
20
21void count_events(const char* filename)
22{
23 TFile* f = TFile::Open(filename, "READ");
24 if (!f || f->IsZombie()) {
25 printf("0\n");
26 return;
27 }
28 TIter next(f->GetListOfKeys());
29 TKey* key;
30 while ((key = (TKey*)next())) {
31 TObject* obj = key->ReadObj();
32 if (obj && obj->InheritsFrom(TTree::Class())) {
33 // print out the answer
34 printf("%lld\n", ((TTree*)obj)->GetEntries());
35 f->Close();
36 return;
37 }
38 }
39 printf("0\n");
40 f->Close();
41}
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
virtual TObject * ReadObj()
virtual Bool_t InheritsFrom(const char *classname) const
static TClass * Class()
void count_events(const char *filename)