1 #ifndef art_Framework_IO_Sources_Source_h 2 #define art_Framework_IO_Sources_Source_h 100 #include "cetlib/exempt_ptr.h" 101 #include "cetlib/metaprogramming.h" 106 #include <type_traits> 117 using cet::enable_if_function_exists_t;
119 template <
typename T,
typename =
void>
123 template <
typename T>
126 enable_if_function_exists_t<bool (T::*)(), &T::hasMoreData>>
130 template <
typename T>
133 enable_if_function_exists_t<bool (T::*)() const, &T::hasMoreData>>
137 template <
typename T>
142 return t.hasMoreData();
146 template <
typename T>
170 std::unique_ptr<FileBlock> readFile()
override;
171 void closeFile()
override;
174 std::unique_ptr<RunPrincipal> readRun()
override;
175 std::unique_ptr<SubRunPrincipal> readSubRun(
176 cet::exempt_ptr<RunPrincipal const> rp)
override;
177 std::unique_ptr<EventPrincipal> readEvent(
178 cet::exempt_ptr<SubRunPrincipal const> srp)
override;
180 std::unique_ptr<art::RangeSetHandler> runRangeSetHandler()
override;
181 std::unique_ptr<art::RangeSetHandler> subRunRangeSetHandler()
override;
184 cet::exempt_ptr<ActivityRegistry>
act_;
193 std::string currentFileName_{};
195 std::unique_ptr<RunPrincipal> newRP_{
nullptr};
196 std::unique_ptr<SubRunPrincipal> newSRP_{
nullptr};
197 std::unique_ptr<EventPrincipal> newE_{
nullptr};
201 cet::exempt_ptr<RunPrincipal> cachedRP_{
nullptr};
202 cet::exempt_ptr<SubRunPrincipal> cachedSRP_{
nullptr};
204 bool pendingSubRun_{
false};
205 bool pendingEvent_{
false};
207 bool subRunIsNew_{
false};
210 bool haveSRLimit_{
false};
212 bool haveEventLimit_{
false};
226 void checkForNextFile_();
229 void readNextAndRequireRun_();
232 void readNextAndRefuseEvent_();
235 void throwIfInsane_(
bool result,
242 static void throwDataCorruption_(
const char* msg);
248 ,
act_{&
d.activityRegistry}
252 p.get<std::vector<std::string>>(
"fileNames", std::vector<std::string>())}
255 int64_t maxSubRuns_par = p.get<int64_t>(
"maxSubRuns", -1);
256 if (maxSubRuns_par > -1) {
261 int64_t maxEvents_par = p.get<int64_t>(
"maxEvents", -1);
262 if (maxEvents_par > -1) {
288 std::ostringstream errMsg;
290 if (!newR && !newSR && !newE) {
292 <<
"readNext returned true but created no new data\n";
297 <<
"readNext returned true but no RunPrincipal has been set, and no " 298 "cached RunPrincipal exists.\n" 299 "This can happen if a new input file has been opened and the " 300 "RunPrincipal has not been appropriately assigned.";
305 <<
"readNext returned true but no SubRunPrincipal has been set, and no " 306 "cached SubRunPrincipal exists.\n" 307 "This can happen if a new input file has been opened and the " 308 "SubRunPrincipal has not been appropriately assigned.";
312 errMsg <<
"readNext returned a new Run which is the old Run for " 314 <<
".\nIf you don't have a new run, don't return one!\n";
317 errMsg <<
"readNext returned a new SubRun which is the old SubRun for " 319 <<
".\nIf you don't have a new subRun, don't return one!\n";
323 if (!errMsg.str().empty())
328 "that was the same as the previous " 332 "that was the same as the previous " 334 if (newR && !newSR && newE)
336 "Event without a SubRun\n");
339 "a SubRun from the wrong Run\n");
348 "readNext returned a Run with an invalid RunID.\n");
355 if (rID != srID.
runID()) {
356 errMsg <<
"readNext returned a SubRun " << srID
357 <<
" which is a mismatch to " << rID <<
"\n";
362 "readNext returned a SubRun with an invalid SubRunID.\n");
366 "readNext returned a SubRun with a non-null embedded Run.\n");
374 errMsg <<
"readNext returned an Event " << eID
375 <<
" which is a mismatch to " << srID <<
"\n";
380 "readNext returned an Event with an invalid EventID.\n");
384 "readNext returned an Event with a non-null embedded SubRun.\n");
388 if (newR || newSR || newE)
390 <<
"readNext returned false but created new data\n";
398 std::unique_ptr<RunPrincipal> newR{
nullptr};
399 std::unique_ptr<SubRunPrincipal> newSR{
nullptr};
400 std::unique_ptr<EventPrincipal> newE{
nullptr};
423 newSR->setRunPrincipal(rp);
428 newE->setSubRunPrincipal(srp);
429 newE_ = std::move(newE);
451 generatorHasMoreData;
452 if (generatorHasMoreData(
detail_)) {
488 <<
newE_->id() <<
" that belongs to no SubRun\n";
540 <<
" where a Run is expected\n";
556 <<
"' has an Event where a Run or SubRun is expected\n";
564 std::unique_ptr<art::RangeSetHandler>
567 return std::make_unique<OpenRangeSetHandler>(
cachedRP_->run());
571 std::unique_ptr<art::RangeSetHandler>
574 return std::make_unique<OpenRangeSetHandler>(
cachedSRP_->run());
578 std::unique_ptr<art::FileBlock>
585 <<
"detail_::readFile() failed to return a valid FileBlock object\n";
587 return std::unique_ptr<FileBlock>(newF);
602 std::unique_ptr<art::RunPrincipal>
607 <<
"Error in Source<T>\n" 608 <<
"readRun() called when no RunPrincipal exists\n" 609 <<
"Please report this to the art developers\n";
615 std::unique_ptr<art::SubRunPrincipal>
620 <<
"Error in Source<T>\n" 621 <<
"readSubRun() called when no SubRunPrincipal exists\n" 622 <<
"Please report this to the art developers\n";
634 std::unique_ptr<art::EventPrincipal>
640 return std::move(
newE_);
SubRunID const & subRunID() const
void registerProducts(MasterProductRegistry &mpr, ProductDescriptions &productsToRegister, ModuleDescription const &md)
static constexpr ModuleDescriptionID invalidID()
void setPresentProducts(cet::exempt_ptr< ProductTables const > presentProducts)
EventNumber_t remainingEvents_
static void throwDataCorruption_(const char *msg)
std::vector< BranchDescription > ProductDescriptions
cet::exempt_ptr< SubRunPrincipal const > subRunPrincipalExemptPtr() const
void readNextAndRequireRun_()
void closeFile() override
RunID const & runID() const
cet::exempt_ptr< SubRunPrincipal > cachedSRP_
std::unique_ptr< SubRunPrincipal > newSRP_
SourceHelper sourceHelper_
cet::exempt_ptr< ActivityRegistry > act_
cet::exempt_ptr< RunPrincipal > cachedRP_
input::ItemType nextItemType() override
ProductTables presentProducts_
IDNumber_t< Level::SubRun > SubRunNumber_t
std::unique_ptr< FileBlock > readFile() override
std::unique_ptr< SubRunPrincipal > readSubRun(cet::exempt_ptr< RunPrincipal const > rp) override
std::unique_ptr< EventPrincipal > newE_
void throwIfInsane_(bool result, RunPrincipal *newR, SubRunPrincipal *newSR, EventPrincipal *newE) const
ModuleDescriptionID id() const
static ProductTables invalid()
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
void finishProductRegistration_(InputSourceDescription &d)
Source(Source< T > const &)=delete
std::unique_ptr< RunPrincipal > newRP_
std::unique_ptr< RunPrincipal > readRun() override
std::string value(boost::any const &)
std::unique_ptr< art::RangeSetHandler > subRunRangeSetHandler() override
detail::FileNamesHandler< Source_wantFileServices< T >::value > fh_
SubRunNumber_t remainingSubRuns_
cet::exempt_ptr< RunPrincipal const > runPrincipalExemptPtr() const
IDNumber_t< Level::Event > EventNumber_t
EventID const & id() const
void readNextAndRefuseEvent_()
std::string currentFileName_
std::unique_ptr< EventPrincipal > readEvent(cet::exempt_ptr< SubRunPrincipal const > srp) override
std::unique_ptr< art::RangeSetHandler > runRangeSetHandler() override
ProcessConfiguration const & processConfiguration() const