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 
17 
18 #include <algorithm>
19 
20 namespace edm {
22  boost::shared_ptr<ProductRegistry const> reg,
23  boost::shared_ptr<BranchIDListHelper const> branchIDListHelper,
24  ProcessConfiguration const& pc,
25  HistoryAppender* historyAppender) :
26  Base(reg, reg->productLookup(InEvent), pc, InEvent, historyAppender),
27  aux_(),
28  luminosityBlockPrincipal_(),
29  branchMapperPtr_(),
30  unscheduledHandler_(),
31  moduleLabelsRunning_(),
32  eventSelectionIDs_(new EventSelectionIDVector),
33  branchIDListHelper_(branchIDListHelper),
34  branchListIndexes_(new BranchListIndexes),
35  branchListIndexToProcessIndex_() {}
36 
37  void
40  aux_ = EventAuxiliary();
42  branchMapperPtr_.reset();
43  unscheduledHandler_.reset();
44  moduleLabelsRunning_.clear();
45  eventSelectionIDs_->clear();
46  branchListIndexes_->clear();
48  }
49 
50  void
52  boost::shared_ptr<EventSelectionIDVector> eventSelectionIDs,
53  boost::shared_ptr<BranchListIndexes> branchListIndexes,
54  boost::shared_ptr<BranchMapper> mapper,
57  aux_ = aux;
58  if(eventSelectionIDs) {
60  }
61  aux_.setProcessHistoryID(processHistoryID());
62 
63  branchMapperPtr_ = mapper;
64 
65  if(branchListIndexes) {
67  }
68 
69  if(productRegistry().productProduced(InEvent)) {
70  // Add index into BranchIDListRegistry for products produced this process
71  branchListIndexes_->push_back(productRegistry().producedBranchListIndex());
72  }
73 
74  // Fill in helper map for Branch to ProductID mapping
75  ProcessIndex pix = 0;
76  for(auto const& blindex : *branchListIndexes_) {
77  branchListIndexToProcessIndex_.insert(std::make_pair(blindex, pix));
78  ++pix;
79  }
80 
81  // Fill in the product ID's in the product holders.
82  for(auto const& prod : *this) {
83  if (prod->singleProduct()) {
84  prod->setProvenance(branchMapperPtr(), processHistoryID(), branchIDToProductID(prod->branchDescription().branchID()));
85  }
86  }
87  }
88 
89  void
90  EventPrincipal::setLuminosityBlockPrincipal(boost::shared_ptr<LuminosityBlockPrincipal> const& lbp) {
92  }
93 
94  RunPrincipal const&
97  }
98 
99  void
101  ConstBranchDescription const& bd,
102  WrapperOwningHolder const& edp,
103  ProductProvenance const& productProvenance) {
104 
105  // assert commented out for DaqSource. When DaqSource no longer uses put(), the assert can be restored.
106  //assert(produced());
107  if(!edp.isValid()) {
108  throw Exception(errors::InsertFailure, "Null Pointer")
109  << "put: Cannot put because ptr to product is null."
110  << "\n";
111  }
112  branchMapperPtr()->insertIntoSet(productProvenance);
114  assert(phb);
115  checkUniquenessAndType(edp, phb);
116  // ProductHolder assumes ownership
117  phb->putProduct(edp, productProvenance);
118  }
119 
120  void
122  ConstBranchDescription const& bd,
123  void const* product,
124  ProductProvenance const& productProvenance) {
125 
126  assert(!bd.produced());
127  branchMapperPtr()->insertIntoSet(productProvenance);
129  assert(phb);
130  WrapperOwningHolder const edp(product, phb->productData().getInterface());
131  checkUniquenessAndType(edp, phb);
132  // ProductHolder assumes ownership
133  phb->putProduct(edp, productProvenance);
134  }
135 
136  void
137  EventPrincipal::resolveProduct_(ProductHolderBase const& phb, bool fillOnDemand) const {
138  // Try unscheduled production.
139  if(phb.onDemand()) {
140  if(fillOnDemand) {
142  }
143  return;
144  }
145 
146  if(phb.branchDescription().produced()) return; // nothing to do.
147  if(phb.product()) return; // nothing to do.
148  if(phb.productUnavailable()) return; // nothing to do.
149  if(!reader()) return; // nothing to do.
150 
151  // must attempt to load from persistent store
152  BranchKey const bk = BranchKey(phb.branchDescription());
153  WrapperOwningHolder edp(reader()->getProduct(bk, phb.productData().getInterface(), this));
154 
155  // Now fix up the ProductHolder
156  checkUniquenessAndType(edp, &phb);
157  phb.putProduct(edp);
158  }
159 
160  BranchID
162  if(!pid.isValid()) {
163  throw Exception(errors::ProductNotFound, "InvalidID")
164  << "get by product ID: invalid ProductID supplied\n";
165  }
166  return productIDToBranchID(pid, branchIDListHelper_->branchIDLists(), *branchListIndexes_);
167  }
168 
169  ProductID
171  if(!bid.isValid()) {
172  throw Exception(errors::NotFound, "InvalidID")
173  << "branchIDToProductID: invalid BranchID supplied\n";
174  }
175  typedef BranchIDListHelper::BranchIDToIndexMap BIDToIndexMap;
176  typedef BIDToIndexMap::const_iterator Iter;
177  typedef std::pair<Iter, Iter> IndexRange;
178 
179  IndexRange range = branchIDListHelper_->branchIDToIndexMap().equal_range(bid);
180  for(Iter it = range.first; it != range.second; ++it) {
181  BranchListIndex blix = it->second.first;
182  std::map<BranchListIndex, ProcessIndex>::const_iterator i = branchListIndexToProcessIndex_.find(blix);
183  if(i != branchListIndexToProcessIndex_.end()) {
184  ProductIndex productIndex = it->second.second;
185  ProcessIndex processIndex = i->second;
186  return ProductID(processIndex+1, productIndex+1);
187  }
188  }
189  // cannot throw, because some products may legitimately not have product ID's (e.g. pile-up).
190  return ProductID();
191  }
192 
195  exception<<"get by product ID: The product with given id: "<<pid
196  <<"\ntype: "<<phb->productType()
197  <<"\nproduct instance name: "<<phb->productInstanceName()
198  <<"\nprocess name: "<<phb->processName()
199  <<"\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.";
200  throw exception;
201  }
202 
203  BasicHandle
205  BranchID bid = pidToBid(pid);
206  ConstProductPtr const phb = getProductHolder(bid, true, true);
207  if(phb == nullptr) {
208  boost::shared_ptr<cms::Exception> whyFailed(new Exception(errors::ProductNotFound, "InvalidID"));
209  *whyFailed
210  << "get by product ID: no product with given id: " << pid << "\n";
211  return BasicHandle(whyFailed);
212  }
213 
214  // Was this already deleted?
215  if(phb->productWasDeleted()) {
217  }
218  // Check for case where we tried on demand production and
219  // it failed to produce the object
220  if(phb->onDemand()) {
221  boost::shared_ptr<cms::Exception> whyFailed(new Exception(errors::ProductNotFound, "InvalidID"));
222  *whyFailed
223  << "get by product ID: no product with given id: " << pid << "\n"
224  << "onDemand production failed to produce it.\n";
225  return BasicHandle(whyFailed);
226  }
227  return BasicHandle(phb->productData());
228  }
229 
232  return getByProductID(pid).wrapperHolder();
233  }
234 
235  Provenance
237  BranchID bid = pidToBid(pid);
238  return getProvenance(bid);
239  }
240 
241  void
242  EventPrincipal::setUnscheduledHandler(boost::shared_ptr<UnscheduledHandler> iHandler) {
243  unscheduledHandler_ = iHandler;
244  }
245 
246  boost::shared_ptr<UnscheduledHandler>
248  return unscheduledHandler_;
249  }
250 
253  return *eventSelectionIDs_;
254  }
255 
256  BranchListIndexes const&
258  return *branchListIndexes_;
259  }
260 
261  bool
262  EventPrincipal::unscheduledFill(std::string const& moduleLabel) const {
263 
264  // If it is a module already currently running in unscheduled
265  // mode, then there is a circular dependency related to which
266  // EDProducts modules require and produce. There is no safe way
267  // to recover from this. Here we check for this problem and throw
268  // an exception.
269  std::vector<std::string>::const_iterator i =
270  find_in_all(moduleLabelsRunning_, moduleLabel);
271 
272  if(i != moduleLabelsRunning_.end()) {
274  << "Hit circular dependency while trying to run an unscheduled module.\n"
275  << "Current implementation of unscheduled execution cannot always determine\n"
276  << "the proper order for module execution. It is also possible the modules\n"
277  << "have a built in circular dependence that will not work with any order.\n"
278  << "In the first case, scheduling some or all required modules in paths will help.\n"
279  << "In the second case, the modules themselves will have to be fixed.\n";
280  }
281 
282  moduleLabelsRunning_.push_back(moduleLabel);
283 
284  if(unscheduledHandler_) {
285  unscheduledHandler_->tryToFill(moduleLabel, *const_cast<EventPrincipal*>(this));
286  }
287  moduleLabelsRunning_.pop_back();
288  return true;
289  }
290 }
RunPrincipal const & runPrincipal() const
void setLuminosityBlockPrincipal(boost::shared_ptr< LuminosityBlockPrincipal > const &lbp)
ProductRegistry const & productRegistry() const
Definition: Principal.h:135
void clearPrincipal()
Definition: Principal.cc:280
int i
Definition: DBlmapReader.cc:9
unsigned short BranchListIndex
void fillEventPrincipal(EventAuxiliary const &aux, boost::shared_ptr< EventSelectionIDVector > eventSelectionIDs=boost::shared_ptr< EventSelectionIDVector >(), boost::shared_ptr< BranchListIndexes > branchListIndexes=boost::shared_ptr< BranchListIndexes >(), boost::shared_ptr< BranchMapper > mapper=boost::shared_ptr< BranchMapper >(new BranchMapper), DelayedReader *reader=0)
WrapperInterfaceBase const * getInterface() const
Definition: ProductData.h:25
EventSelectionIDVector const & eventSelectionIDs() const
boost::shared_ptr< LuminosityBlockPrincipal > luminosityBlockPrincipal_
ConstBranchDescription const & branchDescription() const
Definition: ProductHolder.h:93
BasicHandle getByProductID(ProductID const &oid) const
static void throwProductDeletedException(ProductID const &pid, edm::EventPrincipal::ConstProductPtr const phb)
BranchID pidToBid(ProductID const &pid) const
ConstProductPtr getProductHolder(BranchID const &oid, bool resolveProd, bool fillOnDemand) const
Definition: Principal.cc:399
std::map< BranchListIndex, ProcessIndex > branchListIndexToProcessIndex_
void checkUniquenessAndType(WrapperOwningHolder const &prod, ProductHolderBase const *productHolder) const
Definition: Principal.cc:746
void put(ConstBranchDescription const &bd, WrapperOwningHolder const &edp, ProductProvenance const &productProvenance)
EventAuxiliary aux_
bool isValid() const
Definition: BranchID.h:24
BranchListIndexes const & branchListIndexes() const
WrapperHolder getIt(ProductID const &pid) const
ProductID branchIDToProductID(BranchID const &bid) const
RunPrincipal const & runPrincipal() const
virtual bool unscheduledFill(std::string const &moduleLabel) const override
boost::shared_ptr< void const > product() const
Definition: ProductHolder.h:81
std::vector< EventSelectionID > EventSelectionIDVector
boost::shared_ptr< BranchMapper > branchMapperPtr_
std::vector< BranchListIndex > BranchListIndexes
BranchID productIDToBranchID(ProductID const &pid, BranchIDLists const &lists, BranchListIndexes const &indexes)
EventPrincipal(boost::shared_ptr< ProductRegistry const > reg, boost::shared_ptr< BranchIDListHelper const > branchIDListHelper, ProcessConfiguration const &pc, HistoryAppender *historyAppender)
boost::shared_ptr< UnscheduledHandler > unscheduledHandler() const
boost::shared_ptr< BranchMapper > branchMapperPtr() const
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:129
LuminosityBlockPrincipal const & luminosityBlockPrincipal() const
bool onDemand() const
Definition: ProductHolder.h:75
Base::ConstProductPtr ConstProductPtr
BranchID const & branchID() const
T const * getProduct(RefCore const &ref)
Definition: RefCoreGet.h:33
ProductData const & productData() const
Definition: ProductHolder.h:41
boost::shared_ptr< UnscheduledHandler > unscheduledHandler_
std::multimap< BranchID, IndexPair > BranchIDToIndexMap
boost::shared_ptr< EventSelectionIDVector > eventSelectionIDs_
std::string const & resolvedModuleLabel() const
unsigned short ProcessIndex
Definition: ProductID.h:25
DelayedReader * reader() const
Definition: Principal.h:154
Provenance getProvenance(ProductID const &pid) const
ForwardSequence::const_iterator find_in_all(ForwardSequence const &s, Datum const &d)
wrappers for std::find
Definition: Algorithms.h:32
boost::shared_ptr< BranchListIndexes > branchListIndexes_
void putOnRead(ConstBranchDescription const &bd, void const *product, ProductProvenance const &productProvenance)
virtual void resolveProduct_(ProductHolderBase const &phb, bool fillOnDemand) const override
boost::shared_ptr< BranchIDListHelper const > branchIDListHelper_
ProcessHistoryID const & processHistoryID() const
void putProduct(WrapperOwningHolder const &edp, ProductProvenance const &productProvenance)
bool isValid() const
Definition: WrapperHolder.h:27
void fillPrincipal(ProcessHistoryID const &hist, DelayedReader *reader)
Definition: Principal.cc:303
unsigned short ProductIndex
Definition: ProductID.h:26
void setUnscheduledHandler(boost::shared_ptr< UnscheduledHandler > iHandler)
bool isValid() const
Definition: ProductID.h:35
WrapperHolder wrapperHolder() const
Definition: BasicHandle.h:106
EventAuxiliary const & aux() const
ProductHolderBase * getExistingProduct(BranchID const &branchID)
Definition: Principal.cc:353
std::vector< std::string > moduleLabelsRunning_
bool productUnavailable() const
Definition: ProductHolder.h:69