CMS 3D CMS Logo

Classes | Public Types | Public Member Functions | Private Attributes

perftools::EdmEventSize Class Reference

#include <EdmEventSize.h>

List of all members.

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"
 EdmEventSize (std::string const &fileName, std::string const &treeName="Events")
 Constructor and parse.
 EdmEventSize ()
 Constructor.
void formatNames ()
 transform Branch names in "formatted" prodcut identifiers
void parseFile (std::string const &fileName, std::string const &treeName="Events")
 read file, compute branch size, sort by size
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"
void sortAlpha ()
 sort by name

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.

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


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.

                                                            {
    if (header) {
      co << "File " << m_fileName << " Events " << m_nEvents << "\n";
      co <<"Branch Name | Average Uncompressed Size (Bytes/Event) | Average Compressed Size (Bytes/Event) \n";
    }
    std::for_each(m_branches.begin(),m_branches.end(),
                  boost::bind(detail::dump,boost::ref(co),_1));
  }
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().

                                 {
    std::for_each(m_branches.begin(),m_branches.end(),
                  &detail::shorterName);
  }
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, python::multivaluedict::sort(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by EdmEventSize().

                                                                                     {
    m_fileName = fileName;
    m_branches.clear();

    TFile * file = TFile::Open( fileName.c_str() );
    if( file==0  || ( !(*file).IsOpen() ) )
      throw Error( "unable to open data file " + fileName, 7002);
    
    TObject * o = file->Get(treeName.c_str() );
    if ( o == 0 )
      throw Error("no object \"" + treeName + "\" found in file: " + fileName, 7003);
    
    TTree * events = dynamic_cast<TTree*> (o);
    if ( events == 0 )
      throw Error("object \"" + treeName + "\" is not a TTree in file: " + fileName, 7004);
    
    m_nEvents = events->GetEntries();
    if ( m_nEvents == 0 )
      throw Error("tree \"" + treeName + "\" in file " + fileName + " contains no Events", 7005);


    TObjArray * branches = events->GetListOfBranches();
    if ( branches == 0 )
      throw Error("tree \"" + treeName+ "\" in file " + fileName + " contains no branches", 7006);
    
    const size_t n =  branches->GetEntries();
    m_branches.reserve(n);
    for( size_t i = 0; i < n; ++i ) {
      TBranch * b = dynamic_cast<TBranch*>( branches->At( i ) );
      if (b==0) continue;
      std::string const name( b->GetName() );
      if ( name == "EventAux" ) continue;
      size_type s = getTotalSize(b);
      m_branches.push_back( BranchRecord(name, double(s[kCompressed])/double(m_nEvents), double(s[kUncompressed])/double(m_nEvents)) );
    }
    std::sort(m_branches.begin(),m_branches.end(), 
              boost::bind(std::greater<double>(),
                          boost::bind(&BranchRecord::compr_size,_1),
                          boost::bind(&BranchRecord::compr_size,_2))
              );

  }
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.

                                                                                                {
    if (top==0) top = m_branches.size();
    detail::Hist h(top);
    std::for_each(m_branches.begin(),m_branches.end(),
                  boost::bind(&detail::Hist::fill,boost::ref(h),_1));
    h.finalize();
    if( !plot.empty() ) {
      gROOT->SetStyle( "Plain" );
      gStyle->SetOptStat( kFALSE );
      gStyle->SetOptLogy();
      TCanvas c;
      h.uncompressed.Draw();
      h.compressed.Draw( "same" );
      c.SaveAs( plot.c_str() );
    }
    if ( !file.empty() ) {
      TFile f( file.c_str(), "RECREATE" );
      h.compressed.Write();
      h.uncompressed.Write();
      f.Close();
    }

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

                               {
    std::sort(m_branches.begin(),m_branches.end(), 
              boost::bind(std::less<std::string>(),
                          boost::bind(&BranchRecord::name,_1),
                          boost::bind(&BranchRecord::name,_2))
              );

  }

Member Data Documentation

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

Definition at line 74 of file EdmEventSize.h.

Referenced by dump(), and parseFile().