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", 0U)),
52 treeCacheSize_(pset.getUntrackedParameter<unsigned int>(
"cacheSize", roottree::
defaultCacheSize)),
53 enablePrefetching_(
false),
54 enforceGUIDInFileName_(pset.getUntrackedParameter<bool>(
"enforceGUIDInFileName",
false)),
55 maxFileSkips_(pset.getUntrackedParameter<unsigned int>(
"maxFileSkips", std::
min(3_uz,
numberOfFiles()))) {
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,
161 bool completed =
rootFile()->skipEntries(offset);
170 completed =
rootFile()->skipEntries(offset);
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"
256 if (fileNameHash == 0U) {
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());
346 found =
rootFile()->setEntryAtItem(
id.
run(),
id.luminosityBlock(), 0);
357 size_t& fileNameHash,
358 CLHEP::HepRandomEngine* engine,
363 return (this->*
fptr_)(
cache, fileNameHash, engine,
id, recycleFiles);
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");
373 "True: loopEvents() reads events only in same lumi as the specified event.\n"
374 "False: loopEvents() reads events regardless of lumi.");
377 "Skip the first 'skipEvents' events. Used only if 'sequential' is True and 'sameLumiBlock' is False");
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.");
386 "True: file name part is required to be equal to the GUID of the file\n"
387 "False: file name can be anything");
RootFileSharedPtr makeRootFile(std::shared_ptr< InputFile > filePtr) override
bool readOneRandomWithID(EventPrincipal &cache, size_t &fileNameHash, CLHEP::HepRandomEngine *, EventID const *id, bool)
void readOneSpecified(EventPrincipal &cache, size_t &fileNameHash, SecondaryEventIDAndFileInfo const &id)
bool(RootEmbeddedFileSequence::* fptr_)(EventPrincipal &, size_t &, CLHEP::HepRandomEngine *, EventID const *, bool)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
uint16_t *__restrict__ id
unsigned int nStreams() 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)
bool bypassVersionCheck() const
EmbeddedRootSource & input_
static std::string const input
void closeFile_() override
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 & eventID() const
EventID const & min(EventID const &lh, EventID const &rh)
unsigned int maxFileSkips_
int treeMaxVirtualSize() const
bool skipBadFiles() const
int initialNumberOfEventsToSkip_
static void fillDescription(ParameterSetDescription &desc)
static constexpr EntryNumber_t invalidEntry
size_t fileNameHash() const
ProductSelectorRules const & productSelectorRules() 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_
tuple size
Write out results.
RootEmbeddedFileSequence(ParameterSet const &pset, EmbeddedRootSource &input, InputFileCatalog const &catalog)