11 #include "boost/program_options.hpp" 23 namespace bpo = boost::program_options;
30 pluralize(std::size_t count,
35 ((count == 1) ? singular : plural))
53 TFile*
tf = TFile::Open(fileName.c_str());
56 err << fileName <<
"\tCould not be opened by ROOT: skipped.\n";
59 std::array<std::size_t, art::NumBranchTypes> counters{{0}};
64 TTree*
tree =
static_cast<TTree*
>(tf->Get(treeName.c_str()));
66 err << fileName <<
"\tNot a valid art ROOT-format file: skipped.\n";
69 counters[
i] = tree->GetEntries();
72 auto tree =
static_cast<TTree*
>(
74 if (tree && (tree->GetNbranches() > 1)) {
79 os << fileName <<
"\t" << pluralize(counters[
art::InRun],
"run") <<
", " 81 << pluralize(counters[
art::InEvent],
"event") <<
", and " 84 os << fileName <<
'\t' << counters[
art::InRun] <<
'\t' 95 using stringvec = std::vector<std::string>;
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.");
108 bpo::positional_options_description pd;
109 pd.add(
"source", -1);
111 bpo::variables_map vm;
113 bpo::store(bpo::command_line_parser(argc, argv)
121 std::cerr <<
"Exception from command line processing in " << argv[0] <<
": " 125 if (vm.count(
"help")) {
126 std::cerr << desc << std::endl;
128 }
else if (vm.count(
"hr")) {
131 if (vm.count(
"source") == 0) {
132 std::cerr <<
"Require at least one source file.\n";
133 std::cerr << desc <<
"\n";
138 auto succeeded = std::count_if(
sources.cbegin(),
141 std::placeholders::_1,
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;
150 std::cout <<
"Failed to count events for " << expected - succeeded <<
" of " 151 << expected <<
" specified files." << std::endl;
153 return result & 0xff;
std::string const & BranchTypeToProductTreeName(BranchType const bt)
std::vector< std::string > stringvec
def count_events(folder, key)
std::ostream & operator<<(std::ostream &os, Analyzer::Table< T > const &t)
int main(int argc, char **argv)
std::string to_string(ModuleType const mt)