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 expandtab :
4 
15 #include "fhiclcpp/types/Table.h"
18 
19 #include <array>
20 #include <memory>
21 #include <string>
22 #include <type_traits>
23 #include <vector>
24 
25 namespace art {
26 
28 
29  public: // CONFIGURATION
30  struct Config {
31 
37 
38  struct KeysToIgnore {
39  std::set<std::string>
40  operator()() const
41  {
42  return {"module_label"};
43  }
44  };
45  };
46 
48 
49  private: // TYPES
50  class AccessState {
51 
52  public: // TYPES
53  enum State {
54  SEQUENTIAL = 0,
58  SEEKING_EVENT // 4
59  };
60 
61  public:
62  ~AccessState();
63 
64  AccessState();
65 
66  State state() const;
67 
68  void setState(State state);
69 
70  void resetState();
71 
72  EventID const& lastReadEventID() const;
73 
74  void setLastReadEventID(EventID const&);
75 
76  EventID const& wantedEventID() const;
77 
78  void setWantedEventID(EventID const&);
79 
80  std::shared_ptr<RootInputFile> rootFileForLastReadEvent() const;
81 
82  void setRootFileForLastReadEvent(std::shared_ptr<RootInputFile> const&);
83 
84  private:
87  std::shared_ptr<RootInputFile> rootFileForLastReadEvent_;
89  };
90 
92 
93  public: // MEMBER FUNCTIONS -- Special Member Functions
94  ~RootInput();
95 
97 
98  RootInput(RootInput const&) = delete;
99 
100  RootInput(RootInput&&) = delete;
101 
102  RootInput& operator=(RootInput const&) = delete;
103 
104  RootInput& operator=(RootInput&&) = delete;
105 
106  public:
107  // Find the requested event and set the system up to read run and
108  // subRun records where appropriate. Note the corresponding
109  // seekToEvent function must exist in RootInputFileSequence to
110  // avoid a compile error.
111  template <typename T>
112  bool seekToEvent(T eventSpec, bool exact = false);
113 
114  private: // MEMBER FUNCTIONS -- Serial Interface
115  void finish() override;
116 
117  virtual input::ItemType nextItemType() override;
118 
119  virtual std::unique_ptr<FileBlock> readFile() override;
120 
121  // Not Implemented
122  // virtual
123  // void
124  // closeFile() = 0;
125 
126  virtual std::unique_ptr<RunPrincipal> readRun() override;
127 
128  virtual std::unique_ptr<SubRunPrincipal> readSubRun(
130 
131  virtual std::unique_ptr<EventPrincipal> readEvent(
133 
134  virtual std::unique_ptr<RangeSetHandler> runRangeSetHandler() override;
135 
136  virtual std::unique_ptr<RangeSetHandler> subRunRangeSetHandler() override;
137 
138  private: // MEMBER FUNCTIONS -- Job Interface
139  // Not Implemented.
140  // virtual
141  // void
142  // doBeginJob() override;
143 
144  virtual void endJob() override;
145 
146  private: // MEMBER FUNCTIONS -- Random Access Interface
147  // Note: This pulls in:
148  // virtual
149  // std::unique_ptr<EventPrincipal>
150  // readEvent(EventID const&) override;
152 
153  // Not Implemented.
154  // virtual
155  // void
156  // skipEvents(int n);
157 
158  // Not Implemented.
159  // virtual
160  // void
161  // rewind() override;
162 
163  private
164  : // MEMBER FUNCTIONS -- Required by DecrepitRelicInputSourceImplementation
165  virtual input::ItemType getNextItemType() override;
166 
167  virtual std::unique_ptr<RunPrincipal> readRun_() override;
168 
169  virtual std::unique_ptr<SubRunPrincipal> readSubRun_(
171 
172  virtual std::unique_ptr<EventPrincipal> readEvent_() override;
173 
174  private
175  : // MEMBER FUNCTIONS -- DecrepitRelicInputSourceImplementation Interface
176  virtual std::unique_ptr<FileBlock> readFile_() override;
177 
178  virtual void closeFile_() override;
179 
180  virtual void rewind_() override;
181 
182  private: // MEMBER FUNCTIONS
183  std::unique_ptr<EventPrincipal> readEvent_(
185 
186  private:
187  template <typename T>
189  postSeekChecks(EventID const& foundID, T eventSpec);
190 
191  template <typename T>
193  postSeekChecks(EventID const& foundID, T eventSpec);
194 
195  private:
197  std::unique_ptr<RootInputFileSequence> primaryFileSequence_;
199  };
200 
201  template <typename T>
202  bool
203  RootInput::seekToEvent(T eventSpec, bool exact)
204  {
205  if (accessState_.state()) {
207  << "Attempted to initiate a random access seek "
208  << "with one already in progress at state = " << accessState_.state()
209  << ".\n";
210  }
211  EventID foundID = primaryFileSequence_->seekToEvent(eventSpec, exact);
212  if (!foundID.isValid()) {
213  return false;
214  }
215  foundID = postSeekChecks(foundID, eventSpec);
217  if (primaryFileSequence_->rootFile() !=
220  } else if (foundID.runID() != accessState_.lastReadEventID().runID()) {
222  } else if (foundID.subRunID() !=
225  } else {
227  }
228  return true;
229  }
230 
231  template <typename T>
233  RootInput::postSeekChecks(EventID const& foundID, T eventspec)
234  {
235  if (eventspec == 0 && foundID == accessState_.lastReadEventID()) {
236  // We're supposed to be reading the, "next" event but it's a
237  // duplicate of the current one: skip it.
238  mf::LogWarning("DuplicateEvent")
239  << "Duplicate Events found: "
240  << "both events were " << foundID << ".\n"
241  << "The duplicate will be skipped.\n";
242  return primaryFileSequence_->seekToEvent(1, false);
243  }
244  return foundID;
245  }
246 
247  template <typename T>
250  {
251  // Default implementation is NOP.
252  return foundID;
253  }
254 
255 } // namespace art
256 
257 // Local Variables:
258 // mode: c++
259 // End:
260 #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
fhicl::TableFragment< DecrepitRelicInputSourceImplementation::Config > drisi_config
Definition: RootInput.h:34
std::shared_ptr< RootInputFile > rootFileForLastReadEvent_
Definition: RootInput.h:87
virtual std::unique_ptr< RangeSetHandler > runRangeSetHandler() override
virtual void rewind_() override
std::set< std::string > operator()() const
Definition: RootInput.h:40
virtual std::unique_ptr< EventPrincipal > readEvent(cet::exempt_ptr< SubRunPrincipal const >) override
AccessState accessState_
Definition: RootInput.h:198
void setWantedEventID(EventID const &)
void finish() override
fhicl::TableFragment< InputFileCatalog::Config > ifc_config
Definition: RootInput.h:35
EventID const & lastReadEventID() const
std::shared_ptr< RootInputFile > rootFileForLastReadEvent() const
input::EntryNumber EntryNumber
Definition: RootInput.h:91
RootInput & operator=(RootInput const &)=delete
std::unique_ptr< RootInputFileSequence > primaryFileSequence_
Definition: RootInput.h:197
virtual input::ItemType getNextItemType() override
virtual void endJob() override
virtual input::ItemType nextItemType() override
virtual std::unique_ptr< SubRunPrincipal > readSubRun(cet::exempt_ptr< RunPrincipal const >) override
InputFileCatalog catalog_
Definition: RootInput.h:196
virtual std::unique_ptr< FileBlock > readFile_() override
virtual std::unique_ptr< EventPrincipal > readEvent(cet::exempt_ptr< SubRunPrincipal const >) override
std::enable_if_t< std::is_convertible< T, off_t >::value, EventID > postSeekChecks(EventID const &foundID, T eventSpec)
Definition: RootInput.h:233
virtual std::unique_ptr< FileBlock > readFile() override
Read next file.
bool seekToEvent(T eventSpec, bool exact=false)
Definition: RootInput.h:203
fhicl::TableFragment< RootInputFileSequence::Config > rifs_config
Definition: RootInput.h:36
virtual std::unique_ptr< SubRunPrincipal > readSubRun_(cet::exempt_ptr< RunPrincipal const >) override
Long64_t EntryNumber
Definition: Inputfwd.h:41
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
fhicl::Atom< std::string > module_type
Definition: RootInput.h:32
virtual std::unique_ptr< RunPrincipal > readRun() override
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
virtual std::unique_ptr< RangeSetHandler > subRunRangeSetHandler() override
RootInput(Parameters const &, InputSourceDescription &)
virtual std::unique_ptr< EventPrincipal > readEvent_() override
virtual std::unique_ptr< RunPrincipal > readRun_() override
virtual void closeFile_() override
AdcRoiViewer::Name Name