5 #include "boost/program_options.hpp" 25 namespace bpo = boost::program_options;
54 if (level == kWarning && (!die) &&
55 strcmp(location,
"TClass::TClass") == 0 &&
56 std::string(message).find(
"no dictionary") != std::string::npos) {
60 DefaultErrorHandler(level, die, location, message);
87 dbToFile(sqlite3* pInMemory,
const char* zFilename)
90 sqlite3* pFile{
nullptr};
91 sqlite3_backup* pBackup{
nullptr};
95 rc = sqlite3_open(zFilename, &pFile);
96 if (
rc == SQLITE_OK) {
110 pBackup = sqlite3_backup_init(pFile,
"main", pInMemory,
"main");
111 if (pBackup !=
nullptr) {
112 (void)sqlite3_backup_step(pBackup, -1);
113 (void)sqlite3_backup_finish(pBackup);
115 rc = sqlite3_errcode(pFile);
120 (void)sqlite3_close(pFile);
131 std::ostringstream descstr;
132 descstr << argv[0] <<
" <options> [<source-file>]+";
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")(
140 "prints list of processes that produced this file (output given in " 141 "chronological order)")(
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")(
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)
152 "source,s", bpo::value<stringvec>(),
"source data file (multiple OK)");
154 bpo::options_description all_opts{
"All Options"};
159 bpo::positional_options_description pd;
160 pd.add(
"source", -1);
162 bpo::variables_map vm;
164 bpo::store(bpo::command_line_parser(argc, argv)
172 std::cerr <<
"Exception from command line processing in " << argv[0] <<
": " 177 if (vm.count(
"help")) {
178 std::cout << desc << std::endl;
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]
192 file_names.reserve(file_count);
193 cet::copy_all(vm[
"source"].as<stringvec>(), std::back_inserter(file_names));
196 PrintProcessHistory = 0,
198 PrintRangeSetsCompact,
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);
217 <<
"Incorrect argument value supplied for the 'range-of-validity'\n" 218 <<
"program option. Allowed values are:\n" 219 <<
" \"full\" (default)\n" 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;
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]
237 if (options.test(PrintEventList) && options.test(PrintFileIndex)) {
239 <<
"The --event-list and --file-index options are mutually exclusive.\n";
246 ostream& output = std::cout;
247 ostream& errors = std::cerr;
250 for (
auto const& fn : file_names) {
251 auto const& printed_name =
252 options.test(FullPath) ? fn : fn.substr(fn.find_last_of(
'/') + 1ul);
254 <<
"File: " << printed_name <<
'\n';
256 if (options.test(PrintProcessHistory))
258 if (options.test(PrintRangeSetsFull))
260 if (options.test(PrintRangeSetsCompact))
262 if (options.test(PrintFileIndex))
264 if (options.test(PrintEventList))
266 if (options.test(SaveDBtoFile))
268 if (options.test(PrintBranchIDLists))
275 std::cerr << e.what() <<
'\n';
279 std::cerr <<
"Exception thrown for the last processed file. Please remove " 280 "it from the file list.\n";
296 bool const compactRanges)
326 TFile* current_file = file.
tfile();
327 std::string const& rootFileName = current_file->GetName();
330 std::string::size_type
const dist{rootFileName.find(
".root") -
331 rootFileName.find_last_of(
'/')};
333 rootFileName.substr(rootFileName.find_last_of(
'/') + 1, dist)};
337 int const rc{dbToFile(db, extFileName.c_str())};
339 output <<
"\nRootFileDB from file \"" << current_file->GetName() <<
"\"\n" 340 <<
"saved to external database file \"" << extFileName <<
"\".\n";
342 errors <<
"\nCould not save RootFileDB from file \"" 343 << current_file->GetName() <<
"\"\n" 344 <<
"to external database file.\n";
int main(int argc, char *argv[])
int print_range_sets(InfoDumperInputFile const &file, ostream &output, bool compact)
int print_file_index(InfoDumperInputFile const &file, ostream &output)
std::vector< std::string > stringvec
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
int print_branchIDLists(InfoDumperInputFile const &file, ostream &output)
int print_event_list(InfoDumperInputFile const &file, ostream &output)
int db_to_file(InfoDumperInputFile const &file, ostream &output, ostream &errors)
int print_process_history(InfoDumperInputFile const &file, ostream &output)
auto copy_all(FwdCont &, FwdIter)
cet::coded_exception< error, detail::translate > exception