LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
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>
118  update(OutputFileStatus const status)
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
auto nEvents() const
std::enable_if_t< B==Granularity::InputFile > update()
Int_t B
Definition: plot.C:25
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)
Int_t max
Definition: plot.C:27
OutputFileStatus
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
void updateAge(std::chrono::seconds const age)
auto eventEntryNumber() const
auto granularity() const
auto nRuns() const
auto runEntryNumber() const
static constexpr auto seconds_max()
FILE * fp
Definition: plot.C:36
FileProperties closingCriteria_
#define GRANULARITY_COMMENT
static constexpr auto size_max()
std::enable_if_t< B!=Granularity::InputFile > update(OutputFileStatus const status)
auto subRunEntryNumber() const
HLT enums.
auto size() const
void updateSize(unsigned const size)
auto nInputFiles() const