CMS 3D CMS Logo

JobReport.h
Go to the documentation of this file.
1 #ifndef FWCore_MessageLogger_JobReport_h
2 #define FWCore_MessageLogger_JobReport_h
3 // -*- C++ -*-
4 //
5 // Package: MessageLogger
6 // Class : JobReport
7 //
74 //
75 // Original Author: Marc Paterno
76 //
77 
78 /*
79 Changes Log 1: 2009/01/14 10:29:00, Natalia Garcia Nebot
80  Modified and added some methods to report CPU and memory information from /proc/cpuinfo
81  and /proc/meminfo files and Memory statistics
82 */
83 
87 
88 #include <atomic>
89 #include <cstddef>
90 #include <iosfwd>
91 #include <map>
92 #include <memory>
93 #include <mutex>
94 #include <set>
95 #include <string>
96 #include <vector>
97 
98 #include "tbb/concurrent_unordered_map.h"
99 #include "tbb/concurrent_vector.h"
100 
101 namespace edm {
102 
103  class JobReport {
104  public:
105 
106  typedef unsigned int RunNumber;
107  typedef std::size_t Token;
108 
109  struct RunReport {
110  RunNumber runNumber;
111  std::map<unsigned int,unsigned long> lumiSectionsToNEvents;
112  };
113 
123  struct InputFile {
124  typedef std::vector<std::string> StringVector;
125 
129  std::string inputType; // primaryFiles, secondaryFiles, mixingFiles
130  std::string inputSourceClassName; // class which created the file
131  std::string moduleLabel; // name of class instance
133  std::size_t numEventsRead;
134  StringVector branchNames;
135  std::map<RunNumber, RunReport> runReports;
137  std::set<std::string> fastClonedBranches;
138  };
139 
149  struct OutputFile {
150 
152 
157  std::string moduleLabel; // name of class instance
161  std::size_t numEventsWritten;
162  StringVector branchNames;
163  std::vector<Token> contributingInputs;
164  tbb::concurrent_vector<Token> contributingInputsSecSource;
165  std::map<std::string, bool> fastCopyingInputs;
166  std::map<RunNumber, RunReport> runReports;
168  };
169 
171  public:
172  AtomicLongLong() : value_(0) {}
173  AtomicLongLong(AtomicLongLong const& r) : value_(r.value_.load()) {}
174  std::atomic<long long>& value() { return value_; }
175  std::atomic<long long> const& value() const { return value_; }
176  private:
177  std::atomic<long long> value_;
178  };
179 
180  struct JobReportImpl {
181 
182  JobReportImpl& operator=(JobReportImpl const&) = delete;
183  JobReportImpl(JobReportImpl const&) = delete;
184 
185  InputFile& getInputFileForToken(InputType inputType, Token t);
186  OutputFile& getOutputFileForToken(Token t);
187 
188  /*
189  * Add the input file token provided to every output
190  * file currently available.
191  * Used whenever a new input file is opened, it's token
192  * is added to all open output files as a contributor
193  */
194  void insertInputForOutputs(InputType inputType, Token t);
195 
196  /*
197  * Associate a Lumi Section to all open output files
198  *
199  */
200  void associateLumiSection(JobReport::Token token, unsigned int runNumber, unsigned int lumiSection, unsigned long nEvents);
201 
202  /*
203  * Associate a Lumi Section to all open input files
204  *
205  */
206  void associateInputLumiSection(unsigned int runNumber, unsigned int lumiSection);
207 
208  /*
209  * Associate a run to all open output files
210  */
211  void associateRun(JobReport::Token token, unsigned int runNumber);
212 
213  /*
214  * Associate a run to all open output files
215  */
216  void associateInputRun(unsigned int runNumber);
217 
218  /*
219  * Write an InputFile object to the Logger
220  * Generate XML string for InputFile instance and dispatch to
221  * job report via MessageLogger
222  */
223  void writeInputFile(InputFile const& f);
224 
225  /*
226  * Write an OutputFile object to the Logger
227  * Generate an XML string for the OutputFile provided and
228  * dispatch it to the logger
229  * Contributing input tokens are resolved to the input LFN and PFN
230  *
231  * TODO: We have not yet addressed the issue where we cleanup not
232  * contributing input files.
233  * Also, it is possible to get fake input to output file mappings
234  * if an input file is open already when a new output file is opened
235  * but the input gets closed without contributing events to the
236  * output file due to filtering etc.
237  *
238  */
239  void writeOutputFile(OutputFile const& f);
240 
241  /*
242  * Flush all open files to logger in event of a problem.
243  */
244  void flushFiles(void);
245 
246  JobReportImpl(std::ostream* iOst): printedReadBranches_(false), ost_(iOst) {}
247 
248  std::ostream const* ost() const {return get_underlying_safe(ost_);}
249  std::ostream*& ost() {return get_underlying_safe(ost_);}
250 
251  std::vector<InputFile> inputFiles_;
252  tbb::concurrent_vector<InputFile> inputFilesSecSource_;
253  tbb::concurrent_vector<OutputFile> outputFiles_;
254  std::map<std::string, long long> readBranches_;
255  std::map<std::string, long long> readBranchesSecFile_;
256  tbb::concurrent_unordered_map<std::string, AtomicLongLong> readBranchesSecSource_;
260  };
261 
262  JobReport();
263  //Does not take ownership of pointer
264  JobReport(std::ostream* outputStream);
265 
266  JobReport& operator=(JobReport const&) = delete;
267  JobReport(JobReport const&) = delete;
268 
269  ~JobReport();
270 
274  Token inputFileOpened(std::string const& physicalFileName,
275  std::string const& logicalFileName,
276  std::string const& catalog,
277  std::string const& inputType,
278  std::string const& inputSourceClassName,
279  std::string const& moduleLabel,
280  std::string const& guid,
281  std::vector<std::string> const& branchNames);
282 
285  void eventReadFromFile(InputType inputType, Token fileToken);
286 
291  // CMS-THREADING Current implementation requires an instance of an
292  // OuputModule run on only one thread at a time.
293  void reportDataType(Token fileToken, std::string const& dataType);
294 
295 
299  void inputFileClosed(InputType inputType, Token fileToken);
300 
304  Token outputFileOpened(std::string const& physicalFileName,
305  std::string const& logicalFileName,
306  std::string const& catalog,
307  std::string const& outputModuleClassName,
308  std::string const& moduleLabel,
309  std::string const& guid,
310  std::string const& dataType,
311  std::string const& branchHash,
312  std::vector<std::string> const& branchNames);
313 
316  // CMS-THREADING Current implementation requires an instance of an
317  // OuputModule run on only one thread at a time.
318  void eventWrittenToFile(Token fileToken, RunNumber_t run, EventNumber_t event);
319 
323  void outputFileClosed(Token fileToken);
324 
326 
331  void reportRunNumber(JobReport::Token token, unsigned int run);
332 
337  void reportLumiSection(JobReport::Token token, unsigned int run, unsigned int lumiSectId, unsigned long nEvents=0);
338 
344  void reportInputLumiSection(unsigned int run, unsigned int lumiSectId);
345 
349  void reportInputRunNumber(unsigned int run);
350 
356  void reportError(std::string const& shortDesc,
357  std::string const& longDesc,
358  int const& exitCode);
359 
365  void reportSkippedFile(std::string const& pfn, std::string const& lfn);
366 
367  void reportFallbackAttempt(std::string const& pfn, std::string const& lfn, std::string const& err);
368 
370  std::map<std::string, std::string> const& fileData) ;
371 
378  void reportMemoryInfo(std::vector<std::string> const& memoryData);
379 
386  void reportMessageInfo(std::map<std::string, double> const& messageData);
387 
394  void reportReadBranches();
395 
397  void reportReadBranch(InputType inputType, std::string const& branchName);
398 
400  void reportFastClonedBranches(std::set<std::string> const& fastClonedBranches, long long nEvents);
401 
406 
407  /*
408  * Report information about fast copying. Called for each open output file
409  * whenever an input file is opened.
410  */
411  void reportFastCopyingStatus(Token t, std::string const& inputFileName, bool fastCopying);
412 
420  void reportPerformanceSummary(std::string const& metricClass,
421  std::map<std::string, std::string> const& metrics);
422 
423  void reportPerformanceForModule(std::string const& metricClass,
424  std::string const& moduleName,
425  std::map<std::string, std::string> const& metrics);
426 
428  std::string dumpFiles(void);
429 
430  protected:
432 
433  private:
436  };
437 
438  std::ostream& operator<< (std::ostream& os, JobReport::InputFile const& f);
439  std::ostream& operator<< (std::ostream& os, JobReport::OutputFile const& f);
440 }
441 #endif
InputType
Definition: InputType.h:5
void reportSkippedFile(std::string const &pfn, std::string const &lfn)
Definition: JobReport.cc:545
std::string inputSourceClassName
Definition: JobReport.h:130
std::string outputModuleClassName
Definition: JobReport.h:156
std::string physicalFileName
Definition: JobReport.h:154
void reportMemoryInfo(std::vector< std::string > const &memoryData)
Definition: JobReport.cc:577
void reportInputRunNumber(unsigned int run)
Definition: JobReport.cc:502
void eventReadFromFile(InputType inputType, Token fileToken)
Definition: JobReport.cc:389
std::map< std::string, long long > readBranches_
Definition: JobReport.h:254
static boost::mutex mutex
Definition: LHEProxy.cc:11
std::mutex write_mutex
Definition: JobReport.h:435
void reportFallbackAttempt(std::string const &pfn, std::string const &lfn, std::string const &err)
Definition: JobReport.cc:561
std::string logicalFileName
Definition: JobReport.h:126
std::ostream const * ost() const
Definition: JobReport.h:248
std::set< std::string > fastClonedBranches
Definition: JobReport.h:137
unsigned long long EventNumber_t
std::atomic< long long > & value()
Definition: JobReport.h:174
std::map< std::string, bool > fastCopyingInputs
Definition: JobReport.h:165
std::string logicalFileName
Definition: JobReport.h:153
void reportFastCopyingStatus(Token t, std::string const &inputFileName, bool fastCopying)
Definition: JobReport.cc:481
void reportRunNumber(JobReport::Token token, unsigned int run)
Definition: JobReport.cc:497
void reportRandomStateFile(std::string const &name)
Definition: JobReport.cc:667
JobReport & operator=(JobReport const &)=delete
std::vector< std::string > StringVector
Definition: JobReport.h:124
uint16_t size_type
edm::propagate_const< std::unique_ptr< JobReportImpl > > impl_
Definition: JobReport.h:434
Token inputFileOpened(std::string const &physicalFileName, std::string const &logicalFileName, std::string const &catalog, std::string const &inputType, std::string const &inputSourceClassName, std::string const &moduleLabel, std::string const &guid, std::vector< std::string > const &branchNames)
Definition: JobReport.cc:341
std::vector< InputFile > inputFiles_
Definition: JobReport.h:251
void reportPerformanceForModule(std::string const &metricClass, std::string const &moduleName, std::map< std::string, std::string > const &metrics)
Definition: JobReport.cc:702
edm::propagate_const< std::unique_ptr< JobReportImpl > > & impl()
Definition: JobReport.h:431
std::map< RunNumber, RunReport > runReports
Definition: JobReport.h:135
std::vector< Token > contributingInputs
Definition: JobReport.h:163
std::string physicalFileName
Definition: JobReport.h:127
void reportSkippedEvent(RunNumber_t run, EventNumber_t event)
Definition: JobReport.cc:468
tbb::concurrent_unordered_map< std::string, AtomicLongLong > readBranchesSecSource_
Definition: JobReport.h:256
InputFile::StringVector StringVector
Definition: JobReport.h:151
std::string moduleName(Provenance const &provenance)
Definition: Provenance.cc:27
std::size_t numEventsRead
Definition: JobReport.h:133
StringVector branchNames
Definition: JobReport.h:162
void reportInputLumiSection(unsigned int run, unsigned int lumiSectId)
Definition: JobReport.cc:492
std::map< std::string, long long > readBranchesSecFile_
Definition: JobReport.h:255
std::map< RunNumber, RunReport > runReports
Definition: JobReport.h:166
void reportPerformanceSummary(std::string const &metricClass, std::map< std::string, std::string > const &metrics)
Definition: JobReport.cc:681
std::ostream *& ost()
Definition: JobReport.h:249
double f[11][100]
Token outputFileOpened(std::string const &physicalFileName, std::string const &logicalFileName, std::string const &catalog, std::string const &outputModuleClassName, std::string const &moduleLabel, std::string const &guid, std::string const &dataType, std::string const &branchHash, std::vector< std::string > const &branchNames)
Definition: JobReport.cc:415
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
AtomicLongLong(AtomicLongLong const &r)
Definition: JobReport.h:173
edm::propagate_const< std::ostream * > ost_
Definition: JobReport.h:259
std::atomic< long long > const & value() const
Definition: JobReport.h:175
void reportError(std::string const &shortDesc, std::string const &longDesc, int const &exitCode)
Definition: JobReport.cc:528
unsigned int RunNumber
Definition: JobReport.h:106
std::size_t Token
Definition: JobReport.h:107
void reportReadBranch(InputType inputType, std::string const &branchName)
Inform the job report that a branch has been read.
Definition: JobReport.cc:642
std::size_t numEventsWritten
Definition: JobReport.h:161
void reportFastClonedBranches(std::set< std::string > const &fastClonedBranches, long long nEvents)
Inform the job report that branches have been fast Cloned.
Definition: JobReport.cc:657
void eventWrittenToFile(Token fileToken, RunNumber_t run, EventNumber_t event)
Definition: JobReport.cc:455
tbb::concurrent_vector< InputFile > inputFilesSecSource_
Definition: JobReport.h:252
def load(fileName)
Definition: svgfig.py:546
std::atomic< long long > value_
Definition: JobReport.h:177
void reportMessageInfo(std::map< std::string, double > const &messageData)
Definition: JobReport.cc:592
std::string dumpFiles(void)
debug/test util
Definition: JobReport.cc:725
HLT enums.
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:507
std::vector< InputFile >::size_type lastOpenedPrimaryInputFile_
Definition: JobReport.h:258
void outputFileClosed(Token fileToken)
Definition: JobReport.cc:461
std::map< unsigned int, unsigned long > lumiSectionsToNEvents
Definition: JobReport.h:111
JobReportImpl(std::ostream *iOst)
Definition: JobReport.h:246
unsigned int RunNumber_t
tbb::concurrent_vector< OutputFile > outputFiles_
Definition: JobReport.h:253
void reportDataType(Token fileToken, std::string const &dataType)
Definition: JobReport.cc:395
UInt_t nEvents
Definition: hcalCalib.cc:42
tbb::concurrent_vector< Token > contributingInputsSecSource
Definition: JobReport.h:164
StringVector branchNames
Definition: JobReport.h:134
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger tbale.
void inputFileClosed(InputType inputType, Token fileToken)
Definition: JobReport.cc:401
Definition: event.py:1
void reportReadBranches()
Definition: JobReport.cc:608
void reportLumiSection(JobReport::Token token, unsigned int run, unsigned int lumiSectId, unsigned long nEvents=0)
Definition: JobReport.cc:487