CMS 3D CMS Logo

JobReport.cc
Go to the documentation of this file.
1 
2 // -*- C++ -*-
3 //
4 //
5 // 10/23/07 mf In an attempt to get clues about (or ene) the
6 // does-not-output-branches behavior, changed the
7 // generic os<< lines in JobReport::JobReportImpl::writeOutputFile
8 // to direct use of LogInfo.
9 //
10 // 4/8/08 mf Encase the logdesc for in <CDATA> ... </CDATA>
11 //
12 // 6/19/08 mf reportMessageInfo()
13 //
14 // 24 June 2008 ewv Correct format for CDATA and for second instance of reportError
15 
16 //
17 // Original Author: Marc Paterno
18 //
19 
23 
24 // The part of tinyxml used in JobReport was reviewed and
25 // determined to be threadsafe.
26 #include "tinyxml.h"
27 #include <fstream>
28 #include <iomanip>
29 #include <ostream>
30 #include <sstream>
31 
32 namespace edm {
33  /*
34  * Note that output formatting is spattered across these classes
35  * If something outside these classes requires access to the
36  * same formatting then we need to refactor it into a common library
37  */
38  template <typename S, typename T>
39  S& formatFile(T const& f, S& os) {
40 
41  if(f.fileHasBeenClosed) {
42  os << "\n<State Value=\"closed\"/>";
43  } else {
44  os << "\n<State Value=\"open\"/>";
45  }
46 
47  os << "\n<LFN>" << TiXmlText(f.logicalFileName) << "</LFN>";
48  os << "\n<PFN>" << TiXmlText(f.physicalFileName) << "</PFN>";
49  os << "\n<Catalog>" << TiXmlText(f.catalog) << "</Catalog>";
50  os << "\n<ModuleLabel>" << TiXmlText(f.moduleLabel) << "</ModuleLabel>";
51  os << "\n<GUID>" << f.guid << "</GUID>";
52  os << "\n<Branches>";
53  for(auto const& branch : f.branchNames) {
54  os << "\n <Branch>" << TiXmlText(branch) << "</Branch>";
55  }
56  os << "\n</Branches>";
57  return os;
58  }
59  /*
60  * Note that output formatting is spattered across these classes
61  * If something outside these classes requires access to the
62  * same formatting then we need to refactor it into a common library
63  */
64  template <typename S>
65  S& print(S& os, JobReport::InputFile const& f) {
66 
67  os << "\n<InputFile>";
68  formatFile(f, os);
69  os << "\n<InputType>" << f.inputType << "</InputType>";
70  os << "\n<InputSourceClass>" << TiXmlText(f.inputSourceClassName)
71  << "</InputSourceClass>";
72  os << "\n<EventsRead>" << f.numEventsRead << "</EventsRead>";
73  return os;
74  }
75 
76  template <typename S>
77  S& print(S& os, JobReport::OutputFile const& f) {
78  formatFile(f, os);
79  os << "\n<OutputModuleClass>"
80  << TiXmlText(f.outputModuleClassName)
81  << "</OutputModuleClass>";
82  os << "\n<TotalEvents>"
83  << f.numEventsWritten
84  << "</TotalEvents>\n";
85  os << "\n<DataType>"
86  << TiXmlText(f.dataType)
87  << "</DataType>\n";
88  os << "\n<BranchHash>"
89  << TiXmlText(f.branchHash)
90  << "</BranchHash>\n";
91  return os;
92  }
93 
94  template <typename S>
95  S& print(S& os,
96  JobReport::RunReport const& rep) {
97  os << "\n<Run ID=\""
98  << rep.runNumber
99  << "\">\n";
100 
101  for(auto const& il : rep.lumiSectionsToNEvents) {
102  if(std::numeric_limits<unsigned long>::max() == il.second) {
103  os << " <LumiSection ID=\"" << il.first << "\"/>\n";
104 
105  } else {
106  os << " <LumiSection ID=\"" << il.first << "\" NEvents=\""<<il.second<< "\"/>\n";
107  }
108  }
109  os << "</Run>\n";
110  return os;
111  }
112 
113  std::ostream& operator<< (std::ostream& os, JobReport::InputFile const& f) {
114  return print(os,f);
115  }
116  std::ostream& operator<< (std::ostream& os, JobReport::OutputFile const& f) {
117  return print(os,f);
118  }
119  std::ostream& operator<< (std::ostream& os, JobReport::RunReport const& f) {
120  return print(os,f);
121  }
122 
124 
125  InputFile* inputFile = nullptr;
126  if(inputType == InputType::SecondarySource) {
127  if(t >= inputFilesSecSource_.size()) {
129  << "Access reported for secondary source input file with token "
130  << t
131  << " but no matching input file is found\n";
132  }
133  inputFile = &inputFilesSecSource_[t];
134  } else {
135  if(t >= inputFiles_.size()) {
137  << "Access reported for input file with token "
138  << t
139  << " but no matching input file is found\n";
140  }
141  inputFile = &inputFiles_[t];
142  }
143  if(inputFile->fileHasBeenClosed) {
145  << "Access reported for input file with token "
146  << t
147  << " after this file has been closed.\n"
148  << "File record follows:\n"
149  << *inputFile
150  << '\n';
151  }
152  return *inputFile;
153  }
154 
156  if(t >= outputFiles_.size()) {
158  << "Access reported for output file with token "
159  << t
160  << " but no matching output file is found\n";
161  }
162  if(outputFiles_[t].fileHasBeenClosed) {
164  << "Access reported for output file with token "
165  << t
166  << " after this file has been closed.\n"
167  << "File record follows:\n"
168  << outputFiles_[t]
169  << '\n';
170  }
171  return outputFiles_[t];
172  }
173 
174  /*
175  * Add the input file token provided to every output
176  * file currently available.
177  * Used whenever a new input file is opened, it's token
178  * is added to all open output files as a contributor
179  */
181  for(auto & outputFile : outputFiles_) {
182  if(!outputFile.fileHasBeenClosed) {
183  if(inputType == InputType::SecondarySource) {
184  outputFile.contributingInputsSecSource.push_back(t);
185  } else {
186  outputFile.contributingInputs.push_back(t);
187  }
188  }
189  }
190  }
191 
192  /*
193  * Write anJobReport::InputFile object to the Logger
194  * Generate XML string forJobReport::InputFile instance and dispatch to
195  * job report via MessageLogger
196  */
198  if(ost_) {
199  *ost_ << f ;
200  *ost_ << "\n<Runs>";
201  for(auto const& runReport : f.runReports) {
202  *ost_ << runReport.second;
203  }
204  *ost_ << "\n</Runs>\n";
205  *ost_ << "</InputFile>\n";
206  *ost_ << std::flush;
207  }
208  }
209 
210  /*
211  * Write an OutputFile object to the Logger
212  * Generate an XML string for the OutputFile provided and
213  * dispatch it to the logger
214  * Contributing input tokens are resolved to the input LFN and PFN
215  *
216  * TODO: We have not yet addressed the issue where we cleanup not
217  * contributing input files.
218  * Also, it is possible to get fake input to output file mappings
219  * if an input file is open already when a new output file is opened
220  * but the input gets closed without contributing events to the
221  * output file due to filtering etc.
222  *
223  */
225  if(ost_) {
226  *ost_ << "\n<File>";
227  *ost_ << f;
228 
229  *ost_ << "\n<Runs>";
230  for(auto const& runReport : f.runReports) {
231  *ost_ << runReport.second;
232  }
233  *ost_ << "\n</Runs>\n";
234 
235  *ost_ << "\n<Inputs>";
236  for(auto token : f.contributingInputs) {
237  JobReport::InputFile inpFile = inputFiles_.at(token);
238  *ost_ << "\n<Input>";
239  *ost_ << "\n <LFN>" << TiXmlText(inpFile.logicalFileName) << "</LFN>";
240  *ost_ << "\n <PFN>" << TiXmlText(inpFile.physicalFileName) << "</PFN>";
241  *ost_ << "\n <FastCopying>" << findOrDefault(f.fastCopyingInputs, inpFile.physicalFileName) << "</FastCopying>";
242  *ost_ << "\n</Input>";
243  }
244  for(auto token : f.contributingInputsSecSource) {
245  JobReport::InputFile inpFile = inputFilesSecSource_.at(token);
246  *ost_ << "\n<Input>";
247  *ost_ << "\n <LFN>" << TiXmlText(inpFile.logicalFileName) << "</LFN>";
248  *ost_ << "\n <PFN>" << TiXmlText(inpFile.physicalFileName) << "</PFN>";
249  *ost_ << "\n <FastCopying>" << findOrDefault(f.fastCopyingInputs, inpFile.physicalFileName) << "</FastCopying>";
250  *ost_ << "\n</Input>";
251  }
252  *ost_ << "\n</Inputs>";
253  *ost_ << "\n</File>\n";
254  }
255  }
256 
257  /*
258  * Flush all open files to logger in event of a problem.
259  * Called from JobReport dtor to flush any remaining open files
260  */
262  for(auto const& inputFile : inputFiles_) {
263  if(!(inputFile.fileHasBeenClosed)) {
265  }
266  }
267  for(auto const& inputFile : inputFilesSecSource_) {
268  if(!(inputFile.fileHasBeenClosed)) {
270  }
271  }
272  for(auto const& outputFile : outputFiles_) {
273  if(!(outputFile.fileHasBeenClosed)) {
275  }
276  }
277  }
278 
280  auto& theMap = outputFiles_.at(token).runReports;
281  std::map<RunNumber, RunReport>::iterator iter(theMap.lower_bound(runNumber));
282  if(iter == theMap.end() || runNumber < iter->first) { // not found
283  theMap.emplace_hint(iter, runNumber, JobReport::RunReport{ runNumber, {}}); // insert it
284  }
285  }
286 
288  for(auto& inputFile : inputFiles_) {
289  if(!inputFile.fileHasBeenClosed) {
290  std::map<RunNumber, RunReport>& theMap = inputFile.runReports;
291  std::map<RunNumber, RunReport>::iterator iter(theMap.lower_bound(runNumber));
292  if(iter == theMap.end() || runNumber < iter->first) { // not found
293  theMap.emplace_hint(iter, runNumber, JobReport::RunReport{ runNumber, {}}); // insert it
294  }
295  }
296  }
297  }
298 
299  void JobReport::JobReportImpl::associateLumiSection(JobReport::Token token, unsigned int runNumber, unsigned int lumiSect, unsigned long nEvents) {
300  auto& theMap = outputFiles_.at(token).runReports;
301  std::map<RunNumber, RunReport>::iterator iter(theMap.lower_bound(runNumber));
302  if(iter == theMap.end() || runNumber < iter->first) { // not found
303  theMap.emplace_hint(iter, runNumber, JobReport::RunReport{ runNumber, {{{lumiSect,nEvents}}}}); // insert it
304  } else {
305  iter->second.lumiSectionsToNEvents[lumiSect]+=nEvents;
306  }
307  }
308 
309  void JobReport::JobReportImpl::associateInputLumiSection(unsigned int runNumber, unsigned int lumiSect) {
310  for(auto& inputFile : inputFiles_) {
311  if(!inputFile.fileHasBeenClosed) {
312  std::map<RunNumber, RunReport>& theMap = inputFile.runReports;
313  std::map<RunNumber, RunReport>::iterator iter(theMap.lower_bound(runNumber));
314  if(iter == theMap.end() || runNumber < iter->first) { // not found
315  theMap.emplace_hint(iter, runNumber, JobReport::RunReport{ runNumber, {{lumiSect,std::numeric_limits<unsigned long>::max()}}}); // insert it
316  } else {
317  iter->second.lumiSectionsToNEvents[lumiSect]=std::numeric_limits<unsigned long>::max();
318  }
319  }
320  }
321  }
322 
324  impl_->flushFiles();
325  if(impl_->ost_) {
326  *(impl_->ost_) << "</FrameworkJobReport>\n" << std::flush;
327  }
328  }
329 
331  impl_(new JobReportImpl(0)) {
332  }
333 
334  JobReport::JobReport(std::ostream* iOstream) : impl_(new JobReportImpl(iOstream)) {
335  if(impl_->ost_) {
336  *(impl_->ost_) << "<FrameworkJobReport>\n";
337  }
338  }
339 
340  namespace {
341  void
342  toFileName(std::string const& jobReportFile, unsigned int childIndex, unsigned int numberOfChildren, std::ostringstream& ofilename) {
343  char filler = ofilename.fill();
344  unsigned int numberOfDigitsInIndex = 0U;
345  while (numberOfChildren != 0) {
346  ++numberOfDigitsInIndex;
347  numberOfChildren /= 10;
348  }
349  if(numberOfDigitsInIndex == 0) {
350  numberOfDigitsInIndex = 3; // Protect against zero numberOfChildren
351  }
352  std::string::size_type offset = jobReportFile.rfind('.');
353  if(offset == std::string::npos) {
354  ofilename << jobReportFile;
355  ofilename << '_' << std::setw(numberOfDigitsInIndex) << std::setfill('0') << childIndex << std::setfill(filler);
356  } else {
357  ofilename << jobReportFile.substr(0, offset);
358  ofilename << '_' << std::setw(numberOfDigitsInIndex) << std::setfill('0') << childIndex << std::setfill(filler);
359  ofilename << jobReportFile.substr(offset);
360  }
361  }
362  }
363 
364  void
365  JobReport::parentBeforeFork(std::string const& jobReportFile, unsigned int numberOfChildren) {
366  if(impl_->ost_) {
367  *(impl_->ost_) << "<ChildProcessFiles>\n";
368  for(unsigned int i = 0; i < numberOfChildren; ++i) {
369  std::ostringstream ofilename;
370  toFileName(jobReportFile, i, numberOfChildren, ofilename);
371  *(impl_->ost_) << " <ChildProcessFile>" << ofilename.str() << "</ChildProcessFile>\n";
372  }
373  *(impl_->ost_) << "</ChildProcessFiles>\n";
374  *(impl_->ost_) << "</FrameworkJobReport>\n";
375  std::ofstream* p = dynamic_cast<std::ofstream *>(impl_->ost());
376  if(p) {
377  p->close();
378  }
379  }
380  }
381 
382  void
383  JobReport::parentAfterFork(std::string const& /*jobReportFile*/) {
384  }
385 
386  void
387  JobReport::childAfterFork(std::string const& jobReportFile, unsigned int childIndex, unsigned int numberOfChildren) {
388  std::ofstream* p = dynamic_cast<std::ofstream*>(impl_->ost());
389  if(!p) return;
390  std::ostringstream ofilename;
391  toFileName(jobReportFile, childIndex, numberOfChildren, ofilename);
392  p->open(ofilename.str().c_str());
393  *p << "<FrameworkJobReport>\n";
394  }
395 
397  JobReport::inputFileOpened(std::string const& physicalFileName,
398  std::string const& logicalFileName,
399  std::string const& catalog,
400  std::string const& inputType,
401  std::string const& inputSourceClassName,
402  std::string const& moduleLabel,
403  std::string const& guid,
404  std::vector<std::string> const& branchNames) {
405 
406  InputType theInputType = InputType::Primary;
407  InputFile* newFile = nullptr;
408  JobReport::Token newToken = 0;
409 
410  if (inputType == "mixingFiles") {
411  theInputType = InputType::SecondarySource;
412  auto itr = impl_->inputFilesSecSource_.push_back(InputFile());
413  newFile = &(*itr);
414  newToken = itr - impl_->inputFilesSecSource_.begin();
415  } else {
416  if (inputType == "secondaryFiles") {
417  theInputType = InputType::SecondaryFile;
418  }
419  impl_->inputFiles_.emplace_back();
420  newFile = &impl_->inputFiles_.back();
421  newToken = impl_->inputFiles_.size() - 1;
422  }
423 
424  if(theInputType == InputType::Primary) {
425  impl_->lastOpenedPrimaryInputFile_ = impl_->inputFiles_.size() - 1;
426  }
427  newFile->logicalFileName = logicalFileName;
428  newFile->physicalFileName = physicalFileName;
429  newFile->catalog = catalog;
430  newFile->inputType = inputType;
431  newFile->inputSourceClassName = inputSourceClassName;
432  newFile->moduleLabel = moduleLabel;
433  newFile->guid = guid;
434  newFile->numEventsRead = 0;
435  newFile->branchNames = branchNames;
436  newFile->fileHasBeenClosed = false;
437 
438  // Add the new input file token to all output files
439  // currently open.
440  impl_->insertInputForOutputs(theInputType, newToken);
441  return newToken;
442  }
443 
444  void
446  JobReport::InputFile& f = impl_->getInputFileForToken(inputType, fileToken);
447  ++f.numEventsRead;
448  }
449 
450  void
452  JobReport::OutputFile& f = impl_->getOutputFileForToken(fileToken);
453  f.dataType = dataType;
454  }
455 
456  void
458  JobReport::InputFile& f = impl_->getInputFileForToken(inputType, fileToken);
459  f.fileHasBeenClosed = true;
460  if(inputType == InputType::Primary) {
461  impl_->writeInputFile(f);
462  } else {
463  {
464  std::lock_guard<std::mutex> lock(write_mutex);
465  impl_->writeInputFile(f);
466  }
467  }
468  }
469 
471  JobReport::outputFileOpened(std::string const& physicalFileName,
472  std::string const& logicalFileName,
473  std::string const& catalog,
474  std::string const& outputModuleClassName,
475  std::string const& moduleLabel,
476  std::string const& guid,
477  std::string const& dataType,
478  std::string const& branchHash,
479  std::vector<std::string> const& branchNames) {
480  auto itr = impl_->outputFiles_.emplace_back();
481  JobReport::OutputFile& r = *itr;
482 
483  r.logicalFileName = logicalFileName;
484  r.physicalFileName = physicalFileName;
485  r.catalog = catalog;
486  r.outputModuleClassName = outputModuleClassName;
487  r.moduleLabel = moduleLabel;
488  r.guid = guid;
489  r.dataType = dataType;
490  r.branchHash = branchHash;
491  r.numEventsWritten = 0;
492  r.branchNames = branchNames;
493  r.fileHasBeenClosed = false;
494  //
495  // Init list of contributors to list of open input file Tokens
496  //
497  for(std::vector<Token>::size_type i = 0, iEnd = impl_->inputFiles_.size(); i < iEnd; ++i) {
498  if(!impl_->inputFiles_[i].fileHasBeenClosed) {
499  r.contributingInputs.push_back(i);
500  }
501  }
502  for(tbb::concurrent_vector<Token>::size_type i = 0, iEnd = impl_->inputFilesSecSource_.size(); i < iEnd; ++i) {
503  if(!impl_->inputFilesSecSource_[i].fileHasBeenClosed) {
504  r.contributingInputsSecSource.push_back(i);
505  }
506  }
507  return itr - impl_->outputFiles_.begin();
508  }
509 
510  void
512  JobReport::OutputFile& f = impl_->getOutputFileForToken(fileToken);
513  ++f.numEventsWritten;
514  }
515 
516  void
518  JobReport::OutputFile& f = impl_->getOutputFileForToken(fileToken);
519  f.fileHasBeenClosed = true;
520  impl_->writeOutputFile(f);
521  }
522 
523  void
525  if(impl_->ost_) {
526  std::ostream& msg = *(impl_->ost_);
527  {
528  std::lock_guard<std::mutex> lock(write_mutex);
529  msg << "<SkippedEvent Run=\"" << run << "\"";
530  msg << " Event=\"" << event << "\" />\n";
531  msg << std::flush;
532  }
533  }
534  }
535 
536  void
538  JobReport::OutputFile& f = impl_->getOutputFileForToken(fileToken);
539  f.fastCopyingInputs.insert(std::make_pair(inputFileName, fastCopying));
540  }
541 
542  void
543  JobReport::reportLumiSection(JobReport::Token token, unsigned int run, unsigned int lumiSectId, unsigned long nEvents) {
544  impl_->associateLumiSection(token, run, lumiSectId,nEvents);
545  }
546 
547  void
548  JobReport::reportInputLumiSection(unsigned int run, unsigned int lumiSectId) {
549  impl_->associateInputLumiSection(run, lumiSectId);
550  }
551 
552  void
554  impl_->associateRun(token, run);
555  }
556 
557  void
559  impl_->associateInputRun(run);
560  }
561 
562  void
563  JobReport::reportAnalysisFile(std::string const& fileName, std::map<std::string, std::string> const& fileData) {
564  if(impl_->ost_) {
565  std::ostream& msg = *(impl_->ost_);
566  {
567  std::lock_guard<std::mutex> lock(write_mutex);
568  msg << "<AnalysisFile>\n"
569  << " <FileName>" << TiXmlText(fileName) << "</FileName>\n";
570 
571  typedef std::map<std::string, std::string>::const_iterator const_iterator;
572  for(const_iterator pos = fileData.begin(), posEnd = fileData.end(); pos != posEnd; ++pos) {
573  msg << " <" << pos->first
574  << " Value=\"" << pos->second << "\" />"
575  << "\n";
576  }
577  msg << "</AnalysisFile>\n";
578  msg << std::flush;
579  }
580  }
581  }
582 
583  void
585  std::string const& longDesc,
586  int const& exitCode) {
587  if(impl_->ost_) {
588  {
589  std::lock_guard<std::mutex> lock(write_mutex);
590  std::ostream& msg = *(impl_->ost_);
591  msg << "<FrameworkError ExitStatus=\""<< exitCode
592  << "\" Type=\"" << shortDesc << "\" >\n";
593  msg << "<![CDATA[\n" << longDesc << "\n]]>\n";
594  msg << "</FrameworkError>\n";
595  msg << std::flush;
596  }
597  }
598  }
599 
600  void
602  std::string const& lfn) {
603  if(impl_->ost_) {
604  std::ostream& msg = *(impl_->ost_);
605  TiXmlElement skipped("SkippedFile");
606  skipped.SetAttribute("Pfn", pfn);
607  skipped.SetAttribute("Lfn", lfn);
608  {
609  std::lock_guard<std::mutex> lock(write_mutex);
610  msg << skipped << "\n";
611  msg << std::flush;
612  }
613  }
614  }
615 
616  void
618  if(impl_->ost_) {
619  std::ostream& msg = *(impl_->ost_);
620  TiXmlElement fallback("FallbackAttempt");
621  fallback.SetAttribute("Pfn", pfn);
622  fallback.SetAttribute("Lfn", lfn);
623  {
624  std::lock_guard<std::mutex> lock(write_mutex);
625  msg << fallback << "\n";
626  msg << "<![CDATA[\n" << err << "\n]]>\n";
627  msg << std::flush;
628  }
629  }
630  }
631 
632  void
633  JobReport::reportMemoryInfo(std::vector<std::string> const& memoryData) {
634  if(impl_->ost_) {
635  std::ostream& msg = *(impl_->ost_);
636  msg << "<MemoryService>\n";
637 
638  typedef std::vector<std::string>::const_iterator const_iterator;
639  for(const_iterator pos = memoryData.begin(), posEnd = memoryData.end(); pos != posEnd; ++pos) {
640  msg << *pos << "\n";
641  }
642  msg << "</MemoryService>\n";
643  msg << std::flush;
644  }
645  }
646 
647  void
648  JobReport::reportMessageInfo(std::map<std::string, double> const& messageData) {
649  if(impl_->ost_) {
650  std::ostream& msg = *(impl_->ost_);
651  msg << "<MessageSummary>\n";
652  typedef std::map<std::string, double>::const_iterator const_iterator;
653  for(const_iterator pos = messageData.begin(), posEnd = messageData.end(); pos != posEnd; ++pos) {
654  msg << " <" << pos->first
655  << " Value=\"" << pos->second << "\" />"
656  << "\n";
657  }
658  msg << "</MessageSummary>\n";
659  msg << std::flush;
660  }
661  }
662 
663  void
665  if(impl_->printedReadBranches_) return;
666  impl_->printedReadBranches_ = true;
667  if(impl_->ost_) {
668  std::ostream& ost = *(impl_->ost_);
669  ost << "<ReadBranches>\n";
670  for(auto const& iBranch : impl_->readBranches_) {
671  TiXmlElement branch("Branch");
672  branch.SetAttribute("Name", iBranch.first);
673  branch.SetAttribute("ReadCount", iBranch.second);
674  ost << branch << "\n";
675  }
676  for(auto const& iBranch : impl_->readBranchesSecFile_) {
677  TiXmlElement branch("Branch");
678  branch.SetAttribute("Name", iBranch.first);
679  branch.SetAttribute("ReadCount", iBranch.second);
680  ost << branch << "\n";
681  }
682  ost << "</ReadBranches>\n";
683  if(!impl_->readBranchesSecSource_.empty()) {
684  ost << "<SecondarySourceReadBranches>\n";
685  for(auto const& iBranch : impl_->readBranchesSecSource_) {
686  TiXmlElement branch("Branch");
687  branch.SetAttribute("Name", iBranch.first);
688  branch.SetAttribute("ReadCount", iBranch.second.value().load());
689  ost << branch << "\n";
690  }
691  ost << "</SecondarySourceReadBranches>\n";
692  }
693  ost << std::flush;
694  }
695  }
696 
697  void
698  JobReport::reportReadBranch(InputType inputType, std::string const& branchName) {
699  if(inputType == InputType::Primary) {
700  // Fast cloned branches have already been reported.
701  std::set<std::string> const& clonedBranches = impl_->inputFiles_.at(impl_->lastOpenedPrimaryInputFile_).fastClonedBranches;
702  if(clonedBranches.find(branchName) == clonedBranches.end()) {
703  ++impl_->readBranches_[branchName];
704  }
705  } else if (inputType == InputType::SecondaryFile) {
706  ++impl_->readBranchesSecFile_[branchName];
707  } else if (inputType == InputType::SecondarySource) {
708  ++impl_->readBranchesSecSource_[branchName].value();
709  }
710  }
711 
712  void
713  JobReport::reportFastClonedBranches(std::set<std::string> const& fastClonedBranches, long long nEvents) {
714  std::set<std::string>& clonedBranches = impl_->inputFiles_.at(impl_->lastOpenedPrimaryInputFile_).fastClonedBranches;
715  for(std::set<std::string>::const_iterator it = fastClonedBranches.begin(), itEnd = fastClonedBranches.end();
716  it != itEnd; ++it) {
717  if(clonedBranches.insert(*it).second) {
718  impl_->readBranches_[*it] += nEvents;
719  }
720  }
721  }
722 
724  if(impl_->ost_) {
725  std::ostream& msg = *(impl_->ost_);
726  {
727  std::lock_guard<std::mutex> lock(write_mutex);
728  msg << "<RandomServiceStateFile>\n"
729  << TiXmlText(name) << "\n"
730  << "</RandomServiceStateFile>\n";
731  msg << std::flush;
732  }
733  }
734  }
735 
736  void
738  std::map<std::string, std::string> const& metrics) {
739  if(impl_->ost_) {
740  std::ostream& msg = *(impl_->ost_);
741  msg << "<PerformanceReport>\n"
742  << " <PerformanceSummary Metric=\"" << metricClass << "\">\n";
743 
744  typedef std::map<std::string, std::string>::const_iterator const_iterator;
745  for(const_iterator iter = metrics.begin(), iterEnd = metrics.end(); iter != iterEnd; ++iter) {
746  msg << " <Metric Name=\"" << iter->first << "\" "
747  << "Value=\"" << iter->second << "\"/>\n";
748  }
749 
750  msg << " </PerformanceSummary>\n"
751  << "</PerformanceReport>\n";
752  msg << std::flush;
753  //LogInfo("FwkJob") << msg.str();
754  }
755  }
756 
757  void
759  std::string const& moduleName,
760  std::map<std::string, std::string> const& metrics) {
761  if(impl_->ost_) {
762  std::ostream& msg = *(impl_->ost_);
763  msg << "<PerformanceReport>\n"
764  << " <PerformanceModule Metric=\"" << metricClass << "\" "
765  << " Module=\"" << moduleName << "\" >\n";
766 
767  typedef std::map<std::string, std::string>::const_iterator const_iterator;
768  for(const_iterator iter = metrics.begin(), iterEnd = metrics.end(); iter != iterEnd; ++iter) {
769  msg << " <Metric Name=\"" << iter->first << "\" "
770  << "Value=\"" << iter->second << "\"/>\n";
771  }
772 
773  msg << " </PerformanceModule>\n"
774  << "</PerformanceReport>\n";
775  msg << std::flush;
776  //LogInfo("FwkJob") << msg.str();
777  }
778  }
779 
782  std::ostringstream msg;
783 
784 
785  for(auto const& f :impl_->outputFiles_) {
786 
787  msg << "\n<File>";
788  msg << f;
789 
790  msg << "\n<LumiSections>";
791  msg << "\n<Inputs>";
792  typedef std::vector<JobReport::Token>::iterator iterator;
793  for(auto const& iInput : f.contributingInputs) {
794  auto const& inpFile = impl_->inputFiles_[iInput];
795  msg << "\n<Input>";
796  msg << "\n <LFN>" << TiXmlText(inpFile.logicalFileName) << "</LFN>";
797  msg << "\n <PFN>" << TiXmlText(inpFile.physicalFileName) << "</PFN>";
798  msg << "\n <FastCopying>" << findOrDefault(f.fastCopyingInputs, inpFile.physicalFileName) << "</FastCopying>";
799  msg << "\n</Input>";
800  }
801  msg << "\n</Inputs>";
802  msg << "\n</File>";
803 
804  }
805  return msg.str();
806  }
807 
808 } //namspace edm
InputType
Definition: InputType.h:5
void reportSkippedFile(std::string const &pfn, std::string const &lfn)
Definition: JobReport.cc:601
std::string inputSourceClassName
Definition: JobReport.h:130
std::string outputModuleClassName
Definition: JobReport.h:156
std::string physicalFileName
Definition: JobReport.h:154
void associateRun(JobReport::Token token, unsigned int runNumber)
Definition: JobReport.cc:279
void reportMemoryInfo(std::vector< std::string > const &memoryData)
Definition: JobReport.cc:633
void reportInputRunNumber(unsigned int run)
Definition: JobReport.cc:558
void eventReadFromFile(InputType inputType, Token fileToken)
Definition: JobReport.cc:445
std::mutex write_mutex
Definition: JobReport.h:442
void reportFallbackAttempt(std::string const &pfn, std::string const &lfn, std::string const &err)
Definition: JobReport.cc:617
std::string logicalFileName
Definition: JobReport.h:126
unsigned long long EventNumber_t
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:537
void reportRunNumber(JobReport::Token token, unsigned int run)
Definition: JobReport.cc:553
void reportRandomStateFile(std::string const &name)
Definition: JobReport.cc:723
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
uint16_t size_type
edm::propagate_const< std::unique_ptr< JobReportImpl > > impl_
Definition: JobReport.h:441
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:397
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:758
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:524
void insertInputForOutputs(InputType inputType, Token t)
Definition: JobReport.cc:180
std::string moduleName(Provenance const &provenance)
Definition: Provenance.cc:27
std::size_t numEventsRead
Definition: JobReport.h:133
void writeInputFile(InputFile const &f)
Definition: JobReport.cc:197
StringVector branchNames
Definition: JobReport.h:162
void reportInputLumiSection(unsigned int run, unsigned int lumiSectId)
Definition: JobReport.cc:548
void reportPerformanceSummary(std::string const &metricClass, std::map< std::string, std::string > const &metrics)
Definition: JobReport.cc:737
void childAfterFork(std::string const &jobReportFile, unsigned int childIndex, unsigned int numberOfChildren)
New output file for child.
Definition: JobReport.cc:387
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:471
edm::propagate_const< std::ostream * > ost_
Definition: JobReport.h:259
rep
Definition: cuy.py:1188
void reportError(std::string const &shortDesc, std::string const &longDesc, int const &exitCode)
Definition: JobReport.cc:584
std::size_t Token
Definition: JobReport.h:107
void associateInputRun(unsigned int runNumber)
Definition: JobReport.cc:287
S & formatFile(T const &f, S &os)
Definition: JobReport.cc:39
void reportReadBranch(InputType inputType, std::string const &branchName)
Inform the job report that a branch has been read.
Definition: JobReport.cc:698
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:713
Value const & findOrDefault(std::map< Key, Value > const &m, Key const &k, Value const &defaultValue)
Definition: Map.h:28
void eventWrittenToFile(Token fileToken, RunNumber_t run, EventNumber_t event)
Definition: JobReport.cc:511
tbb::concurrent_vector< InputFile > inputFilesSecSource_
Definition: JobReport.h:252
void parentAfterFork(std::string const &jobReportFile)
Definition: JobReport.cc:383
void reportMessageInfo(std::map< std::string, double > const &messageData)
Definition: JobReport.cc:648
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
void associateLumiSection(JobReport::Token token, unsigned int runNumber, unsigned int lumiSection, unsigned long nEvents)
Definition: JobReport.cc:299
std::string dumpFiles(void)
debug/test util
Definition: JobReport.cc:781
void parentBeforeFork(std::string const &jobReportFile, unsigned int numberOfChildren)
Definition: JobReport.cc:365
HLT enums.
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:563
void outputFileClosed(Token fileToken)
Definition: JobReport.cc:517
void writeOutputFile(OutputFile const &f)
Definition: JobReport.cc:224
std::map< unsigned int, unsigned long > lumiSectionsToNEvents
Definition: JobReport.h:111
unsigned int RunNumber_t
InputFile & getInputFileForToken(InputType inputType, Token t)
Definition: JobReport.cc:123
tbb::concurrent_vector< OutputFile > outputFiles_
Definition: JobReport.h:253
void reportDataType(Token fileToken, std::string const &dataType)
Definition: JobReport.cc:451
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.
long double T
void inputFileClosed(InputType inputType, Token fileToken)
Definition: JobReport.cc:457
void associateInputLumiSection(unsigned int runNumber, unsigned int lumiSection)
Definition: JobReport.cc:309
Definition: event.py:1
void reportReadBranches()
Definition: JobReport.cc:664
OutputFile & getOutputFileForToken(Token t)
Definition: JobReport.cc:155
void reportLumiSection(JobReport::Token token, unsigned int run, unsigned int lumiSectId, unsigned long nEvents=0)
Definition: JobReport.cc:543