CMS 3D CMS Logo

DelayedReaderThrowingSource.cc
Go to the documentation of this file.
13 
14 #include "DataFormats/TestObjects/interface/ToyProducts.h"
15 
17 
18 namespace edm {
19  namespace {
20  class ThrowingDelayedReader : public DelayedReader {
21  public:
22  ThrowingDelayedReader(
23  signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* preEventReadSource,
24  signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* postEventReadSource)
25  : preEventReadFromSourceSignal_(preEventReadSource),
26  postEventReadFromSourceSignal_(postEventReadSource),
27  e_(std::make_exception_ptr(cms::Exception("TEST"))) {}
28 
29  signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* preEventReadFromSourceSignal()
30  const final {
31  return preEventReadFromSourceSignal_;
32  }
33  signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* postEventReadFromSourceSignal()
34  const final {
35  return postEventReadFromSourceSignal_;
36  }
37 
38  private:
39  std::shared_ptr<WrapperBase> getProduct_(BranchID const& k, EDProductGetter const* ep) final {
40  try {
41  std::rethrow_exception(e_);
42  } catch (cms::Exception const& iE) {
43  //avoid adding to the context for each call
44  auto copyException = iE;
45  copyException.addContext("called ThrowingDelayedReader");
46  throw copyException;
47  }
48  }
49  void mergeReaders_(DelayedReader*) final{};
50  void reset_() final{};
51 
52  signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* preEventReadFromSourceSignal_ =
53  nullptr;
54  signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* postEventReadFromSourceSignal_ =
55  nullptr;
56  std::exception_ptr e_;
57  };
58  } // namespace
59 
60  class DelayedReaderThrowingSource : public IDGeneratorSourceBase<InputSource> {
61  public:
63  static void fillDescriptions(ConfigurationDescriptions& descriptions);
64 
65  private:
67  void readEvent_(edm::EventPrincipal&) override;
68 
69  std::pair<SharedResourcesAcquirer*, std::recursive_mutex*> resourceSharedWithDelayedReader_() override {
70  return std::make_pair(resourceSharedWithDelayedReaderPtr_.get(), mutexSharedWithDelayedReader_.get());
71  }
72 
73  ThrowingDelayedReader delayedReader_;
75 
76  std::unique_ptr<SharedResourcesAcquirer>
77  resourceSharedWithDelayedReaderPtr_; // We do not use propagate_const because the acquirer is itself mutable.
78  std::shared_ptr<std::recursive_mutex> mutexSharedWithDelayedReader_;
79  };
80 
83  delayedReader_(&preEventReadFromSourceSignal_, &postEventReadFromSourceSignal_) {
85  resourceSharedWithDelayedReaderPtr_ = std::make_unique<SharedResourcesAcquirer>(std::move(resources.first));
87 
89  dummy.registerIt();
90  auto twd = TypeWithDict::byTypeInfo(typeid(edmtest::IntProduct));
91 
92  std::vector<BranchDescription> branches;
93  for (auto const& label : pset.getUntrackedParameter<std::vector<std::string>>("labels")) {
94  branches.push_back(BranchDescription(InEvent,
95  label, //module label
96  "INPUTTEST", //can't be the present process name
97  twd.userClassName(),
98  twd.friendlyClassName(),
99  "", //product instance name
100  "", //module name which isn't set for items not produced
101  dummy.id(),
102  twd,
103  false //not produced
104  ));
105  branches.back().setOnDemand(true); //says we use delayed reader
106  }
108 
110  ph.emplace_back("INPUTTEST", dummy.id(), PROJECT_VERSION, getPassID());
112  historyID_ = ph.id();
113 
114  BranchIDLists bilists(1);
115  for (auto const& branch : branches) {
116  bilists[0].emplace_back(branch.branchID().id());
117  }
118  branchIDListHelper()->updateFromInput(bilists);
119  }
120 
122  return true;
123  }
124 
126  BranchListIndexes indexes(1, static_cast<unsigned short>(0));
127  branchIDListHelper()->fixBranchListIndexes(indexes);
129  }
130 
133  desc.setComment("Throws an exception when the DelayedReader is used.");
135  desc.addUntracked<std::vector<std::string>>("labels", {{"test"}});
136  descriptions.add("source", desc);
137  }
138 } // namespace edm
139 
T const * getProduct_(RefCore const &ref, const EDProductGetter *prodGetter)
Definition: RefCoreGet.h:21
std::string getPassID()
Definition: GetPassID.h:7
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
ProductRegistry & productRegistryUpdate()
Definition: InputSource.h:330
std::unique_ptr< SharedResourcesAcquirer > resourceSharedWithDelayedReaderPtr_
bool registerProcessHistory(ProcessHistory const &processHistory)
std::vector< EventSelectionID > EventSelectionIDVector
DelayedReaderThrowingSource(ParameterSet const &, InputSourceDescription const &)
char const * label
std::vector< BranchListIndex > BranchListIndexes
#define DEFINE_FWK_INPUT_SOURCE(type)
std::shared_ptr< BranchIDListHelper const > branchIDListHelper() const
Accessors for branchIDListHelper.
Definition: InputSource.h:143
static SharedResourcesRegistry * instance()
void doReadEventWithDelayedReader(EventPrincipal &eventPrincipal, ProcessHistoryID const &historyID, EventSelectionIDVector eventSelectionIDs, BranchListIndexes branchListIndexes, DelayedReader *reader)
static void fillDescriptions(ConfigurationDescriptions &descriptions)
unsigned long long TimeValue_t
Definition: Timestamp.h:21
bool setRunAndEventInfo(EventID &id, TimeValue_t &time, edm::EventAuxiliary::ExperimentType &) override
static TypeWithDict byTypeInfo(std::type_info const &ti)
Definition: TypeWithDict.cc:62
Namespace of DDCMS conversion namespace.
ProcessHistoryRegistry const & processHistoryRegistry() const
Accessors for process history registry.
Definition: InputSource.h:139
static void fillDescription(ParameterSetDescription &desc)
std::shared_ptr< std::recursive_mutex > mutexSharedWithDelayedReader_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void addContext(std::string const &context)
Definition: Exception.cc:169
HLT enums.
std::pair< SharedResourcesAcquirer *, std::recursive_mutex * > resourceSharedWithDelayedReader_() override
void updateFromInput(ProductList const &other)
std::pair< SharedResourcesAcquirer, std::shared_ptr< std::recursive_mutex > > createAcquirerForSourceDelayedReader()
void readEvent_(edm::EventPrincipal &) override
def move(src, dest)
Definition: eostools.py:511