DecrepitRelicInputSourceImplementation.h
Go to the documentation of this file.
1 #ifndef art_Framework_Core_DecrepitRelicInputSourceImplementation_h
2 #define art_Framework_Core_DecrepitRelicInputSourceImplementation_h
3 
4 /*----------------------------------------------------------------------
5 
6 DecrepitRelicInputSourceImplementation: this is the relic we
7 inherited from CMS, which is not an interface. The remaining comments
8 are left over from that.
9 
10 InputSource: Abstract interface for all input sources. Input
11 sources are responsible for creating an EventPrincipal, using data
12 controlled by the source, and external to the EventPrincipal itself.
13 
14 The InputSource is also responsible for dealing with the "process
15 name list" contained within the EventPrincipal. Each InputSource has
16 to know what "process" (HLT, PROD, USER, USER1, etc.) the program is
17 part of. The InputSource is repsonsible for pushing this process name
18 onto the end of the process name list.
19 
20 For now, we specify this process name to the constructor of the
21 InputSource. This should be improved.
22 
23  Some questions about this remain:
24 
25  1. What should happen if we "rerun" a process? i.e., if "USER1" is
26  already last in our input file, and we run again a job which claims
27  to be "USER1", what should happen? For now, we just quietly add
28  this to the history.
29 
30  2. Do we need to detect a problem with a history like:
31  HLT PROD USER1 PROD
32  or is it up to the user not to do something silly? Right now, there
33  is no protection against such sillyness.
34 
35 Some examples of InputSource subclasses may be:
36 
37  1) EmptyEvent: creates EventPrincipals which contain no EDProducts.
38  2) RootInput: creates EventPrincipals which "contain" the data
39  read from a root file. This source should provide for delayed loading
40  of data, thus the quotation marks around contain.
41  3) DAQInputSource: creats EventPrincipals which contain raw data, as
42  delivered by the L1 trigger and event builder.
43 
44 ----------------------------------------------------------------------*/
45 
55 #include "cetlib/exempt_ptr.h"
56 #include "fhiclcpp/types/Atom.h"
58 
59 #include <memory>
60 #include <string>
61 
62 // ----------------------------------------------------------------------
63 
64 namespace art {
65  class ActivityRegistry;
66 
68  public:
73 
74  struct Config {
75 
76  static constexpr char const*
78  {
79  return "RunsSubRunsAndEvents";
80  }
81 
86  false};
88  defaultMode()};
89  };
90 
92  ModuleDescription const&);
93 
94  // Prevent concrete instances of this class even though we don't
95  // have any (other) pure virtual functions.
96  virtual ~DecrepitRelicInputSourceImplementation() noexcept = 0;
97 
98  // Note: this virtual function is implemented here. It is overridden
99  // in RootInput, but may still be called under normal circumstances
100  // by the overriding function.
101  input::ItemType nextItemType() override;
102 
103  /// Read next event
104  /// Indicate inability to get a new event by returning a null unique_ptr.
105  std::unique_ptr<EventPrincipal> readEvent(
107 
108  /// Read next subRun
109  std::unique_ptr<SubRunPrincipal> readSubRun(
111 
112  /// Read next run.
113  std::unique_ptr<RunPrincipal> readRun() override;
114 
115  /// Read next file
116  std::unique_ptr<FileBlock> readFile() override;
117 
118  /// close current file
119  void closeFile() override;
120 
121  /// Skip the number of events specified.
122  /// Offset may be negative.
123  void skipEvents(int offset) override;
124 
125  /// Begin again at the first event
126  void
127  rewind() override
128  {
129  repeat_();
130  doneReadAhead_ = false;
132  rewind_();
133  }
134 
135  /// issue an event report
136  void issueReports(EventID const& eventID);
137 
138  /// Reset the remaining number of events/subRuns to the maximum number.
139  void
141  {
144  doneReadAhead_ = false;
145  }
146 
147  /// Accessor for maximum number of events to be read.
148  /// -1 is used for unlimited.
149  int
150  maxEvents() const
151  {
152  return maxEvents_;
153  }
154 
155  /// Accessor for remaining number of events to be read.
156  /// -1 is used for unlimited.
157  int
159  {
160  return remainingEvents_;
161  }
162 
163  /// Accessor for maximum number of subRuns to be read.
164  /// -1 is used for unlimited.
165  int
166  maxSubRuns() const
167  {
168  return maxSubRuns_;
169  }
170 
171  /// Accessor for remaining number of subRuns to be read.
172  /// -1 is used for unlimited.
173  int
175  {
176  return remainingSubRuns_;
177  }
178 
179  /// Called by framework at beginning of job
180  void doBeginJob() override;
181 
182  /// Called by framework at end of job
183  void doEndJob() override;
184 
185  /// Accessor for the current time, as seen by the input source
186  Timestamp const&
187  timestamp() const
188  {
189  return time_;
190  }
191 
192  /// RunsSubRunsAndEvents (default), RunsAndSubRuns, or Runs.
195  {
196  return processingMode_;
197  }
198 
199  protected:
200  /// To set the current time, as seen by the input source
201  void
202  setTimestamp(Timestamp const& theTime)
203  {
204  time_ = theTime;
205  }
206 
208  state() const
209  {
210  return state_;
211  }
212 
213  // Inform subclasses that they're going to be told to close the file
214  // for non-exceptional reasons (such as hitting the event limit).
215  virtual void
217  {}
218 
221  {
222  return cachedRunPrincipal_;
223  }
226  {
227  return cachedSubRunPrincipal_;
228  }
229 
230  std::unique_ptr<RunPrincipal>
232  {
234  return std::move(runPrincipal_);
235  }
236 
237  std::unique_ptr<SubRunPrincipal>
239  {
241  return std::move(subRunPrincipal_);
242  }
243 
244  std::unique_ptr<EventPrincipal>
246  {
247  return std::move(eventPrincipal_);
248  }
249 
250  void setRunPrincipal(std::unique_ptr<RunPrincipal>&& rp);
251  void setSubRunPrincipal(std::unique_ptr<SubRunPrincipal>&& srp);
252  void setEventPrincipal(std::unique_ptr<EventPrincipal>&& ep);
253  void
255  {
256  runPrincipal_.reset();
257  }
258  void
260  {
261  subRunPrincipal_.reset();
262  }
263  void
265  {
266  eventPrincipal_.reset();
267  }
268  void
270  {
271  doneReadAhead_ = false;
273  }
274 
275  private:
276  bool
278  {
279  return remainingEvents_ == 0;
280  }
281  bool
283  {
284  return remainingSubRuns_ == 0;
285  }
286  bool
287  limitReached() const
288  {
290  }
291  virtual input::ItemType getNextItemType() = 0;
293  virtual std::unique_ptr<RunPrincipal> readRun_() = 0;
294  virtual std::unique_ptr<SubRunPrincipal> readSubRun_() = 0;
295  virtual std::unique_ptr<EventPrincipal> readEvent_() = 0;
296  virtual std::unique_ptr<FileBlock> readFile_();
297  virtual void
299  {}
300  virtual void skip(int);
301  virtual void rewind_();
302  virtual void beginJob();
303  virtual void endJob();
304 
305  private:
308  int const reportFrequency_;
309 
310  int remainingEvents_{maxEvents_};
311  int remainingSubRuns_{maxSubRuns_};
312  int readCount_{};
315  bool doneReadAhead_{false};
317  std::unique_ptr<RunPrincipal> runPrincipal_{nullptr};
318  std::unique_ptr<SubRunPrincipal> subRunPrincipal_{nullptr};
319  std::unique_ptr<EventPrincipal> eventPrincipal_{nullptr};
322  }; // DecrepitRelicInputSourceImplementation
323 
324 } // art
325 
326 // ======================================================================
327 
328 #endif /* art_Framework_Core_DecrepitRelicInputSourceImplementation_h */
329 
330 // Local Variables:
331 // mode: c++
332 // End:
void setEventPrincipal(std::unique_ptr< EventPrincipal > &&ep)
Timestamp const & timestamp() const
Accessor for the current time, as seen by the input source.
std::unique_ptr< EventPrincipal > readEvent(cet::exempt_ptr< SubRunPrincipal const > srp) override
std::unique_ptr< SubRunPrincipal > readSubRun(cet::exempt_ptr< RunPrincipal const > rp) override
Read next subRun.
virtual ~DecrepitRelicInputSourceImplementation() noexcept=0
Int_t eventID
Definition: plot.C:81
void closeFile() override
close current file
void issueReports(EventID const &eventID)
issue an event report
virtual std::unique_ptr< SubRunPrincipal > readSubRun_()=0
virtual std::unique_ptr< EventPrincipal > readEvent_()=0
virtual input::ItemType getNextItemType()=0
input::ItemType nextItemType() override
virtual std::unique_ptr< RunPrincipal > readRun_()=0
std::unique_ptr< RunPrincipal > readRun() override
Read next run.
std::unique_ptr< FileBlock > readFile() override
Read next file.
void setSubRunPrincipal(std::unique_ptr< SubRunPrincipal > &&srp)
void setRunPrincipal(std::unique_ptr< RunPrincipal > &&rp)
void setTimestamp(Timestamp const &theTime)
To set the current time, as seen by the input source.
void rewind() override
Begin again at the first event.
static constexpr Timestamp invalidTimestamp()
Definition: Timestamp.h:83
virtual std::unique_ptr< FileBlock > readFile_()
void repeat_()
Reset the remaining number of events/subRuns to the maximum number.
void doBeginJob() override
Called by framework at beginning of job.
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
ProcessingMode processingMode() const
RunsSubRunsAndEvents (default), RunsAndSubRuns, or Runs.
void doEndJob() override
Called by framework at end of job.
DecrepitRelicInputSourceImplementation & operator=(DecrepitRelicInputSourceImplementation const &)=delete
DecrepitRelicInputSourceImplementation(DecrepitRelicInputSourceImplementation const &)=delete