File indexing completed on 2024-04-06 12:12:13
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
0009 #include <cassert>
0010
0011 namespace edm {
0012
0013 PrincipalCache::PrincipalCache() {}
0014
0015 PrincipalCache::~PrincipalCache() {}
0016
0017 std::shared_ptr<RunPrincipal> PrincipalCache::getAvailableRunPrincipalPtr() { return runHolder_.tryToGet(); }
0018
0019 std::shared_ptr<LuminosityBlockPrincipal> PrincipalCache::getAvailableLumiPrincipalPtr() {
0020 return lumiHolder_.tryToGet();
0021 }
0022
0023 void PrincipalCache::setNumberOfConcurrentPrincipals(PreallocationConfiguration const& iConfig) {
0024 eventPrincipals_.resize(iConfig.numberOfStreams());
0025 }
0026
0027 void PrincipalCache::insert(std::unique_ptr<ProcessBlockPrincipal> pb) { processBlockPrincipal_ = std::move(pb); }
0028
0029 void PrincipalCache::insertForInput(std::unique_ptr<ProcessBlockPrincipal> pb) {
0030 inputProcessBlockPrincipal_ = std::move(pb);
0031 }
0032
0033 void PrincipalCache::insert(std::unique_ptr<RunPrincipal> rp) { runHolder_.add(std::move(rp)); }
0034
0035 void PrincipalCache::insert(std::unique_ptr<LuminosityBlockPrincipal> lbp) { lumiHolder_.add(std::move(lbp)); }
0036
0037 void PrincipalCache::insert(std::shared_ptr<EventPrincipal> ep) {
0038 unsigned int iStreamIndex = ep->streamID().value();
0039 assert(iStreamIndex < eventPrincipals_.size());
0040 eventPrincipals_[iStreamIndex] = ep;
0041 }
0042
0043 void PrincipalCache::adjustEventsToNewProductRegistry(std::shared_ptr<ProductRegistry const> reg) {
0044 for (auto& eventPrincipal : eventPrincipals_) {
0045 if (eventPrincipal) {
0046 eventPrincipal->adjustIndexesAfterProductRegistryAddition();
0047 bool eventOK = eventPrincipal->adjustToNewProductRegistry(*reg);
0048 assert(eventOK);
0049 }
0050 }
0051 }
0052
0053 void PrincipalCache::adjustIndexesAfterProductRegistryAddition() {
0054
0055 std::vector<std::shared_ptr<RunPrincipal>> tempRunPrincipals;
0056 while (auto p = runHolder_.tryToGet()) {
0057 p->adjustIndexesAfterProductRegistryAddition();
0058 tempRunPrincipals.emplace_back(std::move(p));
0059 }
0060
0061 std::vector<std::shared_ptr<LuminosityBlockPrincipal>> tempLumiPrincipals;
0062 while (auto p = lumiHolder_.tryToGet()) {
0063 p->adjustIndexesAfterProductRegistryAddition();
0064 tempLumiPrincipals.emplace_back(std::move(p));
0065 }
0066 }
0067
0068 }