CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Private Attributes
perftools::EdmEventSize Class Reference

#include <EdmEventSize.h>

Classes

struct  BranchRecord
 the information for each branch More...
 
struct  Error
 generic exception More...
 

Public Types

typedef std::vector< BranchRecordBranches
 

Public Member Functions

void dump (std::ostream &co, bool header=true) const
 dump the ascii table on "co" More...
 
 EdmEventSize ()
 Constructor. More...
 
 EdmEventSize (std::string const &fileName, std::string const &treeName="Events")
 Constructor and parse. More...
 
void formatNames ()
 transform Branch names in "formatted" prodcut identifiers More...
 
void parseFile (std::string const &fileName, std::string const &treeName="Events")
 read file, compute branch size, sort by size More...
 
void produceHistos (std::string const &plot, std::string const &file, int top=0) const
 produce histograms and optionally write them in "file" or as "plot" More...
 
void sortAlpha ()
 sort by name More...
 

Private Attributes

Branches m_branches
 
std::string m_fileName
 
int m_nEvents
 

Detailed Description

Measure the size of each product in an edm::event Provides the output as an ascii table or root histograms

Based on the original implementation by Luca Lista

Algorithm: Measure the size of each branch in a tree as the sum of the sizes of all its baskets Estimate the "size in memory" multipling the actual branch size by its compression factor

Author
Vincenzo Innocente

Definition at line 24 of file EdmEventSize.h.

Member Typedef Documentation

Definition at line 50 of file EdmEventSize.h.

Constructor & Destructor Documentation

perftools::EdmEventSize::EdmEventSize ( )

Constructor.

Definition at line 71 of file EdmEventSize.cc.

71  :
72  m_nEvents(0) {}
perftools::EdmEventSize::EdmEventSize ( std::string const &  fileName,
std::string const &  treeName = "Events" 
)
explicit

Constructor and parse.

Definition at line 74 of file EdmEventSize.cc.

References parseFile().

74  :
75  m_nEvents(0) {
77  }
void parseFile(std::string const &fileName, std::string const &treeName="Events")
read file, compute branch size, sort by size
Definition: EdmEventSize.cc:79

Member Function Documentation

void perftools::EdmEventSize::dump ( std::ostream &  co,
bool  header = true 
) const

dump the ascii table on "co"

Definition at line 165 of file EdmEventSize.cc.

References perftools::detail::dump(), m_branches, m_fileName, and m_nEvents.

165  {
166  if (header)
167  co << "File " << m_fileName << " Events " << m_nEvents << "\n";
168  std::for_each(m_branches.begin(),m_branches.end(),
169  boost::bind(detail::dump,boost::ref(co),_1));
170  }
void dump(ostream &co, EdmEventSize::BranchRecord const &br)
void perftools::EdmEventSize::formatNames ( )

transform Branch names in "formatted" prodcut identifiers

Definition at line 150 of file EdmEventSize.cc.

References m_branches, and perftools::detail::shorterName().

