CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
VectorInputSource.h
Go to the documentation of this file.
1 #ifndef FWCore_Sources_VectorInputSource_h
2 #define FWCore_Sources_VectorInputSource_h
3 
4 /*----------------------------------------------------------------------
5 VectorInputSource: Abstract interface for vector input sources.
6 ----------------------------------------------------------------------*/
7 
13 
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 namespace CLHEP {
19  class HepRandomEngine;
20 }
21 
22 namespace edm {
23  class EventPrincipal;
24  struct VectorInputSourceDescription;
25  class EventID;
26  class ParameterSet;
28  public:
30  virtual ~VectorInputSource();
31 
32  template <typename T>
34  size_t& fileNameHash,
35  size_t number,
36  T eventOperator,
37  CLHEP::HepRandomEngine* = nullptr,
38  EventID const* id = nullptr,
39  bool recycleFiles = true);
40 
41  template <typename T, typename Iterator>
42  size_t loopSpecified(
43  EventPrincipal& cache, size_t& fileNameHash, Iterator const& begin, Iterator const& end, T eventOperator);
44 
45  void dropUnwantedBranches(std::vector<std::string> const& wantedBranches);
46  //
48  void doBeginJob();
49 
51  void doEndJob();
52 
53  std::shared_ptr<ProductRegistry const> productRegistry() const { return get_underlying_safe(productRegistry_); }
54  std::shared_ptr<ProductRegistry>& productRegistry() { return get_underlying_safe(productRegistry_); }
58 
59  private:
61 
62  private:
63  virtual bool readOneEvent(
64  EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const* id, bool recycleFiles) = 0;
65  virtual void readOneSpecified(EventPrincipal& cache,
66  size_t& fileNameHash,
68  void readOneSpecified(EventPrincipal& cache, size_t& fileNameHash, EventID const& event) {
69  SecondaryEventIDAndFileInfo info(event, fileNameHash);
70  readOneSpecified(cache, fileNameHash, info);
71  }
72 
73  virtual void dropUnwantedBranches_(std::vector<std::string> const& wantedBranches) = 0;
74  virtual void beginJob() = 0;
75  virtual void endJob() = 0;
76 
77  void throwIfOverLimit(unsigned int consecutiveRejections) const;
78 
82  };
83 
84  template <typename T>
86  size_t& fileNameHash,
87  size_t number,
88  T eventOperator,
89  CLHEP::HepRandomEngine* engine,
90  EventID const* id,
91  bool recycleFiles) {
92  size_t i = 0U;
93  unsigned int consecutiveRejections = 0U;
94  while (i < number) {
95  clearEventPrincipal(cache);
96  bool found = readOneEvent(cache, fileNameHash, engine, id, recycleFiles);
97  if (!found)
98  break;
99  bool used = eventOperator(cache, fileNameHash);
100  if (used) {
101  ++i;
102  consecutiveRejections = 0U;
103  } else if (consecutiveRejectionsLimit_ > 0) {
104  ++consecutiveRejections;
105  throwIfOverLimit(consecutiveRejections);
106  }
107  }
108  return i;
109  }
110 
111  template <typename T, typename Iterator>
113  EventPrincipal& cache, size_t& fileNameHash, Iterator const& begin, Iterator const& end, T eventOperator) {
114  size_t i = 0U;
115  for (Iterator iter = begin; iter != end; ++iter) {
116  clearEventPrincipal(cache);
117  readOneSpecified(cache, fileNameHash, *iter);
118  eventOperator(cache, fileNameHash);
119  ++i;
120  }
121  return i;
122  }
123 } // namespace edm
124 #endif
ProductRegistry & productRegistryUpdate()
static const TGPicture * info(bool iBackgroundIsBlack)
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
ProcessHistoryRegistry const & processHistoryRegistry() const
void dropUnwantedBranches(std::vector< std::string > const &wantedBranches)
void clearEventPrincipal(EventPrincipal &cache)
VectorInputSource(ParameterSet const &pset, VectorInputSourceDescription const &desc)
void doEndJob()
Called at end of job.
constexpr std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
edm::propagate_const< std::unique_ptr< ProcessHistoryRegistry > > processHistoryRegistry_
virtual bool readOneEvent(EventPrincipal &cache, size_t &fileNameHash, CLHEP::HepRandomEngine *, EventID const *id, bool recycleFiles)=0
std::shared_ptr< ProductRegistry const > productRegistry() const
size_t loopOverEvents(EventPrincipal &cache, size_t &fileNameHash, size_t number, T eventOperator, CLHEP::HepRandomEngine *=nullptr, EventID const *id=nullptr, bool recycleFiles=true)
unsigned int consecutiveRejectionsLimit_
void readOneSpecified(EventPrincipal &cache, size_t &fileNameHash, EventID const &event)
std::shared_ptr< ProductRegistry > & productRegistry()
size_t loopSpecified(EventPrincipal &cache, size_t &fileNameHash, Iterator const &begin, Iterator const &end, T eventOperator)
void doBeginJob()
Called at beginning of job.
string end
Definition: dataset.py:937
virtual void dropUnwantedBranches_(std::vector< std::string > const &wantedBranches)=0
edm::propagate_const< std::shared_ptr< ProductRegistry > > productRegistry_
long double T
virtual void beginJob()=0
void throwIfOverLimit(unsigned int consecutiveRejections) const
def cache
Definition: utilities.py:3
virtual void endJob()=0
virtual void readOneSpecified(EventPrincipal &cache, size_t &fileNameHash, SecondaryEventIDAndFileInfo const &event)=0