CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/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 #include "FWCore/Utilities/interface/tinyxml.h"
00038 
00039 namespace edm {
00040 
00041     class JobReport {
00042     public:
00043       typedef unsigned int RunNumber;
00044       typedef std::size_t Token;
00045 
00055       struct LumiSectionReport {
00056         unsigned int  runNumber;
00057         unsigned int lumiSectionId;
00064       };
00065 
00066       struct RunReport {
00067         RunNumber runNumber;
00068         std::set<unsigned int> lumiSections;
00069       };
00070 
00080       struct InputFile {
00081         typedef std::vector<std::string> StringVector;
00082 
00083         std::string     logicalFileName;
00084         std::string     physicalFileName;
00085         std::string     catalog;
00086         std::string     inputType; // primaryFiles, secondaryFiles, mixingFiles
00087         std::string     inputSourceClassName; // class which created the file
00088         std::string     moduleLabel;   // name of class instance
00089         std::string     guid;
00090         size_t          numEventsRead;
00091         StringVector    branchNames;
00092         std::map<RunNumber, RunReport> runReports;
00093         bool            fileHasBeenClosed;
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::ostream* ost_;
00229       };
00230 
00231       JobReport();
00232       //Does not take ownership of pointer
00233       JobReport(std::ostream* outputStream);
00234 
00235       ~JobReport();
00236 
00238       void childAfterFork(std::string const& jobReportFile, unsigned int childIndex, unsigned int numberOfChildren);
00239 
00240       void parentBeforeFork(std::string const& jobReportFile, unsigned int numberOfChildren);
00241 
00242       void parentAfterFork(std::string const& jobReportFile);
00243 
00247       Token inputFileOpened(std::string const& physicalFileName,
00248                             std::string const& logicalFileName,
00249                             std::string const& catalog,
00250                             std::string const& inputType,
00251                             std::string const& inputSourceClassName,
00252                             std::string const& moduleLabel,
00253                             std::string const& guid,
00254                             std::vector<std::string> const& branchNames);
00255 
00258       void eventReadFromFile(Token fileToken, unsigned int run, unsigned int event);
00259 
00264       void reportDataType(Token fileToken, std::string const& dataType);
00265 
00266 
00270       void inputFileClosed(Token fileToken);
00271 
00275       Token outputFileOpened(std::string const& physicalFileName,
00276                              std::string const& logicalFileName,
00277                              std::string const& catalog,
00278                              std::string const& outputModuleClassName,
00279                              std::string const& moduleLabel,
00280                              std::string const& guid,
00281                              std::string const& dataType,
00282                              std::string const& branchHash,
00283                              std::vector<std::string> const& branchNames);
00284 
00287       void eventWrittenToFile(Token fileToken, unsigned int run, unsigned int event);
00288 
00292       void outputFileClosed(Token fileToken);
00293 
00299       void overrideEventsWritten(Token fileToken, int const eventsWritten);
00305       void overrideEventsRead(Token fileToken, int const eventsRead);
00306 
00307       void reportSkippedEvent(unsigned int run, unsigned int event);
00308 
00314       void reportLumiSection(unsigned int run, unsigned int lumiSectId);
00320       void reportInputLumiSection(unsigned int run, unsigned int lumiSectId);
00321 
00325       void reportRunNumber(unsigned int run);
00329       void reportInputRunNumber(unsigned int run);
00330 
00336       void  reportError(std::string const& shortDesc,
00337                         std::string const& longDesc);
00338 
00339       void reportError(std::string const& shortDesc,
00340                        std::string const& longDesc,
00341                        int const& exitCode);
00342 
00348       void reportSkippedFile(std::string const& pfn, std::string const& lfn);
00349 
00350       void reportAnalysisFile(std::string const& fileName,
00351                               std::map<std::string, std::string> const& fileData) ;
00352 
00359       void reportMemoryInfo(std::vector<std::string> const& memoryData);
00360 
00367       void reportMessageInfo(std::map<std::string, double> const& messageData);
00368 
00371       void overrideContributingInputs(Token outputToken, std::vector<Token> const& inputTokens);
00372 
00376       void reportGeneratorInfo(std::string const&  name, std::string const&  value);
00377 
00381       void reportRandomStateFile(std::string const& name);
00382 
00387       void reportPSetHash(std::string const& hashValue);
00388 
00389       /*
00390        * Report information about fast copying. Called for each open output file
00391        * whenever an input file is opened.
00392        */
00393       void reportFastCopyingStatus(Token t, std::string const& inputFileName, bool fastCopying);
00394 
00402       void reportPerformanceSummary(std::string const&  metricClass,
00403                                     std::map<std::string, std::string> const& metrics);
00404 
00405       void reportPerformanceForModule(std::string const&  metricClass,
00406                                       std::string const&  moduleName,
00407                                       std::map<std::string, std::string> const& metrics);
00408 
00410       std::string dumpFiles(void);
00411 
00412    protected:
00413       boost::scoped_ptr<JobReportImpl>& impl() {return impl_;}
00414 
00415    private:
00416       boost::scoped_ptr<JobReportImpl> impl_;
00417 
00418    };
00419 
00420    std::ostream& operator<< (std::ostream& os, JobReport::InputFile const& f);
00421    std::ostream& operator<< (std::ostream& os, JobReport::OutputFile const& f);
00422    std::ostream& operator<< (std::ostream& os, JobReport::LumiSectionReport const& rep);
00423 
00424     /*
00425      * Note that output formatting is spattered across these classes
00426      * If something outside these classes requires access to the
00427      * same formatting then we need to refactor it into a common library
00428      */
00429   template <typename S, typename T>
00430   S& formatFile(T const& f, S& os) {
00431 
00432     if (f.fileHasBeenClosed) {
00433       os << "\n<State  Value=\"closed\"/>";
00434     } else {
00435       os << "\n<State  Value=\"open\"/>";
00436     }
00437 
00438     os << "\n<LFN>" << TiXmlText(f.logicalFileName) << "</LFN>";
00439     os << "\n<PFN>" << TiXmlText(f.physicalFileName) << "</PFN>";
00440     os << "\n<Catalog>" << TiXmlText(f.catalog) << "</Catalog>";
00441     os << "\n<ModuleLabel>" << TiXmlText(f.moduleLabel) << "</ModuleLabel>";
00442     os << "\n<GUID>" << f.guid << "</GUID>";
00443     os << "\n<Branches>";
00444     for (std::vector<std::string>::const_iterator iBranch = f.branchNames.begin(),
00445         iBranchEnd = f.branchNames.end();
00446         iBranch != iBranchEnd;
00447         ++iBranch) {
00448       os << "\n  <Branch>" << TiXmlText(*iBranch) << "</Branch>";
00449     }
00450     os << "\n</Branches>";
00451     return os;
00452   }
00453 }
00454 
00455 #endif