Belle II Software light-2406-ragdoll
numberOfEventsInBelle2Mdst.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <framework/logging/Logger.h>
10#include <framework/dataobjects/FileMetaData.h>
11
12#include <TFile.h>
13#include <TTree.h>
14
15#include <boost/program_options.hpp>
16
17#include <csignal>
18#include <string>
19#include <iostream>
20
21using namespace std;
22using namespace Belle2;
23namespace po = boost::program_options;
24
25int main(int argc, char* argv[])
26{
27 //remove SIGPIPE handler set by ROOT which sometimes caused infinite loops
28 //See https://savannah.cern.ch/bugs/?97991
29 //default action is to abort
30 if (signal(SIGPIPE, SIG_DFL) == SIG_ERR) {
31 B2FATAL("Cannot remove SIGPIPE signal handler");
32 }
33
34 std::string filename;
35 po::options_description description("Options");
36 description.add_options()
37 ("filename", po::value<std::string>(&filename), "belle 2 mdst file");
38 po::variables_map vm;
39 po::positional_options_description p;
40 p.add("filename", -1);
41
42 try {
43 po::parsed_options parsed = po::command_line_parser(argc, argv).options(description).positional(p).run();
44 po::store(parsed, vm);
45
46 if (vm.count("help")) {
47 std::cout << description << std::endl;
48 return 1;
49 }
50 po::notify(vm);
51 } catch (po::error& err) {
52 std::cerr << "Error: " << err.what() << "\n";
53 return 1;
54 }
55
56 FileMetaData metaData;
57 FileMetaData* metaDataPtr = &metaData;
58
59 //Check for file option
60 TFile* file = TFile::Open(filename.c_str(), "READ");
61 if (!file || !file->IsOpen()) {
62 B2ERROR("Couldn't open file " << filename);
63 return 1;
64 }
65 TTree* tree = (TTree*) file->Get("persistent");
66 if (!tree) {
67 B2ERROR("No tree persistent found in " << filename);
68 return 1;
69 }
70 TBranch* branch = tree->GetBranch("FileMetaData");
71 if (!branch) {
72 B2ERROR("No meta data found in " << filename);
73 return 1;
74 }
75
76 branch->SetAddress(&metaDataPtr);
77 tree->GetEntry(0);
78 std::cout << metaDataPtr->getNEvents() << std::endl;
79
80 return 0;
81}
82
Metadata information about a file.
Definition: FileMetaData.h:29
unsigned int getNEvents() const
Number of events getter.
Definition: FileMetaData.h:41
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
STL namespace.