CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/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 Contains a shared pointer to the RunPrincipal,
00006 LuminosityBlockPrincipal, and EventPrincipal.
00007 Manages merging of run and luminosity block
00008 principals when there is more than one principal
00009 from the same run or luminosity block and having
00010 the same reduced ProcessHistoryID.
00011 
00012 The EventPrincipal is reused each event and is created
00013 by the EventProcessor or SubProcess which contains
00014 an object of this type as a data member.
00015 
00016 The RunPrincipal and LuminosityBlockPrincipal is
00017 created by the InputSource each time a different
00018 run or luminosity block is encountered.
00019 
00020 Performs checks that process history IDs or runs and
00021 lumis, run numbers, and luminosity numbers are consistent.
00022 
00023 Original Author: W. David Dagenhart
00024 */
00025 
00026 #include "DataFormats/Provenance/interface/ProcessHistoryID.h"
00027 #include "DataFormats/Provenance/interface/RunID.h"
00028 #include "DataFormats/Provenance/interface/LuminosityBlockID.h"
00029 
00030 #include "boost/shared_ptr.hpp"
00031 
00032 namespace edm {
00033 
00034   class RunPrincipal;
00035   class LuminosityBlockPrincipal;
00036   class EventPrincipal;
00037   class RunAuxiliary;
00038   class LuminosityBlockAuxiliary;
00039   class ProductRegistry;
00040 
00041   class PrincipalCache {
00042   public:
00043 
00044     PrincipalCache();
00045     ~PrincipalCache();
00046 
00047     RunPrincipal& runPrincipal(ProcessHistoryID const& phid, RunNumber_t run) const;
00048     boost::shared_ptr<RunPrincipal> const& runPrincipalPtr(ProcessHistoryID const& phid, RunNumber_t run) const;
00049     RunPrincipal& runPrincipal() const;
00050     boost::shared_ptr<RunPrincipal> const& runPrincipalPtr() const;
00051     bool hasRunPrincipal() const {return runPrincipal_;}
00052 
00053     LuminosityBlockPrincipal& lumiPrincipal(ProcessHistoryID const& phid, RunNumber_t run, LuminosityBlockNumber_t lumi) const;
00054     boost::shared_ptr<LuminosityBlockPrincipal> const& lumiPrincipalPtr(ProcessHistoryID const& phid, RunNumber_t run, LuminosityBlockNumber_t lumi) const;
00055     LuminosityBlockPrincipal& lumiPrincipal() const;
00056     boost::shared_ptr<LuminosityBlockPrincipal> const& lumiPrincipalPtr() const;
00057     bool hasLumiPrincipal() const {return lumiPrincipal_;}
00058 
00059     EventPrincipal& eventPrincipal() const { return *eventPrincipal_; }
00060 
00061     void merge(boost::shared_ptr<RunAuxiliary> aux, boost::shared_ptr<ProductRegistry const> reg);
00062     void merge(boost::shared_ptr<LuminosityBlockAuxiliary> aux, boost::shared_ptr<ProductRegistry const> reg);
00063 
00064     void insert(boost::shared_ptr<RunPrincipal> rp);
00065     void insert(boost::shared_ptr<LuminosityBlockPrincipal> lbp);
00066     void insert(boost::shared_ptr<EventPrincipal> ep) { eventPrincipal_ = ep; }
00067 
00068     void deleteRun(ProcessHistoryID const& phid, RunNumber_t run);
00069     void deleteLumi(ProcessHistoryID const& phid, RunNumber_t run, LuminosityBlockNumber_t lumi);
00070 
00071     void adjustEventToNewProductRegistry(boost::shared_ptr<ProductRegistry const> reg);
00072 
00073     void adjustIndexesAfterProductRegistryAddition();
00074 
00075   private:
00076 
00077     void throwRunMissing() const;
00078     void throwLumiMissing() const;
00079 
00080     // These are explicitly cleared when finished with the run,
00081     // lumi, or event
00082     boost::shared_ptr<RunPrincipal> runPrincipal_;
00083     boost::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal_;
00084     boost::shared_ptr<EventPrincipal> eventPrincipal_;
00085 
00086     // These are intentionally not cleared so that when inserting
00087     // the next principal the conversion from full ProcessHistoryID_
00088     // to reduced ProcessHistoryID_ is still in memory and does
00089     // not need to be recalculated if the ID does not change. I
00090     // expect that very often these ID's will not change from one
00091     // principal to the next and a good amount of CPU can be saved
00092     // by not recalculating.
00093     ProcessHistoryID inputProcessHistoryID_;
00094     ProcessHistoryID reducedInputProcessHistoryID_;
00095     RunNumber_t run_;
00096     LuminosityBlockNumber_t lumi_;
00097   };
00098 }
00099 
00100 #endif