LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 using boost::posix_time::ptime;
8 namespace {
9  auto now = boost::posix_time::second_clock::universal_time;
10 }
11 
12 art::FileStatsCollector::FileStatsCollector(std::string const& moduleLabel,
13  std::string const& processName)
14  : moduleLabel_{moduleLabel}, processName_{processName}
15 {}
16 
17 void
19 {
21  if (!inputFilesSeen_.empty()) {
23  }
24  fo_ = now();
25  fileCloseRecorded_ = false;
26 }
27 
28 void
29 art::FileStatsCollector::recordInputFile(std::string const& inputFileName)
30 {
31  if (!inputFileName.empty()) {
32  inputFilesSeen_.emplace_back(inputFileName);
33  }
34  lastOpenedInputFile_ = inputFileName;
35 }
36 
37 void
39 {
40  ++nEvents_;
41  if (!lowestEventIDSeen_.isValid()) {
43  } else if (id < lowestEventIDSeen_) {
44  lowestEventIDSeen_ = id;
45  } else if (id > highestEventIDSeen_) {
47  }
48 }
49 
50 void
52 {
53  if (!lowestRun_.isValid()) {
54  lowestRun_ = highestRun_ = id;
56  return;
57  }
58 
59  if (id < lowestRun_) {
60  lowestRun_ = id;
61  lowestRunStartTime_ = now();
62  if (lowestSubRun_.runID() != lowestRun_) {
64  lowestSubRunStartTime_ = ptime{};
65  }
66  } else if (id > highestRun_) {
67  highestRun_ = id;
68  highestRunStartTime_ = now();
69  if (highestSubRun_.runID() != highestRun_) {
71  highestSubRunStartTime_ = ptime{};
72  }
73  }
74 }
75 
76 void
78 {
79  if (!lowestSubRun_.isValid()) {
82  } else if (id < lowestSubRun_) {
83  lowestSubRun_ = id;
84  lowestSubRunStartTime_ = now();
85  } else if (id > highestSubRun_) {
86  highestSubRun_ = id;
88  }
89  subRunsSeen_.emplace(id);
90 }
91 
92 void
94 {
95  fc_ = now();
96  fileCloseRecorded_ = true;
97 }
98 
99 std::vector<std::string>
100 art::FileStatsCollector::parents(bool const want_basename) const
101 {
102  std::vector<std::string> result;
103  if (want_basename) {
104  result.reserve(inputFilesSeen_.size());
105  for (auto const& ifile : inputFilesSeen_) {
106  boost::filesystem::path const ifp{ifile};
107  result.emplace_back(ifp.filename().native());
108  }
109  } else {
110  result = inputFilesSeen_;
111  }
112  return result;
113 }
114 
115 void
117 {
118  fo_ = fc_ = ptime{};
123  inputFilesSeen_.clear();
124  nEvents_ = 0ul;
125  subRunsSeen_.clear();
126 }
bool isValid() const
Definition: EventID.h:122
std::string const & processName() const
FileStatsCollector(std::string const &moduleLabel, std::string const &processName)
boost::posix_time::ptime fo_
void recordRun(RunID const &id)
boost::posix_time::ptime highestRunStartTime_
void recordEvent(EventID const &id)
std::vector< std::string > inputFilesSeen_
boost::posix_time::ptime highestSubRunStartTime_
bool isValid() const
Definition: SubRunID.h:97
boost::posix_time::ptime fc_
std::vector< std::string > parents(bool want_basename=true) const
RunID const & runID() const
Definition: SubRunID.h:79
boost::posix_time::ptime lowestSubRunStartTime_
void recordSubRun(SubRunID const &id)
void recordInputFile(std::string const &inputFileName)
boost::posix_time::ptime lowestRunStartTime_
std::string const processName_
bool isValid() const
Definition: RunID.h:70
std::set< SubRunID > subRunsSeen_