Go to the documentation of this file.00001 #include "FWCore/Framework/src/PrincipalCache.h"
00002 #include "FWCore/Framework/interface/EventPrincipal.h"
00003 #include "FWCore/Framework/interface/LuminosityBlockPrincipal.h"
00004 #include "FWCore/Framework/interface/RunPrincipal.h"
00005 #include "FWCore/Utilities/interface/EDMException.h"
00006
00007 namespace edm {
00008
00009 PrincipalCache::PrincipalCache() { }
00010
00011 PrincipalCache::~PrincipalCache() { }
00012
00013 RunPrincipal & PrincipalCache::runPrincipal(ProcessHistoryID const& phid, int run) {
00014 std::map<ProcessHistoryID, int>::const_iterator iphid = processHistoryIDsMap_.find(phid);
00015 RunIterator iter;
00016 if (iphid != processHistoryIDsMap_.end()) {
00017 RunKey key(iphid->second, run);
00018 iter = runPrincipals_.find(key);
00019 }
00020 if (iphid == processHistoryIDsMap_.end() || iter == runPrincipals_.end()) {
00021 throw edm::Exception(edm::errors::LogicError)
00022 << "PrincipalCache::runPrincipal\n"
00023 << "Requested a run that is not in the cache (should never happen)\n"
00024 << "Contact a Framework Developer\n";
00025 }
00026 return *iter->second.get();
00027 }
00028
00029 RunPrincipal const& PrincipalCache::runPrincipal(ProcessHistoryID const& phid, int run) const {
00030 std::map<ProcessHistoryID, int>::const_iterator iphid = processHistoryIDsMap_.find(phid);
00031 ConstRunIterator iter;
00032 if (iphid != processHistoryIDsMap_.end()) {
00033 RunKey key(iphid->second, run);
00034 iter = runPrincipals_.find(key);
00035 }
00036 if (iphid == processHistoryIDsMap_.end() || iter == runPrincipals_.end()) {
00037 throw edm::Exception(edm::errors::LogicError)
00038 << "PrincipalCache::runPrincipal\n"
00039 << "Requested a run that is not in the cache (should never happen)\n"
00040 << "Contact a Framework Developer\n";
00041 }
00042 return *iter->second.get();
00043 }
00044
00045 boost::shared_ptr<RunPrincipal> PrincipalCache::runPrincipalPtr(ProcessHistoryID const& phid, int run) {
00046 std::map<ProcessHistoryID, int>::const_iterator iphid = processHistoryIDsMap_.find(phid);
00047 RunIterator iter;
00048 if (iphid != processHistoryIDsMap_.end()) {
00049 RunKey key(iphid->second, run);
00050 iter = runPrincipals_.find(key);
00051 }
00052 if (iphid == processHistoryIDsMap_.end() || iter == runPrincipals_.end()) {
00053 throw edm::Exception(edm::errors::LogicError)
00054 << "PrincipalCache::runPrincipalPtr\n"
00055 << "Requested a run that is not in the cache (should never happen)\n"
00056 << "Contact a Framework Developer\n";
00057 }
00058 return iter->second;
00059 }
00060
00061 RunPrincipal & PrincipalCache::runPrincipal() {
00062 if (currentRunPrincipal_.get() == 0) {
00063 throw edm::Exception(edm::errors::LogicError)
00064 << "PrincipalCache::runPrincipal\n"
00065 << "Requested current run and it is not initialized (should never happen)\n"
00066 << "Contact a Framework Developer\n";
00067 }
00068 return *currentRunPrincipal_.get();
00069 }
00070
00071 RunPrincipal const& PrincipalCache::runPrincipal() const {
00072 if (currentRunPrincipal_.get() == 0) {
00073 throw edm::Exception(edm::errors::LogicError)
00074 << "PrincipalCache::runPrincipal\n"
00075 << "Requested current run and it is not initialized (should never happen)\n"
00076 << "Contact a Framework Developer\n";
00077 }
00078 return *currentRunPrincipal_.get();
00079 }
00080
00081 boost::shared_ptr<RunPrincipal> PrincipalCache::runPrincipalPtr() {
00082 if (currentRunPrincipal_.get() == 0) {
00083 throw edm::Exception(edm::errors::LogicError)
00084 << "PrincipalCache::runPrincipalPtr\n"
00085 << "Requested current run and it is not initialized (should never happen)\n"
00086 << "Contact a Framework Developer\n";
00087 }
00088 return currentRunPrincipal_;
00089 }
00090
00091 LuminosityBlockPrincipal & PrincipalCache::lumiPrincipal(ProcessHistoryID const& phid, int run, int lumi) {
00092 std::map<ProcessHistoryID, int>::const_iterator iphid = processHistoryIDsMap_.find(phid);
00093 LumiIterator iter;
00094 if (iphid != processHistoryIDsMap_.end()) {
00095 LumiKey key(iphid->second, run, lumi);
00096 iter = lumiPrincipals_.find(key);
00097 }
00098 if (iphid == processHistoryIDsMap_.end() || iter == lumiPrincipals_.end()) {
00099 throw edm::Exception(edm::errors::LogicError)
00100 << "PrincipalCache::lumiPrincipal\n"
00101 << "Requested a lumi that is not in the cache (should never happen)\n"
00102 << "Contact a Framework Developer\n";
00103 }
00104 return *iter->second.get();
00105 }
00106
00107 LuminosityBlockPrincipal const& PrincipalCache::lumiPrincipal(ProcessHistoryID const& phid, int run, int lumi) const {
00108 std::map<ProcessHistoryID, int>::const_iterator iphid = processHistoryIDsMap_.find(phid);
00109 ConstLumiIterator iter;
00110 if (iphid != processHistoryIDsMap_.end()) {
00111 LumiKey key(iphid->second, run, lumi);
00112 iter = lumiPrincipals_.find(key);
00113 }
00114 if (iphid == processHistoryIDsMap_.end() || iter == lumiPrincipals_.end()) {
00115 throw edm::Exception(edm::errors::LogicError)
00116 << "PrincipalCache::lumiPrincipal\n"
00117 << "Requested a lumi that is not in the cache (should never happen)\n"
00118 << "Contact a Framework Developer\n";
00119 }
00120 return *iter->second.get();
00121 }
00122
00123 boost::shared_ptr<LuminosityBlockPrincipal> PrincipalCache::lumiPrincipalPtr(ProcessHistoryID const& phid, int run, int lumi) {
00124 std::map<ProcessHistoryID, int>::const_iterator iphid = processHistoryIDsMap_.find(phid);
00125 LumiIterator iter;
00126 if (iphid != processHistoryIDsMap_.end()) {
00127 LumiKey key(iphid->second, run, lumi);
00128 iter = lumiPrincipals_.find(key);
00129 }
00130 if (iphid == processHistoryIDsMap_.end() || iter == lumiPrincipals_.end()) {
00131 throw edm::Exception(edm::errors::LogicError)
00132 << "PrincipalCache::lumiPrincipalPtr\n"
00133 << "Requested a lumi that is not in the cache (should never happen)\n"
00134 << "Contact a Framework Developer\n";
00135 }
00136 return iter->second;
00137 }
00138
00139 LuminosityBlockPrincipal & PrincipalCache::lumiPrincipal() {
00140 if (currentLumiPrincipal_.get() == 0) {
00141 throw edm::Exception(edm::errors::LogicError)
00142 << "PrincipalCache::lumiPrincipal\n"
00143 << "Requested current lumi and it is not initialized (should never happen)\n"
00144 << "Contact a Framework Developer\n";
00145 }
00146 return *currentLumiPrincipal_.get();
00147 }
00148
00149 LuminosityBlockPrincipal const& PrincipalCache::lumiPrincipal() const {
00150 if (currentLumiPrincipal_.get() == 0) {
00151 throw edm::Exception(edm::errors::LogicError)
00152 << "PrincipalCache::lumiPrincipal\n"
00153 << "Requested current lumi and it is not initialized (should never happen)\n"
00154 << "Contact a Framework Developer\n";
00155 }
00156 return *currentLumiPrincipal_.get();
00157 }
00158
00159 boost::shared_ptr<LuminosityBlockPrincipal> PrincipalCache::lumiPrincipalPtr() {
00160 if (currentLumiPrincipal_.get() == 0) {
00161 throw edm::Exception(edm::errors::LogicError)
00162 << "PrincipalCache::lumiPrincipalPtr\n"
00163 << "Requested current lumi and it is not initialized (should never happen)\n"
00164 << "Contact a Framework Developer\n";
00165 }
00166 return currentLumiPrincipal_;
00167 }
00168
00169 bool PrincipalCache::merge(boost::shared_ptr<RunAuxiliary> aux, boost::shared_ptr<ProductRegistry const> reg) {
00170 ProcessHistoryID phid = aux->processHistoryID();
00171 std::map<ProcessHistoryID, int>::const_iterator iphid = processHistoryIDsMap_.find(phid);
00172 RunIterator iter;
00173 if (iphid != processHistoryIDsMap_.end()) {
00174 int run = aux->run();
00175 RunKey key(iphid->second, run);
00176 iter = runPrincipals_.find(key);
00177 }
00178 if (iphid == processHistoryIDsMap_.end() || iter == runPrincipals_.end()) {
00179 return false;
00180 }
00181 bool runOK = iter->second->adjustToNewProductRegistry(*reg);
00182 assert(runOK);
00183 iter->second->mergeAuxiliary(*aux);
00184 currentRunPrincipal_ = iter->second;
00185 return true;
00186 }
00187
00188 bool PrincipalCache::merge(boost::shared_ptr<LuminosityBlockAuxiliary> aux, boost::shared_ptr<ProductRegistry const> reg) {
00189 ProcessHistoryID phid = aux->processHistoryID();
00190 std::map<ProcessHistoryID, int>::const_iterator iphid = processHistoryIDsMap_.find(phid);
00191 LumiIterator iter;
00192 if (iphid != processHistoryIDsMap_.end()) {
00193 int run = aux->run();
00194 int lumi = aux->luminosityBlock();
00195 LumiKey key(iphid->second, run, lumi);
00196 iter = lumiPrincipals_.find(key);
00197 }
00198 if (iphid == processHistoryIDsMap_.end() || iter == lumiPrincipals_.end()) {
00199 return false;
00200 }
00201 bool lumiOK = iter->second->adjustToNewProductRegistry(*reg);
00202 assert(lumiOK);
00203 iter->second->mergeAuxiliary(*aux);
00204 currentLumiPrincipal_ = iter->second;
00205 return true;
00206 }
00207
00208 bool PrincipalCache::insert(boost::shared_ptr<RunPrincipal> rp) {
00209 ProcessHistoryID phid = rp->aux().processHistoryID();
00210 int run = rp->run();
00211 std::map<ProcessHistoryID, int>::const_iterator iphid = processHistoryIDsMap_.find(phid);
00212 if (iphid == processHistoryIDsMap_.end()) {
00213 processHistoryIDsMap_[phid] = processHistoryIDs_.size();
00214 processHistoryIDs_.push_back(phid);
00215 iphid = processHistoryIDsMap_.find(phid);
00216 }
00217 RunKey key(iphid->second, run);
00218 assert(runPrincipals_.find(key) == runPrincipals_.end());
00219 runPrincipals_[key] = rp;
00220 currentRunPrincipal_ = rp;
00221 return true;
00222 }
00223
00224 bool PrincipalCache::insert(boost::shared_ptr<LuminosityBlockPrincipal> lbp) {
00225 ProcessHistoryID phid = lbp->aux().processHistoryID();
00226 int run = lbp->run();
00227 int lumi = lbp->luminosityBlock();
00228 std::map<ProcessHistoryID, int>::const_iterator iphid = processHistoryIDsMap_.find(phid);
00229 if (iphid == processHistoryIDsMap_.end()) {
00230 processHistoryIDsMap_[phid] = processHistoryIDs_.size();
00231 processHistoryIDs_.push_back(phid);
00232 iphid = processHistoryIDsMap_.find(phid);
00233 }
00234 LumiKey key(iphid->second, run, lumi);
00235 assert(lumiPrincipals_.find(key) == lumiPrincipals_.end());
00236 lumiPrincipals_[key] = lbp;
00237 currentLumiPrincipal_ = lbp;
00238 return true;
00239 }
00240
00241 bool PrincipalCache::noMoreRuns() {
00242 return runPrincipals_.empty();
00243 }
00244
00245 bool PrincipalCache::noMoreLumis() {
00246 return lumiPrincipals_.empty();
00247 }
00248
00249 RunPrincipal const& PrincipalCache::lowestRun() const {
00250 ConstRunIterator iter = runPrincipals_.begin();
00251 return *iter->second.get();
00252 }
00253
00254 LuminosityBlockPrincipal const& PrincipalCache::lowestLumi() const {
00255 ConstLumiIterator iter = lumiPrincipals_.begin();
00256 return *iter->second.get();
00257 }
00258
00259 void PrincipalCache::deleteLowestRun() {
00260 runPrincipals_.erase(runPrincipals_.begin());
00261 }
00262
00263 void PrincipalCache::deleteLowestLumi() {
00264 lumiPrincipals_.erase(lumiPrincipals_.begin());
00265 }
00266
00267 void PrincipalCache::deleteRun(ProcessHistoryID const& phid, int run) {
00268 RunKey key(processHistoryIDsMap_[phid], run);
00269 RunIterator iter = runPrincipals_.find(key);
00270 assert(iter != runPrincipals_.end());
00271 runPrincipals_.erase(iter);
00272 }
00273
00274 void PrincipalCache::deleteLumi(ProcessHistoryID const& phid, int run, int lumi) {
00275 LumiKey key(processHistoryIDsMap_[phid], run, lumi);
00276 LumiIterator iter = lumiPrincipals_.find(key);
00277 assert(iter != lumiPrincipals_.end());
00278 lumiPrincipals_.erase(iter);
00279 }
00280
00281 void PrincipalCache::adjustEventToNewProductRegistry(boost::shared_ptr<ProductRegistry const> reg) {
00282 if (eventPrincipal_) {
00283 eventPrincipal_->adjustIndexesAfterProductRegistryAddition();
00284 bool eventOK = eventPrincipal_->adjustToNewProductRegistry(*reg);
00285 assert(eventOK);
00286 }
00287 }
00288
00289 void PrincipalCache::adjustIndexesAfterProductRegistryAddition() {
00290 for (ConstRunIterator it = runPrincipals_.begin(), itEnd = runPrincipals_.end(); it != itEnd; ++it) {
00291 it->second->adjustIndexesAfterProductRegistryAddition();
00292 }
00293 for (ConstLumiIterator it = lumiPrincipals_.begin(), itEnd = lumiPrincipals_.end(); it != itEnd; ++it) {
00294 it->second->adjustIndexesAfterProductRegistryAddition();
00295 }
00296 }
00297 }