Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
art::MixHelper Class Reference

#include <MixHelper.h>

Inheritance diagram for art::MixHelper:
art::detail::EngineCreator

Classes

struct  Config
 

Public Types

enum  Mode {
  Mode::SEQUENTIAL = 0, Mode::RANDOM_REPLACE, Mode::RANDOM_LIM_REPLACE, Mode::RANDOM_NO_REPLACE,
  Mode::UNKNOWN
}
 

Public Member Functions

 MixHelper (Config const &config, std::string const &moduleLabel, ProducesCollector &collector, std::unique_ptr< MixIOPolicy > ioHandle)
 
 MixHelper (fhicl::ParameterSet const &pset, std::string const &moduleLabel, ProducesCollector &collector, std::unique_ptr< MixIOPolicy > ioHandle)
 
Mode readMode () const
 
void registerSecondaryFileNameProvider (ProviderFunc_ func)
 
template<class P >
void produces (std::string const &instanceName={})
 
template<class P , BranchType B>
void produces (std::string const &instanceName={})
 
template<art::BranchType B = art::InEvent, typename PROD , typename OPROD >
void declareMixOp (InputTag const &inputTag, MixFunc< PROD, OPROD > mixFunc, bool outputProduct=true)
 
template<art::BranchType B = art::InEvent, typename PROD , typename OPROD >
void declareMixOp (InputTag const &inputTag, std::string const &outputInstanceLabel, MixFunc< PROD, OPROD > mixFunc, bool outputProduct=true)
 
template<art::BranchType B = art::InEvent, typename PROD , typename OPROD , typename T >
void declareMixOp (InputTag const &inputTag, bool(T::*mixfunc)(std::vector< PROD const * > const &, OPROD &, PtrRemapper const &), T &t, bool outputProduct=true)
 
template<art::BranchType B = art::InEvent, typename PROD , typename OPROD , typename T >
void declareMixOp (InputTag const &inputTag, std::string const &outputInstanceLabel, bool(T::*mixfunc)(std::vector< PROD const * > const &, OPROD &, PtrRemapper const &), T &t, bool outputProduct=true)
 
template<art::BranchType B = art::InEvent, typename PROD , typename OPROD , typename T >
void declareMixOp (InputTag const &inputTag, bool(T::*mixfunc)(std::vector< PROD const * > const &, OPROD &, PtrRemapper const &) const, T const &t, bool outputProduct=true)
 
template<art::BranchType B = art::InEvent, typename PROD , typename OPROD , typename T >
void declareMixOp (InputTag const &inputTag, std::string const &outputInstanceLabel, bool(T::*mixfunc)(std::vector< PROD const * > const &, OPROD &, PtrRemapper const &) const, T const &t, bool outputProduct=true)
 
base_engine_tcreateEngine (seed_t seed)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make, label_t const &engine_label)
 
bool generateEventSequence (size_t nSecondaries, EntryNumberSequence &enSeq, EventIDSequence &eIDseq)
 
EventAuxiliarySequence generateEventAuxiliarySequence (EntryNumberSequence const &)
 
void mixAndPut (EntryNumberSequence const &enSeq, EventIDSequence const &eIDseq, Event &e)
 
void setEventsToSkipFunction (std::function< size_t()> eventsToSkip)
 
template<art::BranchType B, typename PROD , typename OPROD , typename T >
void declareMixOp (InputTag const &inputTag, bool(T::*mixFunc)(std::vector< PROD const * > const &, OPROD &, PtrRemapper const &), T &t, bool outputProduct)
 
template<art::BranchType B, typename PROD , typename OPROD , typename T >
void declareMixOp (InputTag const &inputTag, std::string const &outputInstanceLabel, bool(T::*mixFunc)(std::vector< PROD const * > const &, OPROD &, PtrRemapper const &), T &t, bool outputProduct)
 
template<art::BranchType B, typename PROD , typename OPROD , typename T >
void declareMixOp (InputTag const &inputTag, bool(T::*mixFunc)(std::vector< PROD const * > const &, OPROD &, PtrRemapper const &) const, T const &t, bool outputProduct)
 
template<art::BranchType B, typename PROD , typename OPROD , typename T >
void declareMixOp (InputTag const &inputTag, std::string const &outputInstanceLabel, bool(T::*mixFunc)(std::vector< PROD const * > const &, OPROD &, PtrRemapper const &) const, T const &t, bool outputProduct)
 

Private Types

using ProviderFunc_ = std::function< std::string()>
 
using MixOpList = std::vector< std::unique_ptr< MixOpBase >>
 
- Private Types inherited from art::detail::EngineCreator
using base_engine_t = CLHEP::HepRandomEngine
 
using label_t = RNGsnapshot::label_t
 
using seed_t = long
 
using engine_state_t = RNGsnapshot::engine_state_t
 

