CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/DataFormats/Provenance/src/FullHistoryToReducedHistoryMap.cc

Go to the documentation of this file.
00001 #include "DataFormats/Provenance/interface/FullHistoryToReducedHistoryMap.h"
00002 #include "DataFormats/Provenance/interface/ProcessHistory.h"
00003 #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"
00004 #include "FWCore/Utilities/interface/EDMException.h"
00005 
00006 namespace edm {
00007 
00008   FullHistoryToReducedHistoryMap::FullHistoryToReducedHistoryMap() {
00009     // Put in the conversion for the ID of an empty process history.
00010     // It always maps onto itself, often is needed, and gives
00011     // us something valid to initialize the iterator with. That removes
00012     // the need to check for its validity and also for the validity
00013     // of the fullID argument to the reduce function, because the invalid
00014     // ProcessHistoryID is strangely also defined as the ID of the empty
00015     // Process History (maybe that should be fixed ...).
00016     ProcessHistory ph;
00017     std::pair<ProcessHistoryID, ProcessHistoryID> newEntry(ph.id(), ph.id());
00018     std::pair<Map::iterator, bool> result = cache_.insert(newEntry);
00019     previous_ = result.first;
00020   }
00021 
00022   ProcessHistoryID const&
00023   FullHistoryToReducedHistoryMap::reduceProcessHistoryID(ProcessHistoryID const& fullID) {
00024     if (previous_->first == fullID) return previous_->second;
00025     Map::const_iterator iter = cache_.find(fullID);
00026     if (iter != cache_.end()) {
00027       previous_ = iter;
00028       return iter->second;
00029     }
00030     ProcessHistoryRegistry* registry = ProcessHistoryRegistry::instance();
00031     ProcessHistory ph;
00032     if (!registry->getMapped(fullID, ph)) {
00033       throw Exception(errors::LogicError)
00034         << "FullHistoryToReducedHistoryMap::reduceProcessHistoryID\n"
00035         << "ProcessHistory not found in registry\n"
00036         << "Contact a Framework developer\n";
00037     }
00038     ph.reduce();
00039     std::pair<ProcessHistoryID, ProcessHistoryID> newEntry(fullID, ph.id());
00040     std::pair<Map::iterator, bool> result = cache_.insert(newEntry);
00041     previous_ = result.first;
00042     return result.first->second;
00043   }
00044 }