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 73 of file EdmEventSize.cc.

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

Constructor and parse.

Definition at line 76 of file EdmEventSize.cc.

References parseFile().

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

Member Function Documentation

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

dump the ascii table on "co"

Definition at line 167 of file EdmEventSize.cc.

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

167  {
168  if (header) {
169  co << "File " << m_fileName << " Events " << m_nEvents << "\n";
170  co <<"Branch Name | Average Uncompressed Size (Bytes/Event) | Average Compressed Size (Bytes/Event) \n";
171  }
172  std::for_each(m_branches.begin(),m_branches.end(),
173  boost::bind(detail::dump,boost::ref(co),_1));
174  }
void dump(ostream &co, EdmEventSize::BranchRecord const &br)
void perftools::EdmEventSize::formatNames ( )

transform Branch names in "formatted" prodcut identifiers

Definition at line 152 of file EdmEventSize.cc.

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

152  {
153  std::for_each(m_branches.begin(),m_branches.end(),
155  }
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 81 of file EdmEventSize.cc.

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

Referenced by EdmEventSize().

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

238  {
239  if (top==0) top = m_branches.size();
240  detail::Hist h(top);
241  std::for_each(m_branches.begin(),m_branches.end(),
242  boost::bind(&detail::Hist::fill,boost::ref(h),_1));
243  h.finalize();
244  if( !plot.empty() ) {
245  gROOT->SetStyle( "Plain" );
246  gStyle->SetOptStat( kFALSE );
247  gStyle->SetOptLogy();
248  TCanvas c;
249  h.uncompressed.Draw();
250  h.compressed.Draw( "same" );
251  c.SaveAs( plot.c_str() );
252  }
253  if ( !file.empty() ) {
254  TFile f( file.c_str(), "RECREATE" );
255  h.compressed.Write();
256  h.uncompressed.Write();
257  f.Close();
258  }
259 
260  }
void fill(EdmEventSize::BranchRecord const &br)
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 124 of file EdmEventSize.cc.

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

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

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