Private Member Functions

 MixHelper (MixHelper const &)=delete
 
MixHelperoperator= (MixHelper const &)=delete
 
cet::exempt_ptr< base_engine_tinitEngine_ (seed_t seed, Mode readMode)
 
std::unique_ptr< CLHEP::RandFlat > initDist_ (cet::exempt_ptr< base_engine_t > engine) const
 
bool consistentRequest_ (std::string const &kind_of_engine_to_make, label_t const &engine_label) const
 
Mode initReadMode_ (std::string const &mode) const
 
bool openNextFile_ ()
 
ProdToProdMapBuilder::ProductIDTransMap buildProductIDTransMap_ (MixOpList &mixOps)
 
- Private Member Functions inherited from art::detail::EngineCreator
 EngineCreator (std::string const &label, ScheduleID sid)
 
base_engine_tcreateEngine (seed_t seed)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make, label_t const &engine_label)
 

Private Attributes

ProducesCollectorcollector_
 
std::string const moduleLabel_
 
std::vector< std::string > const filenames_
 
bool compactMissingProducts_
 
ProviderFunc_ providerFunc_ {}
 
MixOpList mixOps_ {}
 
PtrRemapper ptrRemapper_ {}
 
std::vector< std::string >::const_iterator fileIter_
 
Mode const readMode_
 
double const coverageFraction_
 
std::size_t nEventsReadThisFile_ {}
 
std::size_t totalEventsRead_ {}
 
bool const canWrapFiles_
 
unsigned nOpensOverThreshold_ {}
 
ProdToProdMapBuilder ptpBuilder_ {}
 
cet::exempt_ptr< base_engine_tengine_
 
std::unique_ptr< CLHEP::RandFlat > dist_
 
std::function< size_t()> eventsToSkip_ {}
 
EntryNumberSequence shuffledSequence_ {}
 
bool haveSubRunMixOps_ {false}
 
bool haveRunMixOps_ {false}
 
EventIDIndex eventIDIndex_ {}
 
std::unique_ptr< MixIOPolicyioHandle_ {nullptr}
 

Detailed Description

Definition at line 245 of file MixHelper.h.

Member Typedef Documentation

using art::MixHelper::MixOpList = std::vector<std::unique_ptr<MixOpBase>>
private

Definition at line 381 of file MixHelper.h.

Definition at line 246 of file MixHelper.h.

Member Enumeration Documentation

enum art::MixHelper::Mode
strong
Enumerator
SEQUENTIAL 
RANDOM_REPLACE 
RANDOM_LIM_REPLACE 
RANDOM_NO_REPLACE 
UNKNOWN 

Definition at line 249 of file MixHelper.h.

249  {
250  SEQUENTIAL = 0,
251  RANDOM_REPLACE,
252  RANDOM_LIM_REPLACE,
253  RANDOM_NO_REPLACE,
254  UNKNOWN
255  };

Constructor & Destructor Documentation

art::MixHelper::MixHelper ( Config const &  config,
std::string const &  moduleLabel,
ProducesCollector collector,
std::unique_ptr< MixIOPolicy ioHandle 
)
explicit

Definition at line 99 of file MixHelper.cc.

103  : detail::EngineCreator{moduleLabel, art::ScheduleID::first()}
104  , collector_{collector}
105  , moduleLabel_{moduleLabel}
108  , fileIter_{filenames_.begin()}
110  , coverageFraction_{initCoverageFraction(config.coverageFraction())}
114  , ioHandle_{move(ioHandle)}
115 {}
std::vector< std::string >::const_iterator fileIter_
Definition: MixHelper.h:401
Mode initReadMode_(std::string const &mode) const
Definition: MixHelper.cc:357
cet::exempt_ptr< base_engine_t > initEngine_(seed_t seed, Mode readMode)
Definition: MixHelper.cc:454
static constexpr ScheduleID first()
Definition: ScheduleID.h:50
std::vector< std::string > const filenames_
Definition: MixHelper.h:396
fhicl::Atom< double > coverageFraction
Definition: MixHelper.h:263
fhicl::Atom< bool > wrapFiles
Definition: MixHelper.h:265
std::unique_ptr< CLHEP::RandFlat > dist_
Definition: MixHelper.h:410
double const coverageFraction_
Definition: MixHelper.h:403
Mode const readMode_
Definition: MixHelper.h:402
bool const canWrapFiles_
Definition: MixHelper.h:406
fhicl::Sequence< std::string > filenames
Definition: MixHelper.h:258
ProducesCollector & collector_
Definition: MixHelper.h:394
static Config * config
Definition: config.cpp:1054
def move(depos, offset)
Definition: depos.py:107
bool compactMissingProducts_
Definition: MixHelper.h:397
std::unique_ptr< MixIOPolicy > ioHandle_
Definition: MixHelper.h:417
std::string const moduleLabel_
Definition: MixHelper.h:395
fhicl::Atom< seed_t > seed
Definition: MixHelper.h:266
cet::exempt_ptr< base_engine_t > engine_
Definition: MixHelper.h:409
fhicl::Atom< bool > compactMissingProducts
Definition: MixHelper.h:259
fhicl::Atom< std::string > readMode
Definition: MixHelper.h:262
std::unique_ptr< CLHEP::RandFlat > initDist_(cet::exempt_ptr< base_engine_t > engine) const
Definition: MixHelper.cc:472
art::MixHelper::MixHelper ( fhicl::ParameterSet const &  pset,
std::string const &  moduleLabel,
ProducesCollector collector,
std::unique_ptr< MixIOPolicy ioHandle 
)
explicit

