LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
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 
105  std::unique_ptr<EventPrincipal> readEvent(
106  cet::exempt_ptr<SubRunPrincipal const> srp) override;
107 
109  std::unique_ptr<EventPrincipal> readEvent(EventID const&) override;
110 
112  std::unique_ptr<SubRunPrincipal> readSubRun(
113  cet::exempt_ptr<RunPrincipal const> rp) override;
114 
116  std::unique_ptr<RunPrincipal> readRun() override;
117 
119  std::unique_ptr<FileBlock> readFile() override;
120 
122  void closeFile() override;
123 
126  void skipEvents(int offset) override;
127 
129  void
130  rewind() override
131  {
132  repeat_();
133  doneReadAhead_ = false;
135  rewind_();
136  }
137 
139  void issueReports(EventID const& eventID);
140 
142  void
144  {
147  doneReadAhead_ = false;
148  }
149 
152  int
153  maxEvents() const
154  {
155  return maxEvents_;
156  }
157 
160  int
162  {
163  return remainingEvents_;
164  }
165 
168  int
169  maxSubRuns() const
170  {
171  return maxSubRuns_;
172  }
173 
176  int
178  {
179  return remainingSubRuns_;
180  }
181 
183  void doBeginJob() override;
184 
186  void doEndJob() override;
187 
189  Timestamp const&
190  timestamp() const
191  {
192  return time_;
193  }
194 
198  {
199  return processingMode_;
200  }
201 
202  protected:
204  void
205  setTimestamp(Timestamp const& theTime)
206  {
207  time_ = theTime;
208  }
209 
211  state() const
212  {
213  return state_;
214  }
215 
216  // Inform subclasses that they're going to be told to close the file
217  // for non-exceptional reasons (such as hitting the event limit).
218  virtual void
220  {}
221 
222  cet::exempt_ptr<RunPrincipal>
224  {
225  return cachedRunPrincipal_;
226  }
227  cet::exempt_ptr<SubRunPrincipal>
229  {
230  return cachedSubRunPrincipal_;
231  }
232 
233  std::unique_ptr<RunPrincipal>
235  {
237  return std::move(runPrincipal_);
238  }
239 
240  std::unique_ptr<SubRunPrincipal>
242  {
244  return std::move(subRunPrincipal_);
245  }
246 
247  std::unique_ptr<EventPrincipal>
249  {
250  return std::move(eventPrincipal_);
251  }
252 
253  void setRunPrincipal(std::unique_ptr<RunPrincipal>&& rp);
254  void setSubRunPrincipal(std::unique_ptr<SubRunPrincipal>&& srp);
255  void setEventPrincipal(std::unique_ptr<EventPrincipal>&& ep);
256  void
258  {
259  runPrincipal_.reset();
260  }
261  void
263  {
264  subRunPrincipal_.reset();
265  }
266  void
268  {
269  eventPrincipal_.reset();
270  }
271  void
273  {
274  doneReadAhead_ = false;
276  }
277 
278  private:
279  bool
281  {
282  return remainingEvents_ == 0;
283  }
284  bool
286  {
287  return remainingSubRuns_ == 0;
288  }
289  bool
290  limitReached() const
291  {
293  }
294  virtual input::ItemType getNextItemType() = 0;
296  virtual std::unique_ptr<RunPrincipal> readRun_() = 0;
297  virtual std::unique_ptr<SubRunPrincipal> readSubRun_() = 0;
298  virtual std::unique_ptr<EventPrincipal> readEvent_() = 0;
299  virtual std::unique_ptr<FileBlock> readFile_();
300  virtual void
302  {}
303  virtual void skip(int);
304  virtual void rewind_();
305  virtual void beginJob();
306  virtual void endJob();
307 
308  private:
311  int const reportFrequency_;
312 
313  int remainingEvents_{maxEvents_};
314  int remainingSubRuns_{maxSubRuns_};
315  int readCount_{};
318  bool doneReadAhead_{false};
320  std::unique_ptr<RunPrincipal> runPrincipal_{nullptr};
321  std::unique_ptr<SubRunPrincipal> subRunPrincipal_{nullptr};
322  std::unique_ptr<EventPrincipal> eventPrincipal_{nullptr};
323  cet::exempt_ptr<RunPrincipal> cachedRunPrincipal_{nullptr};
324  cet::exempt_ptr<SubRunPrincipal> cachedSubRunPrincipal_{nullptr};
325  }; // DecrepitRelicInputSourceImplementation
326 
327 } // art
328 
329  // ======================================================================
330 
331 #endif /* art_Framework_Core_DecrepitRelicInputSourceImplementation_h */
332 
333 // Local Variables:
334 // mode: c++
335 // 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
void issueReports(EventID const &eventID)
issue an event report
virtual std::unique_ptr< SubRunPrincipal > readSubRun_()=0
virtual std::unique_ptr< EventPrincipal > readEvent_()=0
std::unique_ptr< SubRunPrincipal > readSubRun(cet::exempt_ptr< RunPrincipal const > rp) override
Read next subRun.
virtual input::ItemType getNextItemType()=0
virtual std::unique_ptr< RunPrincipal > readRun_()=0
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
void repeat_()
Reset the remaining number of events/subRuns to the maximum number.
void doBeginJob() override
Called by framework at beginning of job.
HLT enums.
ProcessingMode processingMode() const
RunsSubRunsAndEvents (default), RunsAndSubRuns, or Runs.
void doEndJob() override
Called by framework at end of job.
std::unique_ptr< FileBlock > readFile() override
Read next file.
std::unique_ptr< RunPrincipal > readRun() override
Read next run.
DecrepitRelicInputSourceImplementation & operator=(DecrepitRelicInputSourceImplementation const &)=delete
DecrepitRelicInputSourceImplementation(DecrepitRelicInputSourceImplementation const &)=delete