CMS 3D CMS Logo

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>
33  size_t loopOverEvents(EventPrincipal& cache,
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_); }
55  ProductRegistry& productRegistryUpdate() { return *productRegistry_; }
56  ProcessHistoryRegistry const& processHistoryRegistry() const { return *processHistoryRegistry_; }
57  ProcessHistoryRegistry& processHistoryRegistryForUpdate() { return *processHistoryRegistry_; }
58 
59  private:
60  void clearEventPrincipal(EventPrincipal& cache);
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>
85  size_t VectorInputSource::loopOverEvents(EventPrincipal& cache,
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>
112  size_t VectorInputSource::loopSpecified(
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
edm::propagate_const< std::unique_ptr< ProcessHistoryRegistry > > processHistoryRegistry_
void beginJob()
Definition: Breakpoints.cc:14
std::shared_ptr< ProductRegistry const > productRegistry() const
unsigned int consecutiveRejectionsLimit_
void readOneSpecified(EventPrincipal &cache, size_t &fileNameHash, EventID const &event)
#define end
Definition: vmac.h:39
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
std::shared_ptr< ProductRegistry > & productRegistry()
#define begin
Definition: vmac.h:32
HLT enums.
def cache(function)
Definition: utilities.py:3
edm::propagate_const< std::shared_ptr< ProductRegistry > > productRegistry_
long double T
Definition: event.py:1