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 
22  ProductProvenanceRetriever::ProductProvenanceRetriever(std::unique_ptr<ProvenanceReaderBase> reader) :
23  entryInfoSet_(),
27  provenanceReader_(reader.release()),
28  transitionIndex_(std::numeric_limits<unsigned int>::max())
29  {
30  assert(provenanceReader_);
31  }
32 
34  delete readEntryInfoSet_.load();
35  }
36 
37  void
39  if(nullptr == readEntryInfoSet_.load() && provenanceReader_) {
40  auto temp = std::make_unique<std::set<ProductProvenance> const>(provenanceReader_->readProvenance(transitionIndex_));
41  std::set<ProductProvenance> const* expected = nullptr;
42  if(readEntryInfoSet_.compare_exchange_strong(expected, temp.get())) {
43  temp.release();
44  }
45  }
46  }
47 
48  void
50  if(provenanceReader_ and nullptr == readEntryInfoSet_.load() ) {
51  provenanceReader_->readProvenanceAsync(task, moduleCallingContext,transitionIndex_,readEntryInfoSet_);
52  }
53  if(nextRetriever_) {
54  nextRetriever_->readProvenanceAsync(task,moduleCallingContext);
55  }
56  }
57 
58 
60  {
61  if(iFrom.readEntryInfoSet_) {
62  if (readEntryInfoSet_) {
63  delete readEntryInfoSet_.exchange(nullptr);
64  }
65  readEntryInfoSet_ = new std::set<ProductProvenance>(*iFrom.readEntryInfoSet_);
66  } else {
67  if(readEntryInfoSet_) {
68  delete readEntryInfoSet_.load();
69  readEntryInfoSet_ = nullptr;
70  }
71  }
74 
75  if(iFrom.nextRetriever_) {
76  if(not nextRetriever_) {
77  nextRetriever_ = std::make_shared<ProductProvenanceRetriever>(transitionIndex_);
78  }
79  nextRetriever_->deepCopy(*(iFrom.nextRetriever_));
80  }
81  }
82 
83  void
85  delete readEntryInfoSet_.load();
86  readEntryInfoSet_ = nullptr;
87  entryInfoSet_.clear();
88  if(nextRetriever_) {
89  nextRetriever_->reset();
90  }
91  parentProcessRetriever_ = nullptr;
92  }
93 
94  void
96  //NOTE:do not read provenance here because we only need the full
97  // provenance when someone tries to access it not when doing the insert
98  // doing the delay saves 20% of time when doing an analysis job
99  //readProvenance();
100  entryInfoSet_.insert(std::move(entryInfo));
101  }
102 
103  void
104  ProductProvenanceRetriever::mergeProvenanceRetrievers(std::shared_ptr<ProductProvenanceRetriever> other) {
106  }
107 
108  void
110  parentProcessRetriever_ = &provRetriever;
111  }
112 
113  ProductProvenance const*
115  ProductProvenance ei(bid);
116  auto it = entryInfoSet_.find(ei);
117  if(it == entryInfoSet_.end()) {
119  return parentProcessRetriever_->branchIDToProvenance(bid);
120  }
121  //check in source
122  readProvenance();
123  auto ptr =readEntryInfoSet_.load();
124  if(ptr) {
125  auto it = ptr->find(ei);
126  if(it!= ptr->end()) {
127  return &*it;
128  }
129  }
130  if(nextRetriever_) {
131  return nextRetriever_->branchIDToProvenance(bid);
132  }
133  return nullptr;
134  }
135  return &*it;
136  }
137 
138  ProductProvenance const*
140  ProductProvenance ei(bid);
141  auto it = entryInfoSet_.find(ei);
142  if(it == entryInfoSet_.end()) {
144  return parentProcessRetriever_->branchIDToProvenanceForProducedOnly(bid);
145  }
146  if(nextRetriever_) {
147  return nextRetriever_->branchIDToProvenanceForProducedOnly(bid);
148  }
149  return nullptr;
150  }
151  return &*it;
152  }
153 
155  }
156 }
tbb::concurrent_unordered_set< ProductProvenance, ProductProvenanceHasher, ProductProvenanceEqual > entryInfoSet_
#define nullptr
void deepCopy(ProductProvenanceRetriever const &)
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:142