Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:04

0001 #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"
0002 #include "FWCore/Utilities/interface/EDMException.h"
0003 
0004 #include <cassert>
0005 namespace edm {
0006   ProcessHistoryRegistry::ProcessHistoryRegistry() : data_(), extra_() {
0007     // insert the mapping for an empty process history
0008     extra_.insert(std::pair<ProcessHistoryID, ProcessHistoryID>(ProcessHistory().id(), ProcessHistory().reduce().id()));
0009   }
0010 
0011   bool ProcessHistoryRegistry::registerProcessHistory(ProcessHistory const& processHistory) {
0012     //make sure the process history ID is cached
0013     auto tmp = processHistory;
0014     ProcessHistoryID id = tmp.setProcessHistoryID();
0015     bool newlyAdded = (data_.find(id) == data_.end());
0016     if (newlyAdded) {
0017       data_.emplace(id, tmp);
0018       extra_.emplace(std::move(id), tmp.reduce().id());
0019     }
0020     return newlyAdded;
0021   }
0022 
0023   ProcessHistoryID const& ProcessHistoryRegistry::reducedProcessHistoryID(ProcessHistoryID const& fullID) const {
0024     auto const& iter = extra_.find(fullID);
0025     assert(iter != extra_.end());
0026     return iter->second;
0027   }
0028 
0029   bool ProcessHistoryRegistry::getMapped(ProcessHistoryID const& key, ProcessHistory& value) const {
0030     auto const& iter = data_.find(key);
0031     bool found = (iter != data_.end());
0032     if (found) {
0033       value = iter->second;
0034     }
0035     return found;
0036   }
0037 
0038   ProcessHistory const* ProcessHistoryRegistry::getMapped(ProcessHistoryID const& key) const {
0039     auto const& iter = data_.find(key);
0040     if (iter == data_.end()) {
0041       return nullptr;
0042     }
0043     return &iter->second;
0044   }
0045 }  // namespace edm