CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/FWCore/Framework/src/PrincipalCache.h

Go to the documentation of this file.
00001 #ifndef FWCore_Framework_PrincipalCache_h
00002 #define FWCore_Framework_PrincipalCache_h
00003 
00004 /*
00005 Designed to save RunPrincipal's and LuminosityBlockPrincipal's
00006 in memory.  Manages merging of products in those principals
00007 when there is more than one principal from the same run
00008 or luminosity block.
00009 
00010 Also contains a non-owning pointer the EventPrincipal, which is reused each event.
00011 
00012 Original Author: W. David Dagenhart
00013 */
00014 
00015 #include "FWCore/Framework/interface/Frameworkfwd.h"
00016 
00017 #include "boost/shared_ptr.hpp"
00018 
00019 #include <map>
00020 
00021 namespace edm {
00022 
00023   class RunKey {
00024   public:
00025     int processHistoryIDIndex() const { return processHistoryIDIndex_; }
00026     int run() const { return run_; }
00027 
00028     RunKey(int index, int run) : processHistoryIDIndex_(index), run_(run) { }
00029 
00030     bool operator<(RunKey const& right) const {
00031       if (processHistoryIDIndex_ == right.processHistoryIDIndex_) {
00032         return run_ < right.run_;
00033       }
00034       return processHistoryIDIndex_ < right.processHistoryIDIndex_;
00035     }
00036 
00037   private:
00038     int processHistoryIDIndex_;
00039     int run_;
00040   };
00041 
00042   class LumiKey {
00043   public:
00044     int processHistoryIDIndex() const { return processHistoryIDIndex_; }
00045     int run() const { return run_; }
00046     int lumi() const { return lumi_; }
00047 
00048     LumiKey(int index, int run, int lumi) : processHistoryIDIndex_(index), run_(run), lumi_(lumi) { }
00049 
00050     bool operator<(const LumiKey& right) const {
00051       if (processHistoryIDIndex_ == right.processHistoryIDIndex_) {
00052         if (run_ == right.run_) return lumi_ < right.lumi_;
00053         return run_ < right.run_;
00054       }
00055       return processHistoryIDIndex_ < right.processHistoryIDIndex_;
00056     }
00057 
00058   private:
00059     int processHistoryIDIndex_;
00060     int run_;
00061     int lumi_;
00062   };
00063 
00064   class PrincipalCache {
00065   public:
00066 
00067     PrincipalCache();
00068     ~PrincipalCache();
00069 
00070     RunPrincipal& runPrincipal(ProcessHistoryID const& phid, int run);
00071     RunPrincipal const& runPrincipal(ProcessHistoryID const& phid, int run) const;
00072     boost::shared_ptr<RunPrincipal> runPrincipalPtr(ProcessHistoryID const& phid, int run);
00073 
00074     // Current run (most recently read and inserted run)
00075     RunPrincipal& runPrincipal();
00076     RunPrincipal const& runPrincipal() const;
00077     boost::shared_ptr<RunPrincipal> runPrincipalPtr();
00078 
00079     LuminosityBlockPrincipal& lumiPrincipal(ProcessHistoryID const& phid, int run, int lumi);
00080     LuminosityBlockPrincipal const& lumiPrincipal(ProcessHistoryID const& phid, int run, int lumi) const;
00081     boost::shared_ptr<LuminosityBlockPrincipal> lumiPrincipalPtr(ProcessHistoryID const& phid, int run, int lumi);
00082 
00083     // Current luminosity block (most recently read and inserted luminosity block)
00084     LuminosityBlockPrincipal& lumiPrincipal();
00085     LuminosityBlockPrincipal const& lumiPrincipal() const;
00086     boost::shared_ptr<LuminosityBlockPrincipal> lumiPrincipalPtr();
00087 
00088     // Event
00089     EventPrincipal& eventPrincipal() {return *eventPrincipal_;}
00090     EventPrincipal const& eventPrincipal() const {return *eventPrincipal_;}
00091 
00092     bool merge(boost::shared_ptr<RunAuxiliary> aux, boost::shared_ptr<ProductRegistry const> reg);
00093     bool merge(boost::shared_ptr<LuminosityBlockAuxiliary> aux, boost::shared_ptr<ProductRegistry const> reg);
00094 
00095     bool insert(boost::shared_ptr<RunPrincipal> rp);
00096     bool insert(boost::shared_ptr<LuminosityBlockPrincipal> lbp);
00097     void insert(boost::shared_ptr<EventPrincipal> ep) {eventPrincipal_ = ep;}
00098 
00099     bool noMoreRuns();
00100     bool noMoreLumis();
00101 
00102     RunPrincipal const& lowestRun() const;
00103     LuminosityBlockPrincipal const& lowestLumi() const;
00104 
00105     void deleteLowestRun();
00106     void deleteLowestLumi();
00107 
00108     void deleteRun(ProcessHistoryID const& phid, int run);
00109     void deleteLumi(ProcessHistoryID const& phid, int run, int lumi);
00110 
00111     void adjustEventToNewProductRegistry(boost::shared_ptr<ProductRegistry const> reg);
00112 
00113     void adjustIndexesAfterProductRegistryAddition();
00114 
00115   private:
00116 
00117     std::vector<ProcessHistoryID> processHistoryIDs_;
00118     std::map<ProcessHistoryID, int> processHistoryIDsMap_;
00119 
00120     typedef std::map<RunKey, boost::shared_ptr<RunPrincipal> >::iterator RunIterator;
00121     typedef std::map<RunKey, boost::shared_ptr<RunPrincipal> >::const_iterator ConstRunIterator;
00122     typedef std::map<LumiKey, boost::shared_ptr<LuminosityBlockPrincipal> >::iterator LumiIterator;
00123     typedef std::map<LumiKey, boost::shared_ptr<LuminosityBlockPrincipal> >::const_iterator ConstLumiIterator;
00124 
00125     std::map<RunKey, boost::shared_ptr<RunPrincipal> > runPrincipals_;
00126     std::map<LumiKey, boost::shared_ptr<LuminosityBlockPrincipal> > lumiPrincipals_;
00127 
00128     boost::shared_ptr<EventPrincipal> eventPrincipal_;
00129     boost::shared_ptr<RunPrincipal> currentRunPrincipal_;
00130     boost::shared_ptr<LuminosityBlockPrincipal> currentLumiPrincipal_;
00131   };
00132 }
00133 
00134 #endif