CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ProductProvenanceRetriever.cc
Go to the documentation of this file.
3 
4 #include <cassert>
5 #include <iostream>
6 #include <limits>
7 
8 /*
9  ProductProvenanceRetriever
10 */
11 
12 namespace edm {
14  entryInfoSet_(),
15  readEntryInfoSet_(),
16  nextRetriever_(),
17  provenanceReader_(),
18  transitionIndex_(iTransitionIndex){
19  }
20 
21  ProductProvenanceRetriever::ProductProvenanceRetriever(std::unique_ptr<ProvenanceReaderBase> reader) :
22  entryInfoSet_(),
23  readEntryInfoSet_(),
24  nextRetriever_(),
25  provenanceReader_(reader.release()),
26  transitionIndex_(std::numeric_limits<unsigned int>::max())
27  {
29  }
30 
32  delete readEntryInfoSet_.load();
33  }
34 
35  void
37  if(nullptr == readEntryInfoSet_.load() && provenanceReader_) {
38  auto temp = std::make_unique<std::set<ProductProvenance> const>(provenanceReader_->readProvenance(transitionIndex_));
39  std::set<ProductProvenance> const* expected = nullptr;
40  if(readEntryInfoSet_.compare_exchange_strong(expected, temp.get())) {
41  temp.release();
42  }
43  }
44  }
45 
47  {
48  if(iFrom.readEntryInfoSet_) {
49  if (readEntryInfoSet_) {
50  delete readEntryInfoSet_.exchange(nullptr);
51  }
52  readEntryInfoSet_ = new std::set<ProductProvenance>(*iFrom.readEntryInfoSet_);
53  } else {
54  if(readEntryInfoSet_) {
55  delete readEntryInfoSet_.load();
56  readEntryInfoSet_ = nullptr;
57  }
58  }
61 
62  if(iFrom.nextRetriever_) {
63  if(not nextRetriever_) {
64  nextRetriever_ = std::make_shared<ProductProvenanceRetriever>(transitionIndex_);
65  }
66  nextRetriever_->deepCopy(*(iFrom.nextRetriever_));
67  }
68  }
69 
70  void
72  delete readEntryInfoSet_.load();
73  readEntryInfoSet_ = nullptr;
74  entryInfoSet_.clear();
75  if(nextRetriever_) {
76  nextRetriever_->reset();
77  }
78  }
79 
80  void
82  //NOTE:do not read provenance here because we only need the full
83  // provenance when someone tries to access it not when doing the insert
84  // doing the delay saves 20% of time when doing an analysis job
85  //readProvenance();
86  entryInfoSet_.insert(entryInfo);
87  }
88 
89  void
90  ProductProvenanceRetriever::mergeProvenanceRetrievers(std::shared_ptr<ProductProvenanceRetriever> other) {
91  nextRetriever_ = other;
92  }
93 
94  ProductProvenance const*
96  ProductProvenance ei(bid);
97  auto it = entryInfoSet_.find(ei);
98  if(it == entryInfoSet_.end()) {
99  //check in source
100  readProvenance();
101  auto ptr =readEntryInfoSet_.load();
102  if(ptr) {
103  auto it = ptr->find(ei);
104  if(it!= ptr->end()) {
105  return &*it;
106  }
107  }
108  if(nextRetriever_) {
109  return nextRetriever_->branchIDToProvenance(bid);
110  }
111  return nullptr;
112  }
113  return &*it;
114  }
115 
117  }
118 }
assert(m_qm.get())
tbb::concurrent_unordered_set< ProductProvenance, ProductProvenanceHasher, ProductProvenanceEqual > entryInfoSet_
void deepCopy(ProductProvenanceRetriever const &)
void mergeProvenanceRetrievers(std::shared_ptr< ProductProvenanceRetriever > other)
std::shared_ptr< const ProvenanceReaderBase > provenanceReader_
std::atomic< const std::set< ProductProvenance > * > readEntryInfoSet_
ProductProvenanceRetriever(unsigned int iTransitionIndex)
edm::propagate_const< std::shared_ptr< ProductProvenanceRetriever > > nextRetriever_
ProductProvenance const * branchIDToProvenance(BranchID const &bid) const
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:142
void insertIntoSet(ProductProvenance const &provenanceProduct) const