LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
count_events.cc File Reference
#include "canvas/Persistency/Provenance/BranchType.h"
#include "canvas/Persistency/Provenance/rootNames.h"
#include "boost/program_options.hpp"
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include "TBranch.h"
#include "TError.h"
#include "TFile.h"
#include "TTree.h"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 93 of file count_events.cc.

References e.

94 {
95  using stringvec = std::vector<std::string>;
96  int result = 1;
97  std::ostringstream descstr;
98  descstr << argv[0] << "Usage: count_events [<options>] <filename>+\n";
99  bpo::options_description desc(descstr.str());
100  desc.add_options()("hr", "Human-readable output")(
101  "help,h", "this help message.")("source,s",
102  bpo::value<stringvec>()->composing(),
103  "source data file (multiple OK).");
104  bpo::options_description all_opts("All Options.");
105  all_opts.add(desc);
106  // Each non-option argument is interpreted as the name of a file to be
107  // processed. Any number of filenames is allowed.
108  bpo::positional_options_description pd;
109  pd.add("source", -1);
110  // The variables_map contains the actual program options.
111  bpo::variables_map vm;
112  try {
113  bpo::store(bpo::command_line_parser(argc, argv)
114  .options(all_opts)
115  .positional(pd)
116  .run(),
117  vm);
118  bpo::notify(vm);
119  }
120  catch (bpo::error const& e) {
121  std::cerr << "Exception from command line processing in " << argv[0] << ": "
122  << e.what() << "\n";
123  return 2;
124  }
125  if (vm.count("help")) {
126  std::cerr << desc << std::endl;
127  return 1;
128  } else if (vm.count("hr")) {
129  want_hr = true;
130  }
131  if (vm.count("source") == 0) {
132  std::cerr << "Require at least one source file.\n";
133  std::cerr << desc << "\n";
134  return 1;
135  }
136  auto const& sources = vm["source"].as<stringvec>();
137  auto const expected = sources.size();
138  auto succeeded = std::count_if(sources.cbegin(),
139  sources.cend(),
140  std::bind(&count_events,
141  std::placeholders::_1,
142  std::ref(std::cout),
143  std::ref(std::cerr)));
144  if (expected == static_cast<size_t>(succeeded)) {
145  std::cout << "Counted events successfully for " << expected
146  << " specified files." << std::endl;
147  result = 0;
148  } else {
149  result = 1;
150  std::cout << "Failed to count events for " << expected - succeeded << " of "
151  << expected << " specified files." << std::endl;
152  }
153  return result & 0xff;
154 }
std::vector< std::string > stringvec
Float_t e
Definition: plot.C:34