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  typedef unsigned int RunNumber;
106  typedef std::size_t Token;
107 
108  struct RunReport {
109  RunNumber runNumber;
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;
133  StringVector branchNames;
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;
160  StringVector branchNames;
161  std::vector<Token> contributingInputs;
162  tbb::concurrent_vector<Token> contributingInputsSecSource;
163  std::map<std::string, bool> fastCopyingInputs;
164  std::map<RunNumber, RunReport> runReports;
166  };
167 
169  public:
170  AtomicLongLong() : value_(0) {}
171  AtomicLongLong(AtomicLongLong const& r) : value_(r.value_.load()) {}
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 
183  InputFile& getInputFileForToken(InputType inputType, Token t);
184  OutputFile& getOutputFileForToken(Token t);
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  */
198  void associateLumiSection(JobReport::Token token,
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  tbb::concurrent_vector<InputFile> inputFilesSecSource_;
254  tbb::concurrent_vector<OutputFile> outputFiles_;
255  std::map<std::string, long long> readBranches_;
256  std::map<std::string, long long> readBranchesSecFile_;
257  tbb::concurrent_unordered_map<std::string, AtomicLongLong> readBranchesSecSource_;
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.
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, 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:
432  };
433 
434  std::ostream& operator<<(std::ostream& os, JobReport::InputFile const& f);
435  std::ostream& operator<<(std::ostream& os, JobReport::OutputFile const& f);
436 } // namespace edm
437 #endif
static boost::mutex mutex
Definition: Proxy.cc:9
InputType
Definition: InputType.h:5
void reportSkippedFile(std::string const &pfn, std::string const &lfn)
Definition: JobReport.cc:506
std::string inputSourceClassName
Definition: JobReport.h:129
std::string outputModuleClassName
Definition: JobReport.h:154
std::string physicalFileName
Definition: JobReport.h:152
void reportMemoryInfo(std::vector< std::string > const &memoryData)
Definition: JobReport.cc:541
void reportInputRunNumber(unsigned int run)
Definition: JobReport.cc:471
void eventReadFromFile(InputType inputType, Token fileToken)
Definition: JobReport.cc:366
std::map< std::string, long long > readBranches_
Definition: JobReport.h:255
std::mutex write_mutex
Definition: JobReport.h:431
void reportFallbackAttempt(std::string const &pfn, std::string const &lfn, std::string const &err)
Definition: JobReport.cc:523
std::string logicalFileName
Definition: JobReport.h:125
std::ostream const * ost() const
Definition: JobReport.h:249
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:451
void reportRunNumber(JobReport::Token token, unsigned int run)
Definition: JobReport.cc:469
void reportRandomStateFile(std::string const &name)
Definition: JobReport.cc:638
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:430
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:320
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:672
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:439
tbb::concurrent_unordered_map< std::string, AtomicLongLong > readBranchesSecSource_
Definition: JobReport.h:257
InputFile::StringVector StringVector
Definition: JobReport.h:149
std::string moduleName(Provenance const &provenance)
Definition: Provenance.cc:27
std::size_t numEventsRead
Definition: JobReport.h:132
StringVector branchNames
Definition: JobReport.h:160
void reportInputLumiSection(unsigned int run, unsigned int lumiSectId)
Definition: JobReport.cc:465
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:652
std::ostream *& ost()
Definition: JobReport.h:250
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:389
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
AtomicLongLong(AtomicLongLong const &r)
Definition: JobReport.h:171
edm::propagate_const< std::ostream * > ost_
Definition: JobReport.h:260
std::atomic< long long > const & value() const
Definition: JobReport.h:173
void reportError(std::string const &shortDesc, std::string const &longDesc, int const &exitCode)
Definition: JobReport.cc:493
unsigned int RunNumber
Definition: JobReport.h:105
std::size_t Token
Definition: JobReport.h:106
void reportReadBranch(InputType inputType, std::string const &branchName)
Inform the job report that a branch has been read.
Definition: JobReport.cc:611
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:626
void eventWrittenToFile(Token fileToken, RunNumber_t run, EventNumber_t event)
Definition: JobReport.cc:428
tbb::concurrent_vector< InputFile > inputFilesSecSource_
Definition: JobReport.h:253
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:555
std::string dumpFiles(void)
debug/test util
Definition: JobReport.cc:694
HLT enums.
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:473
std::vector< InputFile >::size_type lastOpenedPrimaryInputFile_
Definition: JobReport.h:259
void outputFileClosed(Token fileToken)
Definition: JobReport.cc:433
std::map< unsigned int, unsigned long > lumiSectionsToNEvents
Definition: JobReport.h:110
JobReportImpl(std::ostream *iOst)
Definition: JobReport.h:247
unsigned int RunNumber_t
tbb::concurrent_vector< OutputFile > outputFiles_
Definition: JobReport.h:254
void reportDataType(Token fileToken, std::string const &dataType)
Definition: JobReport.cc:371
UInt_t nEvents
Definition: hcalCalib.cc:41
tbb::concurrent_vector< Token > contributingInputsSecSource
Definition: JobReport.h:162
StringVector branchNames
Definition: JobReport.h:133
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger tbale.
void inputFileClosed(InputType inputType, Token fileToken)
Definition: JobReport.cc:376
Definition: event.py:1
void reportReadBranches()
Definition: JobReport.cc:569
void reportLumiSection(JobReport::Token token, unsigned int run, unsigned int lumiSectId, unsigned long nEvents=0)
Definition: JobReport.cc:458