test
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 
23 
24 #include <algorithm>
25 #include <cassert>
26 #include <limits>
27 #include <memory>
28 
29 namespace edm {
31  std::shared_ptr<ProductRegistry const> reg,
32  std::shared_ptr<BranchIDListHelper const> branchIDListHelper,
33  std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper,
34  ProcessConfiguration const& pc,
35  HistoryAppender* historyAppender,
36  unsigned int streamIndex,
37  bool isForPrimaryProcess) :
38  Base(reg, reg->productLookup(InEvent), pc, InEvent, historyAppender,isForPrimaryProcess),
39  aux_(),
40  luminosityBlockPrincipal_(),
41  provRetrieverPtr_(new ProductProvenanceRetriever(streamIndex)),
42  eventSelectionIDs_(),
43  branchIDListHelper_(branchIDListHelper),
44  thinnedAssociationsHelper_(thinnedAssociationsHelper),
45  branchListIndexes_(),
46  branchListIndexToProcessIndex_(),
47  streamID_(streamIndex) {
49  }
50 
51  void
54  aux_ = EventAuxiliary();
55  luminosityBlockPrincipal_ = nullptr; // propagate_const<T> has no reset() function
56  provRetrieverPtr_->reset();
58  }
59 
60  void
62  ProcessHistoryRegistry const& processHistoryRegistry,
63  EventSelectionIDVector&& eventSelectionIDs,
64  BranchListIndexes&& branchListIndexes,
65  ProductProvenanceRetriever const& provRetriever,
68  provRetrieverPtr_->deepCopy(provRetriever);
70  if(branchIDListHelper_->hasProducedProducts()) {
71  // Add index into BranchIDListRegistry for products produced this process
72  branchListIndexes_.push_back(branchIDListHelper_->producedBranchListIndex());
73  }
74  fillEventPrincipal(aux,processHistoryRegistry,reader);
75  }
76 
77  void
79  ProcessHistoryRegistry const& processHistoryRegistry,
80  EventSelectionIDVector&& eventSelectionIDs,
81  BranchListIndexes&& branchListIndexes) {
84  if(branchIDListHelper_->hasProducedProducts()) {
85  // Add index into BranchIDListRegistry for products produced this process
86  branchListIndexes_.push_back(branchIDListHelper_->producedBranchListIndex());
87  }
88  fillEventPrincipal(aux,processHistoryRegistry,nullptr);
89  }
90 
91  void
93  ProcessHistoryRegistry const& processHistoryRegistry,
95  if(aux.event() == invalidEventNumber) {
97  << "EventPrincipal::fillEventPrincipal, Invalid event number provided in EventAuxiliary, It is illegal for the event number to be 0\n";
98  }
99 
100  fillPrincipal(aux.processHistoryID(), processHistoryRegistry, reader);
101  aux_ = aux;
103 
104  if(branchListIndexes_.empty() and branchIDListHelper_->hasProducedProducts()) {
105  // Add index into BranchIDListRegistry for products produced this process
106  // if it hasn't already been filled in by the other fillEventPrincipal or by an earlier call to this function
107  branchListIndexes_.push_back(branchIDListHelper_->producedBranchListIndex());
108  }
109 
110  // Fill in helper map for Branch to ProductID mapping
111  ProcessIndex pix = 0;
112  for(auto const& blindex : branchListIndexes_) {
113  branchListIndexToProcessIndex_.insert(std::make_pair(blindex, pix));
114  ++pix;
115  }
116 
117  // Fill in the product ID's in the product holders.
118  for(auto& prod : *this) {
119  if (prod->singleProduct()) {
120  // If an alias is in the same process as the original then isAlias will be true.
121  // Under that condition, we want the ProductID to be the same as the original.
122  // If not, then we've internally changed the original BranchID to the alias BranchID
123  // in the ProductID lookup so we need the alias BranchID.
124  auto const & bd =prod->branchDescription();
125  prod->setProvenance(productProvenanceRetrieverPtr(),
126  processHistory(),
127  branchIDToProductID(bd.isAlias()?bd.originalBranchID(): bd.branchID()));
128  }
129  }
130  }
131 
132  void
133  EventPrincipal::setLuminosityBlockPrincipal(std::shared_ptr<LuminosityBlockPrincipal> const& lbp) {
135  }
136 
137  void
139  assert(run == luminosityBlockPrincipal_->run());
140  assert(lumi == luminosityBlockPrincipal_->luminosityBlock());
141  EventNumber_t event = aux_.id().event();
142  aux_.id() = EventID(run, lumi, event);
143  }
144 
145  RunPrincipal const&
148  }
149 
150  void
152  BranchDescription const& bd,
153  std::unique_ptr<WrapperBase> edp,
154  ProductProvenance const& productProvenance) const {
155 
156  // assert commented out for DaqSource. When DaqSource no longer uses put(), the assert can be restored.
157  //assert(produced());
158  if(edp.get() == nullptr) {
159  throw Exception(errors::InsertFailure, "Null Pointer")
160  << "put: Cannot put because ptr to product is null."
161  << "\n";
162  }
163  productProvenanceRetrieverPtr()->insertIntoSet(productProvenance);
164  auto phb = getExistingProduct(bd.branchID());
165  assert(phb);
166  // ProductResolver assumes ownership
167  phb->putProduct(std::move(edp));
168  }
169 
170  void
172  BranchDescription const& bd,
173  std::unique_ptr<WrapperBase> edp,
174  ProductProvenance const& productProvenance) const {
175 
176  assert(!bd.produced());
177  productProvenanceRetrieverPtr()->insertIntoSet(productProvenance);
178  auto phb = getExistingProduct(bd.branchID());
179  assert(phb);
180  // ProductResolver assumes ownership
181  phb->putProduct(std::move(edp));
182  }
183 
184  BranchID
186  if(!pid.isValid()) {
187  throw Exception(errors::ProductNotFound, "InvalidID")
188  << "get by product ID: invalid ProductID supplied\n";
189  }
190  return productIDToBranchID(pid, branchIDListHelper_->branchIDLists(), branchListIndexes_);
191  }
192 
193  ProductID
195  if(!bid.isValid()) {
196  throw Exception(errors::NotFound, "InvalidID")
197  << "branchIDToProductID: invalid BranchID supplied\n";
198  }
199  typedef BranchIDListHelper::BranchIDToIndexMap BIDToIndexMap;
200  typedef BIDToIndexMap::const_iterator Iter;
201  typedef std::pair<Iter, Iter> IndexRange;
202 
203  IndexRange range = branchIDListHelper_->branchIDToIndexMap().equal_range(bid);
204  for(Iter it = range.first; it != range.second; ++it) {
205  BranchListIndex blix = it->second.first;
206  std::map<BranchListIndex, ProcessIndex>::const_iterator i = branchListIndexToProcessIndex_.find(blix);
207  if(i != branchListIndexToProcessIndex_.end()) {
208  ProductIndex productIndex = it->second.second;
209  ProcessIndex processIndex = i->second;
210  return ProductID(processIndex+1, productIndex+1);
211  }
212  }
213  // cannot throw, because some products may legitimately not have product ID's (e.g. pile-up).
214  return ProductID();
215  }
216 
217  unsigned int
219  return streamID_.value();
220  }
221 
224  exception<<"get by product ID: The product with given id: "<<pid
225  <<"\ntype: "<<phb->productType()
226  <<"\nproduct instance name: "<<phb->productInstanceName()
227  <<"\nprocess name: "<<phb->processName()
228  <<"\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.";
229  throw exception;
230  }
231 
232  BasicHandle
234  BranchID bid = pidToBid(pid);
236  if(phb == nullptr) {
237  return BasicHandle(makeHandleExceptionFactory([pid]()->std::shared_ptr<cms::Exception> {
238  std::shared_ptr<cms::Exception> whyFailed(std::make_shared<Exception>(errors::ProductNotFound, "InvalidID"));
239  *whyFailed
240  << "get by product ID: no product with given id: " << pid << "\n";
241  return whyFailed;
242  }));
243  }
244 
245  // Was this already deleted?
246  if(phb->productWasDeleted()) {
248  }
249  // Check for case where we tried on demand production and
250  // it failed to produce the object
251  if(phb->unscheduledWasNotRun()) {
252  return BasicHandle(makeHandleExceptionFactory([pid]()->std::shared_ptr<cms::Exception> {
253  std::shared_ptr<cms::Exception> whyFailed(std::make_shared<Exception>(errors::ProductNotFound, "InvalidID"));
254  *whyFailed
255  << "get by ProductID: could not get product with id: " << pid << "\n"
256  << "Unscheduled execution not allowed to get via ProductID.\n";
257  return whyFailed;
258  }));
259  }
260  auto resolution = phb->resolveProduct(*this,false,nullptr,nullptr);
261 
262  auto data = resolution.data();
263  if(data) {
264  return BasicHandle(data->wrapper(), &(data->provenance()));
265  }
266  return BasicHandle(nullptr,nullptr);
267  }
268 
269  WrapperBase const*
271  return getByProductID(pid).wrapper();
272  }
273 
274  WrapperBase const*
275  EventPrincipal::getThinnedProduct(ProductID const& pid, unsigned int& key) const {
276 
277  BranchID parent = pidToBid(pid);
278 
279  // Loop over thinned containers which were made by selecting elements from the parent container
280  for(auto associatedBranches = thinnedAssociationsHelper_->parentBegin(parent),
281  iEnd = thinnedAssociationsHelper_->parentEnd(parent);
282  associatedBranches != iEnd; ++associatedBranches) {
283 
284  ThinnedAssociation const* thinnedAssociation =
285  getThinnedAssociation(associatedBranches->association());
286  if(thinnedAssociation == nullptr) continue;
287 
288  if(associatedBranches->parent() != pidToBid(thinnedAssociation->parentCollectionID())) {
289  continue;
290  }
291 
292  unsigned int thinnedIndex = 0;
293  // Does this thinned container have the element referenced by key?
294  // If yes, thinnedIndex is set to point to it in the thinned container
295  if(!thinnedAssociation->hasParentIndex(key, thinnedIndex)) {
296  continue;
297  }
298  // Get the thinned container and return a pointer if we can find it
299  ProductID const& thinnedCollectionPID = thinnedAssociation->thinnedCollectionID();
300  BasicHandle bhThinned = getByProductID(thinnedCollectionPID);
301  if(!bhThinned.isValid()) {
302  // Thinned container is not found, try looking recursively in thinned containers
303  // which were made by selecting elements from this thinned container.
304  WrapperBase const* wrapperBase = getThinnedProduct(thinnedCollectionPID, thinnedIndex);
305  if(wrapperBase != nullptr) {
306  key = thinnedIndex;
307  return wrapperBase;
308  } else {
309  continue;
310  }
311  }
312  key = thinnedIndex;
313  return bhThinned.wrapper();
314  }
315  return nullptr;
316  }
317 
318  void
320  std::vector<WrapperBase const*>& foundContainers,
321  std::vector<unsigned int>& keys) const {
322 
323  BranchID parent = pidToBid(pid);
324 
325  // Loop over thinned containers which were made by selecting elements from the parent container
326  for(auto associatedBranches = thinnedAssociationsHelper_->parentBegin(parent),
327  iEnd = thinnedAssociationsHelper_->parentEnd(parent);
328  associatedBranches != iEnd; ++associatedBranches) {
329 
330  ThinnedAssociation const* thinnedAssociation =
331  getThinnedAssociation(associatedBranches->association());
332  if(thinnedAssociation == nullptr) continue;
333 
334  if(associatedBranches->parent() != pidToBid(thinnedAssociation->parentCollectionID())) {
335  continue;
336  }
337 
338  unsigned nKeys = keys.size();
339  unsigned int doNotLookForThisIndex = std::numeric_limits<unsigned int>::max();
340  std::vector<unsigned int> thinnedIndexes(nKeys, doNotLookForThisIndex);
341  bool hasAny = false;
342  for(unsigned k = 0; k < nKeys; ++k) {
343  // Already found this one
344  if(foundContainers[k] != nullptr) continue;
345  // Already know this one is not in this thinned container
346  if(keys[k] == doNotLookForThisIndex) continue;
347  // Does the thinned container hold the entry of interest?
348  // Modifies thinnedIndexes[k] only if it returns true and
349  // sets it to the index in the thinned collection.
350  if(thinnedAssociation->hasParentIndex(keys[k], thinnedIndexes[k])) {
351  hasAny = true;
352  }
353  }
354  if(!hasAny) {
355  continue;
356  }
357  // Get the thinned container and set the pointers and indexes into
358  // it (if we can find it)
359  ProductID thinnedCollectionPID = thinnedAssociation->thinnedCollectionID();
360  BasicHandle bhThinned = getByProductID(thinnedCollectionPID);
361  if(!bhThinned.isValid()) {
362  // Thinned container is not found, try looking recursively in thinned containers
363  // which were made by selecting elements from this thinned container.
364  getThinnedProducts(thinnedCollectionPID, foundContainers, thinnedIndexes);
365  for(unsigned k = 0; k < nKeys; ++k) {
366  if(foundContainers[k] == nullptr) continue;
367  if(thinnedIndexes[k] == doNotLookForThisIndex) continue;
368  keys[k] = thinnedIndexes[k];
369  }
370  } else {
371  for(unsigned k = 0; k < nKeys; ++k) {
372  if(thinnedIndexes[k] == doNotLookForThisIndex) continue;
373  keys[k] = thinnedIndexes[k];
374  foundContainers[k] = bhThinned.wrapper();
375  }
376  }
377  }
378  }
379 
380  Provenance
382  BranchID bid = pidToBid(pid);
383  return getProvenance(bid, mcc);
384  }
385 
386  void
388  applyToResolvers([&iConfigure](ProductResolverBase* iResolver) {
389  iResolver->setupUnscheduled(iConfigure);
390  });
391  }
392 
395  return eventSelectionIDs_;
396  }
397 
398  BranchListIndexes const&
400  return branchListIndexes_;
401  }
402 
405 
406  ConstProductResolverPtr const phb = getProductResolver(branchID);
407 
408  if(phb == nullptr) {
410  << "EventPrincipal::getThinnedAssociation, ThinnedAssociation ProductResolver cannot be found\n"
411  << "This should never happen. Contact a Framework developer";
412  }
413  ProductData const* productData = (phb->resolveProduct(*this,false,nullptr,nullptr)).data();
414  if (productData == nullptr) {
415  return nullptr;
416  }
417  WrapperBase const* product = productData->wrapper();
418  if(!(typeid(edm::ThinnedAssociation) == product->dynamicTypeInfo())) {
420  << "EventPrincipal::getThinnedProduct, product has wrong type, not a ThinnedAssociation.\n";
421  }
423  return wrapper->product();
424  }
425 
426 }
RunPrincipal const & runPrincipal() const
std::shared_ptr< ThinnedAssociationsHelper const > thinnedAssociationsHelper_
EventNumber_t event() const
Definition: EventID.h:41
void clearPrincipal()
Definition: Principal.cc:299
int i
Definition: DBlmapReader.cc:9
unsigned short BranchListIndex
void setLuminosityBlockPrincipal(std::shared_ptr< LuminosityBlockPrincipal > const &lbp)
EventSelectionIDVector const & eventSelectionIDs() const
std::type_info const & dynamicTypeInfo() const
Definition: WrapperBase.h:38
BasicHandle getByProductID(ProductID const &oid) const
EventSelectionIDVector eventSelectionIDs_
BranchID pidToBid(ProductID const &pid) const
tuple lumi
Definition: fjr2json.py:35
BranchListIndexes branchListIndexes_
edm::ThinnedAssociation const * getThinnedAssociation(edm::BranchID const &branchID) const
assert(m_qm.get())
ProductResolverBase * getExistingProduct(BranchID const &branchID)
Definition: Principal.cc:373
EventPrincipal(std::shared_ptr< ProductRegistry const > reg, std::shared_ptr< BranchIDListHelper const > branchIDListHelper, std::shared_ptr< ThinnedAssociationsHelper const > thinnedAssociationsHelper, ProcessConfiguration const &pc, HistoryAppender *historyAppender, unsigned int streamIndex=0, bool isForPrimaryProcess=true)
virtual void setupUnscheduled(UnscheduledConfigurator const &)
Provenance getProvenance(ProductID const &pid, ModuleCallingContext const *mcc) const
void applyToResolvers(F iFunc)
Definition: Principal.h:211
std::map< BranchListIndex, ProcessIndex > branchListIndexToProcessIndex_
unsigned long long EventNumber_t
WrapperBase const * wrapper() const
Definition: ProductData.h:32
std::shared_ptr< BranchIDListHelper const > branchIDListHelper_
EventAuxiliary aux_
bool isValid() const
Definition: BranchID.h:24
edm::propagate_const< std::shared_ptr< ProductProvenanceRetriever > > provRetrieverPtr_
BranchListIndexes const & branchListIndexes() const
unsigned int LuminosityBlockNumber_t
ProcessHistory const & processHistory() const
Definition: Principal.h:135
ProductID branchIDToProductID(BranchID const &bid) const
void putOnRead(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const
RunPrincipal const & runPrincipal() const
std::vector< EventSelectionID > EventSelectionIDVector
static void throwProductDeletedException(ProductID const &pid, edm::EventPrincipal::ConstProductResolverPtr const phb)
virtual WrapperBase const * getThinnedProduct(ProductID const &pid, unsigned int &key) const override
EventNumber_t const invalidEventNumber
std::vector< BranchListIndex > BranchListIndexes
BranchID productIDToBranchID(ProductID const &pid, BranchIDLists const &lists, BranchListIndexes const &indexes)
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:139
LuminosityBlockPrincipal const & luminosityBlockPrincipal() const
std::shared_ptr< HandleExceptionFactory > makeHandleExceptionFactory(T &&iFunctor)
Base::ConstProductResolverPtr ConstProductResolverPtr
def move
Definition: eostools.py:510
WrapperBase const * wrapper() const
Definition: BasicHandle.h:90
virtual WrapperBase const * getIt(ProductID const &pid) const override
BranchID const & branchID() const
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const
ProductID const & thinnedCollectionID() const
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
std::multimap< BranchID, IndexPair > BranchIDToIndexMap
ProductProvenanceRetriever const * productProvenanceRetrieverPtr() const
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
unsigned short ProcessIndex
Definition: ProductID.h:25
DelayedReader * reader() const
Definition: Principal.h:178
void setupUnscheduled(UnscheduledConfigurator const &)
unsigned int value() const
Definition: StreamID.h:46
virtual unsigned int transitionIndex_() const override
T const * product() const
Definition: Wrapper.h:32
tuple pid
Definition: sysUtil.py:22
string const
Definition: compareJSON.py:14
edm::propagate_const< std::shared_ptr< LuminosityBlockPrincipal > > luminosityBlockPrincipal_
void setProcessHistoryID(ProcessHistoryID const &phid)
bool isValid() const
Definition: BasicHandle.h:82
ProcessHistoryID const & processHistoryID() const
EventID const & id() const
void fillEventPrincipal(EventAuxiliary const &aux, ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=0)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
ConstProductResolverPtr getProductResolver(BranchID const &oid) const
Definition: Principal.cc:433
unsigned short ProductIndex
Definition: ProductID.h:26
unsigned int RunNumber_t
ProductID const & parentCollectionID() const
bool isValid() const
Definition: ProductID.h:35
bool hasParentIndex(unsigned int parentIndex, unsigned int &thinnedIndex) const
void setRunAndLumiNumber(RunNumber_t run, LuminosityBlockNumber_t lumi)
void fillPrincipal(ProcessHistoryID const &hist, ProcessHistoryRegistry const &phr, DelayedReader *reader)
Definition: Principal.cc:317
EventAuxiliary const & aux() const
virtual void getThinnedProducts(ProductID const &pid, std::vector< WrapperBase const * > &foundContainers, std::vector< unsigned int > &keys) const override
EventNumber_t event() const
static HepMC::HEPEVT_Wrapper wrapper
void insertIntoSet(ProductProvenance const &provenanceProduct) const