Typedefs | Functions
file_info_dumper.cc File Reference
#include "art/Framework/IO/Root/GetFileFormatEra.h"
#include "art/Framework/IO/Root/RootDB/SQLite3Wrapper.h"
#include "art/Framework/IO/Root/RootDB/tkeyvfs.h"
#include "art/Framework/IO/Root/detail/InfoDumperInputFile.h"
#include "boost/program_options.hpp"
#include "canvas/Persistency/Provenance/FileFormatVersion.h"
#include "canvas/Persistency/Provenance/rootNames.h"
#include "cetlib/HorizontalRule.h"
#include "cetlib/container_algorithms.h"
#include "TError.h"
#include "TFile.h"
#include "sqlite3.h"
#include <algorithm>
#include <bitset>
#include <iostream>
#include <ostream>
#include <sstream>
#include <string>

Go to the source code of this file.

Typedefs

using stringvec = vector< string >
 

Functions

int print_process_history (InfoDumperInputFile const &file, ostream &output)
 
int print_range_sets (InfoDumperInputFile const &file, ostream &output, bool compact)
 
int print_event_list (InfoDumperInputFile const &file, ostream &output)
 
int print_file_index (InfoDumperInputFile const &file, ostream &output)
 
int print_branchIDLists (InfoDumperInputFile const &file, ostream &output)
 
int db_to_file (InfoDumperInputFile const &file, ostream &output, ostream &errors)
 
int main (int argc, char *argv[])
 

Typedef Documentation

using stringvec = vector<string>

Definition at line 32 of file file_info_dumper.cc.

Function Documentation

int db_to_file ( InfoDumperInputFile const &  file,
ostream &  output,
ostream &  errors 
)

Definition at line 324 of file file_info_dumper.cc.

325 {
326  TFile* current_file = file.tfile();
327  std::string const& rootFileName = current_file->GetName();
328 
329  // db file name has the same base as the input art/ROOT file
330  std::string::size_type const dist{rootFileName.find(".root") -
331  rootFileName.find_last_of('/')};
332  std::string const base{
333  rootFileName.substr(rootFileName.find_last_of('/') + 1, dist)};
334  std::string const extFileName{base + "db"};
335 
336  art::SQLite3Wrapper db{current_file, "RootFileDB"};
337  int const rc{dbToFile(db, extFileName.c_str())};
338  if (rc == 0) {
339  output << "\nRootFileDB from file \"" << current_file->GetName() << "\"\n"
340  << "saved to external database file \"" << extFileName << "\".\n";
341  } else {
342  errors << "\nCould not save RootFileDB from file \""
343  << current_file->GetName() << "\"\n"
344  << "to external database file.\n";
345  }
346  return rc;
347 }
std::string string
Definition: nybbler.cc:12
int main ( int  argc,
char *  argv[] 
)

Definition at line 127 of file file_info_dumper.cc.

