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 expandtab :
4 
8 #include "fhiclcpp/types/Atom.h"
10 
11 #include <atomic>
12 #include <chrono>
13 #include <limits>
14 #include <string>
15 
16 namespace art {
18  public:
20  // Note: Cannot be noexcept because of age_!
22  // Note: Cannot be noexcept because of age_!
23  FileProperties(unsigned events,
24  unsigned subRuns,
25  unsigned runs,
26  unsigned inputFiles,
27  unsigned size,
29  // Note: Cannot be noexcept because of age_!
31  // Note: Cannot be noexcept because of age_!
33  // Note: Cannot be noexcept because of age_!
35  // Note: Cannot be noexcept because of age_!
37  unsigned nEvents() const;
38  unsigned nSubRuns() const;
39  unsigned nRuns() const;
40  unsigned nInputFiles() const;
41  unsigned size() const;
42  std::chrono::seconds age() const;
46  void update_event();
48  void update_run(OutputFileStatus const status);
49  void update_inputFile();
50  void updateSize(unsigned const size);
51  void updateAge(std::chrono::seconds const age);
52 
53  private:
54  std::atomic<unsigned> counts_event_;
55  std::atomic<unsigned> counts_subRun_;
56  std::atomic<unsigned> counts_run_;
57  std::atomic<unsigned> counts_inputFile_;
58  std::atomic<unsigned> counts_job_;
59  std::atomic<FileIndex::EntryNumber_t> treeEntryNumbers_event_;
60  std::atomic<FileIndex::EntryNumber_t> treeEntryNumbers_subRun_;
61  std::atomic<FileIndex::EntryNumber_t> treeEntryNumbers_run_;
62  std::atomic<FileIndex::EntryNumber_t> treeEntryNumbers_inputFile_;
63  std::atomic<std::chrono::seconds> age_;
64  std::atomic<unsigned> size_;
65  };
66 
67  std::ostream& operator<<(std::ostream& os, FileProperties const& fp);
68 
70  public:
71  struct Defaults {
72  static constexpr unsigned
74  {
76  }
77  static constexpr unsigned
79  {
80  return 0x7f000000u;
81  }
82  static constexpr unsigned
84  {
86  }
87  static constexpr char const*
89  {
90  return "Event";
91  }
92  };
93 
94  struct Config {
95  using Name = fhicl::Name;
97  template <typename T>
99  template <typename T>
101  Atom<unsigned> maxEvents{Name("maxEvents"), Defaults::unsigned_max()};
102  Atom<unsigned> maxSubRuns{Name("maxSubRuns"), Defaults::unsigned_max()};
103  Atom<unsigned> maxRuns{Name("maxRuns"), Defaults::unsigned_max()};
104  Atom<unsigned> maxInputFiles{Name("maxInputFiles"),
105  Defaults::unsigned_max()};
106  Atom<unsigned> maxSize{Name("maxSize"),
107  Comment("Maximum size of file (in KiB)"),
108  Defaults::size_max()};
109  Atom<unsigned> maxAge{Name("maxAge"),
110  Comment("Maximum age of output file (in seconds)"),
111  Defaults::seconds_max()};
112 
113  Atom<std::string> granularity{
114  Name("granularity"),
115  Comment(
116  "The 'granularity' parameter specifies the level at which\n"
117  "a file may be closed, and thereby the granularity of the file.\n"
118  "The following values are possible:\n\n"
119  " Value Meaning\n"
120  " =======================================================\n"
121  " \"Event\" Allow file switch at next Event\n"
122  " \"SubRun\" Allow file switch at next SubRun\n"
123  " \"Run\" Allow file switch at next Run\n"
124  " \"InputFile\" Allow file switch at next InputFile\n"
125  " \"Job\" File closes at the end of Job\n\n"
126  "For example, if a granularity of \"SubRun\" is specified, but the\n"
127  "file has reached the maximum events written to disk (as specified\n"
128  "by the 'maxEvents' parameter), switching to a new file will NOT\n"
129  "happen until a new SubRun has been reached (or there are no more\n"
130  "Events/SubRuns/Runs to process)."),
131  Defaults::granularity_default()};
132  };
133 
134  public:
135  ~ClosingCriteria();
136  ClosingCriteria();
137  ClosingCriteria(Config const& fp);
138  ClosingCriteria(FileProperties const& fp, std::string const& granularity);
139  FileProperties const& fileProperties() const;
140  Granularity granularity() const;
141  bool should_close(FileProperties const&) const;
142 
143  private:
145  Granularity granularity_{
147  };
148 } // namespace art
149 
150 #endif /* art_Framework_IO_ClosingCriteria_h */
151 
152 // Local variables:
153 // mode: c++
154 // End:
unsigned nEvents() const
std::atomic< FileIndex::EntryNumber_t > treeEntryNumbers_subRun_
std::atomic< unsigned > counts_inputFile_
FileIndex::EntryNumber_t runEntryNumber() const
std::atomic< std::chrono::seconds > age_
unsigned nSubRuns() const
std::string string
Definition: nybbler.cc:12
ChannelGroupService::Name Name
std::atomic< FileIndex::EntryNumber_t > treeEntryNumbers_run_
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
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
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_
static int max(int a, int b)
std::atomic< unsigned > counts_job_
static constexpr char const * granularity_default()
#define Comment
std::atomic< unsigned > counts_subRun_
static constexpr unsigned unsigned_max()
unsigned size() const
void update_run(OutputFileStatus const status)
static constexpr unsigned size_max()
FileIndex::EntryNumber_t subRunEntryNumber() const
void updateSize(unsigned const size)
std::atomic< FileIndex::EntryNumber_t > treeEntryNumbers_event_
static constexpr unsigned seconds_max()