17 #include <unordered_set> 26 for (
auto const& element : fileIndex) {
29 result.emplace(element.entry, element.eventID);
38 for (
auto const& mixOp : mixOps) {
39 auto const bt = mixOp->branchType();
42 transMap[mixOp->incomingProductID()] = mixOp->outgoingProductID();
54 auto i = index_.find(entry);
55 if (i ==
cend(index_)) {
57 <<
"MixHelper could not find entry number " << entry
58 <<
" in its own lookup table.\n";
68 initCoverageFraction(
double fraction)
70 if (fraction > (1 + std::numeric_limits<double>::epsilon())) {
72 <<
"coverageFraction > 1: treating as a percentage.\n";
83 std::unique_ptr<MixIOPolicy> ioHandle)
87 ,
filenames_{pset.get<std::vector<std::string>>(
"fileNames", {})}
92 pset.get<
double>(
"coverageFraction", 1.0))}
102 std::unique_ptr<MixIOPolicy> ioHandle)
122 return os <<
"SEQUENTIAL";
124 return os <<
"RANDOM_REPLACE";
126 return os <<
"RANDOM_LIM_REPLACE";
128 return os <<
"RANDOM_NO_REPLACE";
130 return os <<
"UNKNOWN";
141 <<
"Provision of a secondary file name provider is incompatible" 142 <<
" with a\nnon-empty fileNames parameter to the mix filter.\n";
178 seed, kind_of_engine_to_make, engine_label);
186 assert(enSeq.empty());
187 assert(eIDseq.empty());
192 auto const nEventsInFile =
ioHandle_->nEventsInFile();
193 bool const over_threshold =
198 if (over_threshold) {
203 "An error occurred while preparing product-mixing for " 204 "the current event.\n"}
205 <<
"The number of requested secondaries (" << nSecondaries
206 <<
") exceeds the number of events in any\n" 207 <<
"of the files specified for product mixing. For a read mode of '" 209 <<
"the framework does not currently allow product-mixing to span " 210 "multiple secondary\n" 211 <<
"input files for a given event. Please contact artists@fnal.gov " 212 "for more information.\n";
225 enSeq.resize(nSecondaries);
230 std::back_inserter(enSeq), nSecondaries, [
this, nEventsInFile] {
231 return dist_.get()->fireInt(nEventsInFile);
233 std::sort(enSeq.begin(), enSeq.end());
236 std::unordered_set<EntryNumberSequence::value_type>
238 while (entries.size() < nSecondaries) {
240 std::inserter(entries, entries.begin()),
241 nSecondaries - entries.size(),
242 [
this, nEventsInFile] {
return dist_.get()->fireInt(nEventsInFile); });
245 std::sort(
begin(enSeq),
end(enSeq));
251 assert(enSeq.size() == nSecondaries);
255 enSeq.assign(i, i + nSecondaries);
259 <<
"Unrecognized read mode " <<
static_cast<int>(
readMode_)
260 <<
". Contact the art developers.\n";
270 return ioHandle_->generateEventAuxiliarySequence(enSeq);
285 auto const& fileIndex =
ioHandle_->fileIndex();
287 subRunEntries.reserve(eIDseq.size());
288 for (
auto const& eID : eIDseq) {
289 auto const it = fileIndex.findPosition(eID.subRunID(),
true);
291 subRunEntries.emplace_back(it->entry);
294 <<
"- Unable to find an entry in the SubRun tree corresponding to " 296 << eID <<
" in secondary mixing input file " << *
fileIter_ <<
".\n";
301 runEntries.reserve(eIDseq.size());
302 for (
auto const& eID : eIDseq) {
303 auto const it = fileIndex.findPosition(eID.runID(),
true);
305 runEntries.emplace_back(it->entry);
308 <<
"- Unable to find an entry in the Run tree corresponding to " 310 << eID <<
" in secondary mixing input file " << *
fileIter_ <<
".\n";
319 for (
auto const& op :
mixOps_) {
320 switch (op->branchType()) {
322 auto const inProducts =
ioHandle_->readFromFile(*op, eventEntries);
327 auto const inProducts =
ioHandle_->readFromFile(*op, subRunEntries);
329 op->mixAndPut(e, inProducts, nopRemapper);
333 auto const inProducts =
ioHandle_->readFromFile(*op, runEntries);
335 op->mixAndPut(e, inProducts, nopRemapper);
340 <<
"- MixHelper::mixAndPut() attempted to handle unsupported branch " 342 << op->branchType() <<
".\n";
361 static std::regex
const robjs[4]{
362 std::regex(
"^seq", std::regex_constants::icase),
363 std::regex(
"^random(replace)?$", std::regex_constants::icase),
364 std::regex(
"^randomlimreplace$", std::regex_constants::icase),
365 std::regex(
"^randomnoreplace$", std::regex_constants::icase)};
367 for (
auto const&
r : robjs) {
368 if (std::regex_search(mode,
r)) {
375 <<
"Unrecognized value of readMode parameter: \"" << mode
376 <<
"\". Valid values are:\n" 378 <<
" randomReplace (random is accepted for reasons of legacy),\n" 379 <<
" randomLimReplace,\n" 380 <<
" randomNoReplace.\n";
389 if (filename.empty()) {
401 <<
"Wrapping around to initial input file for mixing after " 416 auto transMap = buildProductIDTransMap(
mixOps_);
423 std::random_device rd;
424 std::mt19937
g{rd()};
433 label_t const& engine_label)
const 435 auto const& default_engine_kind =
437 if (kind_of_engine_to_make == default_engine_kind && engine_label.empty()) {
438 mf::LogInfo{
"RANDOM"} <<
"A random number engine has already been created " 439 "since the read mode is " 444 "An error occurred while creating a random number engine " 445 "within a MixFilter detail class.\n"}
446 <<
"A random number engine with an empty label has already been created " 447 "with an engine type of " 448 << default_engine_kind <<
".\n" 449 <<
"If you would like to use a different engine type, please supply a " 450 "different engine label.\n";
458 if (ServiceRegistry::isAvailable<RandomNumberGenerator>()) {
462 <<
"Random event mixing selected but RandomNumberGenerator service " 464 <<
"Ensure service is loaded with: \n" 465 <<
"services.RandomNumberGenerator: {}\n";
471 std::unique_ptr<CLHEP::RandFlat>
474 std::unique_ptr<CLHEP::RandFlat> result{
nullptr};
476 result = std::make_unique<CLHEP::RandFlat>(*engine);
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
base_engine_t & createEngine(seed_t seed)
void registerSecondaryFileNameProvider(ProviderFunc_ func)
std::vector< std::string >::const_iterator fileIter_
std::vector< EventAuxiliary > EventAuxiliarySequence
std::function< size_t()> eventsToSkip_
std::vector< EventID > EventIDSequence
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
static constexpr double g
ProviderFunc_ providerFunc_
Mode initReadMode_(std::string const &mode) const
cet::exempt_ptr< base_engine_t > initEngine_(seed_t seed, Mode readMode)
void mixAndPut(EntryNumberSequence const &enSeq, EventIDSequence const &eIDseq, Event &e)
void setEventsToSkipFunction(std::function< size_t()> eventsToSkip)
bool consistentRequest_(std::string const &kind_of_engine_to_make, label_t const &engine_label) const
std::size_t totalEventsRead_
RNGsnapshot::label_t label_t
std::map< ProductID, ProductID > ProductIDTransMap
static constexpr ScheduleID first()
unsigned nOpensOverThreshold_
EntryNumberSequence shuffledSequence_
std::vector< std::string > const filenames_
fhicl::Atom< double > coverageFraction
base_engine_t & createEngine(seed_t seed)
fhicl::Atom< bool > wrapFiles
std::unique_ptr< CLHEP::RandFlat > dist_
double const coverageFraction_
bool generateEventSequence(size_t nSecondaries, EntryNumberSequence &enSeq, EventIDSequence &eIDseq)
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
fhicl::Sequence< std::string > filenames
ProducesCollector & collector_
bool compactMissingProducts_
void prepareTranslationTables(ProductIDTransMap &transMap)
constexpr exempt_ptr< E > make_exempt_ptr(E *) noexcept
std::unique_ptr< MixIOPolicy > ioHandle_
MixHelper(Config const &config, std::string const &moduleLabel, ProducesCollector &collector, std::unique_ptr< MixIOPolicy > ioHandle)
CLHEP::HepRandomEngine base_engine_t
std::string const moduleLabel_
fhicl::Atom< seed_t > seed
std::vector< FileIndex::EntryNumber_t > EntryNumberSequence
auto transform_all(Container &, OutputIt, UnaryOp)
cet::exempt_ptr< base_engine_t > engine_
std::size_t nEventsReadThisFile_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
std::function< std::string()> ProviderFunc_
std::map< FileIndex::EntryNumber_t, EventID > EventIDIndex
fhicl::Atom< bool > compactMissingProducts
EventAuxiliarySequence generateEventAuxiliarySequence(EntryNumberSequence const &)
EventIDIndex eventIDIndex_
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
fhicl::Atom< std::string > readMode
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
PtrRemapper getRemapper(Event const &e) const
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
std::vector< std::unique_ptr< MixOpBase >> MixOpList
std::unique_ptr< CLHEP::RandFlat > initDist_(cet::exempt_ptr< base_engine_t > engine) const
void function(int client, int *resource, int parblock, int *test, int p)
ProdToProdMapBuilder ptpBuilder_