LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
RootInput.h
Go to the documentation of this file.
1 #ifndef art_Framework_IO_Root_RootInput_h
2 #define art_Framework_IO_Root_RootInput_h
3 // vim: set sw=2:
4 
14 #include "fhiclcpp/types/Table.h"
17 
18 #include <array>
19 #include <memory>
20 #include <string>
21 #include <type_traits>
22 #include <vector>
23 
24 namespace art {
25 
27  public:
28  struct Config {
34 
35  struct KeysToIgnore {
36  std::set<std::string>
37  operator()() const
38  {
39  return {"module_label"};
40  }
41  };
42  };
43 
45 
48  // Find the requested event and set the system up to read run and
49  // subRun records where appropriate. Note the corresponding
50  // seekToEvent function must exist in RootInputFileSequence to
51  // avoid a compile error.
52  template <typename T>
53  bool seekToEvent(T eventSpec, bool exact = false);
54 
55  private:
56  class AccessState {
57  public:
58  enum State {
59  SEQUENTIAL = 0,
63  SEEKING_EVENT // 4
64  };
65 
66  public:
67  AccessState();
68  State
69  state() const
70  {
71  return state_;
72  }
73  void setState(State state);
74  void
76  {
77  state_ = SEQUENTIAL;
78  }
79  EventID const&
81  {
82  return lastReadEventID_;
83  }
84  void setLastReadEventID(EventID const& eid);
85  EventID const&
86  wantedEventID() const
87  {
88  return wantedEventID_;
89  }
90  void setWantedEventID(EventID const& eid);
91  std::shared_ptr<RootInputFile>
93  {
94  return rootFileForLastReadEvent_;
95  }
96  void setRootFileForLastReadEvent(std::shared_ptr<RootInputFile> const&);
97 
98  private:
101  std::shared_ptr<RootInputFile> rootFileForLastReadEvent_;
103  }; // class AccessState
105 
106  private:
108  std::unique_ptr<RootInputFileSequence> primaryFileSequence_;
110 
111  private:
112  void finish() override;
113  input::ItemType nextItemType() override;
115  std::unique_ptr<EventPrincipal> readEvent(
116  cet::exempt_ptr<SubRunPrincipal const>) override;
117  std::unique_ptr<EventPrincipal> readEvent_() override;
118  std::unique_ptr<EventPrincipal> readEvent_(
119  cet::exempt_ptr<SubRunPrincipal const>);
120  std::unique_ptr<SubRunPrincipal> readSubRun(
121  cet::exempt_ptr<RunPrincipal const>) override;
122  std::unique_ptr<SubRunPrincipal> readSubRun_() override;
123  std::unique_ptr<RunPrincipal> readRun() override;
124  std::unique_ptr<RunPrincipal> readRun_() override;
125  std::unique_ptr<FileBlock> readFile() override;
126  std::unique_ptr<FileBlock> readFile_() override;
127  std::unique_ptr<RangeSetHandler> runRangeSetHandler() override;
128  std::unique_ptr<RangeSetHandler> subRunRangeSetHandler() override;
129  void closeFile_() override;
130  void endJob() override;
131  input::ItemType getNextItemType() override;
132  void rewind_() override;
133 
134  template <typename T>
136  postSeekChecks(EventID const& foundID, T eventSpec);
137 
138  template <typename T>
140  postSeekChecks(EventID const& foundID, T eventSpec);
141  }; // class RootInput
142 
143  template <typename T>
144  bool
145  RootInput::seekToEvent(T eventSpec, bool exact)
146  {
147  if (accessState_.state()) {
149  << "Attempted to initiate a random access seek "
150  << "with one already in progress at state = " << accessState_.state()
151  << ".\n";
152  }
153  EventID foundID = primaryFileSequence_->seekToEvent(eventSpec, exact);
154  if (!foundID.isValid()) {
155  return false;
156  }
157  foundID = postSeekChecks(foundID, eventSpec);
159  if (primaryFileSequence_->rootFile() !=
162  } else if (foundID.runID() != accessState_.lastReadEventID().runID()) {
164  } else if (foundID.subRunID() !=
167  } else {
169  }
170  return true;
171  }
172 
173  template <typename T>
175  RootInput::postSeekChecks(EventID const& foundID, T eventspec)
176  {
177  if (eventspec == 0 && foundID == accessState_.lastReadEventID()) {
178  // We're supposed to be reading the, "next" event but it's a
179  // duplicate of the current one: skip it.
180  mf::LogWarning("DuplicateEvent")
181  << "Duplicate Events found: "
182  << "both events were " << foundID << ".\n"
183  << "The duplicate will be skipped.\n";
184  return primaryFileSequence_->seekToEvent(1, false);
185  }
186  return foundID;
187  }
188 
189  template <typename T>
192  {
193  // Default implementation is NOP.
194  return foundID;
195  }
196 
197 } // namespace art
198 
199 // Local Variables:
200 // mode: c++
201 // End:
202 #endif /* art_Framework_IO_Root_RootInput_h */
bool isValid() const
Definition: EventID.h:123
RunID const & runID() const
Definition: EventID.h:93
SubRunID const & subRunID() const
Definition: EventID.h:105
State state() const
Definition: RootInput.h:69
fhicl::TableFragment< DecrepitRelicInputSourceImplementation::Config > drisi_config
Definition: RootInput.h:31
std::shared_ptr< RootInputFile > rootFileForLastReadEvent_
Definition: RootInput.h:101
std::shared_ptr< RootInputFile > rootFileForLastReadEvent() const
Definition: RootInput.h:92
void rewind_() override
std::set< std::string > operator()() const
Definition: RootInput.h:37
EventID const & wantedEventID() const
Definition: RootInput.h:86
std::unique_ptr< SubRunPrincipal > readSubRun_() override
void setWantedEventID(EventID const &eid)
AccessState accessState_
Definition: RootInput.h:109
void finish() override
std::unique_ptr< EventPrincipal > readEvent(cet::exempt_ptr< SubRunPrincipal const > srp) override
EventID const & lastReadEventID() const
Definition: RootInput.h:80
fhicl::TableFragment< InputFileCatalog::Config > ifc_config
Definition: RootInput.h:32
std::unique_ptr< FileBlock > readFile_() override
std::unique_ptr< RunPrincipal > readRun_() override
input::EntryNumber EntryNumber
Definition: RootInput.h:104
std::unique_ptr< RootInputFileSequence > primaryFileSequence_
Definition: RootInput.h:108
input::ItemType getNextItemType() override
std::unique_ptr< SubRunPrincipal > readSubRun(cet::exempt_ptr< RunPrincipal const >) override
Read next subRun.
void endJob() override
input::ItemType nextItemType() override
std::unique_ptr< EventPrincipal > readEvent_() override
InputFileCatalog catalog_
Definition: RootInput.h:107
std::enable_if_t< std::is_convertible< T, off_t >::value, EventID > postSeekChecks(EventID const &foundID, T eventSpec)
Definition: RootInput.h:175
bool seekToEvent(T eventSpec, bool exact=false)
Definition: RootInput.h:145
fhicl::TableFragment< RootInputFileSequence::Config > rifs_config
Definition: RootInput.h:33
Long64_t EntryNumber
Definition: Inputfwd.h:46
std::unique_ptr< RangeSetHandler > runRangeSetHandler() override
std::unique_ptr< EventPrincipal > readEvent(cet::exempt_ptr< SubRunPrincipal const >) override
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
fhicl::Atom< std::string > module_type
Definition: RootInput.h:29
std::string value(boost::any const &)
std::unique_ptr< FileBlock > readFile() override
Read next file.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
HLT enums.
RootInput(Parameters const &, InputSourceDescription &)
std::unique_ptr< RunPrincipal > readRun() override
Read next run.
void closeFile_() override
std::unique_ptr< RangeSetHandler > subRunRangeSetHandler() override