CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/FWCore/MessageLogger/interface/JobReport.h

Go to the documentation of this file.
00001 #ifndef FWCore_MessageLogger_JobReport_h
00002 #define FWCore_MessageLogger_JobReport_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     MessageLogger
00006 // Class  :     JobReport
00007 //
00019 //
00020 // Original Author:  Marc Paterno
00021 //
00022 
00023 /*
00024 Changes Log 1: 2009/01/14 10:29:00, Natalia Garcia Nebot
00025         Modified and added some methods to report CPU and memory information from /proc/cpuinfo
00026         and /proc/meminfo files and Memory statistics
00027 */
00028 
00029 #include <cstddef>
00030 #include <string>
00031 #include <ostream>
00032 #include <set>
00033 #include <map>
00034 #include <vector>
00035 
00036 #include "boost/scoped_ptr.hpp"
00037 
00038 namespace edm {
00039 
00040     class JobReport {
00041     public:
00042       typedef unsigned int RunNumber;
00043       typedef std::size_t Token;
00044 
00054       struct LumiSectionReport {
00055         unsigned int  runNumber;
00056         unsigned int lumiSectionId;
00063       };
00064 
00065       struct RunReport {
00066         RunNumber runNumber;
00067         std::set<unsigned int> lumiSections;
00068       };
00069 
00079       struct InputFile {
00080         typedef std::vector<std::string> StringVector;
00081 
00082         std::string     logicalFileName;
00083         std::string     physicalFileName;
00084         std::string     catalog;
00085         std::string     inputType; // primaryFiles, secondaryFiles, mixingFiles
00086         std::string     inputSourceClassName; // class which created the file
00087         std::string     moduleLabel;   // name of class instance
00088         std::string     guid;
00089         size_t          numEventsRead;
00090         StringVector    branchNames;
00091         std::map<RunNumber, RunReport> runReports;
00092         bool            fileHasBeenClosed;
00093         std::set<std::string> fastClonedBranches;
00094       };
00095 
00105       struct OutputFile {
00106 
00107         typedef InputFile::StringVector StringVector;
00108 
00109         std::string     logicalFileName;
00110         std::string     physicalFileName;
00111         std::string     catalog;
00112         std::string     outputModuleClassName;
00113         std::string     moduleLabel;   // name of class instance
00114         std::string     guid;
00115         std::string     dataType;
00116         std::string     branchHash;
00117         size_t          numEventsWritten;
00118         StringVector    branchNames;
00119         std::vector<Token> contributingInputs;
00120         std::map<std::string, bool> fastCopyingInputs;
00121         std::map<RunNumber, RunReport> runReports;
00122         bool            fileHasBeenClosed;
00123       };
00124 
00125       struct JobReportImpl {
00126         // Helper functions to be called from the xFileClosed functions,
00127         // after the appropriate logging is done.
00128         /*
00129          * Note: We want to keep input files, so we can resolve tokens
00130          * when we close output files
00131          *
00132          * Note2: Erasing the Output files on close invalidates the Tokens
00133          * for existing output files since they are based on position in
00134          * the vector, so I have left off implementing these methods for now
00135          */
00136         void removeInputFileRecord_(Token t);
00137         void removeOutputFileRecord_(Token t);
00138 
00139         InputFile& getInputFileForToken(Token t);
00140         OutputFile& getOutputFileForToken(Token t);
00141         /*
00142          * Add the input file token provided to every output
00143          * file currently available.
00144          * Used whenever a new input file is opened, it's token
00145          * is added to all open output files as a contributor
00146          */
00147         void insertInputForOutputs(Token t);
00148 
00149         /*
00150          * get a vector of Tokens for all currently open
00151          * input files.
00152          * Used when a new output file is opened, all currently open
00153          * input file tokens are used to initialise its list of contributors
00154          */
00155         void openInputFiles(std::vector<Token>& tokens);
00156 
00157         /*
00158          * Get a vector of Tokens for all currently open output files
00159          * Used to add lumi sections to open files
00160          */
00161         void openOutputFiles(std::vector<Token>& tokens);
00162 
00163         /*
00164          * Associate a Lumi Section to all open output files
00165          *
00166          */
00167         void associateLumiSection(unsigned int runNumber, unsigned int lumiSection);
00168 
00169 
00170         /*
00171          * Associate a Lumi Section to all open input files
00172          *
00173          */
00174         void associateInputLumiSection(unsigned int runNumber, unsigned int lumiSection);
00175         /*
00176          * Associate a run to all open output files
00177          */
00178         void associateRun(unsigned int runNumber);
00179         /*
00180          * Associate a run to all open output files
00181          */
00182         void associateInputRun(unsigned int runNumber);
00183 
00184         /*
00185          * Write an InputFile object to the Logger
00186          * Generate XML string for InputFile instance and dispatch to
00187          * job report via MessageLogger
00188          */
00189         void writeInputFile(InputFile const& f);
00190         /*
00191          * Write an OutputFile object to the Logger
00192          * Generate an XML string for the OutputFile provided and
00193          * dispatch it to the logger
00194          * Contributing input tokens are resolved to the input LFN and PFN
00195          *
00196          * TODO: We have not yet addressed the issue where we cleanup not
00197          * contributing input files.
00198          * Also, it is possible to get fake input to output file mappings
00199          * if an input file is open already when a new output file is opened
00200          * but the input gets closed without contributing events to the
00201          * output file due to filtering etc.
00202          *
00203          */
00204         void writeOutputFile(OutputFile const& f);
00205 
00206         /*
00207          * Add Generator info to the map of gen info stored in this
00208          * instance.
00209          */
00210         void addGeneratorInfo(std::string const& name, std::string const& value);
00211 
00212         /*
00213          * Write out generator info to the job report
00214          */
00215         void writeGeneratorInfo(void);
00216 
00217 
00218         /*
00219          *  Flush all open files to logger in event of a problem.
00220          */
00221         void flushFiles(void);
00222 
00223         JobReportImpl(std::ostream* iOst): ost_(iOst) {}
00224 
00225         std::vector<InputFile> inputFiles_;
00226         std::vector<OutputFile> outputFiles_;
00227         std::map<std::string, std::string> generatorInfo_;
00228         std::map<std::string, long long> readBranches_;
00229         std::set<std::string>* fastClonedBranches_;
00230         std::ostream* ost_;
00231       };
00232 
00233       JobReport();
00234       //Does not take ownership of pointer
00235       JobReport(std::ostream* outputStream);
00236 
00237       ~JobReport();
00238 
00240       void childAfterFork(std::string const& jobReportFile, unsigned int childIndex, unsigned int numberOfChildren);
00241 
00242       void parentBeforeFork(std::string const& jobReportFile, unsigned int numberOfChildren);
00243 
00244       void parentAfterFork(std::string const& jobReportFile);
00245 
00249       Token inputFileOpened(std::string const& physicalFileName,
00250                             std::string const& logicalFileName,
00251                             std::string const& catalog,
00252                             std::string const& inputType,
00253                             std::string const& inputSourceClassName,
00254                             std::string const& moduleLabel,
00255                             std::string const& guid,
00256                             std::vector<std::string> const& branchNames);
00257 
00260       void eventReadFromFile(Token fileToken, unsigned int run, unsigned int event);
00261 
00266       void reportDataType(Token fileToken, std::string const& dataType);
00267 
00268 
00272       void inputFileClosed(Token fileToken);
00273 
00277       Token outputFileOpened(std::string const& physicalFileName,
00278                              std::string const& logicalFileName,
00279                              std::string const& catalog,
00280                              std::string const& outputModuleClassName,
00281                              std::string const& moduleLabel,
00282                              std::string const& guid,
00283                              std::string const& dataType,
00284                              std::string const& branchHash,
00285                              std::vector<std::string> const& branchNames);
00286 
00289       void eventWrittenToFile(Token fileToken, unsigned int run, unsigned int event);
00290 
00294       void outputFileClosed(Token fileToken);
00295 
00301       void overrideEventsWritten(Token fileToken, int const eventsWritten);
00307       void overrideEventsRead(Token fileToken, int const eventsRead);
00308 
00309       void reportSkippedEvent(unsigned int run, unsigned int event);
00310 
00316       void reportLumiSection(unsigned int run, unsigned int lumiSectId);
00322       void reportInputLumiSection(unsigned int run, unsigned int lumiSectId);
00323 
00327       void reportRunNumber(unsigned int run);
00331       void reportInputRunNumber(unsigned int run);
00332 
00338       void  reportError(std::string const& shortDesc,
00339                         std::string const& longDesc);
00340 
00341       void reportError(std::string const& shortDesc,
00342                        std::string const& longDesc,
00343                        int const& exitCode);
00344 
00350       void reportSkippedFile(std::string const& pfn, std::string const& lfn);
00351 
00352       void reportFallbackAttempt(std::string const& pfn, std::string const& lfn, std::string const& err);
00353 
00354       void reportAnalysisFile(std::string const& fileName,
00355                               std::map<std::string, std::string> const& fileData) ;
00356 
00363       void reportMemoryInfo(std::vector<std::string> const& memoryData);
00364 
00371       void reportMessageInfo(std::map<std::string, double> const& messageData);
00372 
00379       void reportReadBranches();
00380 
00382       void reportReadBranch(std::string const& branchName);
00383 
00385       void reportFastClonedBranches(std::set<std::string> const& fastClonedBranches, long long nEvents);
00386 
00389       void overrideContributingInputs(Token outputToken, std::vector<Token> const& inputTokens);
00390 
00394       void reportGeneratorInfo(std::string const&  name, std::string const&  value);
00395 
00399       void reportRandomStateFile(std::string const& name);
00400 
00405       void reportPSetHash(std::string const& hashValue);
00406 
00407       /*
00408        * Report information about fast copying. Called for each open output file
00409        * whenever an input file is opened.
00410        */
00411       void reportFastCopyingStatus(Token t, std::string const& inputFileName, bool fastCopying);
00412 
00420       void reportPerformanceSummary(std::string const&  metricClass,
00421                                     std::map<std::string, std::string> const& metrics);
00422 
00423       void reportPerformanceForModule(std::string const&  metricClass,
00424                                       std::string const&  moduleName,
00425                                       std::map<std::string, std::string> const& metrics);
00426 
00428       std::string dumpFiles(void);
00429 
00430    protected:
00431       boost::scoped_ptr<JobReportImpl>& impl() {return impl_;}
00432 
00433    private:
00434       boost::scoped_ptr<JobReportImpl> impl_;
00435 
00436    };
00437 
00438    std::ostream& operator<< (std::ostream& os, JobReport::InputFile const& f);
00439    std::ostream& operator<< (std::ostream& os, JobReport::OutputFile const& f);
00440    std::ostream& operator<< (std::ostream& os, JobReport::LumiSectionReport const& rep);
00441 
00442 }
00443 
00444 #endif