Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-13 23:27:10

0001 #include "FWCore/Framework/interface/PrincipalCache.h"
0002 
0003 #include "FWCore/Framework/interface/EventPrincipal.h"
0004 #include "FWCore/Framework/interface/LuminosityBlockPrincipal.h"
0005 #include "FWCore/Framework/interface/ProcessBlockPrincipal.h"
0006 #include "FWCore/Framework/interface/RunPrincipal.h"
0007 #include "FWCore/Framework/interface/PreallocationConfiguration.h"
0008 #include "FWCore/Utilities/interface/EDMException.h"
0009 #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"
0010 
0011 namespace edm {
0012 
0013   PrincipalCache::PrincipalCache() : run_(0U), lumi_(0U) {}
0014 
0015   PrincipalCache::~PrincipalCache() {}
0016 
0017   void PrincipalCache::setNumberOfConcurrentPrincipals(PreallocationConfiguration const& iConfig) {
0018     eventPrincipals_.resize(iConfig.numberOfStreams());
0019   }
0020 
0021   RunPrincipal& PrincipalCache::runPrincipal(ProcessHistoryID const& phid, RunNumber_t run) const {
0022     if (phid != reducedInputProcessHistoryID_ || run != run_ || runPrincipal_.get() == nullptr) {
0023       throwRunMissing();
0024     }
0025     return *runPrincipal_.get();
0026   }
0027 
0028   std::shared_ptr<RunPrincipal> const& PrincipalCache::runPrincipalPtr(ProcessHistoryID const& phid,
0029                                                                        RunNumber_t run) const {
0030     if (phid != reducedInputProcessHistoryID_ || run != run_ || runPrincipal_.get() == nullptr) {
0031       throwRunMissing();
0032     }
0033     return runPrincipal_;
0034   }
0035 
0036   RunPrincipal& PrincipalCache::runPrincipal() const {
0037     if (runPrincipal_.get() == nullptr) {
0038       throwRunMissing();
0039     }
0040     return *runPrincipal_.get();
0041   }
0042 
0043   std::shared_ptr<RunPrincipal> const& PrincipalCache::runPrincipalPtr() const {
0044     if (runPrincipal_.get() == nullptr) {
0045       throwRunMissing();
0046     }
0047     return runPrincipal_;
0048   }
0049 
0050   std::shared_ptr<LuminosityBlockPrincipal> PrincipalCache::getAvailableLumiPrincipalPtr() {
0051     return lumiHolder_.tryToGet();
0052   }
0053 
0054   void PrincipalCache::merge(std::shared_ptr<RunAuxiliary> aux, std::shared_ptr<ProductRegistry const> reg) {
0055     if (runPrincipal_.get() == nullptr) {
0056       throw edm::Exception(edm::errors::LogicError) << "PrincipalCache::merge\n"
0057                                                     << "Illegal attempt to merge run into cache\n"
0058                                                     << "There is no run in cache to merge with\n"
0059                                                     << "Contact a Framework Developer\n";
0060     }
0061     if (inputProcessHistoryID_ != aux->processHistoryID()) {
0062       if (reducedInputProcessHistoryID_ != processHistoryRegistry_->reducedProcessHistoryID(aux->processHistoryID())) {
0063         throw edm::Exception(edm::errors::LogicError)
0064             << "PrincipalCache::merge\n"
0065             << "Illegal attempt to merge run into cache\n"
0066             << "Reduced ProcessHistoryID inconsistent with the one already in cache\n"
0067             << "Contact a Framework Developer\n";
0068       }
0069       inputProcessHistoryID_ = aux->processHistoryID();
0070     }
0071     if (aux->run() != run_) {
0072       throw edm::Exception(edm::errors::LogicError) << "PrincipalCache::merge\n"
0073                                                     << "Illegal attempt to merge run into cache\n"
0074                                                     << "Run number inconsistent with run number already in cache\n"
0075                                                     << "Contact a Framework Developer\n";
0076     }
0077     bool runOK = runPrincipal_->adjustToNewProductRegistry(*reg);
0078     assert(runOK);
0079     runPrincipal_->mergeAuxiliary(*aux);
0080   }
0081 
0082   void PrincipalCache::insert(std::shared_ptr<RunPrincipal> rp) {
0083     if (runPrincipal_.get() != nullptr) {
0084       throw edm::Exception(edm::errors::LogicError) << "PrincipalCache::insert\n"
0085                                                     << "Illegal attempt to insert run into cache\n"
0086                                                     << "Contact a Framework Developer\n";
0087     }
0088     if (inputProcessHistoryID_ != rp->aux().processHistoryID()) {
0089       reducedInputProcessHistoryID_ = processHistoryRegistry_->reducedProcessHistoryID(rp->aux().processHistoryID());
0090       inputProcessHistoryID_ = rp->aux().processHistoryID();
0091     }
0092     run_ = rp->run();
0093     runPrincipal_ = rp;
0094   }
0095 
0096   void PrincipalCache::insert(std::unique_ptr<ProcessBlockPrincipal> pb) { processBlockPrincipal_ = std::move(pb); }
0097 
0098   void PrincipalCache::insertForInput(std::unique_ptr<ProcessBlockPrincipal> pb) {
0099     inputProcessBlockPrincipal_ = std::move(pb);
0100   }
0101 
0102   void PrincipalCache::insert(std::unique_ptr<LuminosityBlockPrincipal> lbp) { lumiHolder_.add(std::move(lbp)); }
0103 
0104   void PrincipalCache::insert(std::shared_ptr<EventPrincipal> ep) {
0105     unsigned int iStreamIndex = ep->streamID().value();
0106     assert(iStreamIndex < eventPrincipals_.size());
0107     eventPrincipals_[iStreamIndex] = ep;
0108   }
0109 
0110   void PrincipalCache::deleteRun(ProcessHistoryID const& phid, RunNumber_t run) {
0111     if (runPrincipal_.get() == nullptr) {
0112       throw edm::Exception(edm::errors::LogicError) << "PrincipalCache::deleteRun\n"
0113                                                     << "Illegal attempt to delete run from cache\n"
0114                                                     << "There is no run in cache to delete\n"
0115                                                     << "Contact a Framework Developer\n";
0116     }
0117     if (reducedInputProcessHistoryID_ != phid || run != run_) {
0118       throw edm::Exception(edm::errors::LogicError)
0119           << "PrincipalCache::deleteRun\n"
0120           << "Illegal attempt to delete run from cache\n"
0121           << "Run number or reduced ProcessHistoryID inconsistent with those in cache\n"
0122           << "Contact a Framework Developer\n";
0123     }
0124     runPrincipal_.reset();
0125   }
0126 
0127   void PrincipalCache::adjustEventsToNewProductRegistry(std::shared_ptr<ProductRegistry const> reg) {
0128     for (auto& eventPrincipal : eventPrincipals_) {
0129       if (eventPrincipal) {
0130         eventPrincipal->adjustIndexesAfterProductRegistryAddition();
0131         bool eventOK = eventPrincipal->adjustToNewProductRegistry(*reg);
0132         assert(eventOK);
0133       }
0134     }
0135   }
0136 
0137   void PrincipalCache::adjustIndexesAfterProductRegistryAddition() {
0138     if (runPrincipal_) {
0139       runPrincipal_->adjustIndexesAfterProductRegistryAddition();
0140     }
0141     //Need to temporarily hold all the lumis to clear out the lumiHolder_
0142     std::vector<std::shared_ptr<LuminosityBlockPrincipal>> temp;
0143     while (auto p = lumiHolder_.tryToGet()) {
0144       p->adjustIndexesAfterProductRegistryAddition();
0145       temp.emplace_back(std::move(p));
0146     }
0147   }
0148 
0149   void PrincipalCache::preReadFile() {
0150     if (runPrincipal_) {
0151       runPrincipal_->preReadFile();
0152     }
0153   }
0154 
0155   void PrincipalCache::throwRunMissing() const {
0156     throw edm::Exception(edm::errors::LogicError) << "PrincipalCache::runPrincipal\n"
0157                                                   << "Requested a run that is not in the cache (should never happen)\n"
0158                                                   << "Contact a Framework Developer\n";
0159   }
0160 
0161   void PrincipalCache::throwLumiMissing() const {
0162     throw edm::Exception(edm::errors::LogicError)
0163         << "PrincipalCache::lumiPrincipal or PrincipalCache::lumiPrincipalPtr\n"
0164         << "Requested a luminosity block that is not in the cache (should never happen)\n"
0165         << "Contact a Framework Developer\n";
0166   }
0167 }  // namespace edm