127  {
128  // ------------------
129  // use the boost command line option processing library to help out
130  // with command line options
131  std::ostringstream descstr;
132  descstr << argv[0] << " <options> [<source-file>]+";
133 
134  bpo::options_description desc{descstr.str()};
135  desc.add_options()("help,h", "produce help message")(
136  "full-path", "print full path of file name")(
137  "event-list", "print event-list for each input file")(
138  "file-index", "prints FileIndex object for each input file")(
139  "process-history",
140  "prints list of processes that produced this file (output given in "
141  "chronological order)")(
142  "range-of-validity",
143  bpo::value<string>()->implicit_value("full"),
144  "prints range of validity for each input file. Allowed values are\n"
145  " \"full\" (default)\n"
146  " \"compact\"")("branch-ids,B",
147  "prints BranchID lists stored in the file")(
148  "db-to-file",
149  ("Writes RootFileDB to external SQLite database with the same base name as the input file and the suffix '.db'.\n"s +
150  "(Writes to directory in which '"s + argv[0] + "' is executed)."s)
151  .c_str())(
152  "source,s", bpo::value<stringvec>(), "source data file (multiple OK)");
153 
154  bpo::options_description all_opts{"All Options"};
155  all_opts.add(desc);
156 
157  // Each non-option argument is interpreted as the name of a files to
158  // be processed. Any number of filenames is allowed.
159  bpo::positional_options_description pd;
160  pd.add("source", -1);
161  // The variables_map contains the actual program options.
162  bpo::variables_map vm;
163  try {
164  bpo::store(bpo::command_line_parser(argc, argv)
165  .options(all_opts)
166  .positional(pd)
167  .run(),
168  vm);
169  bpo::notify(vm);
170  }
171  catch (bpo::error const& e) {
172  std::cerr << "Exception from command line processing in " << argv[0] << ": "
173  << e.what() << "\n";
174  return 2;
175  }
176 
177  if (vm.count("help")) {
178  std::cout << desc << std::endl;
179  return 1;
180  }
181 
182  // Get the names of the files we will process.
183  stringvec file_names;
184  size_t const file_count{vm.count("source")};
185  if (file_count < 1) {
186  std::cerr << "One or more input files must be specified;"
187  << " supply filenames as program arguments\n"
188  << "For usage and options list, please do '" << argv[0]
189  << " --help'.\n";
190  return 3;
191  }
192  file_names.reserve(file_count);
193  cet::copy_all(vm["source"].as<stringvec>(), std::back_inserter(file_names));
194 
195  enum options_t {
196  PrintProcessHistory = 0,
197  PrintRangeSetsFull,
198  PrintRangeSetsCompact,
199  PrintEventList,
200  PrintFileIndex,
201  SaveDBtoFile,
202  FullPath,
203  PrintBranchIDLists,
204  NumOptions
205  };
206 
207  std::bitset<NumOptions> options;
208  options[PrintProcessHistory] = vm.count("process-history") > 0;
209  if (vm.count("range-of-validity") > 0) {
210  auto const& rov_value = vm["range-of-validity"].as<std::string>();
211  if (rov_value == "full") {
212  options.set(PrintRangeSetsFull);
213  } else if (rov_value == "compact") {
214  options.set(PrintRangeSetsCompact);
215  } else {
216  std::cerr
217  << "Incorrect argument value supplied for the 'range-of-validity'\n"
218  << "program option. Allowed values are:\n"
219  << " \"full\" (default)\n"
220  << " \"compact\"\n";
221  return 4;
222  }
223  }
224  options[PrintEventList] = vm.count("event-list") > 0;
225  options[PrintFileIndex] = vm.count("file-index") > 0;
226  options[SaveDBtoFile] = vm.count("db-to-file") > 0;
227  options[FullPath] = vm.count("full-path") > 0;
228  options[PrintBranchIDLists] = vm.count("branch-ids") > 0;
229 
230  if (options.none()) {
231  std::cerr << "No options were specified for processing input files.\n"
232  << "For usage and options list, please do '" << argv[0]
233  << " --help'.\n";
234  return 5;
235  }
236 
237  if (options.test(PrintEventList) && options.test(PrintFileIndex)) {
238  std::cerr
239  << "The --event-list and --file-index options are mutually exclusive.\n";
240  return 6;
241  }
242 
243  SetErrorHandler(RootErrorHandler);
244  tkeyvfs_init();
245 
246  ostream& output = std::cout;
247  ostream& errors = std::cerr;
248 
249  int rc{0};
250  for (auto const& fn : file_names) {
251  auto const& printed_name =
252  options.test(FullPath) ? fn : fn.substr(fn.find_last_of('/') + 1ul);
253  output << cet::HorizontalRule{30}('=') << '\n'
254  << "File: " << printed_name << '\n';
255  InfoDumperInputFile const file{fn};
256  if (options.test(PrintProcessHistory))
257  rc += print_process_history(file, output);
258  if (options.test(PrintRangeSetsFull))
259  rc += print_range_sets(file, output, false);
260  if (options.test(PrintRangeSetsCompact))
261  rc += print_range_sets(file, output, true);
262  if (options.test(PrintFileIndex))
263  rc += print_file_index(file, output);
264  if (options.test(PrintEventList))
265  rc += print_event_list(file, output);
266  if (options.test(SaveDBtoFile))
267  rc += db_to_file(file, output, errors);
268  if (options.test(PrintBranchIDLists))
269  rc += print_branchIDLists(file, output);
270  output << '\n';
271  }
272  return rc;
273 }
274 catch (cet::exception const& e) {
275  std::cerr << e.what() << '\n';
276  return 7;
277 }
278 catch (...) {
279  std::cerr << "Exception thrown for the last processed file. Please remove "
280  "it from the file list.\n";
281  return 8;
282 }
std::string string
Definition: nybbler.cc:12
int print_range_sets(InfoDumperInputFile const &file, ostream &output, bool compact)
int print_file_index(InfoDumperInputFile const &file, ostream &output)
void RootErrorHandler(int level, bool die, char const *location, char const *message)
std::vector< std::string > stringvec
int print_branchIDLists(InfoDumperInputFile const &file, ostream &output)
error
Definition: includer.cc:31
const double e
int print_event_list(InfoDumperInputFile const &file, ostream &output)
int db_to_file(InfoDumperInputFile const &file, ostream &output, ostream &errors)
int tkeyvfs_init(void)
Definition: tkeyvfs.cc:1768
int print_process_history(InfoDumperInputFile const &file, ostream &output)
auto copy_all(FwdCont &, FwdIter)
static const double s
Definition: Units.h:99
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
unsigned int run
int print_branchIDLists ( InfoDumperInputFile const &  file,
ostream &  output 
)

Definition at line 317 of file file_info_dumper.cc.

318 {
319  file.print_branchIDLists(output);
320  return 0;
321 }
int print_event_list ( InfoDumperInputFile const &  file,
ostream &  output 
)

Definition at line 303 of file file_info_dumper.cc.

304 {
305  file.print_event_list(output);
306  return 0;
307 }
int print_file_index ( InfoDumperInputFile const &  file,
ostream &  output 
)

Definition at line 310 of file file_info_dumper.cc.

311 {
312  file.print_file_index(output);
313  return 0;
314 }
int print_process_history ( InfoDumperInputFile const &  file,
ostream &  output 
)

Definition at line 287 of file file_info_dumper.cc.

288 {
289  file.print_process_history(output);
290  return 0;
291 }
int print_range_sets ( InfoDumperInputFile const &  file,
ostream &  output,
bool  compact 
)

Definition at line 294 of file file_info_dumper.cc.

297 {
298  file.print_range_sets(output, compactRanges);
299  return 0;
300 }