1 #ifndef art_Framework_IO_Sources_Source_h 2 #define art_Framework_IO_Sources_Source_h 113 #include <type_traits> 117 template <
typename T>
120 template <
typename T>
139 template <
typename T,
typename =
void>
142 template <
typename T>
148 template <
typename T>
154 template <
typename T>
159 return t.hasMoreData();
163 template <
typename T>
174 template <
typename T,
typename =
void>
179 template <
typename T>
184 struct SourceConfig {
199 template <
typename T>
204 template <
typename U = Parameters>
205 explicit Source(std::enable_if_t<std::is_same_v<U, fhicl::ParameterSet>,
209 template <
typename U = Parameters>
211 std::enable_if_t<!std::is_same_v<U, fhicl::ParameterSet>, U>
const&
p,
222 std::unique_ptr<FileBlock>
readFile()
override;
227 std::unique_ptr<RunPrincipal> readRun()
override;
228 std::unique_ptr<SubRunPrincipal> readSubRun(
231 std::unique_ptr<EventPrincipal> readEvent(
234 std::unique_ptr<RangeSetHandler> runRangeSetHandler()
override;
235 std::unique_ptr<RangeSetHandler> subRunRangeSetHandler()
override;
249 void checkForNextFile_();
252 void readNextAndRequireRun_();
255 void readNextAndRefuseEvent_();
258 void throwIfInsane_(
bool result,
265 static void throwDataCorruption_(
const char*
msg);
278 std::unique_ptr<RunPrincipal> newRP_{};
279 std::unique_ptr<SubRunPrincipal> newSRP_{};
280 std::unique_ptr<EventPrincipal> newE_{};
287 bool pendingSubRun_{
false};
288 bool pendingEvent_{
false};
289 bool subRunIsNew_{
false};
291 bool haveSRLimit_{
false};
293 bool haveEventLimit_{
false};
296 template <
typename T>
297 template <
typename U>
305 ,
fh_{
p.template get<std::vector<std::string>>(
"fileNames", {})}
307 int64_t
const maxSubRuns_par =
p.template get<int64_t>(
"maxSubRuns", -1);
308 if (maxSubRuns_par > -1) {
312 int64_t
const maxEvents_par =
p.template get<int64_t>(
"maxEvents", -1);
313 if (maxEvents_par > -1) {
319 template <
typename T>
320 template <
typename U>
322 std::enable_if_t<!std::is_same_v<U, fhicl::ParameterSet>, U>
const&
p,
326 , sourceHelper_{
d.moduleDescription}
328 ,
fh_{
p().sourceConfig().fileNames()}
330 if (int64_t
const maxSubRuns_par =
p().sourceConfig().maxSubRuns();
331 maxSubRuns_par > -1) {
335 if (int64_t
const maxEvents_par =
p().sourceConfig().maxEvents();
336 maxEvents_par > -1) {
342 template <
typename T>
349 template <
typename T>
356 std::ostringstream errMsg;
358 if (!newR && !newSR && !newE) {
360 <<
"readNext returned true but created no new data\n";
364 <<
"readNext returned true but no RunPrincipal has been set, and no " 365 "cached RunPrincipal exists.\n" 366 "This can happen if a new input file has been opened and the " 367 "RunPrincipal has not been appropriately assigned.";
371 <<
"readNext returned true but no SubRunPrincipal has been set, and " 372 "no cached SubRunPrincipal exists.\n" 373 "This can happen if a new input file has been opened and the " 374 "SubRunPrincipal has not been appropriately assigned.";
377 errMsg <<
"readNext returned a new Run which is the old Run for " 379 <<
".\nIf you don't have a new run, don't return one!\n";
382 errMsg <<
"readNext returned a new SubRun which is the old SubRun for " 384 <<
".\nIf you don't have a new subRun, don't return one!\n";
388 if (!errMsg.str().empty())
393 "that was the same as the previous " 397 "that was the same as the previous " 399 if (newR && !newSR && newE)
401 "Event without a SubRun\n");
404 "a SubRun from the wrong Run\n");
413 "readNext returned a Run with an invalid RunID.\n");
420 if (rID != srID.
runID()) {
421 errMsg <<
"readNext returned a SubRun " << srID
422 <<
" which is a mismatch to " << rID <<
"\n";
427 "readNext returned a SubRun with an invalid SubRunID.\n");
431 "readNext returned a SubRun with a non-null embedded Run.\n");
439 errMsg <<
"readNext returned an Event " << eID
440 <<
" which is a mismatch to " << srID <<
"\n";
445 "readNext returned an Event with an invalid EventID.\n");
449 "readNext returned an Event with a non-null embedded SubRun.\n");
453 if (newR || newSR || newE)
455 <<
"readNext returned false but created new data\n";
459 template <
typename T>
463 std::unique_ptr<RunPrincipal> newR{
nullptr};
464 std::unique_ptr<SubRunPrincipal> newSR{
nullptr};
465 std::unique_ptr<EventPrincipal> newE{
nullptr};
487 newSR->setRunPrincipal(rp);
492 newE->setSubRunPrincipal(srp);
506 template <
typename T>
515 generatorHasMoreData;
516 if (generatorHasMoreData(
detail_)) {
527 template <
typename T>
552 <<
newE_->eventID() <<
" that belongs to no SubRun\n";
592 template <
typename T>
604 <<
" where a Run is expected\n";
612 template <
typename T>
620 <<
"' has an Event where a Run or SubRun is expected\n";
627 template <
typename T>
628 std::unique_ptr<RangeSetHandler>
631 return std::make_unique<OpenRangeSetHandler>(
cachedRP_->run());
634 template <
typename T>
635 std::unique_ptr<RangeSetHandler>
638 return std::make_unique<OpenRangeSetHandler>(
cachedSRP_->run());
641 template <
typename T>
642 std::unique_ptr<FileBlock>
649 <<
"detail_::readFile() failed to return a valid FileBlock object\n";
651 return std::unique_ptr<FileBlock>(newF);
654 template <
typename T>
665 template <
typename T>
666 std::unique_ptr<RunPrincipal>
671 <<
"Error in Source<T>\n" 672 <<
"readRun() called when no RunPrincipal exists\n" 673 <<
"Please report this to the art developers\n";
678 template <
typename T>
679 std::unique_ptr<SubRunPrincipal>
684 <<
"Error in Source<T>\n" 685 <<
"readSubRun() called when no SubRunPrincipal exists\n" 686 <<
"Please report this to the art developers\n";
697 template <
typename T>
698 std::unique_ptr<EventPrincipal>
707 template <
typename T>
static fhicl::Name plugin_type()
SubRunID const & subRunID() const
cet::exempt_ptr< RunPrincipal const > runPrincipalExemptPtr() const
EventID const & eventID() const
typename T::Parameters user_config_t
RunID const & runID() const
void msg(const char *fmt,...)
std::unique_ptr< EventPrincipal > readEvent(cet::exempt_ptr< SubRunPrincipal const > srp) override
SubRunPrincipal const * subRunPrincipalPtr() const
ChannelGroupService::Name Name
EventNumber_t remainingEvents_
static void throwDataCorruption_(const char *msg)
std::vector< BranchDescription > ProductDescriptions
enable_if_same_t< FT, decltype(f), R > enable_if_function_exists_t
std::unique_ptr< RangeSetHandler > runRangeSetHandler() override
std::unique_ptr< RangeSetHandler > subRunRangeSetHandler() override
void readFile(string fileName, string &content)
void readNextAndRequireRun_()
void closeFile() override
RunID const & runID() const
cet::exempt_ptr< SubRunPrincipal > cachedSRP_
void registerProducts(ProductDescriptions &productsToRegister, ModuleDescription const &md)
std::unique_ptr< SubRunPrincipal > readSubRun(cet::exempt_ptr< RunPrincipal const > rp) override
std::unique_ptr< SubRunPrincipal > newSRP_
input::ItemType nextItemType() override
SourceHelper sourceHelper_
constexpr exempt_ptr< E > make_exempt_ptr(E *) noexcept
cet::exempt_ptr< RunPrincipal > cachedRP_
SubRunID subRunID() const
ProductTables presentProducts_
IDNumber_t< Level::SubRun > SubRunNumber_t
Source(std::enable_if_t< std::is_same_v< U, fhicl::ParameterSet >, fhicl::ParameterSet > const &p, InputSourceDescription &d)
void invoke(ProductTables const &)
std::unique_ptr< EventPrincipal > newE_
void throwIfInsane_(bool result, RunPrincipal *newR, SubRunPrincipal *newSR, EventPrincipal *newE) const
ProcessConfiguration const & processConfiguration() const
ParameterSetID id() const
static ProductTables invalid()
fhicl::TableFragment< T > fragment_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
void finishProductRegistration_(InputSourceDescription &d)
std::unique_ptr< RunPrincipal > newRP_
std::unique_ptr< FileBlock > readFile() override
fhicl::TableFragment< SourceConfig > sourceConfig
detail::FileNamesHandler< Source_wantFileServices< T >::value > fh_
SubRunNumber_t remainingSubRuns_
IDNumber_t< Level::Event > EventNumber_t
UpdateOutputCallbacks & outputCallbacks_
auto const & operator()() const
void readNextAndRefuseEvent_()
std::unique_ptr< RunPrincipal > readRun() override
std::string currentFileName_
typename detail::maybe_has_Parameters< T >::Parameters Parameters
void closeFile(HDFFileInfoPtr hdfFileInfoPtr)