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/FWLiteEnabler.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"
 

Function Documentation

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

Definition at line 32 of file storageSize.cc.

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

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

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().