Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:57

0001 #include "FWCore/Framework/interface/HistoryAppender.h"
0002 #include "DataFormats/Provenance/interface/ProcessConfiguration.h"
0003 #include "FWCore/Utilities/interface/EDMException.h"
0004 
0005 #include <string>
0006 #include <cassert>
0007 
0008 namespace {
0009   edm::ProcessHistory initializeEmpty() {
0010     edm::ProcessHistory tmp{};
0011     tmp.setProcessHistoryID();
0012     return tmp;
0013   }
0014 }  // namespace
0015 static const edm::ProcessHistory s_emptyHistory = initializeEmpty();
0016 
0017 namespace edm {
0018 
0019   HistoryAppender::HistoryAppender() {}
0020 
0021   std::shared_ptr<ProcessHistory const> HistoryAppender::appendToProcessHistory(
0022       ProcessHistoryID const& inputPHID, ProcessHistory const* iInputProcessHistory, ProcessConfiguration const& pc) {
0023     assert((iInputProcessHistory) == nullptr or (inputPHID == iInputProcessHistory->id()));
0024     if (m_cachedHistory.get() != nullptr and inputPHID == m_cachedInputPHID) {
0025       return m_cachedHistory;
0026     }
0027 
0028     ProcessHistory const* inputProcessHistory = iInputProcessHistory ? iInputProcessHistory : &s_emptyHistory;
0029 
0030     if (inputPHID.isValid()) {
0031       if (iInputProcessHistory == nullptr) {
0032         throw Exception(errors::LogicError) << "HistoryAppender::appendToProcessHistory\n"
0033                                             << "Input ProcessHistory has valid ID but is nullptr\n"
0034                                             << "Contact a Framework developer\n";
0035       }
0036     }
0037 
0038     auto newProcessHistory = std::make_shared<ProcessHistory>();
0039     *newProcessHistory = *inputProcessHistory;
0040     checkProcessHistory(*newProcessHistory, pc);
0041     newProcessHistory->push_back(pc);
0042     //force it to create the ID
0043     newProcessHistory->setProcessHistoryID();
0044     m_cachedInputPHID = inputPHID;
0045     m_cachedHistory = newProcessHistory;
0046     return m_cachedHistory;
0047   }
0048 
0049   void HistoryAppender::checkProcessHistory(ProcessHistory const& ph, ProcessConfiguration const& pc) const {
0050     std::string const& processName = pc.processName();
0051     for (auto const& process : ph) {
0052       if (processName == process.processName()) {
0053         throw edm::Exception(errors::Configuration, "Duplicate Process.")
0054             << "The process name " << processName << " was already in the ProcessHistory.\n"
0055             << "Please modify the configuration file to use a distinct process name.\n";
0056       }
0057     }
0058   }
0059 }  // namespace edm