File indexing completed on 2024-04-06 11:56:21
0001 #include "Alignment/Geners/interface/IOException.hh"
0002 #include <cstring>
0003 #include <map>
0004
0005 #include "CmdLine.hh"
0006
0007 #include "Alignment/Geners/interface/stringArchiveIO.hh"
0008
0009 using namespace gs;
0010 using namespace std;
0011
0012 static void print_usage(const char *progname) {
0013 cout << "\nUsage: " << progname << " [-f] [-s] filename\n\n"
0014 << "This program prints the contents of \"geners\" string archives to "
0015 "the standard\n"
0016 << "output. Files which contain string archive can be usually "
0017 "recognised by their\n"
0018 << "extensions \".gssa\" (Generic Serialization String Archive) and "
0019 "\".gssaz\"\n"
0020 << "(string archive with compression). Normally, the program prints "
0021 "item ids,\n"
0022 << "class names, item names, and archive categories for all items in "
0023 "the archive.\n"
0024 << "This default behavior can be modified with option switches. The "
0025 "meaning of\n"
0026 << "the switches is as follows:\n\n"
0027 << " -f Full dump. Print complete info for each catalog entry.\n\n"
0028 << " -s Print only the summary statistics for item types. If option "
0029 "\"-f\" is given\n"
0030 << " together with \"-s\", the summary will be printed after the "
0031 "full dump.\n"
0032 << endl;
0033 }
0034
0035 int main(int argc, char const *argv[]) {
0036 CmdLine cmdline(argc, argv);
0037
0038 if (argc == 1) {
0039 print_usage(cmdline.progname());
0040 return 0;
0041 }
0042
0043 std::string inputfile;
0044 bool fullDump = false;
0045 bool summaryMode = false;
0046
0047 try {
0048 fullDump = cmdline.has("-f");
0049 summaryMode = cmdline.has("-s");
0050
0051 cmdline.optend();
0052
0053 if (cmdline.argc() != 1)
0054 throw CmdLineError("wrong number of command line arguments");
0055 cmdline >> inputfile;
0056 } catch (CmdLineError &e) {
0057 cerr << "Error in " << cmdline.progname() << ": " << e.str() << endl;
0058 print_usage(cmdline.progname());
0059 return 1;
0060 }
0061
0062 StringArchive *ar = 0;
0063 try {
0064 ar = readCompressedStringArchiveExt(inputfile.c_str());
0065 } catch (std::exception &e) {
0066 cerr << "Failed to load string archive from file \"" << inputfile << "\" (" << e.what() << ')' << endl;
0067 return 1;
0068 }
0069
0070 std::map<std::string, unsigned> typecount;
0071
0072 const unsigned long long first = ar->smallestId();
0073 const unsigned long long last = ar->largestId();
0074 for (unsigned long long id = first; id <= last; ++id) {
0075 if (!ar->itemExists(id))
0076 continue;
0077
0078 std::shared_ptr<const CatalogEntry> e = ar->catalogEntry(id);
0079 if (fullDump) {
0080 if (id != first)
0081 cout << '\n';
0082 e->humanReadable(cout);
0083 } else if (!summaryMode)
0084 cout << e->id() << " " << e->type().name() << " " << '"' << e->name() << '"' << " " << '"' << e->category()
0085 << '"' << endl;
0086 if (summaryMode)
0087 typecount[e->type().name()]++;
0088 }
0089
0090 if (summaryMode) {
0091 if (fullDump)
0092 cout << '\n';
0093 for (std::map<std::string, unsigned>::const_iterator it = typecount.begin(); it != typecount.end(); ++it)
0094 cout << it->second << ' ' << it->first << endl;
0095 }
0096
0097 return 0;
0098 }