15 #include <boost/program_options.hpp>
19 #include "TBufferFile.h"
40 descString +=
" [options] [--";
42 descString +=
"] branch_name [--";
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"
47 boost::program_options::options_description desc(descString);
50 (
kEntryNumberCommandOpt, boost::program_options::value<int>(),
"read branch from the given entry value (default 0)")
54 boost::program_options::positional_options_description
p;
58 boost::program_options::variables_map vm;
60 store(boost::program_options::command_line_parser(argc,argv).
options(desc).positional(p).
run(),vm);
63 std::cerr <<
"failed to parse command line \n"<<iException.what()<<
"\n";
90 TFile*
file = TFile::Open(fileName.c_str());
92 std::cerr <<
"failed to open '"<<fileName<<
"'";
96 TTree* eventTree =
dynamic_cast<TTree*
> (file->Get(
"Events"));
99 std::cerr <<
"The file '"<<fileName<<
"' does not contain an 'Events' TTree";
103 TBranch* branch = eventTree->GetBranch(branchName.c_str());
106 std::cerr <<
"The Events TTree does not contain the branch "<<branchName;
113 TClass* cls = TClass::GetClass(branch->GetClassName());
115 std::cerr <<
"class '"<<branch->GetClassName()<<
"' is unknown by ROOT\n";
119 void* objInstance = cls->New();
121 std::cerr <<
"unable to create a default instance of the class "<<branch->GetClassName();
126 void* pObjInstance = &objInstance;
128 branch->SetAddress(pObjInstance);
130 branch->GetEntry(entryNumber);
132 TBufferFile bf(TBuffer::kWrite);
135 cls->WriteBuffer(bf, objInstance);
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;
virtual std::string explainSelf() const
static char const *const kEntryNumberOpt
static char const *const kFileNameOpt
static void enable()
enable automatic library loading
static char const *const kBranchNameOpt
static char const *const kEntryNumberCommandOpt
static char const *const kHelpCommandOpt
static char const *const kHelpOpt