ClosingCriteria.h
Go to the documentation of this file.
1 #ifndef art_Framework_IO_ClosingCriteria_h
2 #define art_Framework_IO_ClosingCriteria_h
3 // vim: set sw=2:
4 
9 #include "fhiclcpp/types/Atom.h"
11 
12 #include <chrono>
13 #include <type_traits>
14 
15 // FIXME: Adjust comment below so that it is not RootOutput module specific.
16 
17 #define GRANULARITY_COMMENT \
18  "The 'granularity' parameter specifies the level at which\n" \
19  "a file may be closed, and thereby the granularity of the file.\n" \
20  "The following values are possible:\n\n" \
21  " Value Meaning\n" \
22  " =======================================================\n" \
23  " \"Event\" Allow file switch at next Event\n" \
24  " \"SubRun\" Allow file switch at next SubRun\n" \
25  " \"Run\" Allow file switch at next Run\n" \
26  " \"InputFile\" Allow file switch at next InputFile\n" \
27  " \"Job\" File closes at the end of Job\n\n" \
28  "For example, if a granularity of \"SubRun\" is specified, but the\n" \
29  "file has reached the maximum events written to disk (as specified\n" \
30  "by the 'maxEvents' parameter), switching to a new file will NOT\n" \
31  "happen until a new SubRun has been reached (or there are no more\n" \
32  "Events/SubRuns/Runs to process)."
33 
34 namespace art {
35 
36  struct Defaults {
37  static constexpr auto
39  {
41  }
42  static constexpr auto
44  {
45  return 0x7f000000u;
46  }
47  static constexpr auto
49  {
51  }
52  static constexpr auto
54  {
55  return "Event";
56  }
57  };
58 
60  public:
61  FileProperties() = default;
62  FileProperties(unsigned events,
63  unsigned subRuns,
64  unsigned runs,
65  unsigned inputFiles,
66  unsigned size,
67  std::chrono::seconds age);
68 
69  auto
70  nEvents() const
71  {
72  return counts_[Granularity::Event];
73  }
74  auto
75  nSubRuns() const
76  {
77  return counts_[Granularity::SubRun];
78  }
79  auto
80  nRuns() const
81  {
82  return counts_[Granularity::Run];
83  }
84  auto
85  nInputFiles() const
86  {
87  return counts_[Granularity::InputFile];
88  }
89  auto
90  size() const
91  {
92  return size_;
93  }
94  auto
95  age() const
96  {
97  return age_;
98  }
99 
100  auto
102  {
103  return treeEntryNumbers_[Granularity::Event];
104  }
105  auto
107  {
108  return treeEntryNumbers_[Granularity::SubRun];
109  }
110  auto
112  {
113  return treeEntryNumbers_[Granularity::Run];
114  }
115 
116  template <Granularity::BT B>
117  std::enable_if_t<B != Granularity::InputFile>
119  {
120  ++treeEntryNumbers_[B];
121  if (status != OutputFileStatus::Switching) {
122  ++counts_[B];
123  }
124  }
125 
126  template <Granularity::BT B>
127  std::enable_if_t<B == Granularity::InputFile>
129  {
130  ++counts_[B];
131  }
132 
133  void
134  updateSize(unsigned const size)
135  {
136  size_ = size;
137  }
138  void
139  updateAge(std::chrono::seconds const age)
140  {
141  age_ = age;
142  }
143 
144  private:
145  std::array<unsigned, Granularity::NBoundaries()> counts_{
146  {}}; // Filled by aggregation
148  treeEntryNumbers_{{}};
149  std::chrono::seconds age_{std::chrono::seconds::zero()};
150  unsigned size_{};
151  };
152 
153  std::ostream& operator<<(std::ostream& os, FileProperties const& fp);
154 
156  public:
157  struct Config : Defaults {
158  using Name = fhicl::Name;
160  template <typename T>
162  template <typename T>
164 
165  Atom<unsigned> maxEvents{Name("maxEvents"), unsigned_max()};
166  Atom<unsigned> maxSubRuns{Name("maxSubRuns"), unsigned_max()};
167  Atom<unsigned> maxRuns{Name("maxRuns"), unsigned_max()};
168  Atom<unsigned> maxInputFiles{Name("maxInputFiles"), unsigned_max()};
169  Atom<unsigned> maxSize{Name("maxSize"),
170  Comment("Maximum size of file (in KiB)"),
171  size_max()};
172  Atom<unsigned> maxAge{Name("maxAge"),
173  Comment("Maximum age of output file (in seconds)"),
174  seconds_max()};
175  fhicl::Atom<std::string> granularity{fhicl::Name("granularity"),
178  };
179 
180  ClosingCriteria(Config const& fp);
181  ClosingCriteria(FileProperties const& fp, std::string const& granularity);
182  ClosingCriteria() = default;
183 
184  auto const&
186  {
187  return closingCriteria_;
188  }
189  auto
190  granularity() const
191  {
192  return granularity_;
193  }
194 
195  bool should_close(FileProperties const&) const;
196 
197  private:
199  Granularity granularity_{
201  };
202 }
203 
204 #undef GRANULARITY_COMMENT
205 #endif /* art_Framework_IO_ClosingCriteria_h */
206 
207 // Local variables:
208 // mode: c++
209 // End:
std::ostream & operator<<(std::ostream &os, EDAnalyzer::Table< T > const &t)
Definition: EDAnalyzer.h:184
static constexpr std::size_t NBoundaries()
auto const & fileProperties() const
auto nSubRuns() const
int status
Definition: fabricate.py:1613
auto nEvents() const
std::enable_if_t< B==Granularity::InputFile > update()
static constexpr auto unsigned_max()
long long EntryNumber_t
Definition: FileIndex.h:43
static constexpr auto granularity_default()
static BT value(std::string const &spec)
OutputFileStatus
void updateAge(std::chrono::seconds const age)
auto eventEntryNumber() const
auto granularity() const
size_t size_
Definition: dot_self.hpp:18
auto nRuns() const
auto runEntryNumber() const
static constexpr auto seconds_max()
FileProperties closingCriteria_
#define GRANULARITY_COMMENT
static constexpr auto size_max()
std::enable_if_t< B!=Granularity::InputFile > update(OutputFileStatus const status)
auto subRunEntryNumber() const
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
FILE * fp
auto size() const
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:68
auto zero()
Definition: PMNS.cxx:47
void events(int which)
Definition: Cana.C:52
void updateSize(unsigned const size)
list runs
Definition: shutoffs.py:47
auto nInputFiles() const
enum BeamMode string