ClosingCriteria.cc
Go to the documentation of this file.
3 // vim: set sw=2 expandtab :
4 
5 using namespace std;
6 
8 
9 namespace {
10  void
11  config_require(bool const cond, string const& msg)
12  {
13  if (!cond)
14  throw art::Exception(art::errors::Configuration) << msg << '\n';
15  }
16 }
17 
18 namespace art {
19 
20  FileProperties::~FileProperties() = default;
21 
22  // Note: Cannot be noexcept because of age_!
23  FileProperties::FileProperties()
24  : counts_event_{0}
25  , counts_subRun_{0}
26  , counts_run_{0}
28  , counts_job_{0}
33  , age_{chrono::seconds::zero()}
34  , size_{0}
35  {}
36 
37  // Note: Cannot be noexcept because of age_!
39  unsigned const subRuns,
40  unsigned const runs,
41  unsigned const inputFiles,
42  unsigned const the_size,
43  chrono::seconds const the_age)
44  : counts_event_{events}
45  , counts_subRun_{subRuns}
46  , counts_run_{runs}
47  , counts_inputFile_{inputFiles}
48  , counts_job_{0}
53  , age_{the_age}
54  , size_{the_size}
55  {}
56 
57  // Note: Cannot be noexcept because of age_!
59  : counts_event_{rhs.counts_event_.load()}
60  , counts_subRun_{rhs.counts_subRun_.load()}
61  , counts_run_{rhs.counts_run_.load()}
62  , counts_inputFile_{rhs.counts_inputFile_.load()}
63  , counts_job_{rhs.counts_job_.load()}
64  , treeEntryNumbers_event_{rhs.treeEntryNumbers_event_.load()}
65  , treeEntryNumbers_subRun_{rhs.treeEntryNumbers_subRun_.load()}
66  , treeEntryNumbers_run_{rhs.treeEntryNumbers_run_.load()}
67  , treeEntryNumbers_inputFile_{rhs.treeEntryNumbers_inputFile_.load()}
68  , age_{rhs.age_.load()}
69  , size_{rhs.size_.load()}
70  {}
71 
72  // Note: Cannot be noexcept because of age_!
74  : counts_event_{rhs.counts_event_.load()}
75  , counts_subRun_{rhs.counts_subRun_.load()}
76  , counts_run_{rhs.counts_run_.load()}
77  , counts_inputFile_{rhs.counts_inputFile_.load()}
78  , counts_job_{rhs.counts_job_.load()}
79  , treeEntryNumbers_event_{rhs.treeEntryNumbers_event_.load()}
80  , treeEntryNumbers_subRun_{rhs.treeEntryNumbers_subRun_.load()}
81  , treeEntryNumbers_run_{rhs.treeEntryNumbers_run_.load()}
82  , treeEntryNumbers_inputFile_{rhs.treeEntryNumbers_inputFile_.load()}
83  , age_{rhs.age_.load()}
84  , size_{rhs.size_.load()}
85  {}
86 
87  // Note: Cannot be noexcept because of age_!
90  {
91  if (this != &rhs) {
92  counts_event_ = rhs.counts_event_.load();
93  counts_subRun_ = rhs.counts_subRun_.load();
94  counts_run_ = rhs.counts_run_.load();
96  counts_job_ = rhs.counts_job_.load();
101  age_ = rhs.age_.load();
102  size_ = rhs.size_.load();
103  }
104  return *this;
105  }
106 
109  {
110  counts_event_ = rhs.counts_event_.load();
111  counts_subRun_ = rhs.counts_subRun_.load();
112  counts_run_ = rhs.counts_run_.load();
113  counts_inputFile_ = rhs.counts_inputFile_.load();
114  counts_job_ = rhs.counts_job_.load();
115  treeEntryNumbers_event_ = rhs.treeEntryNumbers_event_.load();
116  treeEntryNumbers_subRun_ = rhs.treeEntryNumbers_subRun_.load();
117  treeEntryNumbers_run_ = rhs.treeEntryNumbers_run_.load();
118  treeEntryNumbers_inputFile_ = rhs.treeEntryNumbers_inputFile_.load();
119  age_ = rhs.age_.load();
120  size_ = rhs.size_.load();
121  return *this;
122  }
123 
124  unsigned
126  {
127  return counts_event_.load();
128  }
129 
130  unsigned
132  {
133  return counts_subRun_.load();
134  }
135 
136  unsigned
138  {
139  return counts_run_.load();
140  }
141 
142  unsigned
144  {
145  return counts_inputFile_.load();
146  }
147 
148  unsigned
150  {
151  return size_.load();
152  }
153 
156  {
157  return age_.load();
158  }
159 
162  {
163  return treeEntryNumbers_event_.load();
164  }
165 
168  {
169  return treeEntryNumbers_subRun_.load();
170  }
171 
174  {
175  return treeEntryNumbers_run_.load();
176  }
177 
178  void
180  {
181  size_ = size;
182  }
183 
184  void
186  {
187  age_ = age;
188  }
189 
190  void
192  {
194  ++counts_event_;
195  }
196 
197  void
199  {
201  if (status != OutputFileStatus::Switching) {
202  ++counts_subRun_;
203  }
204  }
205 
206  void
208  {
210  if (status != OutputFileStatus::Switching) {
211  ++counts_run_;
212  }
213  }
214 
215  void
217  {
219  }
220 
221  ostream&
222  operator<<(ostream& os, FileProperties const& fp)
223  {
224  os << "[nEvents: " << fp.nEvents() << ", nSubRuns: " << fp.nSubRuns()
225  << ", nRuns: " << fp.nRuns() << ", nInputFiles: " << fp.nInputFiles()
226  << ", size: " << fp.size() << ", age: " << fp.age().count() << "]";
227  return os;
228  }
229 
231 
233  : closingCriteria_{}
235  {}
236 
238  string const& granularity)
240  {}
241 
244  c.maxSubRuns(),
245  c.maxRuns(),
246  c.maxInputFiles(),
247  c.maxSize(),
248  chrono::seconds{c.maxAge()}},
249  c.granularity()}
250  {
251  auto const& cc = closingCriteria_;
252  config_require(cc.nEvents() > 0, "maxEvents must be greater than 0.");
253  config_require(cc.nSubRuns() > 0, "maxSubRuns must be greater than 0.");
254  config_require(cc.nRuns() > 0, "maxRuns must be greater than 0.");
255  config_require(cc.nInputFiles() > 0,
256  "maxInputFiles must be greater than 0.");
257  config_require(cc.size() > 0, "maxSize must be greater than 0 KiB.");
258  config_require(cc.age() > decltype(cc.age())::zero(),
259  "maxAge must be greater than 0 seconds.");
260  }
261 
262  FileProperties const&
264  {
265  return closingCriteria_;
266  }
267 
270  {
271  return granularity_;
272  }
273 
274  bool
276  {
277  return (fp.size() >= closingCriteria_.size()) ||
278  (fp.nEvents() >= closingCriteria_.nEvents()) ||
279  (fp.nSubRuns() >= closingCriteria_.nSubRuns()) ||
280  (fp.nRuns() >= closingCriteria_.nRuns()) ||
282  (fp.age() >= closingCriteria_.age());
283  }
284 
285 } // namespace art
unsigned nEvents() const
std::atomic< FileIndex::EntryNumber_t > treeEntryNumbers_subRun_
std::atomic< unsigned > counts_inputFile_
FileIndex::EntryNumber_t runEntryNumber() const
Granularity granularity() const
std::atomic< std::chrono::seconds > age_
unsigned nSubRuns() const
void msg(const char *fmt,...)
Definition: message.cpp:107
art::FileIndex::EntryNumber_t EntryNumber_t
std::atomic< FileIndex::EntryNumber_t > treeEntryNumbers_run_
STL namespace.
std::atomic< unsigned > size_
unsigned nInputFiles() const
std::atomic< unsigned > counts_run_
FileIndex::EntryNumber_t eventEntryNumber() const
long long EntryNumber_t
Definition: FileIndex.h:41
FileProperties const & fileProperties() const
static BT value(std::string const &spec)
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
unsigned nRuns() const
OutputFileStatus
std::chrono::seconds age() const
bool should_close(FileProperties const &) const
void updateAge(std::chrono::seconds const age)
second seconds
Alias for common language habits.
Definition: spacetime.h:88
void update_subRun(OutputFileStatus const status)
FileProperties & operator=(FileProperties const &)
std::atomic< unsigned > counts_event_
std::atomic< FileIndex::EntryNumber_t > treeEntryNumbers_inputFile_
FileProperties closingCriteria_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::atomic< unsigned > counts_job_
static constexpr char const * granularity_default()
Atom< std::string > granularity
std::atomic< unsigned > counts_subRun_
unsigned size() const
void update_run(OutputFileStatus const status)
FileIndex::EntryNumber_t subRunEntryNumber() const
void updateSize(unsigned const size)
std::atomic< FileIndex::EntryNumber_t > treeEntryNumbers_event_