CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/FWCore/Framework/src/HistoryAppender.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/HistoryAppender.h"
00002 #include "DataFormats/Provenance/interface/ProcessConfiguration.h"
00003 #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"
00004 #include "FWCore/Utilities/interface/EDMException.h"
00005 
00006 #include <string>
00007 
00008 namespace edm {
00009 
00010   HistoryAppender::HistoryAppender() :
00011     previous_(historyMap_.end()) {
00012   }
00013 
00014   CachedHistory const&
00015   HistoryAppender::appendToProcessHistory(ProcessHistoryID const& inputPHID,
00016                                           ProcessConfiguration const& pc) {
00017 
00018     if (previous_ != historyMap_.end() && inputPHID == previous_->first) return previous_->second;
00019 
00020     HistoryMap::iterator iter = historyMap_.find(inputPHID);
00021     if (iter != historyMap_.end()) return iter->second;
00022 
00023     ProcessHistoryRegistry* registry = ProcessHistoryRegistry::instance();
00024 
00025     ProcessHistory const* inputProcessHistory = &emptyHistory_;
00026 
00027     if (inputPHID.isValid()) {
00028       inputProcessHistory = registry->getMapped(inputPHID);
00029       if (inputProcessHistory == 0) {
00030         throw Exception(errors::LogicError)
00031           << "HistoryAppender::appendToProcessHistory\n"
00032           << "Input ProcessHistory not found in registry\n"
00033           << "Contact a Framework developer\n";
00034       }
00035     }
00036 
00037     ProcessHistory newProcessHistory;
00038     newProcessHistory = *inputProcessHistory;
00039     checkProcessHistory(newProcessHistory, pc);
00040     newProcessHistory.push_back(pc);
00041     registry->insertMapped(newProcessHistory);
00042     ProcessHistoryID newProcessHistoryID = newProcessHistory.id();
00043     CachedHistory newValue(inputProcessHistory,
00044                            registry->getMapped(newProcessHistoryID),
00045                            newProcessHistoryID);
00046     std::pair<ProcessHistoryID, CachedHistory> newEntry(inputPHID, newValue);
00047     std::pair<HistoryMap::iterator, bool> result = historyMap_.insert(newEntry);
00048     previous_ = result.first;
00049     return result.first->second;
00050   }
00051 
00052   void
00053   HistoryAppender::checkProcessHistory(ProcessHistory const& ph,
00054                                        ProcessConfiguration const& pc) const {
00055     std::string const& processName = pc.processName();
00056     for (ProcessHistory::const_iterator it = ph.begin(), itEnd = ph.end(); it != itEnd; ++it) {
00057       if (processName == it->processName()) {
00058         throw edm::Exception(errors::Configuration, "Duplicate Process.")
00059           << "The process name " << processName << " was already in the ProcessHistory.\n"
00060           << "Please modify the configuration file to use a distinct process name.\n";
00061       }
00062     }
00063   }
00064 }