LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
FileStatsCollector.cc
Go to the documentation of this file.
2 #include "boost/date_time/posix_time/posix_time.hpp"
3 #include "boost/filesystem.hpp"
4 
5 #include <string>
6 
7 art::FileStatsCollector::FileStatsCollector(std::string const& moduleLabel,
8  std::string const& processName)
9  : moduleLabel_{moduleLabel}, processName_{processName}
10 {}
11 
12 void
14 {
16  if (!inputFilesSeen_.empty()) {
18  }
19  fo_ = boost::posix_time::second_clock::universal_time();
20  fileCloseRecorded_ = false;
21 }
22 
23 void
24 art::FileStatsCollector::recordInputFile(std::string const& inputFileName)
25 {
26  if (!inputFileName.empty()) {
27  inputFilesSeen_.emplace_back(inputFileName);
28  }
29  lastOpenedInputFile_ = inputFileName;
30 }
31 
32 void
34 {
35  ++nEvents_;
36  // Actually saw a real event that we've been asked to write, so
37  // EventID should be valid.
39  lowestEventIDSeen_ = id;
40  }
41  if (id > highestEventIDSeen_) {
42  // Sort-invalid-first gives the correct answer.
44  }
45  // Record that we have seen this SubRunID too.
46  recordSubRun(id.subRunID());
47 }
48 
49 void
51 {
52  if ((!lowestSubRun_.runID().isValid()) || id < lowestSubRun_.runID()) {
54  }
55  if (id > highestSubRun_.runID()) {
56  // Sort-invalid-first gives the correct answer.
58  }
59 }
60 
61 void
63 {
64  recordRun(id.runID());
65  if (id.runID() == lowestSubRun_.runID() &&
66  (id.isValid() && ((!lowestSubRun_.isValid()) || // No valid subrun yet.
67  id < lowestSubRun_))) {
68  lowestSubRun_ = id;
69  }
70  if (id > highestSubRun_) {
71  // Sort-invalid-first gives the correct answer.
72  highestSubRun_ = id;
73  }
74  subRunsSeen_.emplace(id);
75 }
76 
77 void
79 {
80  fc_ = boost::posix_time::second_clock::universal_time();
81  fileCloseRecorded_ = true;
82 }
83 
84 std::vector<std::string>
85 art::FileStatsCollector::parents(bool want_basename) const
86 {
87  std::vector<std::string> result;
88  if (want_basename) {
89  result.reserve(inputFilesSeen_.size());
90  for (auto const& ifile : inputFilesSeen_) {
91  boost::filesystem::path const ifp{ifile};
92  result.emplace_back(ifp.filename().native());
93  }
94  } else {
95  result = inputFilesSeen_;
96  }
97  return result;
98 }
99 
100 void
102 {
103  fo_ = fc_ = boost::posix_time::ptime();
105  inputFilesSeen_.clear();
106  nEvents_ = 0ul;
107  subRunsSeen_.clear();
108 }
bool isValid() const
Definition: EventID.h:123
std::string const & processName() const
FileStatsCollector(std::string const &moduleLabel, std::string const &processName)
boost::posix_time::ptime fo_
void recordRun(RunID const &id)
void recordEvent(EventID const &id)
std::vector< std::string > inputFilesSeen_
bool isValid() const
Definition: SubRunID.h:96
boost::posix_time::ptime fc_
std::vector< std::string > parents(bool want_basename=true) const
RunID const & runID() const
Definition: SubRunID.h:78
void recordSubRun(SubRunID const &id)
void recordInputFile(std::string const &inputFileName)
std::string const processName_
static SubRunID invalidSubRun(RunID const &rID)
Definition: SubRunID.h:164
bool isValid() const
Definition: RunID.h:69
std::set< SubRunID > subRunsSeen_