11 #include <framework/logging/Logger.h>
12 #include <framework/core/FileCatalog.h>
13 #include <framework/dataobjects/FileMetaData.h>
21 #include <boost/program_options.hpp>
28 namespace prog = boost::program_options;
30 int main(
int argc,
char* argv[])
35 if (signal(SIGPIPE, SIG_DFL) == SIG_ERR) {
36 B2FATAL(
"Cannot remove SIGPIPE signal handler");
40 prog::options_description options(
"Options");
42 (
"help,h",
"print all available options")
43 (
"file,f", prog::value<string>(),
"local file name")
44 (
"lfn,l", prog::value<string>(),
"logical file name")
45 (
"all,a",
"print all information")
46 (
"json",
"print machine-readable information in JSON format. Implies --all and --steering.")
47 (
"steering,s",
"print steering file contents")
50 prog::positional_options_description posOptDesc;
51 posOptDesc.add(
"file", -1);
53 prog::variables_map varMap;
55 prog::store(prog::command_line_parser(argc, argv).
56 options(options).positional(posOptDesc).run(), varMap);
58 }
catch (std::exception& e) {
59 cout <<
"Problem parsing command line: " <<
e.what() << endl;
60 cout <<
"Usage: " << argv[0] <<
" [OPTIONS] [FILE]\n";
61 cout << options << endl;
66 if (varMap.count(
"help") or argc == 1) {
67 cout <<
"Usage: " << argv[0] <<
" [OPTIONS] [FILE]\n";
68 cout << options << endl;
76 if (varMap.count(
"file")) {
77 gErrorIgnoreLevel = kError;
78 string fileName = varMap[
"file"].as<
string>();
79 TFile* file = TFile::Open(fileName.c_str(),
"READ");
80 if (!file || !file->IsOpen()) {
81 B2ERROR(
"Couldn't open file " << fileName);
84 auto* tree = (TTree*) file->Get(
"persistent");
86 B2ERROR(
"No tree persistent found in " << fileName);
89 TBranch* branch = tree->GetBranch(
"FileMetaData");
91 B2ERROR(
"No meta data found in " << fileName);
94 metaDataPtr =
nullptr;
95 branch->SetAddress(&metaDataPtr);
98 }
else if (varMap.count(
"lfn")) {
99 std::string lfn = varMap[
"lfn"].as<
string>();
100 if (!FileCatalog::Instance().getMetaData(lfn, metaData)) {
101 B2ERROR(
"No meta data found in file catalog for LFN " << varMap[
"lfn"].as<int>());
106 B2ERROR(
"Please specify either a file name, a unique ID, or a LFN.");
110 const char* option =
"";
111 if (varMap.count(
"json")) option =
"json";
112 else if (varMap.count(
"all")) option =
"all";
113 metaDataPtr->
Print(option);
114 if (
string(option) !=
"json" and varMap.count(
"steering")) metaDataPtr->
Print(
"steering");