CMS 3D CMS Logo

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_(),
25  provenanceReader_(reader.release()),
26  transitionIndex_(std::numeric_limits<unsigned int>::max())
27  {
28  assert(provenanceReader_);
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 
46  void
48  if(provenanceReader_ and nullptr == readEntryInfoSet_.load() ) {
49  provenanceReader_->readProvenanceAsync(task, moduleCallingContext,transitionIndex_,readEntryInfoSet_);
50  }
51  if(nextRetriever_) {
52  nextRetriever_->readProvenanceAsync(task,moduleCallingContext);
53  }
54  }
55 
56 
58  {
59  if(iFrom.readEntryInfoSet_) {
60  if (readEntryInfoSet_) {
61  delete readEntryInfoSet_.exchange(nullptr);
62  }
63  readEntryInfoSet_ = new std::set<ProductProvenance>(*iFrom.readEntryInfoSet_);
64  } else {
65  if(readEntryInfoSet_) {
66  delete readEntryInfoSet_.load();
67  readEntryInfoSet_ = nullptr;
68  }
69  }
72 
73  if(iFrom.nextRetriever_) {
74  if(not nextRetriever_) {
75  nextRetriever_ = std::make_shared<ProductProvenanceRetriever>(transitionIndex_);
76  }
77  nextRetriever_->deepCopy(*(iFrom.nextRetriever_));
78  }
79  }
80 
81  void
83  delete readEntryInfoSet_.load();
84  readEntryInfoSet_ = nullptr;
85  entryInfoSet_.clear();
86  if(nextRetriever_) {
87  nextRetriever_->reset();
88  }
89  }
90 
91  void
93  //NOTE:do not read provenance here because we only need the full
94  // provenance when someone tries to access it not when doing the insert
95  // doing the delay saves 20% of time when doing an analysis job
96  //readProvenance();
97  entryInfoSet_.insert(entryInfo);
98  }
99 
100  void
101  ProductProvenanceRetriever::mergeProvenanceRetrievers(std::shared_ptr<ProductProvenanceRetriever> other) {
103  }
104 
105  ProductProvenance const*
107  ProductProvenance ei(bid);
108  auto it = entryInfoSet_.find(ei);
109  if(it == entryInfoSet_.end()) {
110  //check in source
111  readProvenance();
112  auto ptr =readEntryInfoSet_.load();
113  if(ptr) {
114  auto it = ptr->find(ei);
115  if(it!= ptr->end()) {
116  return &*it;
117  }
118  }
119  if(nextRetriever_) {
120  return nextRetriever_->branchIDToProvenance(bid);
121  }
122  return nullptr;
123  }
124  return &*it;
125  }
126 
128  }
129 }
tbb::concurrent_unordered_set< ProductProvenance, ProductProvenanceHasher, ProductProvenanceEqual > entryInfoSet_
void deepCopy(ProductProvenanceRetriever const &)
void mergeProvenanceRetrievers(std::shared_ptr< ProductProvenanceRetriever > other)
void readProvenanceAsync(WaitingTask *task, ModuleCallingContext const *moduleCallingContext) const
std::shared_ptr< const ProvenanceReaderBase > provenanceReader_
std::atomic< const std::set< ProductProvenance > * > readEntryInfoSet_
ProductProvenanceRetriever(unsigned int iTransitionIndex)
HLT enums.
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