150  {
151  std::for_each(m_branches.begin(),m_branches.end(),
153  }
void shorterName(EdmEventSize::BranchRecord &br)
void perftools::EdmEventSize::parseFile ( std::string const &  fileName,
std::string const &  treeName = "Events" 
)

read file, compute branch size, sort by size

Definition at line 79 of file EdmEventSize.cc.

References perftools::EdmEventSize::BranchRecord::compr_size, patZpeak::events, dbtoweb::file, convertXMLtoSQLite_cfg::fileName, i, m_branches, m_fileName, m_nEvents, n, AlCaRecoCosmics_cfg::name, connectstrParser::o, asciidump::s, and python.multivaluedict::sort().

Referenced by EdmEventSize().

79  {
81  m_branches.clear();
82 
83  TFile * file = TFile::Open( fileName.c_str() );
84  if( file==0 || ( !(*file).IsOpen() ) )
85  throw Error( "unable to open data file " + fileName, 7002);
86 
87  TObject * o = file->Get(treeName.c_str() );
88  if ( o == 0 )
89  throw Error("no object \"" + treeName + "\" found in file: " + fileName, 7003);
90 
91  TTree * events = dynamic_cast<TTree*> (o);
92  if ( events == 0 )
93  throw Error("object \"" + treeName + "\" is not a TTree in file: " + fileName, 7004);
94 
95  m_nEvents = events->GetEntries();
96  if ( m_nEvents == 0 )
97  throw Error("tree \"" + treeName + "\" in file " + fileName + " contains no Events", 7005);
98 
99 
100  TObjArray * branches = events->GetListOfBranches();
101  if ( branches == 0 )
102  throw Error("tree \"" + treeName+ "\" in file " + fileName + " contains no branches", 7006);
103 
104  const size_t n = branches->GetEntries();
105  m_branches.reserve(n);
106  for( size_t i = 0; i < n; ++i ) {
107  TBranch * b = dynamic_cast<TBranch*>( branches->At( i ) );
108  if (b==0) continue;
109  std::string const name( b->GetName() );
110  if ( name == "EventAux" ) continue;
111  size_type s = getTotalSize(b);
112  m_branches.push_back( BranchRecord(name, double(s[0])/double(m_nEvents), double(s[1])/double(m_nEvents)) );
113  }
114  std::sort(m_branches.begin(),m_branches.end(),
115  boost::bind(std::greater<double>(),
116  boost::bind(&BranchRecord::compr_size,_1),
117  boost::bind(&BranchRecord::compr_size,_2))
118  );
119 
120  }
int i
Definition: DBlmapReader.cc:9
list file
Definition: dbtoweb.py:253
uint16_t size_type
double b
Definition: hdecay.h:120
tuple events
Definition: patZpeak.py:19
string s
Definition: asciidump.py:422
void perftools::EdmEventSize::produceHistos ( std::string const &  plot,
std::string const &  file,
int  top = 0 
) const

produce histograms and optionally write them in "file" or as "plot"

Definition at line 234 of file EdmEventSize.cc.

References trackerHits::c, perftools::detail::Hist::compressed, f, perftools::detail::Hist::fill(), perftools::detail::Hist::finalize(), h, m_branches, and perftools::detail::Hist::uncompressed.

234  {
235  if (top==0) top = m_branches.size();
236  detail::Hist h(top);
237  std::for_each(m_branches.begin(),m_branches.end(),
238  boost::bind(&detail::Hist::fill,boost::ref(h),_1));
239  h.finalize();
240  if( !plot.empty() ) {
241  gROOT->SetStyle( "Plain" );
242  gStyle->SetOptStat( kFALSE );
243  gStyle->SetOptLogy();
244  TCanvas c;
245  h.uncompressed.Draw();
246  h.compressed.Draw( "same" );
247  c.SaveAs( plot.c_str() );
248  }
249  if ( !file.empty() ) {
250  TFile f( file.c_str(), "RECREATE" );
251  h.compressed.Write();
252  h.uncompressed.Write();
253  f.Close();
254  }
255 
256  }
void fill(EdmEventSize::BranchRecord const &br)
list file
Definition: dbtoweb.py:253
double f[11][100]
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void perftools::EdmEventSize::sortAlpha ( )

sort by name

Definition at line 122 of file EdmEventSize.cc.

References m_branches, perftools::EdmEventSize::BranchRecord::name, and python.multivaluedict::sort().

122  {
123  std::sort(m_branches.begin(),m_branches.end(),
124  boost::bind(std::less<std::string>(),
125  boost::bind(&BranchRecord::name,_1),
126  boost::bind(&BranchRecord::name,_2))
127  );
128 
129  }

Member Data Documentation

Branches perftools::EdmEventSize::m_branches
private

Definition at line 75 of file EdmEventSize.h.

Referenced by dump(), formatNames(), parseFile(), produceHistos(), and sortAlpha().

std::string perftools::EdmEventSize::m_fileName
private

Definition at line 73 of file EdmEventSize.h.

Referenced by dump(), and parseFile().

int perftools::EdmEventSize::m_nEvents
private

Definition at line 74 of file EdmEventSize.h.

Referenced by dump(), and parseFile().