LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
product_sizes_dumper.cc File Reference
#include "art/Framework/IO/Root/RootSizeOnDisk.h"
#include "boost/program_options.hpp"
#include "cetlib/container_algorithms.h"
#include "TError.h"
#include "TFile.h"
#include <iostream>
#include <memory>
#include <string>

Go to the source code of this file.

Typedefs

typedef std::vector< std::string > stringvec
 

Functions

int main (int argc, char **argv)
 

Typedef Documentation

typedef std::vector<std::string> stringvec

Definition at line 18 of file product_sizes_dumper.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 21 of file product_sizes_dumper.cc.

References e, file, and n.

22 {
23 
24  // Parse and validate command line arguments.
25  // ------------------
26  // use the boost command line option processing library to help out
27  // with command line options
28  std::ostringstream descstr;
29  descstr << argv[0] << " <options> [<source-file>]+";
30  bpo::options_description desc(descstr.str());
31  desc.add_options()("help,h", "this help message.")(
32  "fraction,f",
33  bpo::value<double>()->default_value(0.05, "0.05"),
34  "floating point number on the range [0,1]. "
35  "If a TTree occupies a fraction on disk of the total space in the file "
36  "that is less than <f>, then a detailed analysis of its branches will not "
37  "be done")(
38  "source,s", bpo::value<stringvec>(), "source data file (multiple OK)");
39  bpo::options_description all_opts("All Options.");
40  all_opts.add(desc);
41  // Each non-option argument is interpreted as the name of a file to be
42  // processed. Any number of filenames is allowed.
43  bpo::positional_options_description pd;
44  pd.add("source", -1);
45  // The variables_map contains the actual program options.
46  bpo::variables_map vm;
47  try {
48  bpo::store(bpo::command_line_parser(argc, argv)
49  .options(all_opts)
50  .positional(pd)
51  .run(),
52  vm);
53  bpo::notify(vm);
54  }
55  catch (bpo::error const& e) {
56  std::cerr << "Exception from command line processing in " << argv[0] << ": "
57  << e.what() << "\n";
58  return 2;
59  }
60  if (vm.count("help")) {
61  std::cout << desc << std::endl;
62  return 1;
63  }
64 
65  // Get the desired minimum fraction
66  double minimumFraction(-1.);
67  if (vm.count("fraction")) {
68  minimumFraction = vm["fraction"].as<double>();
69  if (minimumFraction < 0 || minimumFraction > 1) {
70  std::cerr << "Must choose fraction between 0 and 1\n"
71  << "For usage and options list, please do "
72  "'product_sizes_dumper --help'.\n";
73  return 4;
74  }
75  }
76 
77  // Get the names of the files we will process.
78  stringvec file_names;
79  size_t const file_count = vm.count("source");
80  if (file_count < 1) {
81  std::cerr << "One or more input files must be specified;"
82  << " supply filenames as program arguments\n"
83  << "For usage and options list, please do 'product_sizes_dumper "
84  "--help'.\n";
85  return 3;
86  }
87  file_names.reserve(file_count);
88  cet::copy_all(vm["source"].as<stringvec>(), std::back_inserter(file_names));
89 
90  //=================================================================
91  // Separates the output for multiple files.
92  std::string const separator = "\n" + std::string(60, '=') + "\n";
93 
94  int n(-1);
95  for (auto const& filename : file_names) {
96  ++n;
97 
98  if (file_names.size() > 1 && n != 0)
99  std::cout << separator << std::endl;
100 
101  // Suppress warnings messages about "no dictionary".
102  // This is a little dangerous since it might suppress other warnings too ...
103  int errorSave = gErrorIgnoreLevel;
104  gErrorIgnoreLevel = kError;
105  auto file = std::make_unique<TFile>(filename.c_str());
106  gErrorIgnoreLevel = errorSave;
107 
108  // Extract and print the information.
109  art::RootSizeOnDisk info(filename, file.get());
110  file->Close();
111  info.print(std::cout, minimumFraction);
112 
113  // Mark end of output for this file.
114  if (file_names.size() > 1)
115  std::cout << "Done: " << filename << std::endl;
116  }
117 
118  return 0;
119 }
std::vector< std::string > stringvec
TFile * file
Char_t n[5]
Float_t e
Definition: plot.C:34