8 #include "cetlib/container_algorithms.h" 9 #include "cetlib/exempt_ptr.h" 14 #include "boost/program_options.hpp" 32 namespace bpo = boost::program_options;
37 using std::back_inserter;
53 sqlite3_prepare_v2(db,
"PRAGMA page_size;", -1, &stmt,
nullptr);
55 size_t page_size = sqlite3_column_int64(stmt, 0);
56 sqlite3_finalize(stmt);
57 sqlite3_prepare_v2(db,
"PRAGMA page_count;", -1, &stmt,
nullptr);
59 size_t page_count = sqlite3_column_int64(stmt, 0);
60 sqlite3_finalize(stmt);
61 return page_size * page_count;
69 std::vector<std::string> units = {
"b",
"KiB",
"MiB",
"GiB",
"TiB"};
70 auto unit = units.cbegin(),
end = units.cend();
71 while (size > 1024.0 && unit !=
end) {
75 std::ostringstream
ss;
76 ss << std::fixed << std::setprecision(1) << size <<
" " << *unit;
100 throw std::string(
"INTERNAL ERROR: unknown mode ")
104 return (filters.empty() || label.empty() || cet::search_all(filters, label)) ?
115 result.
erase(
"module_label");
118 result.
erase(
"service_type");
119 result.
erase(
"service_provider");
122 result.
erase(
"process_name");
125 throw std::string(
"INTERNAL ERROR: unknown mode ")
140 TTree* metadata_tree =
142 if (!metadata_tree) {
143 errors <<
"Unable to find the metadata tree in file '" << file.GetName()
144 <<
"';\nthis may not be an ART event data file.\n";
147 if (metadata_tree->GetBranch(
148 art::rootNames::metaBranchRootName<ParameterSetMap>())) {
149 metadata_tree->SetBranchAddress(
150 art::rootNames::metaBranchRootName<ParameterSetMap>(), &psm_address);
154 metadata_tree->SetBranchAddress(
155 art::rootNames::metaBranchRootName<art::FileFormatVersion>(), &ffv_address);
156 long bytes_read = metadata_tree->GetEntry(0);
157 if (bytes_read < 0) {
158 errors <<
"Unable to read the metadata tree in file '" << file.GetName()
159 <<
";\nthis file appears to be corrupted.\n";
164 if (ffv.
era_ != expected_era) {
165 errors <<
"Can only read files written during the \"" << expected_era
168 <<
"\"" << file.GetName() <<
"\" was " 169 << (ffv.
era_.empty() ?
"not set" : (
"set to \"" + ffv.
era_ +
"\" "))
173 for (
auto const& pr : psm) {
182 std::cout <<
"# Read SQLiteDB from file, total size: " 212 errors <<
"Unable to to read parameter sets.\n";
223 std::map<std::string, cet::exempt_ptr<fhicl::ParameterSet const>> sorted_pses;
224 for (
auto const& pr : collection) {
225 auto const& pset = pr.second;
230 sorted_pses.emplace(
label, &pset);
233 for (
auto const& pr : sorted_pses) {
234 auto const& pset = *pr.second;
235 output << pr.first <<
": {\n";
260 for (
auto const& file_name : file_names) {
261 std::unique_ptr<TFile> current_file{TFile::Open(file_name.c_str(),
"READ")};
262 if (!current_file || current_file->IsZombie()) {
264 errors <<
"Unable to open file '" << file_name <<
"' for reading." 265 <<
"\nSkipping to next file.\n";
267 std::cout <<
"=============================================\n";
268 std::cout <<
"Processing file: " << file_name << std::endl;
281 std::ostringstream descstr;
282 descstr << argv[0] <<
" <PsetType> <options> [<source-file>]+";
283 bpo::options_description desc(descstr.str());
286 bpo::value<stringvec>()->composing(),
287 "Only entities whose identifier (label (M), service type (S) " 288 "or process name (P)) match (multiple OK).")(
"help,h",
289 "this help message.")(
290 "modules,M",
"PsetType: print module configurations (default).")(
292 bpo::value<stringvec>()->composing(),
293 "source data file (multiple OK).")(
294 "services,S",
"PsetType: print service configurations.")(
295 "process,P",
"PsetType: print process configurations.");
296 bpo::options_description all_opts(
"All Options.");
300 bpo::positional_options_description pd;
301 pd.add(
"source", -1);
303 bpo::variables_map vm;
305 bpo::store(bpo::command_line_parser(argc, argv)
313 std::cerr <<
"Exception from command line processing in " << argv[0] <<
": " 317 if (vm.count(
"help")) {
318 std::cout << desc << std::endl;
324 if (vm.count(
"services")) {
326 }
else if (vm.count(
"process")) {
334 if (vm.count(
"filter")) {
335 cet::copy_all(vm[
"filter"].as<stringvec>(), std::back_inserter(filters));
340 size_t file_count = vm.count(
"source");
341 if (file_count < 1) {
342 cerr <<
"ERROR: One or more input files must be specified;" 343 <<
" supply filenames as program arguments\n" 344 <<
"For usage and options list, please do 'config_dumper --help'.\n";
347 file_names.reserve(file_count);
348 cet::copy_all(vm[
"source"].as<stringvec>(), std::back_inserter(file_names));
bool read_all_parameter_sets(TFile &file, ostream &errors)
ParameterSet strip_pset(ParameterSet const &ps, PsetType mode)
static ParameterSetID const & put(ParameterSet const &ps)
static collection_type const & get() noexcept
void make_ParameterSet(intermediate_table const &tbl, ParameterSet &ps)
std::vector< std::string > stringvec
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
std::string const & metaDataTreeName()
size_t db_size(sqlite3 *db)
std::string to_indented_string() const
vector< string > stringvec
bool get_if_present(std::string const &key, T &value) const
int print_pset_from_file(TFile &file, stringvec const &filters, PsetType const mode, ostream &output, ostream &errors)
int print_psets_from_files(stringvec const &file_names, stringvec const &filters, PsetType const mode, ostream &output, ostream &errors)
std::string const & getFileFormatEra()
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
int main(int argc, char *argv[])
std::string db_size_hr(sqlite3 *db)
std::string want_pset(ParameterSet const &ps, stringvec const &filters, PsetType mode)
bool erase(std::string const &key)
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
std::map< fhicl::ParameterSetID, ParameterSetBlob > ParameterSetMap
static void importFrom(sqlite3 *db)