CMS 3D CMS Logo

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

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

Constructor and parse.

Definition at line 75 of file EdmEventSize.cc.

References parseFile().

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

Member Function Documentation

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

dump the ascii table on "co"

Definition at line 166 of file EdmEventSize.cc.

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

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

transform Branch names in "formatted" prodcut identifiers

Definition at line 151 of file EdmEventSize.cc.

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

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

References b, perftools::EdmEventSize::BranchRecord::compr_size, PatBasicFWLiteAnalyzer::events, FrontierConditions_GlobalTag_cff::file, MillePedeFileConverter_cfg::fileName, mps_fire::i, m_branches, m_fileName, m_nEvents, gen::n, dataset::name, connectstrParser::o, alignCSCRings::s, jetUpdater_cfi::sort, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by EdmEventSize().

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

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

237  {
238  if (top==0) top = m_branches.size();
239  detail::Hist h(top);
240  std::for_each(m_branches.begin(),m_branches.end(),
241  boost::bind(&detail::Hist::fill,boost::ref(h),_1));
242  h.finalize();
243  if( !plot.empty() ) {
244  gROOT->SetStyle( "Plain" );
245  gStyle->SetOptStat( kFALSE );
246  gStyle->SetOptLogy();
247  TCanvas c;
248  h.uncompressed.Draw();
249  h.compressed.Draw( "same" );
250  c.SaveAs( plot.c_str() );
251  }
252  if ( !file.empty() ) {
253  TFile f( file.c_str(), "RECREATE" );
254  h.compressed.Write();
255  h.uncompressed.Write();
256  f.Close();
257  }
258 
259  }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void fill(EdmEventSize::BranchRecord const &br)
double f[11][100]
void perftools::EdmEventSize::sortAlpha ( )

sort by name

Definition at line 123 of file EdmEventSize.cc.

References m_branches, perftools::EdmEventSize::BranchRecord::name, and jetUpdater_cfi::sort.

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

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