CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
storageSize.cc File Reference
#include <iostream>
#include <boost/program_options.hpp>
#include "TClass.h"
#include "TBufferFile.h"
#include "FWCore/FWLite/interface/AutoLibraryLoader.h"
#include "FWCore/Utilities/interface/Exception.h"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Variables

static char const *const kClassNameOpt = "className"
 
static char const *const kHelpCommandOpt ="help,h"
 
static char const *const kHelpOpt = "help"
 
static char const *const kProgramName = "edmClassStorageSize"
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 33 of file storageSize.cc.

References dtNoiseDBValidation_cfg::cerr, className(), gather_cfg::cout, AutoLibraryLoader::enable(), relativeConstraints::error, kClassNameOpt, kHelpCommandOpt, kHelpOpt, AlCaHLTBitMon_ParallelJobs::options, AlCaHLTBitMon_ParallelJobs::p, DTTTrigCorrFirst::run, and AlCaHLTBitMon_QueryRunRegistry::string.

34 {
35  std::string descString(argv[0]);
36  descString += " [options] [--";
37  descString += kClassNameOpt;
38  descString += "] class_name"
39  "\n The program dumps information about how much storage space is needed to store the class"
40  "\nAllowed options";
41  boost::program_options::options_description desc(descString);
42  desc.add_options()
43  (kHelpCommandOpt, "show this help message")
44  (kClassNameOpt,"name of class");
45 
46  boost::program_options::positional_options_description p;
47  p.add(kClassNameOpt, 1);
48 
49  boost::program_options::variables_map vm;
50  try {
51  store(boost::program_options::command_line_parser(argc,argv).options(desc).positional(p).run(),vm);
52  notify(vm);
53  } catch(boost::program_options::error const& iException) {
54  std::cerr <<"failed to parse command line \n"<<iException.what()<<"\n";
55  return 1;
56  }
57 
58  if(vm.count(kHelpOpt)) {
59  std::cout << desc <<std::endl;
60  return 0;
61  }
62 
63  if(!vm.count(kClassNameOpt)) {
64  std::cerr <<"no class name given\n";
65  return 1;
66  }
67 
68  std::string className(vm[kClassNameOpt].as<std::string>());
69 
71 
72  TClass* cls = TClass::GetClass(className.c_str());
73  if(0==cls) {
74  std::cerr <<"class '"<<className<<"' is unknown by ROOT\n";
75  return 1;
76  }
77 
78  void* objInstance = cls->New();
79  if(0==objInstance) {
80  std::cerr <<"unable to create a default instance of the class "<<className;
81  return 1;
82  }
83 
84  TBufferFile bf(TBuffer::kWrite);
85 
86  gDebug = 3;
87  cls->WriteBuffer(bf, objInstance);
88 
89  gDebug = 0;
90  std::cout <<"Total amount stored: "<<bf.Length()<<" bytes"<<std::endl;
91  std::cout<<"\nNOTE: add 4 bytes for each 'has written' value because of a bug in ROOT's printout of the accounting"
92  <<"\n Each class (inheriting or as member data) has metadata an overhead of 10 bytes"<<std::endl;
93  return 0;
94 } catch(cms::Exception const& e) {
95  std::cerr << e.explainSelf() << std::endl;
96  return 1;
97 } catch(std::exception const& e) {
98  std::cerr << e.what() << std::endl;
99  return 1;
100 }
static char const *const kHelpCommandOpt
Definition: storageSize.cc:29
virtual std::string explainSelf() const
Definition: Exception.cc:146
static char const *const kClassNameOpt
Definition: storageSize.cc:27
static char const *const kHelpOpt
Definition: storageSize.cc:28
tuple argc
Definition: dir2webdir.py:38
static void enable()
enable automatic library loading
tuple cout
Definition: gather_cfg.py:121
std::string className(const T &t)
Definition: ClassName.h:30

Variable Documentation

char const* const kClassNameOpt = "className"
static

Definition at line 27 of file storageSize.cc.

Referenced by main().

char const* const kHelpCommandOpt ="help,h"
static

Definition at line 29 of file storageSize.cc.

Referenced by main().

char const* const kHelpOpt = "help"
static

Definition at line 28 of file storageSize.cc.

Referenced by main().

char const* const kProgramName = "edmClassStorageSize"
static

Definition at line 30 of file storageSize.cc.