CMS 3D CMS Logo

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 30 of file storageSize.cc.

References beam_dqm_sourceclient-live_cfg::cerr, className(), gather_cfg::cout, MillePedeFileConverter_cfg::e, FWLiteEnabler::enable(), relativeConstraints::error, cppFunctionSkipper::exception, cms::Exception::explainSelf(), kClassNameOpt, kHelpCommandOpt, kHelpOpt, AlcaSiPixelAliHarvester0T_cff::options, AlCaHLTBitMon_ParallelJobs::p, writedatasetfile::run, AlCaHLTBitMon_QueryRunRegistry::string, and cms::Exception::what().

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

Variable Documentation

char const* const kClassNameOpt = "className"
static

Definition at line 26 of file storageSize.cc.

Referenced by main().

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

Definition at line 28 of file storageSize.cc.

Referenced by main().

char const* const kHelpOpt = "help"
static

Definition at line 27 of file storageSize.cc.

Referenced by main().