Definition at line 80 of file MixHelper.cc.

84  : detail::EngineCreator{moduleLabel, art::ScheduleID::first()}
85  , collector_{collector}
86  , moduleLabel_{moduleLabel}
87  , filenames_{pset.get<std::vector<std::string>>("fileNames", {})}
88  , compactMissingProducts_{pset.get<bool>("compactMissingProducts", false)}
89  , fileIter_{filenames_.begin()}
90  , readMode_{initReadMode_(pset.get<std::string>("readMode", "sequential"))}
91  , coverageFraction_{initCoverageFraction(
92  pset.get<double>("coverageFraction", 1.0))}
93  , canWrapFiles_{pset.get<bool>("wrapFiles", false)}
94  , engine_{initEngine_(pset.get<long>("seed", -1), readMode_)}
96  , ioHandle_{move(ioHandle)}
97 {}
std::vector< std::string >::const_iterator fileIter_
Definition: MixHelper.h:401
Mode initReadMode_(std::string const &mode) const
Definition: MixHelper.cc:357
cet::exempt_ptr< base_engine_t > initEngine_(seed_t seed, Mode readMode)
Definition: MixHelper.cc:454
std::string string
Definition: nybbler.cc:12
static constexpr ScheduleID first()
Definition: ScheduleID.h:50
std::vector< std::string > const filenames_
Definition: MixHelper.h:396
std::unique_ptr< CLHEP::RandFlat > dist_
Definition: MixHelper.h:410
double const coverageFraction_
Definition: MixHelper.h:403
Mode const readMode_
Definition: MixHelper.h:402
bool const canWrapFiles_
Definition: MixHelper.h:406
ProducesCollector & collector_
Definition: MixHelper.h:394
def move(depos, offset)
Definition: depos.py:107
bool compactMissingProducts_
Definition: MixHelper.h:397
std::unique_ptr< MixIOPolicy > ioHandle_
Definition: MixHelper.h:417
std::string const moduleLabel_
Definition: MixHelper.h:395
cet::exempt_ptr< base_engine_t > engine_
Definition: MixHelper.h:409
std::unique_ptr< CLHEP::RandFlat > initDist_(cet::exempt_ptr< base_engine_t > engine) const
Definition: MixHelper.cc:472
art::MixHelper::MixHelper ( MixHelper const &  )
privatedelete

Member Function Documentation

ProdToProdMapBuilder::ProductIDTransMap art::MixHelper::buildProductIDTransMap_ ( MixOpList mixOps)
private
bool art::MixHelper::consistentRequest_ ( std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
) const
private

Definition at line 432 of file MixHelper.cc.

434 {
435  auto const& default_engine_kind =
436  ServiceHandle<RandomNumberGenerator const>()->defaultEngineKind();
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 "
440  << readMode_ << '.';
441  return true;
442  }
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";
451 }
Mode const readMode_
Definition: MixHelper.h:402
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
art::MixHelper::base_engine_t & art::MixHelper::createEngine ( seed_t  seed)

Definition at line 148 of file MixHelper.cc.

149 {
150  if (engine_ &&
152  ServiceHandle<RandomNumberGenerator const>()->defaultEngineKind(),
153  ""s)) {
154  return *engine_;
155  }
157 }
base_engine_t & createEngine(seed_t seed)
bool consistentRequest_(std::string const &kind_of_engine_to_make, label_t const &engine_label) const
Definition: MixHelper.cc:432
cet::exempt_ptr< base_engine_t > engine_
Definition: MixHelper.h:409
static QCString * s
Definition: config.cpp:1042
art::MixHelper::base_engine_t & art::MixHelper::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make 
)

Definition at line 160 of file MixHelper.cc.

