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