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

◆ Branches

Definition at line 44 of file EdmEventSize.h.

Constructor & Destructor Documentation

◆ EdmEventSize() [1/2]

perftools::EdmEventSize::EdmEventSize ( )

Constructor.

Definition at line 72 of file EdmEventSize.cc.

72 : m_nEvents(0) {}

◆ EdmEventSize() [2/2]

perftools::EdmEventSize::EdmEventSize ( std::string const &  fileName,
std::string const &  treeName = "Events" 
)
explicit

Constructor and parse.

Definition at line 74 of file EdmEventSize.cc.

74  : m_nEvents(0) {
76  }

References MillePedeFileConverter_cfg::fileName, and parseFile().

Member Function Documentation

◆ dump()

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

dump the ascii table on "co"

Definition at line 160 of file EdmEventSize.cc.

160  {
161  if (header) {
162  co << "File " << m_fileName << " Events " << m_nEvents << "\n";
163  co << "Branch Name | Average Uncompressed Size (Bytes/Event) | Average Compressed Size (Bytes/Event) \n";
164  }
165  std::for_each(m_branches.begin(), m_branches.end(), std::bind(detail::dump, std::ref(co), std::placeholders::_1));
166  }

References cms::cuda::co, perftools::detail::dump(), RecoTauValidation_cfi::header, m_branches, m_fileName, and m_nEvents.

◆ formatNames()

void perftools::EdmEventSize::formatNames ( )

transform Branch names in "formatted" prodcut identifiers

Definition at line 151 of file EdmEventSize.cc.

151 { std::for_each(m_branches.begin(), m_branches.end(), &detail::shorterName); }

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

◆ parseFile()

void perftools::EdmEventSize::parseFile ( std::string const &  fileName,
std::string const &  treeName = "Events" 
)

read file, compute branch size, sort by size

Definition at line 78 of file EdmEventSize.cc.

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

References b, perftools::EdmEventSize::BranchRecord::compr_size, patZpeak::events, geometryDiff::file, MillePedeFileConverter_cfg::fileName, mps_fire::i, m_branches, m_fileName, m_nEvents, dqmiodumpmetadata::n, Skims_PA_cff::name, EcalTangentSkim_cfg::o, alignCSCRings::s, jetUpdater_cfi::sort, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by EdmEventSize().

◆ produceHistos()

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

230  {
231  if (top == 0)
232  top = m_branches.size();
233  detail::Hist h(top);
234  std::for_each(
235  m_branches.begin(), m_branches.end(), std::bind(&detail::Hist::fill, std::ref(h), std::placeholders::_1));
236  h.finalize();
237  if (!plot.empty()) {
238  gROOT->SetStyle("Plain");
239  gStyle->SetOptStat(kFALSE);
240  gStyle->SetOptLogy();
241  TCanvas c;
242  h.uncompressed.Draw();
243  h.compressed.Draw("same");
244  c.SaveAs(plot.c_str());
245  }
246  if (!file.empty()) {
247  TFile f(file.c_str(), "RECREATE");
248  h.compressed.Write();
249  h.uncompressed.Write();
250  f.Close();
251  }
252  }

References c, f, geometryDiff::file, perftools::detail::Hist::fill(), h, m_branches, and plotFactory::plot.

◆ sortAlpha()

void perftools::EdmEventSize::sortAlpha ( )

sort by name

Definition at line 122 of file EdmEventSize.cc.

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

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

Member Data Documentation

◆ m_branches

Branches perftools::EdmEventSize::m_branches
private

Definition at line 69 of file EdmEventSize.h.

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

◆ m_fileName

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

Definition at line 67 of file EdmEventSize.h.

Referenced by dump(), and parseFile().

◆ m_nEvents

int perftools::EdmEventSize::m_nEvents
private

Definition at line 68 of file EdmEventSize.h.

Referenced by dump(), and parseFile().

perftools::detail::dump
void dump(std::ostream &co, EdmEventSize::BranchRecord const &br)
Definition: EdmEventSize.cc:155
mps_fire.i
i
Definition: mps_fire.py:428
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
perftools::EdmEventSize::BranchRecord::compr_size
double compr_size
Definition: EdmEventSize.h:40
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
h
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
patZpeak.events
events
Definition: patZpeak.py:20
plotFactory.plot
plot
Definition: plotFactory.py:109
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:42
perftools::detail::shorterName
void shorterName(EdmEventSize::BranchRecord &br)
Definition: EdmEventSize.cc:132
alignCSCRings.s
s
Definition: alignCSCRings.py:92
perftools::EdmEventSize::parseFile
void parseFile(std::string const &fileName, std::string const &treeName="Events")
read file, compute branch size, sort by size
Definition: EdmEventSize.cc:78
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
cms::cuda::co
__host__ __device__ VT * co
Definition: prefixScan.h:47
gpuVertexFinder::Hist
cms::cuda::HistoContainer< uint8_t, 256, 16000, 8, uint16_t > Hist
Definition: gpuClusterTracksDBSCAN.h:47
perftools::EdmEventSize::BranchRecord::name
std::string name
Definition: EdmEventSize.h:39
h
perftools::EdmEventSize::m_nEvents
int m_nEvents
Definition: EdmEventSize.h:68
b
double b
Definition: hdecay.h:118
geometryDiff.file
file
Definition: geometryDiff.py:13
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
leef::Error
edm::ErrorSummaryEntry Error
Definition: LogErrorEventFilter.cc:29
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
perftools::EdmEventSize::m_branches
Branches m_branches
Definition: EdmEventSize.h:69
perftools::detail::Hist::fill
void fill(EdmEventSize::BranchRecord const &br)
Definition: EdmEventSize.cc:179
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
perftools::EdmEventSize::m_fileName
std::string m_fileName
Definition: EdmEventSize.h:67
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:291
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56