162 {
163  if (engine_ && consistentRequest_(kind_of_engine_to_make, ""s)) {
164  return *engine_;
165  }
166  return detail::EngineCreator::createEngine(seed, kind_of_engine_to_make);
167 }
base_engine_t & createEngine(seed_t seed)
bool consistentRequest_(std::string const &kind_of_engine_to_make, label_t const &engine_label) const
Definition: MixHelper.cc:432
cet::exempt_ptr< base_engine_t > engine_
Definition: MixHelper.h:409
static QCString * s
Definition: config.cpp:1042
art::MixHelper::base_engine_t & art::MixHelper::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
)

Definition at line 170 of file MixHelper.cc.

173 {
174  if (engine_ && consistentRequest_(kind_of_engine_to_make, engine_label)) {
175  return *engine_;
176  }
178  seed, kind_of_engine_to_make, engine_label);
179 }
base_engine_t & createEngine(seed_t seed)
bool consistentRequest_(std::string const &kind_of_engine_to_make, label_t const &engine_label) const
Definition: MixHelper.cc:432
cet::exempt_ptr< base_engine_t > engine_
Definition: MixHelper.h:409
template<art::BranchType B, typename PROD , typename OPROD >
void art::MixHelper::declareMixOp ( InputTag const &  inputTag,
MixFunc< PROD, OPROD >  mixFunc,
bool  outputProduct = true 
)
inline

Definition at line 448 of file MixHelper.h.

451 {
452  declareMixOp<B>(inputTag, inputTag.instance(), mixFunc, outputProduct); // 2.
453 }
template<art::BranchType B, typename PROD , typename OPROD >
void art::MixHelper::declareMixOp ( InputTag const &  inputTag,
std::string const &  outputInstanceLabel,
MixFunc< PROD, OPROD >  mixFunc,
bool  outputProduct = true 
)

Definition at line 458 of file MixHelper.h.

462 {
463  if (outputProduct) {
464  produces<OPROD>(outputInstanceLabel);
465  }
466  if (B == art::InSubRun) {
467  haveSubRunMixOps_ = true;
468  } else if (B == art::InRun) {
469  haveRunMixOps_ = true;
470  }
471  mixOps_.emplace_back(new MixOp<PROD, OPROD>(moduleLabel_,
472  inputTag,
473  outputInstanceLabel,
474  mixFunc,
475  outputProduct,
477  B));
478 }
MixOpList mixOps_
Definition: MixHelper.h:399
bool haveSubRunMixOps_
Definition: MixHelper.h:413
bool compactMissingProducts_
Definition: MixHelper.h:397
std::string const moduleLabel_
Definition: MixHelper.h:395
bool haveRunMixOps_
Definition: MixHelper.h:414
template<art::BranchType B = art::InEvent, typename PROD , typename OPROD , typename T >
void art::MixHelper::declareMixOp ( InputTag const &  inputTag,
bool(T::*)(std::vector< PROD const * > const &, OPROD &, PtrRemapper const &)  mixfunc,
T &  t,
bool  outputProduct = true 
)
template<art::BranchType B = art::InEvent, typename PROD , typename OPROD , typename T >
void art::MixHelper::declareMixOp ( InputTag const &  inputTag,
std::string const &  outputInstanceLabel,
bool(T::*)(std::vector< PROD const * > const &, OPROD &, PtrRemapper const &)  mixfunc,
T &  t,
bool  outputProduct = true 
)
template<art::BranchType B = art::InEvent, typename PROD , typename OPROD , typename T >
void art::MixHelper::declareMixOp ( InputTag const &  inputTag,
bool(T::*)(std::vector< PROD const * > const &, OPROD &, PtrRemapper const &) const  mixfunc,
T const &  t,
bool  outputProduct = true 
)
template<art::BranchType B = art::InEvent, typename PROD , typename OPROD , typename T >
void art::MixHelper::declareMixOp ( InputTag const &  inputTag,
std::string const &  outputInstanceLabel,
bool(T::*)(std::vector< PROD const * > const &, OPROD &, PtrRemapper const &) const  mixfunc,
T const &  t,
bool  outputProduct = true 
)
template<art::BranchType B, typename PROD , typename OPROD , typename T >
void art::MixHelper::declareMixOp ( InputTag const &  inputTag,
bool(T::*)(std::vector< PROD const * > const &, OPROD &, PtrRemapper const &)  mixFunc,
T &  t,
bool  outputProduct 
)
inline

Definition at line 483 of file MixHelper.h.

489 {
490  declareMixOp<B>(inputTag,
491  inputTag.instance(),
492  mixFunc,
493  t,
494  outputProduct); // 4.
495 }
template<art::BranchType B, typename PROD , typename OPROD , typename T >
void art::MixHelper::declareMixOp ( InputTag const &  inputTag,
std::string const &  outputInstanceLabel,
bool(T::*)(std::vector< PROD const * > const &, OPROD &, PtrRemapper const &)  mixFunc,
T &  t,
bool  outputProduct 
)

Definition at line 500 of file MixHelper.h.

