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 "oneapi/tbb/concurrent_unordered_map.h"
99 #include "oneapi/tbb/concurrent_vector.h"
100 
101 namespace edm {
102 
103  class JobReport {
104  public:
105  typedef unsigned int RunNumber;
106  typedef std::size_t Token;
107 
108  struct RunReport {
110  std::map<unsigned int, unsigned long> lumiSectionsToNEvents;
111  };
112 
122  struct InputFile {
123  typedef std::vector<std::string> StringVector;
124 
128  std::string inputType; // primaryFiles, secondaryFiles, mixingFiles
129  std::string inputSourceClassName; // class which created the file
130  std::string moduleLabel; // name of class instance
132  std::size_t numEventsRead;
134  std::map<RunNumber, RunReport> runReports;
136  std::set<std::string> fastClonedBranches;
137  };
138 
148  struct OutputFile {
150 
155  std::string moduleLabel; // name of class instance
159  std::size_t numEventsWritten;
161  std::vector<Token> contributingInputs;
162  oneapi::tbb::concurrent_vector<Token> contributingInputsSecSource;
163  std::map<std::string, bool> fastCopyingInputs;
164  std::map<RunNumber, RunReport> runReports;
166  };
167 
169  public:
172  std::atomic<long long>& value() { return value_; }
173  std::atomic<long long> const& value() const { return value_; }
174 
175  private:
176  std::atomic<long long> value_;
177  };
178 
179  struct JobReportImpl {
180  JobReportImpl& operator=(JobReportImpl const&) = delete;
181  JobReportImpl(JobReportImpl const&) = delete;
182 
185 
186  /*
187  * Add the input file token provided to every output
188  * file currently available.
189  * Used whenever a new input file is opened, it's token
190  * is added to all open output files as a contributor
191  */
192  void insertInputForOutputs(InputType inputType, Token t);
193 
194  /*
195  * Associate a Lumi Section to all open output files
196  *
197  */
199  unsigned int runNumber,
200  unsigned int lumiSection,
201  unsigned long nEvents);
202 
203  /*
204  * Associate a Lumi Section to all open input files
205  *
206  */
207  void associateInputLumiSection(unsigned int runNumber, unsigned int lumiSection);
208 
209  /*
210  * Associate a run to all open output files
211  */
212  void associateRun(JobReport::Token token, unsigned int runNumber);
213 
214  /*
215  * Associate a run to all open output files
216  */
217  void associateInputRun(unsigned int runNumber);
218 
219  /*
220  * Write an InputFile object to the Logger
221  * Generate XML string for InputFile instance and dispatch to
222  * job report via MessageLogger
223  */
224  void writeInputFile(InputFile const& f);
225 
226  /*
227  * Write an OutputFile object to the Logger
228  * Generate an XML string for the OutputFile provided and
229  * dispatch it to the logger
230  * Contributing input tokens are resolved to the input LFN and PFN
231  *
232  * TODO: We have not yet addressed the issue where we cleanup not
233  * contributing input files.
234  * Also, it is possible to get fake input to output file mappings
235  * if an input file is open already when a new output file is opened
236  * but the input gets closed without contributing events to the
237  * output file due to filtering etc.
238  *
239  */
240  void writeOutputFile(OutputFile const& f);
241 
242  /*
243  * Flush all open files to logger in event of a problem.
244  */
245  void flushFiles(void);
246 
247  JobReportImpl(std::ostream* iOst) : printedReadBranches_(false), ost_(iOst) {}
248 
249  std::ostream const* ost() const { return get_underlying_safe(ost_); }
250  std::ostream*& ost() { return get_underlying_safe(ost_); }
251 
252  std::vector<InputFile> inputFiles_;
253  oneapi::tbb::concurrent_vector<InputFile> inputFilesSecSource_;
254  oneapi::tbb::concurrent_vector<OutputFile> outputFiles_;
255  std::map<std::string, long long> readBranches_;
256  std::map<std::string, long long> readBranchesSecFile_;
257  oneapi::tbb::concurrent_unordered_map<std::string, AtomicLongLong> readBranchesSecSource_;
258  std::atomic<bool> printedReadBranches_;
261  };
262 
263  JobReport();
264  //Does not take ownership of pointer
265  JobReport(std::ostream* outputStream);
266 
267  JobReport& operator=(JobReport const&) = delete;
268  JobReport(JobReport const&) = delete;
269 
270  ~JobReport();
271 
275  Token inputFileOpened(std::string const& physicalFileName,
276  std::string const& logicalFileName,
277  std::string const& catalog,
278  std::string const& inputType,
279  std::string const& inputSourceClassName,
280  std::string const& moduleLabel,
281  std::string const& guid,
282  std::vector<std::string> const& branchNames);
283 
286  void eventReadFromFile(InputType inputType, Token fileToken);
287 
292  // CMS-THREADING Current implementation requires an instance of an
293  // OuputModule run on only one thread at a time.
294  void reportDataType(Token fileToken, std::string const& dataType);
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.
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, std::string const& longDesc, int const& exitCode);
357 
363  void reportSkippedFile(std::string const& pfn, std::string const& lfn);
364 
365  void reportFallbackAttempt(std::string const& pfn, std::string const& lfn, std::string const& err);
366 
367  void reportAnalysisFile(std::string const& fileName, std::map<std::string, std::string> const& fileData);
368 
375  void reportMemoryInfo(std::vector<std::string> const& memoryData);
376 
383  void reportMessageInfo(std::map<std::string, double> const& messageData);
384 
391  void reportReadBranches();
392 
394  void reportReadBranch(InputType inputType, std::string const& branchName);
395 
397  void reportFastClonedBranches(std::set<std::string> const& fastClonedBranches, long long nEvents);
398 
403 
404  /*
405  * Report information about fast copying. Called for each open output file
406  * whenever an input file is opened.
407  */
408  void reportFastCopyingStatus(Token t, std::string const& inputFileName, bool fastCopying);
409 
417  void reportPerformanceSummary(std::string const& metricClass, std::map<std::string, std::string> const& metrics);
418 
419  void reportPerformanceForModule(std::string const& metricClass,
420  std::string const& moduleName,
421  std::map<std::string, std::string> const& metrics);
422 
424  std::string dumpFiles(void);
425 
426  protected:
428 
429  private:
430  void temporarilyCloseXML();
433  };
434 
435  std::ostream& operator<<(std::ostream& os, JobReport::InputFile const& f);
436  std::ostream& operator<<(std::ostream& os, JobReport::OutputFile const& f);
437 } // namespace edm
438 #endif
InputType
Definition: InputType.h:5
void reportSkippedFile(std::string const &pfn, std::string const &lfn)
Definition: JobReport.cc:519
std::string inputSourceClassName
Definition: JobReport.h:129
std::string outputModuleClassName
Definition: JobReport.h:154
std::string physicalFileName
Definition: JobReport.h:152
void associateRun(JobReport::Token token, unsigned int runNumber)
Definition: JobReport.cc:255
void reportMemoryInfo(std::vector< std::string > const &memoryData)
Definition: JobReport.cc:554
void reportInputRunNumber(unsigned int run)
Definition: JobReport.cc:484
void eventReadFromFile(InputType inputType, Token fileToken)
Definition: JobReport.cc:377
std::map< std::string, long long > readBranches_
Definition: JobReport.h:255
oneapi::tbb::concurrent_vector< OutputFile > outputFiles_
Definition: JobReport.h:254
std::mutex write_mutex
Definition: JobReport.h:432
void reportFallbackAttempt(std::string const &pfn, std::string const &lfn, std::string const &err)
Definition: JobReport.cc:536
std::string logicalFileName
Definition: JobReport.h:125
static std::mutex mutex
Definition: Proxy.cc:8
std::set< std::string > fastClonedBranches
Definition: JobReport.h:136
unsigned long long EventNumber_t
std::atomic< long long > & value()
Definition: JobReport.h:172
std::map< std::string, bool > fastCopyingInputs
Definition: JobReport.h:163
std::string logicalFileName
Definition: JobReport.h:151
void reportFastCopyingStatus(Token t, std::string const &inputFileName, bool fastCopying)
Definition: JobReport.cc:464
JobReportImpl(JobReportImpl const &)=delete
std::atomic< bool > printedReadBranches_
Definition: JobReport.h:258
constexpr std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
void temporarilyCloseXML()
Definition: JobReport.cc:312
void reportRunNumber(JobReport::Token token, unsigned int run)
Definition: JobReport.cc:482
void reportRandomStateFile(std::string const &name)
Definition: JobReport.cc:654
JobReport & operator=(JobReport const &)=delete
std::vector< std::string > StringVector
Definition: JobReport.h:123
uint16_t size_type
edm::propagate_const< std::unique_ptr< JobReportImpl > > impl_
Definition: JobReport.h:431
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:331
std::vector< InputFile > inputFiles_
Definition: JobReport.h:252
void reportPerformanceForModule(std::string const &metricClass, std::string const &moduleName, std::map< std::string, std::string > const &metrics)
Definition: JobReport.cc:687
edm::propagate_const< std::unique_ptr< JobReportImpl > > & impl()
Definition: JobReport.h:427
std::map< RunNumber, RunReport > runReports
Definition: JobReport.h:134
std::vector< Token > contributingInputs
Definition: JobReport.h:161
std::string physicalFileName
Definition: JobReport.h:126
void reportSkippedEvent(RunNumber_t run, EventNumber_t event)
Definition: JobReport.cc:452
void insertInputForOutputs(InputType inputType, Token t)
Definition: JobReport.cc:151
InputFile::StringVector StringVector
Definition: JobReport.h:149
std::size_t numEventsRead
Definition: JobReport.h:132
void writeInputFile(InputFile const &f)
Definition: JobReport.cc:168
StringVector branchNames
Definition: JobReport.h:160
JobReportImpl & operator=(JobReportImpl const &)=delete
void reportInputLumiSection(unsigned int run, unsigned int lumiSectId)
Definition: JobReport.cc:478
std::map< std::string, long long > readBranchesSecFile_
Definition: JobReport.h:256
std::map< RunNumber, RunReport > runReports
Definition: JobReport.h:164
void reportPerformanceSummary(std::string const &metricClass, std::map< std::string, std::string > const &metrics)
Definition: JobReport.cc:668
std::ostream *& ost()
Definition: JobReport.h:250
double f[11][100]
oneapi::tbb::concurrent_unordered_map< std::string, AtomicLongLong > readBranchesSecSource_
Definition: JobReport.h:257
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:399
AtomicLongLong(AtomicLongLong const &r)
Definition: JobReport.h:171
edm::propagate_const< std::ostream * > ost_
Definition: JobReport.h:260
void reportError(std::string const &shortDesc, std::string const &longDesc, int const &exitCode)
Definition: JobReport.cc:506
unsigned int RunNumber
Definition: JobReport.h:105
std::size_t Token
Definition: JobReport.h:106
void associateInputRun(unsigned int runNumber)
Definition: JobReport.cc:263
void reportReadBranch(InputType inputType, std::string const &branchName)
Inform the job report that a branch has been read.
Definition: JobReport.cc:627
std::size_t numEventsWritten
Definition: JobReport.h:159
void reportFastClonedBranches(std::set< std::string > const &fastClonedBranches, long long nEvents)
Inform the job report that branches have been fast Cloned.
Definition: JobReport.cc:642
std::atomic< long long > const & value() const
Definition: JobReport.h:173
void eventWrittenToFile(Token fileToken, RunNumber_t run, EventNumber_t event)
Definition: JobReport.cc:439
std::ostream const * ost() const
Definition: JobReport.h:249
def load(fileName)
Definition: svgfig.py:547
std::atomic< long long > value_
Definition: JobReport.h:176
void reportMessageInfo(std::map< std::string, double > const &messageData)
Definition: JobReport.cc:569
void associateLumiSection(JobReport::Token token, unsigned int runNumber, unsigned int lumiSection, unsigned long nEvents)
Definition: JobReport.cc:275
std::string dumpFiles(void)
debug/test util
Definition: JobReport.cc:708
std::string moduleName(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:27
HLT enums.
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:486
std::vector< InputFile >::size_type lastOpenedPrimaryInputFile_
Definition: JobReport.h:259
void outputFileClosed(Token fileToken)
Definition: JobReport.cc:444
std::map< unsigned int, unsigned long > lumiSectionsToNEvents
Definition: JobReport.h:110
void writeOutputFile(OutputFile const &f)
Definition: JobReport.cc:195
JobReportImpl(std::ostream *iOst)
Definition: JobReport.h:247
unsigned int RunNumber_t
InputFile & getInputFileForToken(InputType inputType, Token t)
Definition: JobReport.cc:107
void reportDataType(Token fileToken, std::string const &dataType)
Definition: JobReport.cc:382
oneapi::tbb::concurrent_vector< Token > contributingInputsSecSource
Definition: JobReport.h:162
StringVector branchNames
Definition: JobReport.h:133
branchNames
Definition: haddnano.py:54
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger table.
void inputFileClosed(InputType inputType, Token fileToken)
Definition: JobReport.cc:387
void associateInputLumiSection(unsigned int runNumber, unsigned int lumiSection)
Definition: JobReport.cc:288
Definition: event.py:1
void reportReadBranches()
Definition: JobReport.cc:584
OutputFile & getOutputFileForToken(Token t)
Definition: JobReport.cc:131
oneapi::tbb::concurrent_vector< InputFile > inputFilesSecSource_
Definition: JobReport.h:253
void reportLumiSection(JobReport::Token token, unsigned int run, unsigned int lumiSectId, unsigned long nEvents=0)
Definition: JobReport.cc:471