Belle II Software  release-05-01-25
showbginfo.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 Kuhr, Peter Kvasnicka *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <framework/logging/Logger.h>
12 #include <framework/gearbox/Unit.h>
13 #include <framework/dataobjects/BackgroundMetaData.h>
14 
15 #include <TFile.h>
16 #include <TTree.h>
17 #include <TError.h>
18 
19 #include <boost/program_options.hpp>
20 
21 #include <string>
22 #include <iostream>
23 
24 using namespace std;
25 using namespace Belle2;
26 namespace prog = boost::program_options;
27 
28 int main(int argc, char* argv[])
29 {
30  // Define command line options
31  prog::options_description options("Options");
32  options.add_options()
33  ("help,h", "print available options")
34  ("file,f", prog::value<string>(), "local file name")
35  ;
36 
37  prog::positional_options_description posOptDesc;
38  posOptDesc.add("file", -1);
39 
40  prog::variables_map varMap;
41  prog::store(prog::command_line_parser(argc, argv).
42  options(options).positional(posOptDesc).run(), varMap);
43  prog::notify(varMap);
44 
45  //Check for help option
46  if (varMap.count("help")) {
47  cout << "Usage: " << argv[0] << " [OPTIONS] [FILE]\n";
48  cout << options << endl;
49  return 0;
50  }
51 
52  BackgroundMetaData metaData;
53  BackgroundMetaData* metaDataPtr = &metaData;
54 
55  //Check for file option
56  if (varMap.count("file")) {
57  gErrorIgnoreLevel = kError;
58  string fileName = varMap["file"].as<string>();
59  TFile* file = TFile::Open(fileName.c_str(), "READ");
60  if (!file || !file->IsOpen()) {
61  B2ERROR("Couldn't open file " << fileName);
62  return 1;
63  }
64  TTree* tree = (TTree*) file->Get("persistent");
65  if (!tree) {
66  B2ERROR("No tree persistent found in " << fileName);
67  return 1;
68  }
69  TBranch* branch = tree->GetBranch("BackgroundMetaData");
70  if (!branch) {
71  B2ERROR("No meta data found in " << fileName);
72  return 1;
73  }
74  metaDataPtr = 0;
75  branch->SetAddress(&metaDataPtr);
76  tree->GetEntry(0);
77 
78  } else {
79  B2ERROR("Please specify a file name.");
80  return 1;
81  }
82 
83  cout << "BackgroundMetaData in file " << varMap["file"].as<string>() << ": " << endl;
84  cout << "Background type : " << metaDataPtr->getBackgroundType() << endl;
85  cout << "Real time : " << metaDataPtr->getRealTime() / Unit::us << " us" << endl << endl;
86 
87  return 0;
88 }
89 
Belle2::BackgroundMetaData::getBackgroundType
const std::string & getBackgroundType() const
Returns the type of background.
Definition: BackgroundMetaData.h:116
Belle2::BackgroundMetaData::getRealTime
float getRealTime() const
Returns real time that corresponds to this background sample.
Definition: BackgroundMetaData.h:128
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
Belle2::BackgroundMetaData
Metadata information about the beam background file.
Definition: BackgroundMetaData.h:34