20 #include "CLHEP/Random/RandFlat.h" 27 std::atomic<unsigned int> badFilesSkipped_{0};
28 auto operator"" _uz(
unsigned long long i) -> std::size_t {
return std::size_t{
i}; }
39 orderedProcessHistoryIDs_(),
40 sequential_(
pset.getUntrackedParameter<
bool>(
"sequential",
false)),
41 sameLumiBlock_(
pset.getUntrackedParameter<
bool>(
"sameLumiBlock",
false)),
43 eventsRemainingInFile_(0),
51 initialNumberOfEventsToSkip_(
pset.getUntrackedParameter<unsigned
int>(
"skipEvents", 0
U)),
53 enablePrefetching_(
false),
54 enforceGUIDInFileName_(
pset.getUntrackedParameter<
bool>(
"enforceGUIDInFileName",
false)),
58 <<
"RootEmbeddedFileSequence no input files specified for secondary input source.\n";
100 std::ifstream
f(
"/dev/urandom");
102 f.read(reinterpret_cast<char*>(&
seed),
sizeof(
seed));
103 std::default_random_engine dre(
seed);
104 std::uniform_int_distribution<int> distribution(0,
numberOfFiles() - 1);
106 int offset = distribution(dre);
118 <<
" input file retries exhausted.\n";
138 std::shared_ptr<InputFile> filePtr) {
140 return std::make_shared<RootFile>(
fileNames()[0],
152 currentIndexIntoFile,
218 rootFile()->indexIntoFileIter().
lumi() !=
id.luminosityBlock()) {
225 bool found =
rootFile()->setEntryAtNextEventInLumi(
id.
run(),
id.luminosityBlock());
242 size_t& fileNameHash,
248 <<
" do not contain specified event:\n" 249 <<
id <<
" in file id " <<
idx.fileNameHash() <<
"\n";
255 fileNameHash =
idx.fileNameHash();
256 if (fileNameHash == 0
U) {
271 if (newSeqNumber != currentSeqNumber) {
273 currentSeqNumber = newSeqNumber;
280 <<
fileNames()[0] <<
" contains no events.\n";
282 LogWarning(
"RootEmbeddedFileSequence") <<
"RootEmbeddedFileSequence::readOneRandom(): Secondary Input file " 283 <<
fileNames()[0] <<
" contains no events and will be skipped.\n";
289 if (newSeqNumber != currentSeqNumber) {
296 <<
" input file retries exhausted.\n";
314 size_t& fileNameHash,
315 CLHEP::HepRandomEngine* engine,
322 rootFile()->indexIntoFileIter().
lumi() !=
id.luminosityBlock()) {
327 int eventsInLumi = 0;
329 while (
rootFile()->setEntryAtNextEventInLumi(
id.
run(),
id.luminosityBlock()))
333 int eventInLumi = CLHEP::RandFlat::shootInt(engine, eventsInLumi);
334 for (
int i = 0;
i < eventInLumi; ++
i) {
335 bool foundEventInLumi =
rootFile()->setEntryAtNextEventInLumi(
id.
run(),
id.luminosityBlock());
340 bool found =
rootFile()->setEntryAtNextEventInLumi(
id.
run(),
id.luminosityBlock());
357 size_t& fileNameHash,
358 CLHEP::HepRandomEngine* engine,
363 return (this->*
fptr_)(
cache, fileNameHash, engine,
id, recycleFiles);
367 desc.addUntracked<
bool>(
"sequential",
false)
369 "True: loopEvents() reads events sequentially from beginning of first file.\n" 370 "False: loopEvents() first reads events beginning at random event. New files also chosen randomly");
371 desc.addUntracked<
bool>(
"sameLumiBlock",
false)
373 "True: loopEvents() reads events only in same lumi as the specified event.\n" 374 "False: loopEvents() reads events regardless of lumi.");
375 desc.addUntracked<
unsigned int>(
"skipEvents", 0
U)
377 "Skip the first 'skipEvents' events. Used only if 'sequential' is True and 'sameLumiBlock' is False");
378 desc.addUntracked<
unsigned int>(
"maxFileSkips")
380 "How many files to try if 'sequential' is False and 'skipBadFiles' is True.\n" 381 "Defaults to 3 (or # of files if smaller).");
383 ->setComment(
"Size of ROOT TTree prefetch cache. Affects performance.");
384 desc.addUntracked<
bool>(
"enforceGUIDInFileName",
false)
386 "True: file name part is required to be equal to the GUID of the file\n" 387 "False: file name can be anything");
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
RootFileSharedPtr makeRootFile(std::shared_ptr< InputFile > filePtr) override
bool(RootEmbeddedFileSequence::* fptr_)(EventPrincipal &, size_t &, CLHEP::HepRandomEngine *, EventID const *, bool)
bool readOneRandomWithID(EventPrincipal &cache, size_t &fileNameHash, CLHEP::HepRandomEngine *, EventID const *id, bool)
void readOneSpecified(EventPrincipal &cache, size_t &fileNameHash, SecondaryEventIDAndFileInfo const &id)
int treeMaxVirtualSize() const
bool readOneSequentialWithID(EventPrincipal &cache, size_t &fileNameHash, CLHEP::HepRandomEngine *, EventID const *id, bool)
void initFile_(bool skipBadFiles) override
unsigned int const defaultCacheSize
~RootEmbeddedFileSequence() override
bool readOneRandom(EventPrincipal &cache, size_t &fileNameHash, CLHEP::HepRandomEngine *, EventID const *, bool)
EmbeddedRootSource & input_
static std::string const input
void closeFile_() override
ProductSelectorRules const & productSelectorRules() const
bool skipBadFiles() const
bool readOneEvent(EventPrincipal &cache, size_t &fileNameHash, CLHEP::HepRandomEngine *, EventID const *id, bool recycleFiles)
bool readOneSequential(EventPrincipal &cache, size_t &fileNameHash, CLHEP::HepRandomEngine *, EventID const *, bool recycleFiles)
bool enforceGUIDInFileName_
RunHelperBase * runHelper()
EventID const & min(EventID const &lh, EventID const &rh)
unsigned int maxFileSkips_
ProductRegistry & productRegistryUpdate()
unsigned int nStreams() const
int initialNumberOfEventsToSkip_
static void fillDescription(ParameterSetDescription &desc)
static constexpr EntryNumber_t invalidEntry
bool bypassVersionCheck() const
void updateFromInput(ProductList const &other)
std::vector< ProcessHistoryID > orderedProcessHistoryIDs_
void skipEntries(unsigned int offset)
Log< level::Warning, false > LogWarning
int eventsRemainingInFile_
unsigned int treeCacheSize_
RootEmbeddedFileSequence(ParameterSet const &pset, EmbeddedRootSource &input, InputFileCatalog const &catalog)