507 {
508  using std::placeholders::_1;
509  using std::placeholders::_2;
510  using std::placeholders::_3;
511  declareMixOp<B>(
512  inputTag,
513  outputInstanceLabel,
514  static_cast<MixFunc<PROD, OPROD>>(std::bind(mixFunc, &t, _1, _2, _3)),
515  outputProduct); // 2.
516 }
template<art::BranchType B, typename PROD , typename OPROD , typename T >
void art::MixHelper::declareMixOp ( InputTag const &  inputTag,
bool(T::*)(std::vector< PROD const * > const &, OPROD &, PtrRemapper const &) const  mixFunc,
T const &  t,
bool  outputProduct 
)
inline

Definition at line 521 of file MixHelper.h.

527 {
528  declareMixOp<B>(inputTag,
529  inputTag.instance(),
530  mixFunc,
531  t,
532  outputProduct); // 6.
533 }
template<art::BranchType B, typename PROD , typename OPROD , typename T >
void art::MixHelper::declareMixOp ( InputTag const &  inputTag,
std::string const &  outputInstanceLabel,
bool(T::*)(std::vector< PROD const * > const &, OPROD &, PtrRemapper const &) const  mixFunc,
T const &  t,
bool  outputProduct 
)

Definition at line 538 of file MixHelper.h.

545 {
546  using std::placeholders::_1;
547  using std::placeholders::_2;
548  using std::placeholders::_3;
549  declareMixOp<B>(
550  inputTag,
551  outputInstanceLabel,
552  static_cast<MixFunc<PROD, OPROD>>(std::bind(mixFunc, &t, _1, _2, _3)),
553  outputProduct); // 2.
554 }
art::EventAuxiliarySequence art::MixHelper::generateEventAuxiliarySequence ( EntryNumberSequence const &  enSeq)

Definition at line 268 of file MixHelper.cc.

269 {
270  return ioHandle_->generateEventAuxiliarySequence(enSeq);
271 }
std::unique_ptr< MixIOPolicy > ioHandle_
Definition: MixHelper.h:417
bool art::MixHelper::generateEventSequence ( size_t  nSecondaries,
EntryNumberSequence enSeq,
EventIDSequence eIDseq 
)

Definition at line 182 of file MixHelper.cc.

185 {
186  assert(enSeq.empty());
187  assert(eIDseq.empty());
188  if (not ioHandle_->fileOpen() and not openNextFile_()) {
189  return false;
190  }
191 
192  auto const nEventsInFile = ioHandle_->nEventsInFile();
193  bool const over_threshold =
195  ((nEventsReadThisFile_ + nSecondaries) > nEventsInFile) :
196  ((nEventsReadThisFile_ + nSecondaries) >
197  (nEventsInFile * coverageFraction_));
198  if (over_threshold) {
199  if (!providerFunc_) {
201  if (nOpensOverThreshold_ > filenames_.size()) {
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 '"
208  << readMode_ << "',\n"
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";
213  }
214  }
215  if (openNextFile_()) {
216  return generateEventSequence(nSecondaries, enSeq, eIDseq);
217  } else {
218  return false;
219  }
220  }
221 
223  switch (readMode_) {
224  case Mode::SEQUENTIAL:
225  enSeq.resize(nSecondaries);
226  std::iota(begin(enSeq), end(enSeq), nEventsReadThisFile_);
227  break;
229  std::generate_n(
230  std::back_inserter(enSeq), nSecondaries, [this, nEventsInFile] {
231  return dist_.get()->fireInt(nEventsInFile);
232  });
233  std::sort(enSeq.begin(), enSeq.end());
234  break;
236  std::unordered_set<EntryNumberSequence::value_type>
237  entries; // Guaranteed unique.
238  while (entries.size() < nSecondaries) {
239  std::generate_n(
240  std::inserter(entries, entries.begin()),
241  nSecondaries - entries.size(),
242  [this, nEventsInFile] { return dist_.get()->fireInt(nEventsInFile); });
243  }
244  enSeq.assign(cbegin(entries), cend(entries));
245  std::sort(begin(enSeq), end(enSeq));
246  // Since we need to sort at the end anyway, it's unclear whether
247  // unordered_set is faster than set even though inserts are
248  // approximately linear time. Since the complexity of the sort is
249  // NlogN, we'd need a profile run for it all to come out in the
250  // wash.
251  assert(enSeq.size() == nSecondaries); // Should be true by construction.
252  } break;
254  auto i = shuffledSequence_.cbegin() + nEventsReadThisFile_;
255  enSeq.assign(i, i + nSecondaries);
256  } break;
257  default:
259  << "Unrecognized read mode " << static_cast<int>(readMode_)
260  << ". Contact the art developers.\n";
261  }
263  enSeq, back_inserter(eIDseq), EventIDLookup{eventIDIndex_});
264  return true;
265 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
Definition: StdUtils.h:87
ProviderFunc_ providerFunc_
Definition: MixHelper.h:398
unsigned nOpensOverThreshold_
Definition: MixHelper.h:407
EntryNumberSequence shuffledSequence_
Definition: MixHelper.h:412
std::vector< std::string > const filenames_
Definition: MixHelper.h:396
std::unique_ptr< CLHEP::RandFlat > dist_
Definition: MixHelper.h:410
double const coverageFraction_
Definition: MixHelper.h:403
Mode const readMode_
Definition: MixHelper.h:402
bool generateEventSequence(size_t nSecondaries, EntryNumberSequence &enSeq, EventIDSequence &eIDseq)
Definition: MixHelper.cc:182
bool openNextFile_()
Definition: MixHelper.cc:384
std::unique_ptr< MixIOPolicy > ioHandle_
Definition: MixHelper.h:417
auto transform_all(Container &, OutputIt, UnaryOp)
std::size_t nEventsReadThisFile_
Definition: MixHelper.h:404
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
EventIDIndex eventIDIndex_
Definition: MixHelper.h:415
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
Definition: StdUtils.h:82
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
std::unique_ptr< CLHEP::RandFlat > art::MixHelper::initDist_ ( cet::exempt_ptr< base_engine_t engine) const
private

