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 UNLIKELY (itFound == entryInfoSet_.end() or itFound->branchID() != entryInfo.branchID()) {
132  throw edm::Exception(edm::errors::LogicError) << "ProductProvenanceRetriever::insertIntoSet passed a BranchID "
133  << entryInfo.branchID().id() << " that has not been pre-registered";
134  }
135  itFound->threadsafe_set(entryInfo.moveParentageID());
136  }
137 
138  void ProductProvenanceRetriever::mergeProvenanceRetrievers(std::shared_ptr<ProductProvenanceRetriever> other) {
140  }
141 
143  parentProcessRetriever_ = &provRetriever;
144  }
145 
147  auto itFound = std::lower_bound(
148  entryInfoSet_.begin(), entryInfoSet_.end(), bid, [](auto const& iEntry, edm::BranchID const& iValue) {
149  return iEntry.branchID() < iValue;
150  });
151  if (itFound != entryInfoSet_.end() and itFound->branchID() == bid) {
152  if (auto p = itFound->productProvenance()) {
153  return p;
154  }
155  }
157  return parentProcessRetriever_->branchIDToProvenance(bid);
158  }
159  //check in source
160  readProvenance();
161  auto ptr = readEntryInfoSet_.load();
162  if (ptr) {
163  ProductProvenance ei(bid);
164  auto itRead = ptr->find(ei);
165  if (itRead != ptr->end()) {
166  return &*itRead;
167  }
168  }
169  if (nextRetriever_) {
170  return nextRetriever_->branchIDToProvenance(bid);
171  }
172  return nullptr;
173  }
174 
176  auto itFound = std::lower_bound(
177  entryInfoSet_.begin(), entryInfoSet_.end(), bid, [](auto const& iEntry, edm::BranchID const& iValue) {
178  return iEntry.branchID() < iValue;
179  });
180  if (itFound != entryInfoSet_.end() and itFound->branchID() == bid) {
181  if (auto p = itFound->productProvenance()) {
182  return p;
183  }
184  }
186  return parentProcessRetriever_->branchIDToProvenanceForProducedOnly(bid);
187  }
188  if (nextRetriever_) {
189  return nextRetriever_->branchIDToProvenanceForProducedOnly(bid);
190  }
191  return nullptr;
192  }
193 
195 } // namespace edm
edm::errors::LogicError
Definition: EDMException.h:37
edm::ProductProvenanceRetriever::readProvenanceAsync
void readProvenanceAsync(WaitingTaskHolder task, ModuleCallingContext const *moduleCallingContext) const
Definition: ProductProvenanceRetriever.cc:76
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
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:142
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:1460
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:138
edm::ProductProvenanceRetriever::readProvenance
void readProvenance() const
Definition: ProductProvenanceRetriever.cc:45
fetchall_from_DQM_v2.release
release
Definition: fetchall_from_DQM_v2.py:92
edm::WaitingTaskHolder
Definition: WaitingTaskHolder.h:32
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:194
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
std
Definition: JetResolutionObject.h:76
edm::ProductRegistry::productList
ProductList const & productList() const
Definition: ProductRegistry.h:76
Exception
Definition: hltDiff.cc:245
edm::ProductProvenanceRetriever::branchIDToProvenance
ProductProvenance const * branchIDToProvenance(BranchID const &bid) const
Definition: ProductProvenanceRetriever.cc:146
edm::ProductProvenanceRetriever::transitionIndex_
unsigned int transitionIndex_
Definition: ProductProvenanceRetriever.h:146
edm::ProductProvenanceRetriever::branchIDToProvenanceForProducedOnly
ProductProvenance const * branchIDToProvenanceForProducedOnly(BranchID const &bid) const
Definition: ProductProvenanceRetriever.cc:175
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