CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
storageSize.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FWLite
4 // Class : storageSize
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Chris Jones
10 // Created: Thu Jan 20 09:50:58 CST 2011
11 //
12 
13 // system include files
14 #include <iostream>
15 #include <boost/program_options.hpp>
16 #include "TClass.h"
17 #include "TBufferFile.h"
18 
19 // user include files
22 
23 
24 //
25 // constants, enums and typedefs
26 //
27 static char const* const kClassNameOpt = "className";
28 static char const* const kHelpOpt = "help";
29 static char const* const kHelpCommandOpt="help,h";
30 
31 
32 int main(int argc, char* argv[]) try
33 {
34  std::string descString(argv[0]);
35  descString += " [options] [--";
36  descString += kClassNameOpt;
37  descString += "] class_name"
38  "\n The program dumps information about how much storage space is needed to store the class"
39  "\nAllowed options";
40  boost::program_options::options_description desc(descString);
41  desc.add_options()
42  (kHelpCommandOpt, "show this help message")
43  (kClassNameOpt,"name of class");
44 
45  boost::program_options::positional_options_description p;
46  p.add(kClassNameOpt, 1);
47 
48  boost::program_options::variables_map vm;
49  try {
50  store(boost::program_options::command_line_parser(argc,argv).options(desc).positional(p).run(),vm);
51  notify(vm);
52  } catch(boost::program_options::error const& iException) {
53  std::cerr <<"failed to parse command line \n"<<iException.what()<<"\n";
54  return 1;
55  }
56 
57  if(vm.count(kHelpOpt)) {
58  std::cout << desc <<std::endl;
59  return 0;
60  }
61 
62  if(!vm.count(kClassNameOpt)) {
63  std::cerr <<"no class name given\n";
64  return 1;
65  }
66 
67  std::string className(vm[kClassNameOpt].as<std::string>());
68 
70 
71  TClass* cls = TClass::GetClass(className.c_str());
72  if(0==cls) {
73  std::cerr <<"class '"<<className<<"' is unknown by ROOT\n";
74  return 1;
75  }
76 
77  void* objInstance = cls->New();
78  if(0==objInstance) {
79  std::cerr <<"unable to create a default instance of the class "<<className;
80  return 1;
81  }
82 
83  TBufferFile bf(TBuffer::kWrite);
84 
85  gDebug = 3;
86  cls->WriteBuffer(bf, objInstance);
87 
88  gDebug = 0;
89  std::cout <<"Total amount stored: "<<bf.Length()<<" bytes"<<std::endl;
90  std::cout<<"\nNOTE: add 4 bytes for each 'has written' value because of a bug in ROOT's printout of the accounting"
91  <<"\n Each class (inheriting or as member data) has metadata an overhead of 10 bytes"<<std::endl;
92  return 0;
93 } catch(cms::Exception const& e) {
94  std::cerr << e.explainSelf() << std::endl;
95  return 1;
96 } catch(std::exception const& e) {
97  std::cerr << e.what() << std::endl;
98  return 1;
99 }
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 void enable()
enable automatic library loading
static char const *const kHelpOpt
Definition: storageSize.cc:28
tuple argc
Definition: dir2webdir.py:38
tuple cout
Definition: gather_cfg.py:121
std::string className(const T &t)
Definition: ClassName.h:30