Definition at line 472 of file MixHelper.cc.

473 {
474  std::unique_ptr<CLHEP::RandFlat> result{nullptr};
475  if (engine) {
476  result = std::make_unique<CLHEP::RandFlat>(*engine);
477  }
478  return result;
479 }
static QCString result
cet::exempt_ptr< art::MixHelper::base_engine_t > art::MixHelper::initEngine_ ( seed_t  seed,
Mode  readMode 
)
private

Definition at line 454 of file MixHelper.cc.

455 {
456  using namespace art;
458  if (ServiceRegistry::isAvailable<RandomNumberGenerator>()) {
460  } else {
461  throw Exception{errors::Configuration, "MixHelper"}
462  << "Random event mixing selected but RandomNumberGenerator service "
463  "not loaded.\n"
464  << "Ensure service is loaded with: \n"
465  << "services.RandomNumberGenerator: {}\n";
466  }
467  }
468  return nullptr;
469 }
base_engine_t & createEngine(seed_t seed)
constexpr exempt_ptr< E > make_exempt_ptr(E *) noexcept
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
Mode readMode() const
Definition: MixHelper.h:424
auto art::MixHelper::initReadMode_ ( std::string const &  mode) const
private

Definition at line 357 of file MixHelper.cc.

358 {
359  // These regexes must correspond by index to the valid Mode enumerator
360  // values.
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)};
366  int i{0};
367  for (auto const& r : robjs) {
368  if (std::regex_search(mode, r)) {
369  return Mode(i);
370  } else {
371  ++i;
372  }
373  }
375  << "Unrecognized value of readMode parameter: \"" << mode
376  << "\". Valid values are:\n"
377  << " sequential,\n"
378  << " randomReplace (random is accepted for reasons of legacy),\n"
379  << " randomLimReplace,\n"
380  << " randomNoReplace.\n";
381 }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void art::MixHelper::mixAndPut ( EntryNumberSequence const &  enSeq,
EventIDSequence const &  eIDseq,
Event e 
)

Definition at line 278 of file MixHelper.cc.

