CMS 3D CMS Logo

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 // 
00020 //
00021 // Original Author:  Marc Paterno
00022 // $Id: JobReport.h,v 1.27 2008/09/29 19:14:03 evansde Exp $
00023 //
00024 
00025 #include <cstddef>
00026 #include <string>
00027 #include <ostream>
00028 #include <set>
00029 #include <map>
00030 #include <vector>
00031 
00032 
00033 #include "boost/scoped_ptr.hpp"
00034 
00035 namespace edm {
00036 
00037     class JobReport {
00038     public:
00039       typedef unsigned int RunNumber;
00040       typedef std::size_t Token;
00041 
00042 
00052       struct LumiSectionReport {
00053         unsigned int  runNumber;
00054         unsigned int lumiSectionId;
00061         
00062       };
00063   
00064       struct RunReport {
00065         RunNumber runNumber;
00066         std::set<unsigned int> lumiSections;
00067         
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     inputSourceClassName; // class which created the file
00086         std::string     moduleLabel;   // name of class instance
00087         std::string     guid;
00088         size_t          numEventsRead;
00089         StringVector    branchNames;
00090         std::map<RunNumber, RunReport> runReports;
00091         bool            fileHasBeenClosed;
00092       };
00093 
00094   
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<RunNumber, RunReport> runReports;
00121         bool            fileHasBeenClosed;
00122       };
00123   
00124       struct JobReportImpl {
00125         // Helper functions to be called from the xFileClosed functions,
00126         // after the appropriate logging is done.
00127         /*
00128          * Note: We want to keep input files, so we can resolve tokens
00129          * when we close output files
00130          *
00131          * Note2: Erasing the Output files on close invalidates the Tokens
00132          * for existing output files since they are based on position in 
00133          * the vector, so I have left off implementing these methods for now
00134          */
00135         void removeInputFileRecord_(Token t); 
00136         void removeOutputFileRecord_(Token t);
00137   
00138         InputFile& getInputFileForToken(Token t);
00139         OutputFile& getOutputFileForToken(Token t);
00140         /*
00141          * Add the input file token provided to every output 
00142          * file currently available.
00143          * Used whenever a new input file is opened, it's token
00144          * is added to all open output files as a contributor
00145          */
00146         void insertInputForOutputs(Token t);
00147   
00148         /*
00149          * get a vector of Tokens for all currently open
00150          * input files. 
00151          * Used when a new output file is opened, all currently open
00152          * input file tokens are used to initialise its list of contributors
00153          */
00154         std::vector<Token> openInputFiles(void);
00155 
00156         /*
00157          * Get a vector of Tokens for all currently open output files
00158          * Used to add lumi sections to open files
00159          */
00160         std::vector<Token> openOutputFiles(void);
00161   
00162         /*
00163          * Associate a Lumi Section to all open output files
00164          *
00165          */
00166         void associateLumiSection(unsigned int runNumber, unsigned int lumiSection);
00167 
00168 
00169         /*
00170          * Associate a Lumi Section to all open input files
00171          *
00172          */
00173         void associateInputLumiSection(unsigned int runNumber, unsigned int lumiSection);
00174         /*
00175          * Associate a run to all open output files
00176          */
00177         void associateRun(unsigned int runNumber);
00178         /*
00179          * Associate a run to all open output files
00180          */
00181         void associateInputRun(unsigned int runNumber);
00182 
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(const InputFile & 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(const OutputFile & f);
00205         
00206 
00207         /*
00208          * Add Generator info to the map of gen info stored in this 
00209          * instance.
00210          */
00211         void addGeneratorInfo(const std::string& name, const std::string& value);
00212         
00213         /*
00214          * Write out generator info to the job report
00215          */
00216         void writeGeneratorInfo(void);
00217         
00218 
00219         /*
00220          *  Flush all open files to logger in event of a problem.
00221          */
00222         void flushFiles(void);
00223         
00224         JobReportImpl(std::ostream* iOst): ost_(iOst) {}
00225         
00226         std::vector<InputFile> inputFiles_;
00227         std::vector<OutputFile> outputFiles_;
00228         std::map<std::string, std::string> generatorInfo_;
00229         std::ostream* ost_;
00230       };
00231 
00232       JobReport();
00233       //Does not take ownership of pointer
00234       JobReport(std::ostream* outputStream);
00235       
00236       ~JobReport();
00237          
00241       Token inputFileOpened(std::string const& physicalFileName,
00242                             std::string const& logicalFileName,
00243                             std::string const& catalog,
00244                             std::string const& inputSourceClassName,
00245                             std::string const& moduleLabel,
00246                             std::string const& guid,
00247                             std::vector<std::string> const& branchNames);
00248       
00249      Token inputFileOpened(std::string const& physicalFileName,
00250                             std::string const& logicalFileName,
00251                             std::string const& catalog,
00252                             std::string const& inputSourceClassName,
00253                             std::string const& moduleLabel,
00254                             std::vector<std::string> const& branchNames);
00257       void eventReadFromFile(Token fileToken, unsigned int run, unsigned int event);
00258 
00263       void reportDataType(Token fileToken, std::string const& dataType);
00264 
00265 
00269       void inputFileClosed(Token fileToken);
00270 
00274       Token outputFileOpened(std::string const& physicalFileName,
00275                              std::string const& logicalFileName,
00276                              std::string const& catalog,
00277                              std::string const& outputModuleClassName,
00278                              std::string const& moduleLabel,
00279                              std::string const& guid,
00280                              std::string const& dataType,
00281                              std::string const& branchHash,
00282                              std::vector<std::string> const& branchNames);
00283 
00284       Token outputFileOpened(std::string const& physicalFileName,
00285                              std::string const& logicalFileName,
00286                              std::string const& catalog,
00287                              std::string const& outputModuleClassName,
00288                              std::string const& moduleLabel,
00289                              std::string const& guid,
00290                              std::string const& dataType,
00291                              std::vector<std::string> const& branchNames);
00292       
00293       /*      Token outputFileOpened(std::string const& physicalFileName,
00294                              std::string const& logicalFileName,
00295                              std::string const& catalog,
00296                              std::string const& outputModuleClassName,
00297                              std::string const& moduleLabel,
00298                              std::string const& dataType,
00299                              std::vector<std::string> const& branchNames);
00300       */
00301       
00302       Token outputFileOpened(std::string const& physicalFileName,
00303                              std::string const& logicalFileName,
00304                              std::string const& catalog,
00305                              std::string const& outputModuleClassName,
00306                              std::string const& moduleLabel,
00307                              std::string const& guid,
00308                              std::vector<std::string> const& branchNames);
00309       
00310       
00311       Token outputFileOpened(std::string const& physicalFileName,
00312                              std::string const& logicalFileName,
00313                              std::string const& catalog,
00314                              std::string const& outputModuleClassName,
00315                              std::string const& moduleLabel,
00316                              std::vector<std::string> const& branchNames);
00317                              
00318       
00319 
00322       void eventWrittenToFile(Token fileToken, unsigned int run, unsigned int event);
00323       
00327       void outputFileClosed(Token fileToken);
00328 
00334       void overrideEventsWritten(Token fileToken, const int eventsWritten);
00340       void overrideEventsRead(Token fileToken, const int eventsRead);
00341 
00342       void reportSkippedEvent(unsigned int run, unsigned int event);
00343 
00344 
00350       void reportLumiSection(unsigned int run, unsigned int lumiSectId);
00356       void reportInputLumiSection(unsigned int run, unsigned int lumiSectId);
00357 
00361       void reportRunNumber(unsigned int run);
00365       void reportInputRunNumber(unsigned int run);
00366 
00372       void  reportError(std::string const& shortDesc,
00373                         std::string const& longDesc);
00374       
00375       void reportError(std::string const& shortDesc,
00376                        std::string const& longDesc,
00377                        int const& exitCode);
00378 
00384       void reportSkippedFile(std::string const& pfn, std::string const& lfn);
00385         
00386       void reportAnalysisFile(std::string const& fileName, 
00387                               std::map<std::string, std::string> const& fileData) ;
00393       void reportTimingInfo(std::map<std::string, double> const & timingData);
00394 
00400       void reportMemoryInfo(std::map<std::string, double> const& memoryData);
00401 
00408       void reportMemoryInfo(std::vector<std::string> const& memoryData);
00409 
00416       void reportMessageInfo(std::map<std::string, double> const & messageData);
00417 
00419       void reportStorageStats(std::string const & data); 
00420 
00423       void overrideContributingInputs(Token outputToken, std::vector<Token> const& inputTokens);
00424       
00428       void reportGeneratorInfo(std::string const&  name, std::string const&  value);
00429       
00433       void reportRandomStateFile(std::string const& name);
00434 
00439       void reportPSetHash(std::string const& hashValue);
00440       
00441 
00449       void reportPerformanceSummary(std::string const&  metricClass,
00450                                     std::map<std::string, std::string> const& metrics);
00451       
00452       void reportPerformanceForModule(std::string const&  metricClass,
00453                                       std::string const&  moduleName,
00454                                       std::map<std::string, std::string> const& metrics);
00455 
00456       
00457 
00459       std::string dumpFiles(void);
00460 
00461    protected:
00462       boost::scoped_ptr<JobReportImpl>& impl() {return impl_;}
00463 
00464    private:
00465       boost::scoped_ptr<JobReportImpl> impl_;
00466 
00467    };
00468 
00469    std::ostream& operator<< (std::ostream& os, JobReport::InputFile const& f);
00470    std::ostream& operator<< (std::ostream& os, JobReport::OutputFile const& f);
00471    std::ostream& operator<< (std::ostream& os, JobReport::LumiSectionReport const& rep);
00472 
00473     /*
00474      * Note that output formatting is spattered across these classes
00475      * If something outside these classes requires access to the 
00476      * same formatting then we need to refactor it into a common library
00477      */
00478   template <typename S, typename T>
00479   S& formatFile(const T& f, S& os) {
00480 
00481     if (f.fileHasBeenClosed) {
00482       os << "\n<State  Value=\"closed\"/>";
00483     } else {
00484       os << "\n<State  Value=\"open\"/>";
00485     }
00486     os << "\n<LFN>" << f.logicalFileName << "</LFN>";
00487     os << "\n<PFN>" << f.physicalFileName << "</PFN>";
00488     os << "\n<Catalog>" << f.catalog << "</Catalog>";
00489     os << "\n<ModuleLabel>" << f.moduleLabel << "</ModuleLabel>";
00490     os << "\n<GUID>" << f.guid << "</GUID>";
00491     os << "\n<Branches>";
00492     std::vector<std::string>::const_iterator iBranch;
00493     for (iBranch = f.branchNames.begin(); 
00494         iBranch != f.branchNames.end(); 
00495         iBranch++) {
00496       os << "\n  <Branch>" << *iBranch << "</Branch>";
00497     }
00498     os << "\n</Branches>";
00499     return os;
00500   }
00501 }
00502 
00503 #endif

Generated on Tue Jun 9 17:36:17 2009 for CMSSW by  doxygen 1.5.4