rangeSetFromFileIndex.cc
Go to the documentation of this file.
2 
3 #include <algorithm>
4 
5 using namespace art;
6 
7 namespace {
8 
9  class next_run_in_file {
10  public:
11  bool
12  operator()(FileIndex::Element const element) const
13  {
14  return element.getEntryType() == FileIndex::kRun;
15  }
16  };
17 
18  class next_subrun_in_run {
19  public:
20  next_subrun_in_run(RunID const runID) : runID_{runID} {}
21  bool
22  operator()(FileIndex::Element const element) const
23  {
24  return element.getEntryType() == FileIndex::kSubRun &&
25  element.eventID_.runID() == runID_;
26  }
27 
28  private:
29  RunID const runID_;
30  };
31 
32  class next_event_in_subrun {
33  public:
34  next_event_in_subrun(SubRunID const subRunID) : subRunID_{subRunID} {}
35  bool
36  operator()(FileIndex::Element const& element) const
37  {
38  return element.getEntryType() == FileIndex::kEvent &&
39  element.eventID_.subRunID() == subRunID_;
40  }
41 
42  private:
43  SubRunID const subRunID_;
44  };
45 
46  class end_of_subrun {
47  public:
48  end_of_subrun(SubRunID const subRunID) : subRunID_{subRunID} {}
49  bool
50  operator()(FileIndex::Element const element) const
51  {
52  return element.eventID_.subRunID() != subRunID_;
53  }
54 
55  private:
56  SubRunID const subRunID_;
57  };
58 
59  class end_of_run {
60  public:
61  end_of_run(RunID const runID) : runID_{runID} {}
62  bool
63  operator()(FileIndex::Element const element) const
64  {
65  return element.eventID_.runID() != runID_;
66  }
67 
68  private:
69  RunID const runID_;
70  };
71 }
72 
75  SubRunID const subRunID,
76  bool const compactRanges)
77 {
78  RangeSet rangeSet{subRunID.run()};
79  auto begin = std::cbegin(fileIndex);
80  auto end = std::cend(fileIndex);
81 
82  auto subrun_begin =
83  std::find_if(begin, end, next_subrun_in_run{subRunID.runID()});
84  if (subrun_begin == end) {
85  // SubRun does not exist in the provided fileIndex
86  return rangeSet;
87  }
88 
89  auto event_it =
90  std::find_if(subrun_begin, end, next_event_in_subrun{subRunID});
91  if (event_it == end) {
92  // SubRun has no event entries entries
93  return rangeSet;
94  }
95 
96  auto const& eid = event_it->eventID_;
97  auto event_end =
98  std::find_if_not(event_it, end, next_event_in_subrun{subRunID});
99 
100  if (compactRanges) {
101  auto const count = std::distance(event_it, event_end);
102  if (count < 1) {
103  // Should never get here, and should probably throw
104  return rangeSet;
105  }
106 
107  auto const subrun = subRunID.subRun();
108  auto const ebegin = eid.event();
109  auto const eend = (count == 1) ?
110  eid.next().event() :
111  std::prev(event_end)->eventID_.next().event();
112  rangeSet.emplace_range(subrun, ebegin, eend);
113  return rangeSet;
114  }
115 
116  std::for_each(event_it, event_end, [&rangeSet](auto const& element) {
117  rangeSet.update(element.eventID_);
118  });
119  return rangeSet;
120 }
121 
122 RangeSet
124  RunID const runID,
125  bool const compactRanges)
126 {
127  auto const run = runID.run();
128  auto const begin = std::cbegin(fileIndex);
129  auto const end = std::cend(fileIndex);
130 
131  RangeSet rangeSet{run};
132 
133  // Loop through SubRuns in Run
134  auto subrun_begin = std::find_if(begin, end, next_subrun_in_run{runID});
135  if (subrun_begin == end) {
136  // Run has no entries -- early bail out
137  return rangeSet;
138  }
139 
140  auto const run_end = std::find_if(subrun_begin, end, end_of_run{runID});
141  while (subrun_begin != run_end) {
142  auto const subRunID = subrun_begin->eventID_.subRunID();
143  auto rs = rangeSetFromFileIndex(fileIndex, subRunID, compactRanges);
144  if (rs.is_valid()) {
145  rangeSet.merge(rs);
146  }
147  auto subrun_end = std::find_if(subrun_begin, end, end_of_subrun{subRunID});
148  subrun_begin = subrun_end;
149  }
150 
151  return rangeSet;
152 }
RunID const & runID() const
Definition: EventID.h:93
SubRunID const & subRunID() const
Definition: EventID.h:105
unsigned int subrun
RangeSet rangeSetFromFileIndex(FileIndex const &fileIndex, RunID runID, bool compactRanges)
RunNumber_t run() const
Definition: RunID.h:65
RunID const & runID() const
Definition: SubRunID.h:78
RunNumber_t run() const
Definition: SubRunID.h:84
auto begin(Data< Value > const &data)
EntryType getEntryType() const
Definition: FileIndex.cc:42
end
Definition: test.py:8
SubRunNumber_t subRun() const
Definition: SubRunID.h:90
unsigned int run