CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/FWCore/Framework/interface/HistoryAppender.h

Go to the documentation of this file.
00001 #ifndef FWCore_Framework_HistoryAppender_h
00002 #define FWCore_Framework_HistoryAppender_h
00003 
00004 #include "DataFormats/Provenance/interface/ProcessHistory.h"
00005 #include "DataFormats/Provenance/interface/ProcessHistoryID.h"
00006 
00007 #include <map>
00008 
00009 namespace edm {
00010 
00011   class ProcessConfiguration;
00012 
00013   class CachedHistory {
00014   public:
00015 
00016     CachedHistory(ProcessHistory const* inputProcessHistory,
00017                   ProcessHistory const* processHistory,
00018                   ProcessHistoryID const& processHistoryID) :
00019       inputProcessHistory_(inputProcessHistory),
00020       processHistory_(processHistory),
00021       processHistoryID_(processHistoryID) {
00022     }
00023 
00024     ProcessHistory const* inputProcessHistory() const { return inputProcessHistory_; }
00025     ProcessHistory const* processHistory() const { return processHistory_; }
00026     ProcessHistoryID const& processHistoryID () const { return processHistoryID_; }
00027 
00028   private:
00029 
00030     // This class does not own the memory
00031     ProcessHistory const* inputProcessHistory_;
00032     ProcessHistory const* processHistory_;
00033 
00034     ProcessHistoryID processHistoryID_;
00035   };
00036 
00037   class HistoryAppender {
00038   public:
00039 
00040     HistoryAppender();
00041 
00042     // Used to append the current process to the process history
00043     // when necessary. Optimized to cache the results so it
00044     // does not need to repeat the same calculations many times.
00045     CachedHistory const&
00046     appendToProcessHistory(ProcessHistoryID const& inputPHID,
00047                            ProcessConfiguration const& pc);
00048 
00049   private:
00050     HistoryAppender(HistoryAppender const&);
00051     HistoryAppender& operator=(HistoryAppender const&);
00052 
00053     // Throws if the new process name is already in the process
00054     // process history
00055     void checkProcessHistory(ProcessHistory const& ph,
00056                              ProcessConfiguration const& pc) const;
00057 
00058     // The map is intended to have the key be the ProcessHistoryID
00059     // read from the input file in one of the Auxiliary objects.
00060     // The CachedHistory has the ProcessHistoryID after adding
00061     // the current process and the two pointers to the corresponding
00062     // ProcessHistory objects in the registry, except if the history
00063     // is empty then the pointer is to the data member of this class
00064     // because the empty one is never in the registry.
00065     typedef std::map<ProcessHistoryID, CachedHistory> HistoryMap;
00066     HistoryMap historyMap_;
00067 
00068     // We cache iterator to the previous element for
00069     // performance. We expect the IDs to repeat many times
00070     // and this avoids the lookup in that case.
00071     HistoryMap::const_iterator previous_;
00072 
00073     ProcessHistory emptyHistory_;
00074   };
00075 }
00076 #endif