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  ProcessConfiguration const& pc,
24  HistoryAppender* historyAppender) :
25  Base(reg, pc, InEvent, historyAppender),
26  aux_(),
27  luminosityBlockPrincipal_(),
28  branchMapperPtr_(),
29  unscheduledHandler_(),
30  moduleLabelsRunning_(),
31  eventSelectionIDs_(new EventSelectionIDVector),
32  branchListIndexes_(new BranchListIndexes),
33  branchListIndexToProcessIndex_() {}
34 
35  void
38  aux_ = EventAuxiliary();
40  branchMapperPtr_.reset();
41  unscheduledHandler_.reset();
42  moduleLabelsRunning_.clear();
43  eventSelectionIDs_->clear();
44  branchListIndexes_->clear();
46  }
47 
48  void
50  boost::shared_ptr<LuminosityBlockPrincipal> lbp,
51  boost::shared_ptr<EventSelectionIDVector> eventSelectionIDs,
52  boost::shared_ptr<BranchListIndexes> branchListIndexes,
53  boost::shared_ptr<BranchMapper> mapper,
56  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  for(BranchListIndexes::const_iterator
76  it = branchListIndexes_->begin(),
77  itEnd = branchListIndexes_->end();
78  it != itEnd; ++it) {
79  ProcessIndex pix = it - branchListIndexes_->begin();
80  branchListIndexToProcessIndex_.insert(std::make_pair(*it, pix));
81  }
82 
83  // Fill in the product ID's in the groups.
84  for(const_iterator it = this->begin(), itEnd = this->end(); it != itEnd; ++it) {
85  (*it)->setProvenance(branchMapperPtr(), processHistoryID(), branchIDToProductID((*it)->branchDescription().branchID()));
86  }
87  }
88 
89  void
90  EventPrincipal::setLuminosityBlockPrincipal(boost::shared_ptr<LuminosityBlockPrincipal> const& lbp) {
92  }
93 
94  RunPrincipal const&
97  }
98 
99  RunPrincipal &
102  }
103 
104  void
106  ConstBranchDescription const& bd,
107  WrapperOwningHolder const& edp,
108  ProductProvenance const& productProvenance) {
109 
110  // assert commented out for DaqSource. When DaqSource no longer uses put(), the assert can be restored.
111  //assert(produced());
112  if(!edp.isValid()) {
113  throw Exception(errors::InsertFailure, "Null Pointer")
114  << "put: Cannot put because ptr to product is null."
115  << "\n";
116  }
117  branchMapperPtr()->insertIntoSet(productProvenance);
118  Group* g = getExistingGroup(bd.branchID());
119  assert(g);
120  checkUniquenessAndType(edp, g);
121  // Group assumes ownership
122  g->putProduct(edp, productProvenance);
123  }
124 
125  void
127  ConstBranchDescription const& bd,
128  void const* product,
129  ProductProvenance const& productProvenance) {
130 
131  assert(!bd.produced());
132  branchMapperPtr()->insertIntoSet(productProvenance);
133  Group* g = getExistingGroup(bd.branchID());
134  assert(g);
135  WrapperOwningHolder const edp(product, g->productData().getInterface());
136  checkUniquenessAndType(edp, g);
137  // Group assumes ownership
138  g->putProduct(edp, productProvenance);
139  }
140 
141  void
142  EventPrincipal::resolveProduct_(Group const& g, bool fillOnDemand) const {
143  // Try unscheduled production.
144  if(g.onDemand()) {
145  if(fillOnDemand) {
147  }
148  return;
149  }
150 
151  if(g.branchDescription().produced()) return; // nothing to do.
152  if(g.product()) return; // nothing to do.
153  if(g.productUnavailable()) return; // nothing to do.
154  if(!reader()) return; // nothing to do.
155 
156  // must attempt to load from persistent store
157  BranchKey const bk = BranchKey(g.branchDescription());
159 
160  // Now fix up the Group
161  checkUniquenessAndType(edp, &g);
162  g.putProduct(edp);
163  }
164 
165  BranchID
167  if(!pid.isValid()) {
168  throw Exception(errors::ProductNotFound, "InvalidID")
169  << "get by product ID: invalid ProductID supplied\n";
170  }
172  }
173 
174  ProductID
176  if(!bid.isValid()) {
177  throw Exception(errors::NotFound, "InvalidID")
178  << "branchIDToProductID: invalid BranchID supplied\n";
179  }
180  typedef BranchIDListHelper::BranchIDToIndexMap BIDToIndexMap;
181  typedef BIDToIndexMap::const_iterator Iter;
182  typedef std::pair<Iter, Iter> IndexRange;
183 
184  BIDToIndexMap const& branchIDToIndexMap = BranchIDListRegistry::instance()->extra().branchIDToIndexMap();
185  IndexRange range = branchIDToIndexMap.equal_range(bid);
186  for(Iter it = range.first; it != range.second; ++it) {
187  BranchListIndex blix = it->second.first;
188  std::map<BranchListIndex, ProcessIndex>::const_iterator i = branchListIndexToProcessIndex_.find(blix);
189  if(i != branchListIndexToProcessIndex_.end()) {
190  ProductIndex productIndex = it->second.second;
191  ProcessIndex processIndex = i->second;
192  return ProductID(processIndex+1, productIndex+1);
193  }
194  }
195  // cannot throw, because some products may legitimately not have product ID's (e.g. pile-up).
196  return ProductID();
197  }
198 
201  exception<<"get by product ID: The product with given id: "<<pid
202  <<"\ntype: "<<g->productType()
203  <<"\nproduct instance name: "<<g->productInstanceName()
204  <<"\nprocess name: "<<g->processName()
205  <<"\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.";
206  throw exception;
207  }
208 
209  BasicHandle
211  BranchID bid = pidToBid(pid);
212  ConstGroupPtr const g = getGroup(bid, true, true);
213  if(g == 0) {
214  boost::shared_ptr<cms::Exception> whyFailed(new Exception(errors::ProductNotFound, "InvalidID"));
215  *whyFailed
216  << "get by product ID: no product with given id: " << pid << "\n";
217  return BasicHandle(whyFailed);
218  }
219 
220  // Was this already deleted?
221  if(g->productWasDeleted()) {
223  }
224  // Check for case where we tried on demand production and
225  // it failed to produce the object
226  if(g->onDemand()) {
227  boost::shared_ptr<cms::Exception> whyFailed(new Exception(errors::ProductNotFound, "InvalidID"));
228  *whyFailed
229  << "get by product ID: no product with given id: " << pid << "\n"
230  << "onDemand production failed to produce it.\n";
231  return BasicHandle(whyFailed);
232  }
233  return BasicHandle(g->productData());
234  }
235 
238  return getByProductID(pid).wrapperHolder();
239  }
240 
241  Provenance
243  BranchID bid = pidToBid(pid);
244  return getProvenance(bid);
245  }
246 
247  void
248  EventPrincipal::setUnscheduledHandler(boost::shared_ptr<UnscheduledHandler> iHandler) {
249  unscheduledHandler_ = iHandler;
250  }
251 
252  boost::shared_ptr<UnscheduledHandler>
254  return unscheduledHandler_;
255  }
256 
259  return *eventSelectionIDs_;
260  }
261 
262  BranchListIndexes const&
264  return *branchListIndexes_;
265  }
266 
267  bool
268  EventPrincipal::unscheduledFill(std::string const& moduleLabel) const {
269 
270  // If it is a module already currently running in unscheduled
271  // mode, then there is a circular dependency related to which
272  // EDProducts modules require and produce. There is no safe way
273  // to recover from this. Here we check for this problem and throw
274  // an exception.
275  std::vector<std::string>::const_iterator i =
276  find_in_all(moduleLabelsRunning_, moduleLabel);
277 
278  if(i != moduleLabelsRunning_.end()) {
280  << "Hit circular dependency while trying to run an unscheduled module.\n"
281  << "Current implementation of unscheduled execution cannot always determine\n"
282  << "the proper order for module execution. It is also possible the modules\n"
283  << "have a built in circular dependence that will not work with any order.\n"
284  << "In the first case, scheduling some or all required modules in paths will help.\n"
285  << "In the second case, the modules themselves will have to be fixed.\n";
286  }
287 
288  moduleLabelsRunning_.push_back(moduleLabel);
289 
290  if(unscheduledHandler_) {
291  unscheduledHandler_->tryToFill(moduleLabel, *const_cast<EventPrincipal*>(this));
292  }
293  moduleLabelsRunning_.pop_back();
294  return true;
295  }
296 }
RunPrincipal const & runPrincipal() const
Base::ConstGroupPtr ConstGroupPtr
void setLuminosityBlockPrincipal(boost::shared_ptr< LuminosityBlockPrincipal > const &lbp)
ProductRegistry const & productRegistry() const
Definition: Principal.h:132
void clearPrincipal()
Definition: Principal.cc:206
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_
virtual ProductData const & productData() const =0
const_iterator end() const
Definition: Principal.h:141
Group * getExistingGroup(BranchID const &branchID)
Definition: Principal.cc:267
BasicHandle getByProductID(ProductID const &oid) const
BranchID pidToBid(ProductID const &pid) const
ConstGroupPtr getGroup(BranchID const &oid, bool resolveProd, bool fillOnDemand) const
Definition: Principal.cc:313
static void throwProductDeletedException(ProductID const &pid, edm::EventPrincipal::ConstGroupPtr const g)
std::map< BranchListIndex, ProcessIndex > branchListIndexToProcessIndex_
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
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
ProductID branchIDToProductID(BranchID const &bid) const
RunPrincipal const & runPrincipal() const
std::vector< EventSelectionID > EventSelectionIDVector
boost::shared_ptr< BranchMapper > branchMapperPtr_
std::vector< BranchListIndex > BranchListIndexes
virtual void resolveProduct_(Group const &g, bool fillOnDemand) const
BranchID productIDToBranchID(ProductID const &pid, BranchIDLists const &lists, BranchListIndexes const &indexes)
bool onDemand() const
Definition: Group.h:49
boost::shared_ptr< UnscheduledHandler > unscheduledHandler() const
boost::shared_ptr< BranchMapper > branchMapperPtr() const
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:126
LuminosityBlockPrincipal const & luminosityBlockPrincipal() const
static ThreadSafeIndexedRegistry * instance()
BranchID const & branchID() const
T const * getProduct(RefCore const &ref)
Definition: RefCoreGet.h:33
boost::shared_ptr< UnscheduledHandler > unscheduledHandler_
std::multimap< BranchID, IndexPair > BranchIDToIndexMap
boost::shared_ptr< EventSelectionIDVector > eventSelectionIDs_
EventPrincipal(boost::shared_ptr< ProductRegistry const > reg, ProcessConfiguration const &pc, HistoryAppender *historyAppender=0)
void fillEventPrincipal(EventAuxiliary const &aux, boost::shared_ptr< LuminosityBlockPrincipal > lbp, 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)
unsigned short ProcessIndex
Definition: ProductID.h:25
DelayedReader * reader() const
Definition: Principal.h:149
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< void const > product() const
Definition: Group.h:55
boost::shared_ptr< BranchListIndexes > branchListIndexes_
void putOnRead(ConstBranchDescription const &bd, void const *product, ProductProvenance const &productProvenance)
const_iterator begin() const
Definition: Principal.h:140
virtual bool unscheduledFill(std::string const &moduleLabel) const
ProcessHistoryID const & processHistoryID() const
boost::filter_iterator< FilledGroupPtr, GroupCollection::const_iterator > const_iterator
Definition: Principal.h:55
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
bool isValid() const
Definition: WrapperHolder.h:27
void fillPrincipal(ProcessHistoryID const &hist, DelayedReader *reader)
Definition: Principal.cc:229
unsigned short ProductIndex
Definition: ProductID.h:26
void setUnscheduledHandler(boost::shared_ptr< UnscheduledHandler > iHandler)
bool productUnavailable() const
Definition: Group.h:43
bool isValid() const
Definition: ProductID.h:35
WrapperHolder wrapperHolder() const
Definition: BasicHandle.h:106
void putProduct(WrapperOwningHolder const &edp, ProductProvenance const &productProvenance)
Definition: Group.h:107
EventAuxiliary const & aux() const
void checkUniquenessAndType(WrapperOwningHolder const &prod, Group const *group) const
Definition: Principal.cc:744
ConstBranchDescription const & branchDescription() const
Definition: Group.h:69
std::vector< std::string > moduleLabelsRunning_
std::string const & moduleLabel() const