281 {
282  // Create required info only if we're likely to need it.
283  EntryNumberSequence subRunEntries;
284  EntryNumberSequence runEntries;
285  auto const& fileIndex = ioHandle_->fileIndex();
286  if (haveSubRunMixOps_) {
287  subRunEntries.reserve(eIDseq.size());
288  for (auto const& eID : eIDseq) {
289  auto const it = fileIndex.findPosition(eID.subRunID(), true);
290  if (it != std::cend(fileIndex)) {
291  subRunEntries.emplace_back(it->entry);
292  } else {
293  throw Exception(errors::NotFound, "NO_SUBRUN")
294  << "- Unable to find an entry in the SubRun tree corresponding to "
295  "event ID "
296  << eID << " in secondary mixing input file " << *fileIter_ << ".\n";
297  }
298  }
299  }
300  if (haveRunMixOps_) {
301  runEntries.reserve(eIDseq.size());
302  for (auto const& eID : eIDseq) {
303  auto const it = fileIndex.findPosition(eID.runID(), true);
304  if (it != std::cend(fileIndex)) {
305  runEntries.emplace_back(it->entry);
306  } else {
307  throw Exception(errors::NotFound, "NO_RUN")
308  << "- Unable to find an entry in the Run tree corresponding to "
309  "event ID "
310  << eID << " in secondary mixing input file " << *fileIter_ << ".\n";
311  }
312  }
313  }
314 
315  // Populate the remapper in case we need to remap any Ptrs.
317 
318  // Do the branch-wise read, mix and put.
319  for (auto const& op : mixOps_) {
320  switch (op->branchType()) {
321  case InEvent: {
322  auto const inProducts = ioHandle_->readFromFile(*op, eventEntries);
323  op->mixAndPut(e, inProducts, ptrRemapper_);
324  break;
325  }
326  case InSubRun: {
327  auto const inProducts = ioHandle_->readFromFile(*op, subRunEntries);
328  // Ptrs not supported for subrun product mixing.
329  op->mixAndPut(e, inProducts, nopRemapper);
330  break;
331  }
332  case InRun: {
333  auto const inProducts = ioHandle_->readFromFile(*op, runEntries);
334  // Ptrs not support for run product mixing.
335  op->mixAndPut(e, inProducts, nopRemapper);
336  break;
337  }
338  default:
339  throw Exception(errors::LogicError, "Unsupported BranchType")
340  << "- MixHelper::mixAndPut() attempted to handle unsupported branch "
341  "type "
342  << op->branchType() << ".\n";
343  }
344  }
345 
346  nEventsReadThisFile_ += eventEntries.size();
347  totalEventsRead_ += eventEntries.size();
348 }
std::vector< std::string >::const_iterator fileIter_
Definition: MixHelper.h:401
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
Definition: StdUtils.h:87
std::size_t totalEventsRead_
Definition: MixHelper.h:405
MixOpList mixOps_
Definition: MixHelper.h:399
bool haveSubRunMixOps_
Definition: MixHelper.h:413
std::unique_ptr< MixIOPolicy > ioHandle_
Definition: MixHelper.h:417
std::vector< FileIndex::EntryNumber_t > EntryNumberSequence
Definition: MixTypes.h:27
PtrRemapper ptrRemapper_
Definition: MixHelper.h:400
std::size_t nEventsReadThisFile_
Definition: MixHelper.h:404
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bool haveRunMixOps_
Definition: MixHelper.h:414
PtrRemapper getRemapper(Event const &e) const
ProdToProdMapBuilder ptpBuilder_
Definition: MixHelper.h:408
bool art::MixHelper::openNextFile_ ( )
private

Definition at line 384 of file MixHelper.cc.

385 {
387  if (providerFunc_) {
388  filename = providerFunc_();
389  if (filename.empty()) {
390  return false;
391  }
392  } else if (filenames_.empty()) {
393  return false;
394  } else {
395  if (ioHandle_->fileOpen()) { // Already seen one file.
396  ++fileIter_;
397  }
398  if (fileIter_ == filenames_.end()) {
399  if (canWrapFiles_) {
400  mf::LogWarning("MixingInputWrap")
401  << "Wrapping around to initial input file for mixing after "
402  << totalEventsRead_ << " secondary events read.";
403  fileIter_ = filenames_.begin();
404  } else {
405  return false;
406  }
407  }
408  filename = *fileIter_;
409  }
411  eventsToSkip_() :
412  0; // Reset for this file.
413  ioHandle_->openAndReadMetaData(filename, mixOps_);
414 
415  eventIDIndex_ = buildEventIDIndex(ioHandle_->fileIndex());
416  auto transMap = buildProductIDTransMap(mixOps_);
418 
420  // Prepare shuffled event sequence.
421  shuffledSequence_.resize(ioHandle_->nEventsInFile());
422  std::iota(shuffledSequence_.begin(), shuffledSequence_.end(), 0);
423  std::random_device rd;
424  std::mt19937 g{rd()};
425  std::shuffle(shuffledSequence_.begin(), shuffledSequence_.end(), g);
426  }
427 
428  return true;
429 }
std::vector< std::string >::const_iterator fileIter_
Definition: MixHelper.h:401
std::function< size_t()> eventsToSkip_
Definition: MixHelper.h:411
static constexpr double g
Definition: Units.h:144
ProviderFunc_ providerFunc_
Definition: MixHelper.h:398
std::size_t totalEventsRead_
Definition: MixHelper.h:405
std::string string
Definition: nybbler.cc:12
MixOpList mixOps_
Definition: MixHelper.h:399
EntryNumberSequence shuffledSequence_
Definition: MixHelper.h:412
std::vector< std::string > const filenames_
Definition: MixHelper.h:396
string filename
Definition: train.py:213
Mode const readMode_
Definition: MixHelper.h:402
bool const canWrapFiles_
Definition: MixHelper.h:406
void prepareTranslationTables(ProductIDTransMap &transMap)
std::unique_ptr< MixIOPolicy > ioHandle_
Definition: MixHelper.h:417
std::size_t nEventsReadThisFile_
Definition: MixHelper.h:404
EventIDIndex eventIDIndex_
Definition: MixHelper.h:415
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
ProdToProdMapBuilder ptpBuilder_
Definition: MixHelper.h:408
MixHelper& art::MixHelper::operator= ( MixHelper const &  )
privatedelete
template<class P >
void art::MixHelper::produces ( std::string const &  instanceName = {})
inline

