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