File indexing completed on 2024-04-06 12:12:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <iostream>
0015 #include <boost/program_options.hpp>
0016 #include "TClass.h"
0017 #include "TBufferFile.h"
0018
0019
0020 #include "FWCore/FWLite/interface/FWLiteEnabler.h"
0021 #include "FWCore/Utilities/interface/Exception.h"
0022
0023
0024
0025
0026 static char const* const kClassNameOpt = "className";
0027 static char const* const kHelpOpt = "help";
0028 static char const* const kHelpCommandOpt = "help,h";
0029
0030 int main(int argc, char* argv[]) try {
0031 std::string descString(argv[0]);
0032 descString += " [options] [--";
0033 descString += kClassNameOpt;
0034 descString +=
0035 "] class_name"
0036 "\n The program dumps information about how much storage space is needed to store the class"
0037 "\nAllowed options";
0038 boost::program_options::options_description desc(descString);
0039 desc.add_options()(kHelpCommandOpt, "show this help message")(kClassNameOpt, "name of class");
0040
0041 boost::program_options::positional_options_description p;
0042 p.add(kClassNameOpt, 1);
0043
0044 boost::program_options::variables_map vm;
0045 try {
0046 store(boost::program_options::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
0047 notify(vm);
0048 } catch (boost::program_options::error const& iException) {
0049 std::cerr << "failed to parse command line \n" << iException.what() << "\n";
0050 return 1;
0051 }
0052
0053 if (vm.count(kHelpOpt)) {
0054 std::cout << desc << std::endl;
0055 return 0;
0056 }
0057
0058 if (!vm.count(kClassNameOpt)) {
0059 std::cerr << "no class name given\n";
0060 return 1;
0061 }
0062
0063 std::string className(vm[kClassNameOpt].as<std::string>());
0064
0065 FWLiteEnabler::enable();
0066
0067 TClass* cls = TClass::GetClass(className.c_str());
0068 if (nullptr == cls) {
0069 std::cerr << "class '" << className << "' is unknown by ROOT\n";
0070 return 1;
0071 }
0072
0073 void* objInstance = cls->New();
0074 if (nullptr == objInstance) {
0075 std::cerr << "unable to create a default instance of the class " << className;
0076 return 1;
0077 }
0078
0079 TBufferFile bf(TBuffer::kWrite);
0080
0081 gDebug = 3;
0082 cls->WriteBuffer(bf, objInstance);
0083
0084 gDebug = 0;
0085 std::cout << "Total amount stored: " << bf.Length() << " bytes" << std::endl;
0086 std::cout << "\nNOTE: add 4 bytes for each 'has written' value because of a bug in ROOT's printout of the accounting"
0087 << "\n Each class (inheriting or as member data) has metadata an overhead of 10 bytes" << std::endl;
0088 return 0;
0089 } catch (cms::Exception const& e) {
0090 std::cerr << e.explainSelf() << std::endl;
0091 return 1;
0092 } catch (std::exception const& e) {
0093 std::cerr << e.what() << std::endl;
0094 return 1;
0095 }