LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
RootInput_source.cc
Go to the documentation of this file.
2 // vim: set sw=2:
3 
4 #include "TTreeCache.h"
16 
17 #include <cassert>
18 #include <memory>
19 #include <set>
20 
21 using namespace art;
22 
24  : state_(SEQUENTIAL)
25  , lastReadEventID_()
26  , rootFileForLastReadEvent_()
27  , wantedEventID_()
28 {}
29 
30 void
32 {
33  state_ = state;
34 }
35 
36 void
38 {
39  lastReadEventID_ = eid;
40 }
41 
42 void
44 {
45  wantedEventID_ = eid;
46 }
47 
48 void
50  std::shared_ptr<RootInputFile> const& ptr)
51 {
53 }
54 
57  : DecrepitRelicInputSourceImplementation{config().drisi_config,
58  desc.moduleDescription}
59  , catalog_{config().ifc_config}
60  , primaryFileSequence_{std::make_unique<RootInputFileSequence>(
61  config().rifs_config,
62  catalog_,
63  FastCloningInfoProvider(cet::exempt_ptr<RootInput>(this)),
65  desc.productRegistry,
67  , accessState_{}
68 {}
69 
70 void
72 {
73  primaryFileSequence_->endJob();
74 }
75 
76 void
78 {
79  primaryFileSequence_->closeFile_();
80 }
81 
82 void
84 {
85  // Rewind to before the first event that was read.
87  primaryFileSequence_->rewind_();
88 }
89 
92 {
93  return primaryFileSequence_->getNextItemType();
94 }
95 
96 void
98 {
99  primaryFileSequence_->finish();
100 }
101 
104 {
105  switch (accessState_.state()) {
109  return input::IsFile;
113  return input::IsRun;
115  // RunPrincipal has been handed off to the EventProcessor by this point.
116  // Used the cached pointer.
119  return input::IsSubRun;
121  auto const wantedEventID = accessState_.wantedEventID();
122  setEventPrincipal(primaryFileSequence_->readIt(wantedEventID, true));
123  accessState_.setLastReadEventID(wantedEventID);
125  primaryFileSequence_->rootFileForLastReadEvent());
126  return input::IsEvent;
127  }
128  default:
130  << "RootInputSource::nextItemType encountered an "
131  "unknown AccessState.\n";
132  }
133 }
134 
135 std::unique_ptr<FileBlock>
137 {
138  switch (accessState_.state()) {
143  return readFile_();
144  default:
146  << "RootInputSource::readFile encountered an "
147  "unknown or inappropriate AccessState.\n";
148  }
149 }
150 
151 std::unique_ptr<FileBlock>
153 {
154  return primaryFileSequence_->readFile_();
155 }
156 
157 std::unique_ptr<RunPrincipal>
159 {
160  switch (accessState_.state()) {
165  return runPrincipal();
166  default:
168  << "RootInputSource::readRun encountered an "
169  "unknown or inappropriate AccessState.\n";
170  }
171 }
172 
173 std::unique_ptr<RunPrincipal>
175 {
176  return primaryFileSequence_->readRun_();
177 }
178 
179 std::unique_ptr<RangeSetHandler>
181 {
182  return primaryFileSequence_->runRangeSetHandler();
183 }
184 
185 std::unique_ptr<SubRunPrincipal>
186 RootInput::readSubRun(cet::exempt_ptr<RunPrincipal const> rp)
187 {
188  switch (accessState_.state()) {
193  return subRunPrincipal();
194  default:
196  << "RootInputSource::readSubRun encountered an "
197  "unknown or inappropriate AccessState.\n";
198  }
199 }
200 
201 std::unique_ptr<SubRunPrincipal>
203 {
204  return primaryFileSequence_->readSubRun_(runPrincipalExemptPtr());
205 }
206 
207 std::unique_ptr<RangeSetHandler>
209 {
210  return primaryFileSequence_->subRunRangeSetHandler();
211 }
212 
213 std::unique_ptr<EventPrincipal>
214 RootInput::readEvent(cet::exempt_ptr<SubRunPrincipal const> srp)
215 {
216  return readEvent_(srp);
217 }
218 
219 std::unique_ptr<EventPrincipal>
220 RootInput::readEvent_(cet::exempt_ptr<SubRunPrincipal const> srp)
221 {
222  switch (accessState_.state()) {
227  return eventPrincipal();
228  default:
230  << "RootInputSource::readEvent encountered an "
231  "unknown or inappropriate AccessState.\n";
232  }
233 }
234 
235 std::unique_ptr<EventPrincipal>
237 {
238  std::unique_ptr<EventPrincipal> result;
239  if (!result.get()) {
240  result = primaryFileSequence_->readEvent_();
241  }
242  if (result.get()) {
245  primaryFileSequence_->rootFileForLastReadEvent());
246  }
247  return result;
248 }
249 
void setRootFileForLastReadEvent(std::shared_ptr< RootInputFile > const &)
RunID const & runID() const
Definition: EventID.h:93
SubRunID const & subRunID() const
Definition: EventID.h:105
State state() const
Definition: RootInput.h:69
std::shared_ptr< RootInputFile > rootFileForLastReadEvent_
Definition: RootInput.h:101
void setEventPrincipal(std::unique_ptr< EventPrincipal > &&ep)
void rewind_() override
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
std::unique_ptr< FileBlock > readFile_() override
std::unique_ptr< RunPrincipal > readRun_() override
std::unique_ptr< SubRunPrincipal > readSubRun(cet::exempt_ptr< RunPrincipal const > rp) override
Read next subRun.
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
void setSubRunPrincipal(std::unique_ptr< SubRunPrincipal > &&srp)
void setRunPrincipal(std::unique_ptr< RunPrincipal > &&rp)
auto const & processConfiguration() const
Definition: InputSource.h:64
void setLastReadEventID(EventID const &eid)
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
std::unique_ptr< FileBlock > readFile() override
Read next file.
ModuleDescription const & moduleDescription
HLT enums.
ProcessingMode processingMode() const
RunsSubRunsAndEvents (default), RunsAndSubRuns, or Runs.
EventID const & id() const
RootInput(Parameters const &, InputSourceDescription &)
std::unique_ptr< FileBlock > readFile() override
Read next file.
std::unique_ptr< RunPrincipal > readRun() override
Read next run.
#define DEFINE_ART_INPUT_SOURCE(klass)
std::unique_ptr< RunPrincipal > readRun() override
Read next run.
void closeFile_() override
std::unique_ptr< RangeSetHandler > subRunRangeSetHandler() override