Definition at line 432 of file MixHelper.h.

433 {
434  collector_.produces<P>(instanceName);
435 }
std::pair< float, std::string > P
void produces(std::string const &instanceName={}, Persistable const persistable=Persistable::Yes)
ProducesCollector & collector_
Definition: MixHelper.h:394
template<class P , art::BranchType B>
void art::MixHelper::produces ( std::string const &  instanceName = {})
inline

Definition at line 440 of file MixHelper.h.

441 {
442  collector_.produces<P, B>(instanceName);
443 }
std::pair< float, std::string > P
void produces(std::string const &instanceName={}, Persistable const persistable=Persistable::Yes)
ProducesCollector & collector_
Definition: MixHelper.h:394
auto art::MixHelper::readMode ( ) const
inline

Definition at line 424 of file MixHelper.h.

425 {
426  return readMode_;
427 }
Mode const readMode_
Definition: MixHelper.h:402
void art::MixHelper::registerSecondaryFileNameProvider ( ProviderFunc_  func)

Definition at line 137 of file MixHelper.cc.

138 {
139  if (!filenames_.empty()) {
141  << "Provision of a secondary file name provider is incompatible"
142  << " with a\nnon-empty fileNames parameter to the mix filter.\n";
143  }
145 }
ProviderFunc_ providerFunc_
Definition: MixHelper.h:398
std::vector< std::string > const filenames_
Definition: MixHelper.h:396
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
def func()
Definition: docstring.py:7
void art::MixHelper::setEventsToSkipFunction ( std::function< size_t()>  eventsToSkip)

Definition at line 351 of file MixHelper.cc.

352 {
353  eventsToSkip_ = eventsToSkip;
354 }
std::function< size_t()> eventsToSkip_
Definition: MixHelper.h:411

Member Data Documentation

bool const art::MixHelper::canWrapFiles_
private

Definition at line 406 of file MixHelper.h.

ProducesCollector& art::MixHelper::collector_
private

Definition at line 394 of file MixHelper.h.

bool art::MixHelper::compactMissingProducts_
private

Definition at line 397 of file MixHelper.h.

double const art::MixHelper::coverageFraction_
private

Definition at line 403 of file MixHelper.h.

std::unique_ptr<CLHEP::RandFlat> art::MixHelper::dist_
private

Definition at line 410 of file MixHelper.h.

cet::exempt_ptr<base_engine_t> art::MixHelper::engine_
private

Definition at line 409 of file MixHelper.h.

EventIDIndex art::MixHelper::eventIDIndex_ {}
private

Definition at line 415 of file MixHelper.h.

std::function<size_t()> art::MixHelper::eventsToSkip_ {}
private

Definition at line 411 of file MixHelper.h.

std::vector<std::string>::const_iterator art::MixHelper::fileIter_
private

Definition at line 401 of file MixHelper.h.

std::vector<std::string> const art::MixHelper::filenames_
private

Definition at line 396 of file MixHelper.h.

bool art::MixHelper::haveRunMixOps_ {false}
private

Definition at line 414 of file MixHelper.h.

bool art::MixHelper::haveSubRunMixOps_ {false}
private

Definition at line 413 of file MixHelper.h.

std::unique_ptr<MixIOPolicy> art::MixHelper::ioHandle_ {nullptr}
private

Definition at line 417 of file MixHelper.h.

MixOpList art::MixHelper::mixOps_ {}
private

Definition at line 399 of file MixHelper.h.

std::string const art::MixHelper::moduleLabel_
private

Definition at line 395 of file MixHelper.h.

std::size_t art::MixHelper::nEventsReadThisFile_ {}
private

Definition at line 404 of file MixHelper.h.

unsigned art::MixHelper::nOpensOverThreshold_ {}
private

Definition at line 407 of file MixHelper.h.

ProviderFunc_ art::MixHelper::providerFunc_ {}
private

Definition at line 398 of file MixHelper.h.

ProdToProdMapBuilder art::MixHelper::ptpBuilder_ {}
private

Definition at line 408 of file MixHelper.h.

PtrRemapper art::MixHelper::ptrRemapper_ {}
private

Definition at line 400 of file MixHelper.h.

Mode const art::MixHelper::readMode_
private

Definition at line 402 of file MixHelper.h.

EntryNumberSequence art::MixHelper::shuffledSequence_ {}
private

Definition at line 412 of file MixHelper.h.

std::size_t art::MixHelper::totalEventsRead_ {}
private

Definition at line 405 of file MixHelper.h.


The documentation for this class was generated from the following files: