Go to the documentation of this file.00001 #include "FWCore/Framework/src/PrincipalCache.h"
00002
00003 #include "FWCore/Framework/interface/EventPrincipal.h"
00004 #include "FWCore/Framework/interface/LuminosityBlockPrincipal.h"
00005 #include "FWCore/Framework/interface/RunPrincipal.h"
00006 #include "FWCore/Utilities/interface/EDMException.h"
00007 #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"
00008
00009 namespace edm {
00010
00011 PrincipalCache::PrincipalCache() :
00012 run_(0U),
00013 lumi_(0U) {
00014 }
00015
00016 PrincipalCache::~PrincipalCache() { }
00017
00018 RunPrincipal&
00019 PrincipalCache::runPrincipal(ProcessHistoryID const& phid, RunNumber_t run) const {
00020 if (phid != reducedInputProcessHistoryID_ ||
00021 run != run_ ||
00022 runPrincipal_.get() == 0) {
00023 throwRunMissing();
00024 }
00025 return *runPrincipal_.get();
00026 }
00027
00028 boost::shared_ptr<RunPrincipal> const&
00029 PrincipalCache::runPrincipalPtr(ProcessHistoryID const& phid, RunNumber_t run) const {
00030 if (phid != reducedInputProcessHistoryID_ ||
00031 run != run_ ||
00032 runPrincipal_.get() == 0) {
00033 throwRunMissing();
00034 }
00035 return runPrincipal_;
00036 }
00037
00038 RunPrincipal&
00039 PrincipalCache::runPrincipal() const {
00040 if (runPrincipal_.get() == 0) {
00041 throwRunMissing();
00042 }
00043 return *runPrincipal_.get();
00044 }
00045
00046 boost::shared_ptr<RunPrincipal> const&
00047 PrincipalCache::runPrincipalPtr() const {
00048 if (runPrincipal_.get() == 0) {
00049 throwRunMissing();
00050 }
00051 return runPrincipal_;
00052 }
00053
00054 LuminosityBlockPrincipal&
00055 PrincipalCache::lumiPrincipal(ProcessHistoryID const& phid, RunNumber_t run, LuminosityBlockNumber_t lumi) const {
00056 if (phid != reducedInputProcessHistoryID_ ||
00057 run != run_ ||
00058 lumi != lumi_ ||
00059 lumiPrincipal_.get() == 0) {
00060 throwLumiMissing();
00061 }
00062 return *lumiPrincipal_.get();
00063 }
00064
00065 boost::shared_ptr<LuminosityBlockPrincipal> const&
00066 PrincipalCache::lumiPrincipalPtr(ProcessHistoryID const& phid, RunNumber_t run, LuminosityBlockNumber_t lumi) const {
00067 if (phid != reducedInputProcessHistoryID_ ||
00068 run != run_ ||
00069 lumi != lumi_ ||
00070 lumiPrincipal_.get() == 0) {
00071 throwLumiMissing();
00072 }
00073 return lumiPrincipal_;
00074 }
00075
00076 LuminosityBlockPrincipal&
00077 PrincipalCache::lumiPrincipal() const {
00078 if (lumiPrincipal_.get() == 0) {
00079 throwLumiMissing();
00080 }
00081 return *lumiPrincipal_.get();
00082 }
00083
00084 boost::shared_ptr<LuminosityBlockPrincipal> const&
00085 PrincipalCache::lumiPrincipalPtr() const {
00086 if (lumiPrincipal_.get() == 0) {
00087 throwLumiMissing();
00088 }
00089 return lumiPrincipal_;
00090 }
00091
00092 void PrincipalCache::merge(boost::shared_ptr<RunAuxiliary> aux, boost::shared_ptr<ProductRegistry const> reg) {
00093 if (runPrincipal_.get() == 0) {
00094 throw edm::Exception(edm::errors::LogicError)
00095 << "PrincipalCache::merge\n"
00096 << "Illegal attempt to merge run into cache\n"
00097 << "There is no run in cache to merge with\n"
00098 << "Contact a Framework Developer\n";
00099 }
00100 if (inputProcessHistoryID_ != aux->processHistoryID()) {
00101 if (reducedInputProcessHistoryID_ != ProcessHistoryRegistry::instance()->extra().reduceProcessHistoryID(aux->processHistoryID())) {
00102 throw edm::Exception(edm::errors::LogicError)
00103 << "PrincipalCache::insert\n"
00104 << "Illegal attempt to merge run into cache\n"
00105 << "Reduced ProcessHistoryID inconsistent with the one already in cache\n"
00106 << "Contact a Framework Developer\n";
00107 }
00108 inputProcessHistoryID_ = aux->processHistoryID();
00109 }
00110 if (aux->run() != run_) {
00111 throw edm::Exception(edm::errors::LogicError)
00112 << "PrincipalCache::insert\n"
00113 << "Illegal attempt to merge run into cache\n"
00114 << "Run number inconsistent with run number already in cache\n"
00115 << "Contact a Framework Developer\n";
00116 }
00117 bool runOK = runPrincipal_->adjustToNewProductRegistry(*reg);
00118 assert(runOK);
00119 runPrincipal_->mergeAuxiliary(*aux);
00120 }
00121
00122 void PrincipalCache::merge(boost::shared_ptr<LuminosityBlockAuxiliary> aux, boost::shared_ptr<ProductRegistry const> reg) {
00123 if (lumiPrincipal_.get() == 0) {
00124 throw edm::Exception(edm::errors::LogicError)
00125 << "PrincipalCache::merge\n"
00126 << "Illegal attempt to merge luminosity block into cache\n"
00127 << "There is no luminosity block in the cache to merge with\n"
00128 << "Contact a Framework Developer\n";
00129 }
00130 if (inputProcessHistoryID_ != aux->processHistoryID()) {
00131 if (reducedInputProcessHistoryID_ != ProcessHistoryRegistry::instance()->extra().reduceProcessHistoryID(aux->processHistoryID())) {
00132 throw edm::Exception(edm::errors::LogicError)
00133 << "PrincipalCache::insert\n"
00134 << "Illegal attempt to merge run into cache\n"
00135 << "Reduced ProcessHistoryID inconsistent with the one already in cache\n"
00136 << "Contact a Framework Developer\n";
00137 }
00138 inputProcessHistoryID_ = aux->processHistoryID();
00139 }
00140 if (aux->run() != run_ ||
00141 aux->luminosityBlock() != lumi_) {
00142 throw edm::Exception(edm::errors::LogicError)
00143 << "PrincipalCache::insert\n"
00144 << "Illegal attempt to merge lumi into cache\n"
00145 << "Run and lumi numbers are inconsistent with the ones already in the cache\n"
00146 << "Contact a Framework Developer\n";
00147 }
00148 bool lumiOK = lumiPrincipal_->adjustToNewProductRegistry(*reg);
00149 assert(lumiOK);
00150 lumiPrincipal_->mergeAuxiliary(*aux);
00151 }
00152
00153 void PrincipalCache::insert(boost::shared_ptr<RunPrincipal> rp) {
00154 if (runPrincipal_.get() != 0) {
00155 throw edm::Exception(edm::errors::LogicError)
00156 << "PrincipalCache::insert\n"
00157 << "Illegal attempt to insert run into cache\n"
00158 << "Contact a Framework Developer\n";
00159 }
00160 if (inputProcessHistoryID_ != rp->aux().processHistoryID()) {
00161 reducedInputProcessHistoryID_ = ProcessHistoryRegistry::instance()->extra().reduceProcessHistoryID(rp->aux().processHistoryID());
00162 inputProcessHistoryID_ = rp->aux().processHistoryID();
00163 }
00164 run_ = rp->run();
00165 runPrincipal_ = rp;
00166 }
00167
00168 void PrincipalCache::insert(boost::shared_ptr<LuminosityBlockPrincipal> lbp) {
00169 if (lumiPrincipal_.get() != 0) {
00170 throw edm::Exception(edm::errors::LogicError)
00171 << "PrincipalCache::insert\n"
00172 << "Illegal attempt to insert lumi into cache\n"
00173 << "Contact a Framework Developer\n";
00174 }
00175 if (runPrincipal_.get() == 0) {
00176 throw edm::Exception(edm::errors::LogicError)
00177 << "PrincipalCache::insert\n"
00178 << "Illegal attempt to insert lumi into cache\n"
00179 << "Run is invalid\n"
00180 << "Contact a Framework Developer\n";
00181 }
00182 if (inputProcessHistoryID_ != lbp->aux().processHistoryID()) {
00183 if (reducedInputProcessHistoryID_ != ProcessHistoryRegistry::instance()->extra().reduceProcessHistoryID(lbp->aux().processHistoryID())) {
00184 throw edm::Exception(edm::errors::LogicError)
00185 << "PrincipalCache::insert\n"
00186 << "Illegal attempt to insert lumi into cache\n"
00187 << "luminosity block has ProcessHistoryID inconsistent with run\n"
00188 << "Contact a Framework Developer\n";
00189 }
00190 inputProcessHistoryID_ = lbp->aux().processHistoryID();
00191 }
00192 if (lbp->run() != run_) {
00193 throw edm::Exception(edm::errors::LogicError)
00194 << "PrincipalCache::insert\n"
00195 << "Illegal attempt to insert lumi into cache\n"
00196 << "luminosity block inconsistent with run number of run in cache\n"
00197 << "Contact a Framework Developer\n";
00198 }
00199 lumi_ = lbp->luminosityBlock();
00200 lumiPrincipal_ = lbp;
00201 }
00202
00203 void PrincipalCache::deleteRun(ProcessHistoryID const& phid, RunNumber_t run) {
00204 if (runPrincipal_.get() == 0) {
00205 throw edm::Exception(edm::errors::LogicError)
00206 << "PrincipalCache::deleteRun\n"
00207 << "Illegal attempt to delete run from cache\n"
00208 << "There is no run in cache to delete\n"
00209 << "Contact a Framework Developer\n";
00210 }
00211 if (reducedInputProcessHistoryID_ != phid ||
00212 run != run_) {
00213 throw edm::Exception(edm::errors::LogicError)
00214 << "PrincipalCache::deleteRun\n"
00215 << "Illegal attempt to delete run from cache\n"
00216 << "Run number or reduced ProcessHistoryID inconsistent with those in cache\n"
00217 << "Contact a Framework Developer\n";
00218 }
00219 runPrincipal_.reset();
00220 }
00221
00222 void PrincipalCache::deleteLumi(ProcessHistoryID const& phid, RunNumber_t run, LuminosityBlockNumber_t lumi) {
00223 if (lumiPrincipal_.get() == 0) {
00224 throw edm::Exception(edm::errors::LogicError)
00225 << "PrincipalCache::deleteLumi\n"
00226 << "Illegal attempt to delete luminosity block from cache\n"
00227 << "There is no luminosity block in the cache to delete\n"
00228 << "Contact a Framework Developer\n";
00229 }
00230 if (reducedInputProcessHistoryID_ != phid ||
00231 run != run_ ||
00232 lumi != lumi_) {
00233 throw edm::Exception(edm::errors::LogicError)
00234 << "PrincipalCache::deleteLumi\n"
00235 << "Illegal attempt to delete luminosity block from cache\n"
00236 << "Run number, lumi numbers, or reduced ProcessHistoryID inconsistent with those in cache\n"
00237 << "Contact a Framework Developer\n";
00238 }
00239 lumiPrincipal_.reset();
00240 }
00241
00242 void PrincipalCache::adjustEventToNewProductRegistry(boost::shared_ptr<ProductRegistry const> reg) {
00243 if (eventPrincipal_) {
00244 eventPrincipal_->adjustIndexesAfterProductRegistryAddition();
00245 bool eventOK = eventPrincipal_->adjustToNewProductRegistry(*reg);
00246 assert(eventOK);
00247 }
00248 }
00249
00250 void PrincipalCache::adjustIndexesAfterProductRegistryAddition() {
00251 if (runPrincipal_) {
00252 runPrincipal_->adjustIndexesAfterProductRegistryAddition();
00253 }
00254 if (lumiPrincipal_) {
00255 lumiPrincipal_->adjustIndexesAfterProductRegistryAddition();
00256 }
00257 }
00258
00259 void
00260 PrincipalCache::throwRunMissing() const {
00261 throw edm::Exception(edm::errors::LogicError)
00262 << "PrincipalCache::runPrincipal\n"
00263 << "Requested a run that is not in the cache (should never happen)\n"
00264 << "Contact a Framework Developer\n";
00265 }
00266
00267 void
00268 PrincipalCache::throwLumiMissing() const {
00269 throw edm::Exception(edm::errors::LogicError)
00270 << "PrincipalCache::lumiPrincipal or PrincipalCache::lumiPrincipalPtr\n"
00271 << "Requested a luminosity block that is not in the cache (should never happen)\n"
00272 << "Contact a Framework Developer\n";
00273 }
00274 }