CMS 3D CMS Logo

ProductProvenanceRetriever.cc
Go to the documentation of this file.
4 
5 #include <cassert>
6 #include <iostream>
7 #include <limits>
8 
9 /*
10  ProductProvenanceRetriever
11 */
12 
13 namespace edm {
15  : entryInfoSet_(),
16  readEntryInfoSet_(),
17  nextRetriever_(),
18  parentProcessRetriever_(nullptr),
19  provenanceReader_(),
20  transitionIndex_(iTransitionIndex) {}
21 
23  edm::ProductRegistry const& iReg)
24  : entryInfoSet_(),
25  readEntryInfoSet_(),
26  nextRetriever_(),
27  parentProcessRetriever_(nullptr),
28  provenanceReader_(),
29  transitionIndex_(iTransitionIndex) {
30  setupEntryInfoSet(iReg);
31  }
32 
33  ProductProvenanceRetriever::ProductProvenanceRetriever(std::unique_ptr<ProvenanceReaderBase> reader)
34  : entryInfoSet_(),
35  readEntryInfoSet_(),
36  nextRetriever_(),
37  parentProcessRetriever_(nullptr),
38  provenanceReader_(reader.release()),
39  transitionIndex_(std::numeric_limits<unsigned int>::max()) {
41  }
42 
44 
46  if (nullptr == readEntryInfoSet_.load() && provenanceReader_) {
47  auto temp =
48  std::make_unique<std::set<ProductProvenance> const>(provenanceReader_->readProvenance(transitionIndex_));
49  std::set<ProductProvenance> const* expected = nullptr;
50  if (readEntryInfoSet_.compare_exchange_strong(expected, temp.get())) {
51  temp.release();
52  }
53  }
54  }
55 
57  std::set<BranchID> ids;
58  for (auto const& p : iReg.productList()) {
59  if (p.second.branchType() == edm::InEvent) {
60  if (p.second.produced() or p.second.isProvenanceSetOnRead()) {
61  ids.insert(p.second.branchID());
62  }
63  }
64  }
65  entryInfoSet_.reserve(ids.size());
66  for (auto const& b : ids) {
67  entryInfoSet_.emplace_back(b);
68  }
69  }
70 
72  entryInfoSet_.clear();
73  setupEntryInfoSet(iReg);
74  }
75 
77  ModuleCallingContext const* moduleCallingContext) const {
78  if (provenanceReader_ and nullptr == readEntryInfoSet_.load()) {
79  provenanceReader_->readProvenanceAsync(task, moduleCallingContext, transitionIndex_, readEntryInfoSet_);
80  }
81  if (nextRetriever_) {
82  nextRetriever_->readProvenanceAsync(task, moduleCallingContext);
83  }
84  }
85 
87  if (iFrom.readEntryInfoSet_) {
88  if (readEntryInfoSet_) {
89  delete readEntryInfoSet_.exchange(nullptr);
90  }
91  readEntryInfoSet_ = new std::set<ProductProvenance>(*iFrom.readEntryInfoSet_);
92  } else {
93  if (readEntryInfoSet_) {
94  delete readEntryInfoSet_.load();
95  readEntryInfoSet_ = nullptr;
96  }
97  }
98  assert(iFrom.entryInfoSet_.empty());
100 
101  if (iFrom.nextRetriever_) {
102  if (not nextRetriever_) {
103  nextRetriever_ = std::make_shared<ProductProvenanceRetriever>(transitionIndex_);
104  }
105  nextRetriever_->deepCopy(*(iFrom.nextRetriever_));
106  }
107  }
108 
110  delete readEntryInfoSet_.load();
111  readEntryInfoSet_ = nullptr;
112  for (auto& e : entryInfoSet_) {
113  e.resetParentage();
114  }
115  if (nextRetriever_) {
116  nextRetriever_->reset();
117  }
118  parentProcessRetriever_ = nullptr;
119  }
120 
122  //NOTE:do not read provenance here because we only need the full
123  // provenance when someone tries to access it not when doing the insert
124  // doing the delay saves 20% of time when doing an analysis job
125  //readProvenance();
126  auto itFound =
128  entryInfoSet_.end(),
129  entryInfo.branchID(),
130  [](auto const& iEntry, edm::BranchID const& iValue) { return iEntry.branchID() < iValue; });
131  if
132  UNLIKELY(itFound == entryInfoSet_.end() or itFound->branchID() != entryInfo.branchID()) {
134  << "ProductProvenanceRetriever::insertIntoSet passed a BranchID " << entryInfo.branchID().id()
135  << " that has not been pre-registered";
136  }
137  itFound->threadsafe_set(entryInfo.moveParentageID());
138  }
139 
140  void ProductProvenanceRetriever::mergeProvenanceRetrievers(std::shared_ptr<ProductProvenanceRetriever> other) {
142  }
143 
145  parentProcessRetriever_ = &provRetriever;
146  }
147 
149  auto itFound = std::lower_bound(
150  entryInfoSet_.begin(), entryInfoSet_.end(), bid, [](auto const& iEntry, edm::BranchID const& iValue) {
151  return iEntry.branchID() < iValue;
152  });
153  if (itFound != entryInfoSet_.end() and itFound->branchID() == bid) {
154  if (auto p = itFound->productProvenance()) {
155  return p;
156  }
157  }
159  return parentProcessRetriever_->branchIDToProvenance(bid);
160  }
161  //check in source
162  readProvenance();
163  auto ptr = readEntryInfoSet_.load();
164  if (ptr) {
165  ProductProvenance ei(bid);
166  auto itRead = ptr->find(ei);
167  if (itRead != ptr->end()) {
168  return &*itRead;
169  }
170  }
171  if (nextRetriever_) {
172  return nextRetriever_->branchIDToProvenance(bid);
173  }
174  return nullptr;
175  }
176 
178  auto itFound = std::lower_bound(
179  entryInfoSet_.begin(), entryInfoSet_.end(), bid, [](auto const& iEntry, edm::BranchID const& iValue) {
180  return iEntry.branchID() < iValue;
181  });
182  if (itFound != entryInfoSet_.end() and itFound->branchID() == bid) {
183  if (auto p = itFound->productProvenance()) {
184  return p;
185  }
186  }
188  return parentProcessRetriever_->branchIDToProvenanceForProducedOnly(bid);
189  }
190  if (nextRetriever_) {
191  return nextRetriever_->branchIDToProvenanceForProducedOnly(bid);
192  }
193  return nullptr;
194  }
195 
197 } // namespace edm
edm::errors::LogicError
Definition: EDMException.h:37
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::max
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:118
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
edm::ProductProvenance::moveParentageID
ParentageID moveParentageID()
Definition: ProductProvenance.h:43
edm::ProductProvenanceRetriever::readEntryInfoSet_
std::atomic< const std::set< ProductProvenance > * > readEntryInfoSet_
Definition: ProductProvenanceRetriever.h:142
cms::cuda::assert
assert(be >=bs)
ProductRegistry.h
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::BranchID::id
unsigned int id() const
Definition: BranchID.h:21
edm::ProductProvenanceRetriever::update
void update(edm::ProductRegistry const &)
Definition: ProductProvenanceRetriever.cc:71
edm::ProductRegistry
Definition: ProductRegistry.h:37
edm::ProductProvenanceRetriever::readProvenanceAsync
void readProvenanceAsync(WaitingTask *task, ModuleCallingContext const *moduleCallingContext) const
Definition: ProductProvenanceRetriever.cc:76
EDMException.h
UNLIKELY
#define UNLIKELY(x)
Definition: Likely.h:21
edm::ProductProvenanceRetriever::insertIntoSet
void insertIntoSet(ProductProvenance provenanceProduct) const
Definition: ProductProvenanceRetriever.cc:121
edm::ProductProvenance
Definition: ProductProvenance.h:24
DQM.reader
reader
Definition: DQM.py:105
edm::ProductProvenanceRetriever::mergeParentProcessRetriever
void mergeParentProcessRetriever(ProductProvenanceRetriever const &provRetriever)
Definition: ProductProvenanceRetriever.cc:144
edm::BranchID
Definition: BranchID.h:14
TrackValidation_cff.task
task
Definition: TrackValidation_cff.py:252
edm::ProductProvenance::branchID
BranchID const & branchID() const
Definition: ProductProvenance.h:38
trackingPlots.other
other
Definition: trackingPlots.py:1467
edm::ProductProvenanceRetriever::reset
void reset()
Definition: ProductProvenanceRetriever.cc:109
edm::InEvent
Definition: BranchType.h:11
edm::ProductProvenanceRetriever::entryInfoSet_
std::vector< ProducedProvenanceInfo > entryInfoSet_
Definition: ProductProvenanceRetriever.h:141
b
double b
Definition: hdecay.h:118
edm::ProductProvenanceRetriever::~ProductProvenanceRetriever
~ProductProvenanceRetriever()
Definition: ProductProvenanceRetriever.cc:43
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
edm::ProductProvenanceRetriever::mergeProvenanceRetrievers
void mergeProvenanceRetrievers(std::shared_ptr< ProductProvenanceRetriever > other)
Definition: ProductProvenanceRetriever.cc:140
edm::ProductProvenanceRetriever::readProvenance
void readProvenance() const
Definition: ProductProvenanceRetriever.cc:45
fetchall_from_DQM_v2.release
release
Definition: fetchall_from_DQM_v2.py:92
edm::ProductProvenanceRetriever::setupEntryInfoSet
void setupEntryInfoSet(edm::ProductRegistry const &)
Definition: ProductProvenanceRetriever.cc:56
createfilelist.int
int
Definition: createfilelist.py:10
edm::ProvenanceReaderBase::~ProvenanceReaderBase
virtual ~ProvenanceReaderBase()
Definition: ProductProvenanceRetriever.cc:196
ProductProvenanceRetriever.h
edm::ProductProvenanceRetriever::deepCopy
void deepCopy(ProductProvenanceRetriever const &)
Definition: ProductProvenanceRetriever.cc:86
edm::ProductProvenanceRetriever
Definition: ProductProvenanceRetriever.h:56
edm::ProductProvenanceRetriever::nextRetriever_
edm::propagate_const< std::shared_ptr< ProductProvenanceRetriever > > nextRetriever_
Definition: ProductProvenanceRetriever.h:143
edm::WaitingTask
Definition: WaitingTask.h:36
std
Definition: JetResolutionObject.h:76
edm::ProductRegistry::productList
ProductList const & productList() const
Definition: ProductRegistry.h:76
Exception
Definition: hltDiff.cc:246
edm::ProductProvenanceRetriever::branchIDToProvenance
ProductProvenance const * branchIDToProvenance(BranchID const &bid) const
Definition: ProductProvenanceRetriever.cc:148
edm::ProductProvenanceRetriever::transitionIndex_
unsigned int transitionIndex_
Definition: ProductProvenanceRetriever.h:146
edm::ProductProvenanceRetriever::branchIDToProvenanceForProducedOnly
ProductProvenance const * branchIDToProvenanceForProducedOnly(BranchID const &bid) const
Definition: ProductProvenanceRetriever.cc:177
or
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
edm::ProductProvenanceRetriever::ProductProvenanceRetriever
ProductProvenanceRetriever(unsigned int iTransitionIndex)
Definition: ProductProvenanceRetriever.cc:14
edm::ProductProvenanceRetriever::provenanceReader_
std::shared_ptr< const ProvenanceReaderBase > provenanceReader_
Definition: ProductProvenanceRetriever.h:145
edm::ProductProvenanceRetriever::parentProcessRetriever_
edm::propagate_const< ProductProvenanceRetriever const * > parentProcessRetriever_
Definition: ProductProvenanceRetriever.h:144
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::ModuleCallingContext
Definition: ModuleCallingContext.h:29