CMS 3D CMS Logo

PrincipalCache.cc

Go to the documentation of this file.
00001 
00002 
00003 // $Id: PrincipalCache.cc,v 1.2 2008/01/23 23:36:23 wdd Exp $
00004 
00005 #include "FWCore/Framework/src/PrincipalCache.h"
00006 #include "FWCore/Framework/interface/LuminosityBlockPrincipal.h"
00007 #include "FWCore/Framework/interface/RunPrincipal.h"
00008 #include "FWCore/Utilities/interface/EDMException.h"
00009 
00010 namespace edm {
00011 
00012   PrincipalCache::PrincipalCache() { }
00013 
00014   PrincipalCache::~PrincipalCache() { }
00015 
00016   RunPrincipal & PrincipalCache::runPrincipal(int run) {
00017     RunIterator iter = runPrincipals_.find(run);
00018     if (iter == runPrincipals_.end()) {
00019       throw edm::Exception(edm::errors::LogicError)
00020         << "PrincipalCache::runPrincipal\n"
00021         << "Requested a run that is not in the cache (should never happen)\n"
00022         << "Contact a Framework Developer\n";
00023     }
00024     return *iter->second.get();
00025   }
00026 
00027   RunPrincipal const& PrincipalCache::runPrincipal(int run) const {
00028     ConstRunIterator iter = runPrincipals_.find(run);
00029     if (iter == runPrincipals_.end()) {
00030       throw edm::Exception(edm::errors::LogicError)
00031         << "PrincipalCache::runPrincipal\n"
00032         << "Requested a run that is not in the cache (should never happen)\n"
00033         << "Contact a Framework Developer\n";
00034     }
00035     return *iter->second.get();
00036   }
00037 
00038   boost::shared_ptr<RunPrincipal> PrincipalCache::runPrincipalPtr(int run) {
00039     RunIterator iter = runPrincipals_.find(run);
00040     if (iter == runPrincipals_.end()) {
00041       throw edm::Exception(edm::errors::LogicError)
00042         << "PrincipalCache::runPrincipalPtr\n"
00043         << "Requested a run that is not in the cache (should never happen)\n"
00044         << "Contact a Framework Developer\n";
00045     }
00046     return iter->second;
00047   }
00048 
00049   RunPrincipal & PrincipalCache::runPrincipal() {
00050     if (currentRunPrincipal_.get() == 0) {
00051       throw edm::Exception(edm::errors::LogicError)
00052         << "PrincipalCache::runPrincipal\n"
00053         << "Requested current run and it is not initialized (should never happen)\n"
00054         << "Contact a Framework Developer\n";
00055     }
00056     return *currentRunPrincipal_.get();
00057   }
00058 
00059   RunPrincipal const& PrincipalCache::runPrincipal() const {
00060     if (currentRunPrincipal_.get() == 0) {
00061       throw edm::Exception(edm::errors::LogicError)
00062         << "PrincipalCache::runPrincipal\n"
00063         << "Requested current run and it is not initialized (should never happen)\n"
00064         << "Contact a Framework Developer\n";
00065     }
00066     return *currentRunPrincipal_.get();
00067   }
00068 
00069   boost::shared_ptr<RunPrincipal> PrincipalCache::runPrincipalPtr() {
00070     if (currentRunPrincipal_.get() == 0) {
00071       throw edm::Exception(edm::errors::LogicError)
00072         << "PrincipalCache::runPrincipalPtr\n"
00073         << "Requested current run and it is not initialized (should never happen)\n"
00074         << "Contact a Framework Developer\n";
00075     }
00076     return currentRunPrincipal_;
00077   }
00078 
00079   LuminosityBlockPrincipal & PrincipalCache::lumiPrincipal(int run, int lumi) {
00080     LumiKey key(run, lumi);
00081     LumiIterator iter = lumiPrincipals_.find(key);
00082     if (iter == lumiPrincipals_.end()) {
00083       throw edm::Exception(edm::errors::LogicError)
00084         << "PrincipalCache::lumiPrincipal\n"
00085         << "Requested a lumi that is not in the cache (should never happen)\n"
00086         << "Contact a Framework Developer\n";
00087     }
00088     return *iter->second.get();
00089   }
00090 
00091   LuminosityBlockPrincipal const& PrincipalCache::lumiPrincipal(int run, int lumi) const {
00092     LumiKey key(run, lumi);
00093     ConstLumiIterator iter = lumiPrincipals_.find(key);
00094     if (iter == lumiPrincipals_.end()) {
00095       throw edm::Exception(edm::errors::LogicError)
00096         << "PrincipalCache::lumiPrincipal\n"
00097         << "Requested a lumi that is not in the cache (should never happen)\n"
00098         << "Contact a Framework Developer\n";
00099     }
00100     return *iter->second.get();
00101   }
00102 
00103   boost::shared_ptr<LuminosityBlockPrincipal> PrincipalCache::lumiPrincipalPtr(int run, int lumi) {
00104     LumiKey key(run, lumi);
00105     LumiIterator iter = lumiPrincipals_.find(key);
00106     if (iter == lumiPrincipals_.end()) {
00107       throw edm::Exception(edm::errors::LogicError)
00108         << "PrincipalCache::lumiPrincipalPtr\n"
00109         << "Requested a lumi that is not in the cache (should never happen)\n"
00110         << "Contact a Framework Developer\n";
00111     }
00112     return iter->second;
00113   }
00114 
00115   LuminosityBlockPrincipal & PrincipalCache::lumiPrincipal() {
00116     if (currentLumiPrincipal_.get() == 0) {
00117       throw edm::Exception(edm::errors::LogicError)
00118         << "PrincipalCache::lumiPrincipal\n"
00119         << "Requested current lumi and it is not initialized (should never happen)\n"
00120         << "Contact a Framework Developer\n";
00121     }
00122     return *currentLumiPrincipal_.get();
00123   }
00124 
00125   LuminosityBlockPrincipal const& PrincipalCache::lumiPrincipal() const {
00126     if (currentLumiPrincipal_.get() == 0) {
00127       throw edm::Exception(edm::errors::LogicError)
00128         << "PrincipalCache::lumiPrincipal\n"
00129         << "Requested current lumi and it is not initialized (should never happen)\n"
00130         << "Contact a Framework Developer\n";
00131     }
00132     return *currentLumiPrincipal_.get();
00133   }
00134 
00135   boost::shared_ptr<LuminosityBlockPrincipal> PrincipalCache::lumiPrincipalPtr() {
00136     if (currentLumiPrincipal_.get() == 0) {
00137       throw edm::Exception(edm::errors::LogicError)
00138         << "PrincipalCache::lumiPrincipalPtr\n"
00139         << "Requested current lumi and it is not initialized (should never happen)\n"
00140         << "Contact a Framework Developer\n";
00141     }
00142     return currentLumiPrincipal_;
00143   }
00144 
00145   bool PrincipalCache::insert(boost::shared_ptr<RunPrincipal> rp) {
00146     int run = rp->run();
00147     RunIterator iter = runPrincipals_.find(run); 
00148     if (iter == runPrincipals_.end()) {
00149       runPrincipals_[run] = rp;
00150       currentRunPrincipal_ = rp;
00151       return true;
00152     }
00153 
00154     iter->second->mergeRun(rp);
00155     currentRunPrincipal_ = iter->second;
00156     
00157     return true;
00158   }
00159 
00160   bool PrincipalCache::insert(boost::shared_ptr<LuminosityBlockPrincipal> lbp) {
00161     int run = lbp->run();
00162     int lumi = lbp->luminosityBlock();
00163     LumiKey key(run, lumi);
00164     LumiIterator iter = lumiPrincipals_.find(key); 
00165     if (iter == lumiPrincipals_.end()) {
00166       lumiPrincipals_[key] = lbp;
00167       currentLumiPrincipal_ = lbp;
00168       return true;
00169     }
00170 
00171     iter->second->mergeLuminosityBlock(lbp);
00172     currentLumiPrincipal_ = iter->second;
00173     
00174     return true;
00175   }
00176 
00177   bool PrincipalCache::noMoreRuns() {
00178     return runPrincipals_.empty();
00179   }
00180 
00181   bool PrincipalCache::noMoreLumis() {
00182     return lumiPrincipals_.empty();
00183   }
00184 
00185   RunPrincipal const& PrincipalCache::lowestRun() const {
00186     ConstRunIterator iter = runPrincipals_.begin();
00187     return *iter->second.get();
00188   }
00189 
00190   LuminosityBlockPrincipal const& PrincipalCache::lowestLumi() const {
00191     ConstLumiIterator iter = lumiPrincipals_.begin();
00192     return *iter->second.get();
00193   }
00194 
00195   void PrincipalCache::deleteLowestRun() {
00196     runPrincipals_.erase(runPrincipals_.begin());
00197   }
00198 
00199   void PrincipalCache::deleteLowestLumi() {
00200     lumiPrincipals_.erase(lumiPrincipals_.begin());
00201   }
00202 
00203   void PrincipalCache::deleteRun(int run) {
00204     runPrincipals_.erase(runPrincipals_.find(run));
00205   }
00206 
00207   void PrincipalCache::deleteLumi(int run, int lumi) {
00208     lumiPrincipals_.erase(lumiPrincipals_.find(LumiKey(run, lumi)));
00209   }
00210 }

Generated on Tue Jun 9 17:36:11 2009 for CMSSW by  doxygen 1.5.4