5 #include "boost/program_options.hpp" 8 #include "cetlib/HorizontalRule.h" 9 #include "cetlib/container_algorithms.h" 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);
126 main(
int argc,
char* argv[])
try {
130 std::ostringstream descstr;
131 descstr << argv[0] <<
" <options> [<source-file>]+";
133 bpo::options_description desc{descstr.str()};
134 desc.add_options()(
"help,h",
"produce help message")(
135 "full-path",
"print full path of file name")(
136 "event-list",
"print event-list for each input file")(
137 "file-index",
"prints FileIndex object for each input file")(
139 "prints list of processes that produced this file (output given in " 140 "chronological order)")(
142 bpo::value<string>()->implicit_value(
"full"),
143 "prints range of validity for each input file. Allowed values are\n" 144 " \"full\" (default)\n" 145 " \"compact\"")(
"branch-ids,B",
146 "prints BranchID lists stored in the file")(
148 (
"Writes RootFileDB to external SQLite database with the same base name as the input file and the suffix '.db'.\n"s +
149 "(Writes to directory in which '"s + argv[0] +
"' is executed)."s)
151 "source,s", bpo::value<stringvec>(),
"source data file (multiple OK)");
153 bpo::options_description all_opts{
"All Options"};
158 bpo::positional_options_description pd;
159 pd.add(
"source", -1);
161 bpo::variables_map vm;
163 bpo::store(bpo::command_line_parser(argc, argv)
171 std::cerr <<
"Exception from command line processing in " << argv[0] <<
": " 176 if (vm.count(
"help")) {
177 std::cout << desc << std::endl;
183 size_t const file_count{vm.count(
"source")};
184 if (file_count < 1) {
185 std::cerr <<
"One or more input files must be specified;" 186 <<
" supply filenames as program arguments\n" 187 <<
"For usage and options list, please do '" << argv[0]
191 file_names.reserve(file_count);
192 cet::copy_all(vm[
"source"].as<stringvec>(), std::back_inserter(file_names));
195 PrintProcessHistory = 0,
197 PrintRangeSetsCompact,
206 std::bitset<NumOptions> options;
207 options[PrintProcessHistory] = vm.count(
"process-history") > 0;
208 if (vm.count(
"range-of-validity") > 0) {
209 auto const& rov_value = vm[
"range-of-validity"].as<std::string>();
210 if (rov_value ==
"full") {
211 options.set(PrintRangeSetsFull);
212 }
else if (rov_value ==
"compact") {
213 options.set(PrintRangeSetsCompact);
216 <<
"Incorrect argument value supplied for the 'range-of-validity'\n" 217 <<
"program option. Allowed values are:\n" 218 <<
" \"full\" (default)\n" 223 options[PrintEventList] = vm.count(
"event-list") > 0;
224 options[PrintFileIndex] = vm.count(
"file-index") > 0;
225 options[SaveDBtoFile] = vm.count(
"db-to-file") > 0;
226 options[FullPath] = vm.count(
"full-path") > 0;
227 options[PrintBranchIDLists] = vm.count(
"branch-ids") > 0;
229 if (options.none()) {
230 std::cerr <<
"No options were specified for processing input files.\n" 231 <<
"For usage and options list, please do '" << argv[0]
236 if (options.test(PrintEventList) && options.test(PrintFileIndex)) {
238 <<
"The --event-list and --file-index options are mutually exclusive.\n";
245 ostream& output = std::cout;
246 ostream& errors = std::cerr;
249 for (
auto const& fn : file_names) {
250 auto const& printed_name =
251 options.test(FullPath) ? fn : fn.substr(fn.find_last_of(
'/') + 1ul);
252 output << cet::HorizontalRule{30}(
'=') <<
'\n' 253 <<
"File: " << printed_name <<
'\n';
255 if (options.test(PrintProcessHistory))
257 if (options.test(PrintRangeSetsFull))
259 if (options.test(PrintRangeSetsCompact))
261 if (options.test(PrintFileIndex))
263 if (options.test(PrintEventList))
265 if (options.test(SaveDBtoFile))
267 if (options.test(PrintBranchIDLists))
274 std::cerr << e.what() <<
'\n';
278 std::cerr <<
"Exception thrown for the last processed file. Please remove " 279 "it from the file list.\n";
295 bool const compactRanges)
325 TFile* current_file = file.
tfile();
326 std::string
const& rootFileName = current_file->GetName();
329 std::string::size_type
const dist{rootFileName.find(
".root") -
330 rootFileName.find_last_of(
'/')};
331 std::string
const base{
332 rootFileName.substr(rootFileName.find_last_of(
'/') + 1, dist)};
333 std::string
const extFileName{base +
"db"};
336 int const rc{dbToFile(db, extFileName.c_str())};
338 output <<
"\nRootFileDB from file \"" << current_file->GetName() <<
"\"\n" 339 <<
"saved to external database file \"" << extFileName <<
"\".\n";
341 errors <<
"\nCould not save RootFileDB from file \"" 342 << current_file->GetName() <<
"\"\n" 343 <<
"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)
cet::coded_exception< error, detail::translate > exception