CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
storageSizeForBranch.cc File Reference
#include <iostream>
#include <boost/program_options.hpp>
#include "TClass.h"
#include "TFile.h"
#include "TBranch.h"
#include "TBufferFile.h"
#include "TTree.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 kBranchNameOpt = "branchName"
 
static char const *const kEntryNumberCommandOpt = "entryNumber,e"
 
static char const *const kEntryNumberOpt = "entryNumber"
 
static char const *const kFileNameOpt = "fileName"
 
static char const *const kHelpCommandOpt ="help,h"
 
static char const *const kHelpOpt = "help"
 

Function Documentation

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

Definition at line 37 of file storageSizeForBranch.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, gather_cfg::cout, FWLiteEnabler::enable(), relativeConstraints::error, mergeVDriftHistosByStation::file, MillePedeFileConverter_cfg::fileName, kBranchNameOpt, kEntryNumberCommandOpt, kEntryNumberOpt, kFileNameOpt, kHelpCommandOpt, kHelpOpt, AlCaHLTBitMon_ParallelJobs::options, AlCaHLTBitMon_ParallelJobs::p, DTTTrigCorrFirst::run, and AlCaHLTBitMon_QueryRunRegistry::string.

38 {
39  std::string descString(argv[0]);
40  descString += " [options] [--";
41  descString += kBranchNameOpt;
42  descString += "] branch_name [--";
43  descString += kFileNameOpt;
44  descString += "] file_name"
45  "\n The program dumps information about how much storage space is needed to store a given TBranch within a ROOT file"
46  "\nAllowed options";
47  boost::program_options::options_description desc(descString);
48  desc.add_options()
49  (kHelpCommandOpt, "show this help message")
50  (kEntryNumberCommandOpt, boost::program_options::value<int>(),"read branch from the given entry value (default 0)")
51  (kBranchNameOpt,"name of branch")
52  (kFileNameOpt,"name of file");
53 
54  boost::program_options::positional_options_description p;
55  p.add(kBranchNameOpt, 1);
56  p.add(kFileNameOpt, 1);
57 
58  boost::program_options::variables_map vm;
59  try {
60  store(boost::program_options::command_line_parser(argc,argv).options(desc).positional(p).run(),vm);
61  notify(vm);
62  } catch(boost::program_options::error const& iException) {
63  std::cerr <<"failed to parse command line \n"<<iException.what()<<"\n";
64  return 1;
65  }
66 
67  if(vm.count(kHelpOpt)) {
68  std::cout << desc <<std::endl;
69  return 0;
70  }
71  int entryNumber = 0;
72  if(vm.count(kEntryNumberOpt)) {
73  entryNumber = vm[kEntryNumberOpt].as<int>();
74  }
75 
76  if(!vm.count(kBranchNameOpt)) {
77  std::cerr <<"no branch name given\n";
78  return 1;
79  }
80 
81 
82  if(!vm.count(kFileNameOpt)) {
83  std::cerr <<"no branch name given\n";
84  return 1;
85  }
86 
87  std::string branchName(vm[kBranchNameOpt].as<std::string>());
88  std::string fileName(vm[kFileNameOpt].as<std::string>());
89 
90  TFile* file = TFile::Open(fileName.c_str());
91  if (0 == file) {
92  std::cerr <<"failed to open '"<<fileName<<"'";
93  return 1;
94  }
95 
96  TTree* eventTree = dynamic_cast<TTree*> (file->Get("Events"));
97 
98  if(0 == eventTree) {
99  std::cerr <<"The file '"<<fileName<<"' does not contain an 'Events' TTree";
100  return 1;
101  }
102 
103  TBranch* branch = eventTree->GetBranch(branchName.c_str());
104 
105  if(0==branch) {
106  std::cerr <<"The Events TTree does not contain the branch "<<branchName;
107  return 1;
108  }
109 
110 
112 
113  TClass* cls = TClass::GetClass(branch->GetClassName());
114  if(0==cls) {
115  std::cerr <<"class '"<<branch->GetClassName()<<"' is unknown by ROOT\n";
116  return 1;
117  }
118 
119  void* objInstance = cls->New();
120  if(0==objInstance) {
121  std::cerr <<"unable to create a default instance of the class "<<branch->GetClassName();
122  return 1;
123  }
124 
125  //associate this with the branch
126  void* pObjInstance = &objInstance;
127 
128  branch->SetAddress(pObjInstance);
129 
130  branch->GetEntry(entryNumber);
131 
132  TBufferFile bf(TBuffer::kWrite);
133 
134  gDebug = 3;
135  cls->WriteBuffer(bf, objInstance);
136 
137  gDebug = 0;
138  std::cout <<"Total amount stored: "<<bf.Length()<<" bytes"<<std::endl;
139  std::cout<<"\nNOTE: add 4 bytes for each 'has written' value because of a bug in ROOT's printout of the accounting"
140  <<"\n Each class (inheriting or as member data) has metadata an overhead of 10 bytes"<<std::endl;
141  return 0;
142 } catch(cms::Exception const& e) {
143  std::cerr << e.explainSelf() << std::endl;
144  return 1;
145 } catch(std::exception const& e) {
146  std::cerr << e.what() << std::endl;
147  return 1;
148 }
virtual std::string explainSelf() const
Definition: Exception.cc:146
static char const *const kEntryNumberOpt
static char const *const kFileNameOpt
static void enable()
enable automatic library loading
static char const *const kBranchNameOpt
tuple argc
Definition: dir2webdir.py:38
static char const *const kEntryNumberCommandOpt
static char const *const kHelpCommandOpt
tuple cout
Definition: gather_cfg.py:121
static char const *const kHelpOpt

Variable Documentation

char const* const kBranchNameOpt = "branchName"
static

Definition at line 30 of file storageSizeForBranch.cc.

Referenced by main().

char const* const kEntryNumberCommandOpt = "entryNumber,e"
static

Definition at line 34 of file storageSizeForBranch.cc.

Referenced by main().

char const* const kEntryNumberOpt = "entryNumber"
static

Definition at line 35 of file storageSizeForBranch.cc.

Referenced by main().

char const* const kFileNameOpt = "fileName"
static

Definition at line 31 of file storageSizeForBranch.cc.

Referenced by main().

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

Definition at line 33 of file storageSizeForBranch.cc.

Referenced by main().

char const* const kHelpOpt = "help"
static

Definition at line 32 of file storageSizeForBranch.cc.

Referenced by main().