CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EventPrincipal.cc
Go to the documentation of this file.
2 
19 
20 #include <algorithm>
21 #include <memory>
22 
23 namespace edm {
25  boost::shared_ptr<ProductRegistry const> reg,
26  boost::shared_ptr<BranchIDListHelper const> branchIDListHelper,
27  ProcessConfiguration const& pc,
28  HistoryAppender* historyAppender,
29  unsigned int streamIndex) :
30  Base(reg, reg->productLookup(InEvent), pc, InEvent, historyAppender),
31  aux_(),
32  luminosityBlockPrincipal_(),
33  provRetrieverPtr_(new ProductProvenanceRetriever(streamIndex)),
34  unscheduledHandler_(),
35  moduleLabelsRunning_(),
36  eventSelectionIDs_(),
37  branchIDListHelper_(branchIDListHelper),
38  branchListIndexes_(),
39  branchListIndexToProcessIndex_(),
40  streamID_(streamIndex){}
41 
42  void
45  aux_ = EventAuxiliary();
47  provRetrieverPtr_->reset();
48  unscheduledHandler_.reset();
49  moduleLabelsRunning_.clear();
51  }
52 
53  void
55  ProcessHistoryRegistry const& processHistoryRegistry,
56  EventSelectionIDVector&& eventSelectionIDs,
57  BranchListIndexes&& branchListIndexes,
58  ProductProvenanceRetriever& provRetriever,
61  provRetrieverPtr_->deepSwap(provRetriever);
63  if(branchIDListHelper_->hasProducedProducts()) {
64  // Add index into BranchIDListRegistry for products produced this process
65  branchListIndexes_.push_back(branchIDListHelper_->producedBranchListIndex());
66  }
67  fillEventPrincipal(aux,processHistoryRegistry,reader);
68  }
69 
70  void
72  ProcessHistoryRegistry const& processHistoryRegistry,
73  EventSelectionIDVector&& eventSelectionIDs,
74  BranchListIndexes&& branchListIndexes) {
77  if(branchIDListHelper_->hasProducedProducts()) {
78  // Add index into BranchIDListRegistry for products produced this process
79  branchListIndexes_.push_back(branchIDListHelper_->producedBranchListIndex());
80  }
81  fillEventPrincipal(aux,processHistoryRegistry,nullptr);
82  }
83 
84  void
86  ProcessHistoryRegistry const& processHistoryRegistry,
88  fillPrincipal(aux.processHistoryID(), processHistoryRegistry, reader);
89  aux_ = aux;
91 
92  if(branchListIndexes_.empty() and branchIDListHelper_->hasProducedProducts()) {
93  // Add index into BranchIDListRegistry for products produced this process
94  // if it hasn't already been filled in by the other fillEventPrincipal or by an earlier call to this function
95  branchListIndexes_.push_back(branchIDListHelper_->producedBranchListIndex());
96  }
97 
98  // Fill in helper map for Branch to ProductID mapping
99  ProcessIndex pix = 0;
100  for(auto const& blindex : branchListIndexes_) {
101  branchListIndexToProcessIndex_.insert(std::make_pair(blindex, pix));
102  ++pix;
103  }
104 
105  // Fill in the product ID's in the product holders.
106  for(auto const& prod : *this) {
107  if (prod->singleProduct()) {
108  prod->setProvenance(productProvenanceRetrieverPtr(), processHistory(), branchIDToProductID(prod->branchDescription().branchID()));
109  }
110  }
111  }
112 
113  void
114  EventPrincipal::setLuminosityBlockPrincipal(boost::shared_ptr<LuminosityBlockPrincipal> const& lbp) {
116  }
117 
118  void
120  assert(run == luminosityBlockPrincipal_->run());
121  assert(lumi == luminosityBlockPrincipal_->luminosityBlock());
122  EventNumber_t event = aux_.id().event();
123  aux_.id() = EventID(run, lumi, event);
124  }
125 
126  RunPrincipal const&
129  }
130 
131  void
133  BranchDescription const& bd,
134  WrapperOwningHolder const& edp,
135  ProductProvenance const& productProvenance) {
136 
137  // assert commented out for DaqSource. When DaqSource no longer uses put(), the assert can be restored.
138  //assert(produced());
139  if(!edp.isValid()) {
140  throw Exception(errors::InsertFailure, "Null Pointer")
141  << "put: Cannot put because ptr to product is null."
142  << "\n";
143  }
144  productProvenanceRetrieverPtr()->insertIntoSet(productProvenance);
146  assert(phb);
147  checkUniquenessAndType(edp, phb);
148  // ProductHolder assumes ownership
149  phb->putProduct(edp, productProvenance);
150  }
151 
152  void
154  BranchDescription const& bd,
155  void const* product,
156  ProductProvenance const& productProvenance) {
157 
158  assert(!bd.produced());
159  productProvenanceRetrieverPtr()->insertIntoSet(productProvenance);
161  assert(phb);
162  WrapperOwningHolder const edp(product, phb->productData().getInterface());
163  checkUniquenessAndType(edp, phb);
164  // ProductHolder assumes ownership
165  phb->putProduct(edp, productProvenance);
166  }
167 
168  void
170  if(phb.branchDescription().produced()) return; // nothing to do.
171  if(phb.product()) return; // nothing to do.
172  if(phb.productUnavailable()) return; // nothing to do.
173  if(!reader()) return; // nothing to do.
174 
175  // must attempt to load from persistent store
176  BranchKey const bk = BranchKey(phb.branchDescription());
177  {
178  if(mcc) {
180  }
181  std::shared_ptr<void> guard(nullptr,[this,mcc](const void*){
182  if(mcc) {
184  }
185  });
186 
187  WrapperOwningHolder edp(reader()->getProduct(bk, phb.productData().getInterface(), this));
188 
189  // Now fix up the ProductHolder
190  checkUniquenessAndType(edp, &phb);
191  phb.putProduct(edp);
192  }
193  }
194 
195  BranchID
197  if(!pid.isValid()) {
198  throw Exception(errors::ProductNotFound, "InvalidID")
199  << "get by product ID: invalid ProductID supplied\n";
200  }
201  return productIDToBranchID(pid, branchIDListHelper_->branchIDLists(), branchListIndexes_);
202  }
203 
204  ProductID
206  if(!bid.isValid()) {
207  throw Exception(errors::NotFound, "InvalidID")
208  << "branchIDToProductID: invalid BranchID supplied\n";
209  }
210  typedef BranchIDListHelper::BranchIDToIndexMap BIDToIndexMap;
211  typedef BIDToIndexMap::const_iterator Iter;
212  typedef std::pair<Iter, Iter> IndexRange;
213 
214  IndexRange range = branchIDListHelper_->branchIDToIndexMap().equal_range(bid);
215  for(Iter it = range.first; it != range.second; ++it) {
216  BranchListIndex blix = it->second.first;
217  std::map<BranchListIndex, ProcessIndex>::const_iterator i = branchListIndexToProcessIndex_.find(blix);
218  if(i != branchListIndexToProcessIndex_.end()) {
219  ProductIndex productIndex = it->second.second;
220  ProcessIndex processIndex = i->second;
221  return ProductID(processIndex+1, productIndex+1);
222  }
223  }
224  // cannot throw, because some products may legitimately not have product ID's (e.g. pile-up).
225  return ProductID();
226  }
227 
228  unsigned int
230  return streamID_.value();
231  }
232 
235  exception<<"get by product ID: The product with given id: "<<pid
236  <<"\ntype: "<<phb->productType()
237  <<"\nproduct instance name: "<<phb->productInstanceName()
238  <<"\nprocess name: "<<phb->processName()
239  <<"\nwas already deleted. This is a configuration error. Please change the configuration of the module which caused this exception to state it reads this data.";
240  throw exception;
241  }
242 
243  BasicHandle
245  BranchID bid = pidToBid(pid);
246  ConstProductHolderPtr const phb = getProductHolder(bid);
247  if(phb == nullptr) {
248  return BasicHandle(makeHandleExceptionFactory([pid]()->std::shared_ptr<cms::Exception> {
249  std::shared_ptr<cms::Exception> whyFailed(std::make_shared<Exception>(errors::ProductNotFound, "InvalidID"));
250  *whyFailed
251  << "get by product ID: no product with given id: " << pid << "\n";
252  return whyFailed;
253  }));
254  }
255 
256  // Was this already deleted?
257  if(phb->productWasDeleted()) {
259  }
260  // Check for case where we tried on demand production and
261  // it failed to produce the object
262  if(phb->onDemand()) {
263  return BasicHandle(makeHandleExceptionFactory([pid]()->std::shared_ptr<cms::Exception> {
264  std::shared_ptr<cms::Exception> whyFailed(std::make_shared<Exception>(errors::ProductNotFound, "InvalidID"));
265  *whyFailed
266  << "get by ProductID: could not get product with id: " << pid << "\n"
267  << "Unscheduled execution not allowed to get via ProductID.\n";
268  return whyFailed;
269  }));
270  }
272  phb->resolveProduct(status,false,nullptr);
273 
274  return BasicHandle(phb->productData());
275  }
276 
279  return getByProductID(pid).wrapperHolder();
280  }
281 
282  Provenance
284  BranchID bid = pidToBid(pid);
285  return getProvenance(bid, mcc);
286  }
287 
288  void
289  EventPrincipal::setUnscheduledHandler(boost::shared_ptr<UnscheduledHandler> iHandler) {
290  unscheduledHandler_ = iHandler;
291  }
292 
293  boost::shared_ptr<UnscheduledHandler>
295  return unscheduledHandler_;
296  }
297 
300  return eventSelectionIDs_;
301  }
302 
303  BranchListIndexes const&
305  return branchListIndexes_;
306  }
307 
308  bool
310  ModuleCallingContext const* mcc) const {
311 
312  // If it is a module already currently running in unscheduled
313  // mode, then there is a circular dependency related to which
314  // EDProducts modules require and produce. There is no safe way
315  // to recover from this. Here we check for this problem and throw
316  // an exception.
317  std::vector<std::string>::const_iterator i =
318  find_in_all(moduleLabelsRunning_, moduleLabel);
319 
320  if(i != moduleLabelsRunning_.end()) {
322  << "Hit circular dependency while trying to run an unscheduled module.\n"
323  << "The last module on the stack shown above requested data from the\n"
324  << "module with label: '" << moduleLabel << "'.\n"
325  << "This is illegal because this module is already running (it is in the\n"
326  << "stack shown above, it might or might not be asking for data from itself).\n"
327  << "More information related to resolving circular dependences can be found here:\n"
328  << "https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideUnscheduledExecution#Circular_Dependence_Errors.";
329  }
330 
331  UnscheduledSentry sentry(&moduleLabelsRunning_, moduleLabel);
332 
333  if(unscheduledHandler_) {
334  if(mcc == nullptr) {
336  << "EventPrincipal::unscheduledFill, Attempting to run unscheduled production\n"
337  << "with a null pointer to the ModuleCalling Context. This should never happen.\n"
338  << "Contact a Framework developer";
339  }
341  std::shared_ptr<void> guard(nullptr,[this,mcc](const void*){
343  });
344  unscheduledHandler_->tryToFill(moduleLabel, *const_cast<EventPrincipal*>(this), mcc);
345  }
346  return true;
347  }
348 }
RunPrincipal const & runPrincipal() const
void setLuminosityBlockPrincipal(boost::shared_ptr< LuminosityBlockPrincipal > const &lbp)
EventNumber_t event() const
Definition: EventID.h:44
void clearPrincipal()
Definition: Principal.cc:304
int i
Definition: DBlmapReader.cc:9
unsigned short BranchListIndex
WrapperInterfaceBase const * getInterface() const
Definition: ProductData.h:25
EventSelectionIDVector const & eventSelectionIDs() const
boost::shared_ptr< LuminosityBlockPrincipal > luminosityBlockPrincipal_
ConstProductHolderPtr getProductHolder(BranchID const &oid) const
Definition: Principal.cc:429
StreamContext const * getStreamContext() const
unsigned int EventNumber_t
Definition: EventID.h:30
BasicHandle getByProductID(ProductID const &oid) const
EventSelectionIDVector eventSelectionIDs_
BranchID pidToBid(ProductID const &pid) const
tuple lumi
Definition: fjr2json.py:35
BranchListIndexes branchListIndexes_
Provenance getProvenance(ProductID const &pid, ModuleCallingContext const *mcc) const
std::map< BranchListIndex, ProcessIndex > branchListIndexToProcessIndex_
void checkUniquenessAndType(WrapperOwningHolder const &prod, ProductHolderBase const *productHolder) const
Definition: Principal.cc:792
virtual void readFromSource_(ProductHolderBase const &phb, ModuleCallingContext const *mcc) const override
EventAuxiliary aux_
bool isValid() const
Definition: BranchID.h:24
BranchListIndexes const & branchListIndexes() const
unsigned int LuminosityBlockNumber_t
Definition: EventID.h:31
WrapperHolder getIt(ProductID const &pid) const
ProcessHistory const & processHistory() const
Definition: Principal.h:139
ProductID branchIDToProductID(BranchID const &bid) const
RunPrincipal const & runPrincipal() const
boost::shared_ptr< void const > product() const
Definition: ProductHolder.h:83
std::vector< EventSelectionID > EventSelectionIDVector
virtual bool unscheduledFill(std::string const &moduleLabel, ModuleCallingContext const *mcc) const override
static void throwProductDeletedException(ProductID const &pid, edm::EventPrincipal::ConstProductHolderPtr const phb)
EventPrincipal(boost::shared_ptr< ProductRegistry const > reg, boost::shared_ptr< BranchIDListHelper const > branchIDListHelper, ProcessConfiguration const &pc, HistoryAppender *historyAppender, unsigned int streamIndex=0)
std::vector< BranchListIndex > BranchListIndexes
BranchDescription const & branchDescription() const
Definition: ProductHolder.h:95
BranchID productIDToBranchID(ProductID const &pid, BranchIDLists const &lists, BranchListIndexes const &indexes)
boost::shared_ptr< UnscheduledHandler > unscheduledHandler() const
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:143
LuminosityBlockPrincipal const & luminosityBlockPrincipal() const
std::shared_ptr< HandleExceptionFactory > makeHandleExceptionFactory(T &&iFunctor)
T const * getProduct(RefCore const &ref)
Definition: RefCoreGet.h:33
BranchID const & branchID() const
ProductData const & productData() const
Definition: ProductHolder.h:42
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
boost::shared_ptr< UnscheduledHandler > unscheduledHandler_
std::multimap< BranchID, IndexPair > BranchIDToIndexMap
void fillEventPrincipal(EventAuxiliary const &aux, ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=nullptr)
unsigned short ProcessIndex
Definition: ProductID.h:25
DelayedReader * reader() const
Definition: Principal.h:173
unsigned int value() const
Definition: StreamID.h:46
ForwardSequence::const_iterator find_in_all(ForwardSequence const &s, Datum const &d)
wrappers for std::find
Definition: Algorithms.h:32
virtual unsigned int transitionIndex_() const override
boost::shared_ptr< ProductProvenanceRetriever > productProvenanceRetrieverPtr() const
tuple pid
Definition: sysUtil.py:22
void setProcessHistoryID(ProcessHistoryID const &phid)
boost::shared_ptr< BranchIDListHelper const > branchIDListHelper_
ProcessHistoryID const & processHistoryID() const
EventID const & id() const
void putProduct(WrapperOwningHolder const &edp, ProductProvenance const &productProvenance)
Base::ConstProductHolderPtr ConstProductHolderPtr
bool isValid() const
Definition: WrapperHolder.h:27
unsigned short ProductIndex
Definition: ProductID.h:26
void setUnscheduledHandler(boost::shared_ptr< UnscheduledHandler > iHandler)
void putOnRead(BranchDescription const &bd, void const *product, ProductProvenance const &productProvenance)
unsigned int RunNumber_t
Definition: EventRange.h:32
boost::shared_ptr< ProductProvenanceRetriever > provRetrieverPtr_
signalslot::Signal< void(StreamContext const &, ModuleCallingContext const &)> preModuleDelayedGetSignal_
bool isValid() const
Definition: ProductID.h:35
tuple status
Definition: ntuplemaker.py:245
WrapperHolder wrapperHolder() const
Definition: BasicHandle.h:114
void setRunAndLumiNumber(RunNumber_t run, LuminosityBlockNumber_t lumi)
void fillPrincipal(ProcessHistoryID const &hist, ProcessHistoryRegistry const &phr, DelayedReader *reader)
Definition: Principal.cc:327
EventAuxiliary const & aux() const
void emit(Args &&...args) const
Definition: Signal.h:47
ProductHolderBase * getExistingProduct(BranchID const &branchID)
Definition: Principal.cc:383
std::vector< std::string > moduleLabelsRunning_
void put(BranchDescription const &bd, WrapperOwningHolder const &edp, ProductProvenance const &productProvenance)
signalslot::Signal< void(StreamContext const &, ModuleCallingContext const &)> postModuleDelayedGetSignal_
bool productUnavailable() const
Definition: ProductHolder.h:71