CMS 3D CMS Logo

PrincipalCache.h

Go to the documentation of this file.
00001 #ifndef FWCore_Framework_PrincipalCache_h
00002 #define FWCore_Framework_PrincipalCache_h
00003 
00004 /*
00005 $Id: PrincipalCache.h,v 1.1 2008/01/07 23:29:45 wdd Exp $
00006 
00007 Designed to save RunPrincipal's and LuminosityBlockPrincipal's
00008 in memory.  Manages merging of products in those principals
00009 when there is more than one principal from the same run
00010 or luminosity block.
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 LumiKey {
00024   public:
00025     int run() { return run_; }
00026     int lumi() { return lumi_; }
00027 
00028     LumiKey(int run, int lumi) : run_(run), lumi_(lumi) { }
00029 
00030     bool operator<(const LumiKey& right) const {
00031       if (run_ == right.run_) return lumi_ < right.lumi_;
00032       return run_ < right.run_;
00033     }
00034 
00035   private:
00036     int run_;
00037     int lumi_;
00038   };
00039 
00040   class PrincipalCache
00041   {
00042   public:
00043 
00044     PrincipalCache();
00045     ~PrincipalCache();
00046 
00047     RunPrincipal & runPrincipal(int run);
00048     RunPrincipal const& runPrincipal(int run) const;
00049     boost::shared_ptr<RunPrincipal> runPrincipalPtr(int run);
00050 
00051     // Current run (most recently read and inserted run)
00052     RunPrincipal & runPrincipal();
00053     RunPrincipal const& runPrincipal() const;
00054     boost::shared_ptr<RunPrincipal> runPrincipalPtr();
00055 
00056     LuminosityBlockPrincipal & lumiPrincipal(int run, int lumi);
00057     LuminosityBlockPrincipal const& lumiPrincipal(int run, int lumi) const;
00058     boost::shared_ptr<LuminosityBlockPrincipal> lumiPrincipalPtr(int run, int lumi);
00059 
00060     // Current luminosity block (most recently read and inserted luminosity block)
00061     LuminosityBlockPrincipal & lumiPrincipal();
00062     LuminosityBlockPrincipal const& lumiPrincipal() const;
00063     boost::shared_ptr<LuminosityBlockPrincipal> lumiPrincipalPtr();
00064 
00065     bool insert(boost::shared_ptr<RunPrincipal> rp);
00066     bool insert(boost::shared_ptr<LuminosityBlockPrincipal> lbp);
00067 
00068     bool noMoreRuns();
00069     bool noMoreLumis();
00070 
00071     RunPrincipal const& lowestRun() const;
00072     LuminosityBlockPrincipal const& lowestLumi() const;
00073 
00074     void deleteLowestRun();
00075     void deleteLowestLumi();
00076 
00077     void deleteRun(int run);
00078     void deleteLumi(int run, int lumi);
00079 
00080   private:
00081 
00082     typedef std::map<int, boost::shared_ptr<RunPrincipal> >::iterator RunIterator;
00083     typedef std::map<int, boost::shared_ptr<RunPrincipal> >::const_iterator ConstRunIterator;
00084     typedef std::map<LumiKey, boost::shared_ptr<LuminosityBlockPrincipal> >::iterator LumiIterator;
00085     typedef std::map<LumiKey, boost::shared_ptr<LuminosityBlockPrincipal> >::const_iterator ConstLumiIterator;
00086 
00087     std::map<int, boost::shared_ptr<RunPrincipal> > runPrincipals_;
00088     std::map<LumiKey, boost::shared_ptr<LuminosityBlockPrincipal> > lumiPrincipals_;
00089 
00090     boost::shared_ptr<RunPrincipal> currentRunPrincipal_;
00091     boost::shared_ptr<LuminosityBlockPrincipal> currentLumiPrincipal_;
00092   };
00093 }
00094 
00095 #endif

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