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 
15 
16 #include <algorithm>
17 
18 namespace edm {
20  boost::shared_ptr<ProductRegistry const> reg,
21  ProcessConfiguration const& pc) :
22  Base(reg, pc, InEvent),
23  aux_(),
24  luminosityBlockPrincipal_(),
25  unscheduledHandler_(),
26  moduleLabelsRunning_(),
27  eventSelectionIDs_(),
28  branchListIndexes_(),
29  branchListIndexToProcessIndex_() {}
30 
31  void
34  aux_.reset();
36  unscheduledHandler_.reset();
37  moduleLabelsRunning_.clear();
38  eventSelectionIDs_.reset();
39  branchListIndexes_.reset();
41  }
42 
43  void
44  EventPrincipal::fillEventPrincipal(std::auto_ptr<EventAuxiliary> aux,
45  boost::shared_ptr<LuminosityBlockPrincipal> lbp,
46  boost::shared_ptr<EventSelectionIDVector> eventSelectionIDs,
47  boost::shared_ptr<BranchListIndexes> branchListIndexes,
48  boost::shared_ptr<BranchMapper> mapper,
49  boost::shared_ptr<DelayedReader> rtrv) {
50  fillPrincipal(aux->processHistoryID(), mapper, rtrv);
51  aux_.reset(aux.release());
55 
58  aux_->setProcessHistoryID(processHistoryID());
59  }
60 
61  mapper->processHistoryID() = processHistoryID();
63 
64  if(productRegistry().productProduced(InEvent)) {
65  // Add index into BranchIDListRegistry for products produced this process
66  branchListIndexes_->push_back(productRegistry().producedBranchListIndex());
67  }
68 
69  // Fill in helper map for Branch to ProductID mapping
70  for(BranchListIndexes::const_iterator
71  it = branchListIndexes_->begin(),
72  itEnd = branchListIndexes_->end();
73  it != itEnd; ++it) {
74  ProcessIndex pix = it - branchListIndexes_->begin();
75  branchListIndexToProcessIndex_.insert(std::make_pair(*it, pix));
76  }
77  // Fill in the product ID's in the groups.
78  for(const_iterator it = this->begin(), itEnd = this->end(); it != itEnd; ++it) {
79  (*it)->setProvenance(mapper, branchIDToProductID((*it)->branchDescription().branchID()));
80  }
81  }
82 
83  RunPrincipal const&
86  }
87 
88  RunPrincipal &
91  }
92 
93  void
95  ConstBranchDescription const& bd,
96  std::auto_ptr<EDProduct> edp,
97  std::auto_ptr<ProductProvenance> productProvenance) {
98 
99  assert(bd.produced());
100  if(edp.get() == 0) {
101  throw Exception(errors::InsertFailure, "Null Pointer")
102  << "put: Cannot put because auto_ptr to product is null."
103  << "\n";
104  }
105  branchMapperPtr()->insert(*productProvenance);
106  Group *g = getExistingGroup(bd.branchID());
107  assert(g);
108  checkUniquenessAndType(edp, g);
109  // Group assumes ownership
110  g->putProduct(edp, productProvenance);
111  }
112 
113  void
115  ConstBranchDescription const& bd,
116  std::auto_ptr<EDProduct> edp,
117  std::auto_ptr<ProductProvenance> productProvenance) {
118 
119  assert(!bd.produced());
120  branchMapperPtr()->insert(*productProvenance);
121  Group *g = getExistingGroup(bd.branchID());
122  assert(g);
123  checkUniquenessAndType(edp, g);
124  // Group assumes ownership
125  g->putProduct(edp, productProvenance);
126  }
127 
128  void
129  EventPrincipal::resolveProduct_(Group const& g, bool fillOnDemand) const {
130  // Try unscheduled production.
131  if(g.onDemand()) {
132  if(fillOnDemand) {
134  }
135  return;
136  }
137 
138  if(g.branchDescription().produced()) return; // nothing to do.
139  if(g.product()) return; // nothing to do.
140  if(g.productUnavailable()) return; // nothing to do.
141 
142  // must attempt to load from persistent store
143  BranchKey const bk = BranchKey(g.branchDescription());
144  std::auto_ptr<EDProduct> edp(store()->getProduct(bk, this));
145 
146  // Now fix up the Group
147  checkUniquenessAndType(edp, &g);
148  g.putProduct(edp);
149  }
150 
151  BranchID
153  if(!pid.isValid()) {
154  throw Exception(errors::ProductNotFound, "InvalidID")
155  << "get by product ID: invalid ProductID supplied\n";
156  }
158  }
159 
160  ProductID
162  if(!bid.isValid()) {
163  throw Exception(errors::NotFound, "InvalidID")
164  << "branchIDToProductID: invalid BranchID supplied\n";
165  }
166  typedef BranchIDListHelper::BranchIDToIndexMap BIDToIndexMap;
167  typedef BIDToIndexMap::const_iterator Iter;
168  typedef std::pair<Iter, Iter> IndexRange;
169 
170  BIDToIndexMap const& branchIDToIndexMap = BranchIDListRegistry::instance()->extra().branchIDToIndexMap();
171  IndexRange range = branchIDToIndexMap.equal_range(bid);
172  for(Iter it = range.first; it != range.second; ++it) {
173  BranchListIndex blix = it->second.first;
174  std::map<BranchListIndex, ProcessIndex>::const_iterator i = branchListIndexToProcessIndex_.find(blix);
175  if(i != branchListIndexToProcessIndex_.end()) {
176  ProductIndex productIndex = it->second.second;
177  ProcessIndex processIndex = i->second;
178  return ProductID(processIndex+1, productIndex+1);
179  }
180  }
181  // cannot throw, because some products may legitimately not have product ID's (e.g. pile-up).
182  return ProductID();
183  }
184 
187  BranchID bid = pidToBid(pid);
188  SharedConstGroupPtr const& g = getGroup(bid, true, true);
189  if(g.get() == 0) {
190  boost::shared_ptr<cms::Exception> whyFailed(new Exception(errors::ProductNotFound, "InvalidID"));
191  *whyFailed
192  << "get by product ID: no product with given id: " << pid << "\n";
193  return BasicHandle(whyFailed);
194  }
195 
196  // Check for case where we tried on demand production and
197  // it failed to produce the object
198  if(g->onDemand()) {
199  boost::shared_ptr<cms::Exception> whyFailed(new Exception(errors::ProductNotFound, "InvalidID"));
200  *whyFailed
201  << "get by product ID: no product with given id: " << pid << "\n"
202  << "onDemand production failed to produce it.\n";
203  return BasicHandle(whyFailed);
204  }
205  return BasicHandle(g->product(), g->provenance());
206  }
207 
208  EDProduct const *
210  return getByProductID(pid).wrapper();
211  }
212 
213  Provenance
215  BranchID bid = pidToBid(pid);
216  return getProvenance(bid);
217  }
218 
219  void
220  EventPrincipal::setUnscheduledHandler(boost::shared_ptr<UnscheduledHandler> iHandler) {
221  unscheduledHandler_ = iHandler;
222  }
223 
224  boost::shared_ptr<UnscheduledHandler>
226  return unscheduledHandler_;
227  }
228 
231  return *eventSelectionIDs_;
232  }
233 
234  BranchListIndexes const&
236  return *branchListIndexes_;
237  }
238 
239  bool
240  EventPrincipal::unscheduledFill(std::string const& moduleLabel) const {
241 
242  // If it is a module already currently running in unscheduled
243  // mode, then there is a circular dependency related to which
244  // EDProducts modules require and produce. There is no safe way
245  // to recover from this. Here we check for this problem and throw
246  // an exception.
247  std::vector<std::string>::const_iterator i =
248  find_in_all(moduleLabelsRunning_, moduleLabel);
249 
250  if(i != moduleLabelsRunning_.end()) {
252  << "Hit circular dependency while trying to run an unscheduled module.\n"
253  << "Current implementation of unscheduled execution cannot always determine\n"
254  << "the proper order for module execution. It is also possible the modules\n"
255  << "have a built in circular dependence that will not work with any order.\n"
256  << "In the first case, scheduling some or all required modules in paths will help.\n"
257  << "In the second case, the modules themselves will have to be fixed.\n";
258  }
259 
260  moduleLabelsRunning_.push_back(moduleLabel);
261 
262  if(unscheduledHandler_) {
263  unscheduledHandler_->tryToFill(moduleLabel, *const_cast<EventPrincipal *>(this));
264  }
265  moduleLabelsRunning_.pop_back();
266  return true;
267  }
268 
269  ProductID
270  EventPrincipal::oldToNewProductID_(ProductID const& oldProductID) const {
271  BranchID bid = branchMapperPtr()->oldProductIDToBranchID(oldProductID);
272  if(!bid.isValid()) return oldProductID;
273  return branchIDToProductID(bid);
274  }
275 }
RunPrincipal const & runPrincipal() const
ProductRegistry const & productRegistry() const
Definition: Principal.h:122
void clearPrincipal()
Definition: Principal.cc:125
int i
Definition: DBlmapReader.cc:9
unsigned short BranchListIndex
boost::shared_ptr< DelayedReader > store() const
Definition: Principal.h:141
EventSelectionIDVector const & eventSelectionIDs() const
boost::shared_ptr< LuminosityBlockPrincipal > luminosityBlockPrincipal_
void putOnRead(ConstBranchDescription const &bd, std::auto_ptr< EDProduct > edp, std::auto_ptr< ProductProvenance > productProvenance)
const_iterator end() const
Definition: Principal.h:131
Group * getExistingGroup(BranchID const &branchID)
Definition: Principal.cc:155
BasicHandle getByProductID(ProductID const &oid) const
BranchID pidToBid(ProductID const &pid) const
std::map< BranchListIndex, ProcessIndex > branchListIndexToProcessIndex_
EDProduct const * wrapper() const
Definition: BasicHandle.h:87
bool isValid() const
Definition: BranchID.h:24
BranchListIndexes const & branchListIndexes() 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
static void fixBranchListIndexes(BranchListIndexes &indexes)
Base::SharedConstGroupPtr SharedConstGroupPtr
RunPrincipal const & runPrincipal() const
std::vector< EventSelectionID > EventSelectionIDVector
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:78
boost::shared_ptr< UnscheduledHandler > unscheduledHandler() const
EventPrincipal(boost::shared_ptr< ProductRegistry const > reg, ProcessConfiguration const &pc)
boost::scoped_ptr< EventAuxiliary > aux_
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:116
void putProduct(std::auto_ptr< EDProduct > edp, boost::shared_ptr< ProductProvenance > productProvenance)
Definition: Group.h:125
LuminosityBlockPrincipal const & luminosityBlockPrincipal() const
void setProcessHistory(Principal const &principal)
Definition: Principal.cc:201
void fillPrincipal(ProcessHistoryID const &hist, boost::shared_ptr< BranchMapper > mapper, boost::shared_ptr< DelayedReader > rtrv)
Definition: Principal.cc:138
void checkUniquenessAndType(std::auto_ptr< EDProduct > &prod, Group const *group) const
Definition: Principal.cc:608
BranchID const & branchID() const
T const * getProduct(RefCore const &ref)
Definition: RefCoreGet.h:37
boost::shared_ptr< UnscheduledHandler > unscheduledHandler_
std::multimap< BranchID, IndexPair > BranchIDToIndexMap
boost::shared_ptr< EventSelectionIDVector > eventSelectionIDs_
void put(ConstBranchDescription const &bd, std::auto_ptr< EDProduct > edp, std::auto_ptr< ProductProvenance > productProvenance)
unsigned short ProcessIndex
Definition: ProductID.h:25
void fillEventPrincipal(std::auto_ptr< EventAuxiliary > aux, boost::shared_ptr< LuminosityBlockPrincipal > lbp, boost::shared_ptr< EventSelectionIDVector > eventSelectionIDs=boost::shared_ptr< EventSelectionIDVector >(new EventSelectionIDVector), boost::shared_ptr< BranchListIndexes > branchListIndexes=boost::shared_ptr< BranchListIndexes >(new BranchListIndexes), boost::shared_ptr< BranchMapper > mapper=boost::shared_ptr< BranchMapper >(new BranchMapper), boost::shared_ptr< DelayedReader > rtrv=boost::shared_ptr< DelayedReader >(new NoDelayedReader))
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_
const_iterator begin() const
Definition: Principal.h:130
SharedConstGroupPtr const getGroup(BranchID const &oid, bool resolveProd, bool fillOnDemand) const
Definition: Principal.cc:207
virtual bool unscheduledFill(std::string const &moduleLabel) const
boost::shared_ptr< EDProduct > product() const
Definition: Group.h:81
boost::filter_iterator< FilledGroupPtr, GroupCollection::const_iterator > const_iterator
Definition: Principal.h:48
virtual EDProduct const * getIt(ProductID const &pid) const
static ThreadSafeIndexedRegistry * instance()
boost::shared_ptr< BranchMapper > branchMapperPtr() const
Definition: Principal.h:139
unsigned short ProductIndex
Definition: ProductID.h:26
void setUnscheduledHandler(boost::shared_ptr< UnscheduledHandler > iHandler)
bool productUnavailable() const
Definition: Group.h:72
bool isValid() const
Definition: ProductID.h:36
ConstBranchDescription const & branchDescription() const
Definition: Group.h:90
virtual ProductID oldToNewProductID_(ProductID const &oldProductID) const
std::vector< std::string > moduleLabelsRunning_
std::string const & moduleLabel() const
const std::string * moduleLabel() const
Definition: HLTadd.h:40