Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <iostream>
00016 #include <boost/program_options.hpp>
00017 #include "TClass.h"
00018 #include "TBufferFile.h"
00019
00020
00021 #include "FWCore/FWLite/interface/AutoLibraryLoader.h"
00022
00023
00024
00025
00026
00027 static char const* const kClassNameOpt = "className";
00028 static char const* const kHelpOpt = "help";
00029 static char const* const kHelpCommandOpt="help,h";
00030 static char const* const kProgramName = "edmClassStorageSize";
00031
00032
00033 int main(int argc, char* argv[])
00034 {
00035 std::string descString(argv[0]);
00036 descString += " [options] [--";
00037 descString += kClassNameOpt;
00038 descString += "] class_name"
00039 "\n The program dumps information about how much storage space is needed to store the class"
00040 "\nAllowed options";
00041 boost::program_options::options_description desc(descString);
00042 desc.add_options()
00043 (kHelpCommandOpt, "show this help message")
00044 (kClassNameOpt,"name of class");
00045
00046 boost::program_options::positional_options_description p;
00047 p.add(kClassNameOpt, 1);
00048
00049 boost::program_options::variables_map vm;
00050 try {
00051 store(boost::program_options::command_line_parser(argc,argv).options(desc).positional(p).run(),vm);
00052 notify(vm);
00053 } catch(boost::program_options::error const& iException) {
00054 std::cerr <<"failed to parse command line \n"<<iException.what()<<"\n";
00055 return 1;
00056 }
00057
00058 if(vm.count(kHelpOpt)) {
00059 std::cout << desc <<std::endl;
00060 return 0;
00061 }
00062
00063 if(!vm.count(kClassNameOpt)) {
00064 std::cerr <<"no class name given\n";
00065 return 1;
00066 }
00067
00068 std::string className( vm[kClassNameOpt].as<std::string>());
00069
00070 AutoLibraryLoader::enable();
00071
00072 TClass* cls = TClass::GetClass(className.c_str());
00073 if(0==cls) {
00074 std::cerr <<"class '"<<className<<"' is unknown by ROOT\n";
00075 return 1;
00076 }
00077
00078 void* objInstance = cls->New();
00079 if(0==objInstance) {
00080 std::cerr <<"unable to create a default instance of the class "<<className;
00081 return 1;
00082 }
00083
00084 TBufferFile bf(TBuffer::kWrite);
00085
00086 gDebug = 3;
00087 cls->WriteBuffer(bf, objInstance);
00088
00089 gDebug = 0;
00090 std::cout <<"Total amount stored: "<<bf.Length()<<" bytes"<<std::endl;
00091 std::cout<<"\nNOTE: add 4 bytes for each 'has written' value because of a bug in ROOT's printout of the accounting"
00092 <<"\n Each class (inheriting or as member data) has metadata an overhead of 10 bytes"<<std::endl;
00093 return 0;
00094 }