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  parentProcessRetriever_(nullptr),
18  provenanceReader_(),
19  transitionIndex_(iTransitionIndex) {}
20 
21  ProductProvenanceRetriever::ProductProvenanceRetriever(std::unique_ptr<ProvenanceReaderBase> reader)
22  : entryInfoSet_(),
26  provenanceReader_(reader.release()),
27  transitionIndex_(std::numeric_limits<unsigned int>::max()) {
28  assert(provenanceReader_);
29  }
30 
32 
34  if (nullptr == readEntryInfoSet_.load() && provenanceReader_) {
35  auto temp =
36  std::make_unique<std::set<ProductProvenance> const>(provenanceReader_->readProvenance(transitionIndex_));
37  std::set<ProductProvenance> const* expected = nullptr;
38  if (readEntryInfoSet_.compare_exchange_strong(expected, temp.get())) {
39  temp.release();
40  }
41  }
42  }
43 
45  ModuleCallingContext const* moduleCallingContext) const {
46  if (provenanceReader_ and nullptr == readEntryInfoSet_.load()) {
47  provenanceReader_->readProvenanceAsync(task, moduleCallingContext, transitionIndex_, readEntryInfoSet_);
48  }
49  if (nextRetriever_) {
50  nextRetriever_->readProvenanceAsync(task, moduleCallingContext);
51  }
52  }
53 
55  if (iFrom.readEntryInfoSet_) {
56  if (readEntryInfoSet_) {
57  delete readEntryInfoSet_.exchange(nullptr);
58  }
59  readEntryInfoSet_ = new std::set<ProductProvenance>(*iFrom.readEntryInfoSet_);
60  } else {
61  if (readEntryInfoSet_) {
62  delete readEntryInfoSet_.load();
63  readEntryInfoSet_ = nullptr;
64  }
65  }
68 
69  if (iFrom.nextRetriever_) {
70  if (not nextRetriever_) {
71  nextRetriever_ = std::make_shared<ProductProvenanceRetriever>(transitionIndex_);
72  }
73  nextRetriever_->deepCopy(*(iFrom.nextRetriever_));
74  }
75  }
76 
78  delete readEntryInfoSet_.load();
79  readEntryInfoSet_ = nullptr;
80  entryInfoSet_.clear();
81  if (nextRetriever_) {
82  nextRetriever_->reset();
83  }
84  parentProcessRetriever_ = nullptr;
85  }
86 
88  //NOTE:do not read provenance here because we only need the full
89  // provenance when someone tries to access it not when doing the insert
90  // doing the delay saves 20% of time when doing an analysis job
91  //readProvenance();
92  entryInfoSet_.insert(std::move(entryInfo));
93  }
94 
95  void ProductProvenanceRetriever::mergeProvenanceRetrievers(std::shared_ptr<ProductProvenanceRetriever> other) {
97  }
98 
100  parentProcessRetriever_ = &provRetriever;
101  }
102 
104  ProductProvenance ei(bid);
105  auto it = entryInfoSet_.find(ei);
106  if (it == entryInfoSet_.end()) {
108  return parentProcessRetriever_->branchIDToProvenance(bid);
109  }
110  //check in source
111  readProvenance();
112  auto ptr = readEntryInfoSet_.load();
113  if (ptr) {
114  auto itRead = ptr->find(ei);
115  if (itRead != ptr->end()) {
116  return &*itRead;
117  }
118  }
119  if (nextRetriever_) {
120  return nextRetriever_->branchIDToProvenance(bid);
121  }
122  return nullptr;
123  }
124  return &*it;
125  }
126 
128  ProductProvenance ei(bid);
129  auto it = entryInfoSet_.find(ei);
130  if (it == entryInfoSet_.end()) {
132  return parentProcessRetriever_->branchIDToProvenanceForProducedOnly(bid);
133  }
134  if (nextRetriever_) {
135  return nextRetriever_->branchIDToProvenanceForProducedOnly(bid);
136  }
137  return nullptr;
138  }
139  return &*it;
140  }
141 
143 } // namespace edm
tbb::concurrent_unordered_set< ProductProvenance, ProductProvenanceHasher, ProductProvenanceEqual > entryInfoSet_
#define nullptr
void deepCopy(ProductProvenanceRetriever const &)
reader
Definition: DQM.py:105
std::map< l1t::HGCalMulticluster::EnergyInterpretation, double > ei
Definition: classes.h:67
void mergeParentProcessRetriever(ProductProvenanceRetriever const &provRetriever)
void mergeProvenanceRetrievers(std::shared_ptr< ProductProvenanceRetriever > other)
void readProvenanceAsync(WaitingTask *task, ModuleCallingContext const *moduleCallingContext) const
std::shared_ptr< const ProvenanceReaderBase > provenanceReader_
edm::propagate_const< ProductProvenanceRetriever const * > parentProcessRetriever_
void insertIntoSet(ProductProvenance provenanceProduct) const
std::atomic< const std::set< ProductProvenance > * > readEntryInfoSet_
ProductProvenance const * branchIDToProvenanceForProducedOnly(BranchID const &bid) const
ProductProvenanceRetriever(unsigned int iTransitionIndex)
HLT enums.
edm::propagate_const< std::shared_ptr< ProductProvenanceRetriever > > nextRetriever_
ProductProvenance const * branchIDToProvenance(BranchID const &bid) const
def move(src, dest)
Definition: eostools.py:511
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:118