Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:15:37

0001 #ifndef PerfTools_EdmEventSize_H
0002 #define PerfTools_EdmEventSize_H
0003 
0004 #include <string>
0005 #include <vector>
0006 #include <iosfwd>
0007 
0008 namespace perftools {
0009 
0010   /** \class EdmEventSize
0011    *  Measure the size of each product in an edm::event
0012    *  Provides the output as an ascii table or root histograms
0013 
0014    *  Based on the original implementation by Luca Lista
0015    *
0016    *  Algorithm:
0017    *  Measure the size of each branch in a tree as the sum of the sizes of 
0018    *  all its baskets
0019    *  Estimate the "size in memory" multipling the actual branch size 
0020    *  by its compression factor
0021    *
0022    *  \author Vincenzo Innocente
0023    */
0024   class EdmEventSize {
0025   public:
0026     /// generic exception
0027     struct Error {
0028       Error(std::string const& idescr, int icode) : descr(idescr), code(icode) {}
0029       std::string descr;
0030       int code;
0031     };
0032 
0033     /// the information for each branch
0034     struct BranchRecord {
0035       BranchRecord() : compr_size(0.), uncompr_size(0.) {}
0036       BranchRecord(std::string const& iname, double compr, double uncompr)
0037           : fullName(iname), name(iname), compr_size(compr), uncompr_size(uncompr) {}
0038       std::string fullName;
0039       std::string name;
0040       double compr_size;
0041       double uncompr_size;
0042     };
0043 
0044     typedef std::vector<BranchRecord> Branches;
0045 
0046     /// Constructor
0047     EdmEventSize();
0048     /// Constructor and parse
0049     explicit EdmEventSize(std::string const& fileName, std::string const& treeName = "Events");
0050 
0051     /// read file, compute branch size, sort by size
0052     void parseFile(std::string const& fileName, std::string const& treeName = "Events");
0053 
0054     /// sort by name
0055     void sortAlpha();
0056 
0057     /// transform Branch names in "formatted" prodcut identifiers
0058     void formatNames();
0059 
0060     /// dump the ascii table on "co"
0061     void dump(std::ostream& co, bool header = true) const;
0062 
0063     /// produce histograms and optionally write them in "file" or as "plot"
0064     void produceHistos(std::string const& plot, std::string const& file, int top = 0) const;
0065 
0066   private:
0067     std::string m_fileName;
0068     int m_nEvents;
0069     Branches m_branches;
0070   };
0071 
0072 }  // namespace perftools
0073 
0074 #endif  // PerfTools_EdmEventSize_H