Belle II Software  release-05-01-25
numberOfEventsInBelleMdst.cc
1 
6 #include <framework/core/Environment.h>
7 #include <framework/datastore/DataStore.h>
8 #include <framework/datastore/StoreObjPtr.h>
9 #include <framework/utilities/FileSystem.h>
10 
11 #include <framework/logging/Logger.h>
12 
13 #define BELLE_TARGET_H "belle-x86_64-unknown-linux-gnu-g++.h"
14 #include "belle_legacy/panther/panther.h"
15 #include "belle_legacy/panther/panther_group.h"
16 #include "belle_legacy/tables/belletdf.h"
17 
18 #include <boost/program_options.hpp>
19 #include <iostream>
20 #include <cstdlib>
21 #include <algorithm>
22 #include <boost/filesystem.hpp>
23 
24 using namespace std;
25 using namespace Belle2;
26 namespace po = boost::program_options;
27 
28 
29 int main(int argc, char* argv[])
30 {
31 
32  std::string filename;
33  po::options_description description("Options");
34  description.add_options()
35  ("filename", po::value<std::string>(&filename), "belle 1 mdst file");
36  po::variables_map vm;
37  po::positional_options_description p;
38  p.add("filename", -1);
39 
40  try {
41  po::parsed_options parsed = po::command_line_parser(argc, argv).options(description).positional(p).run();
42  po::store(parsed, vm);
43 
44  if (vm.count("help")) {
45  std::cout << description << std::endl;
46  return 1;
47  }
48  po::notify(vm);
49  } catch (po::error& err) {
50  std::cerr << "Error: " << err.what() << "\n";
51  return 1;
52  }
53 
54  // check environment
55  const char* table_dir = getenv("PANTHER_TABLE_DIR");
56  if (!table_dir or !FileSystem::isDir(table_dir)) {
57  string fixed_table_dir = Environment::Instance().getExternalsPath() + "/share/belle_legacy/panther";
58  B2WARNING("PANTHER_TABLE_DIR environment variable not set correctly. This is a known problem with externals v00-05-09, using " <<
59  fixed_table_dir << " instead.");
60  if (!FileSystem::isDir(fixed_table_dir))
61  B2FATAL("Path " << fixed_table_dir << " does not exist, your externals setup seems broken.");
62  setenv("PANTHER_TABLE_DIR", fixed_table_dir.c_str(), 1); //overwrite existing value
63  }
64 
65  // Initialize Panther
66  BsInit(0);
67  // delete existing FileIO
68  BsClrTab(BBS_CLEAR_ALL);
69  // Check if file exists
70  if (!boost::filesystem::exists(filename)) {
71  std::cout << "Couldn't find file!" << std::endl;
72  return 1;
73  }
74 
75  // Open data file
76  Belle::Panther_FileIO* fd = new Belle::Panther_FileIO(filename.c_str(), BBS_READ);
77 
78  // Read first record (does not contain event data)
79  if (fd->read() == -1) {
80  B2FATAL("Couldn't read file '" << filename << "'!");
81  }
82 
83  unsigned int nevt = 0;
84 
85  // read event
86  int rectype = -1;
87  while (rectype > -2) {
88  rectype = -1;
89  while (rectype < 0 && rectype != -2) {
90  //clear all previous event data before reading!
91  BsClrTab(BBS_CLEAR);
92  rectype = fd->read();
93  if (rectype == -1) {
94  B2ERROR("Error while reading panther tables! Record skipped.");
95  }
96  nevt++;
97  }
98  }
99 
100  delete fd;
101 
102  std::cout << static_cast<int>(nevt) - 2 << std::endl;
103  if (rectype == -2) { // EoF detected
104  return 0;
105  }
106 
107 }
main
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:77
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