Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <iterator>
0002 #include <ostream>
0003 #include <sstream>
0004 #include "FWCore/Utilities/interface/Digest.h"
0005 #include "FWCore/Utilities/interface/Algorithms.h"
0006 
0007 #include "DataFormats/Provenance/interface/ProcessHistory.h"
0008 
0009 namespace edm {
0010   ProcessHistoryID ProcessHistory::id() const {
0011     if (transient_.phid_.isValid()) {
0012       return transient_.phid_;
0013     }
0014     // This implementation is ripe for optimization.
0015     // We do not use operator<< because it does not write out everything.
0016     std::ostringstream oss;
0017     for (auto const& item : *this) {
0018       oss << item.processName() << ' ' << item.parameterSetID() << ' ' << item.releaseVersion() << ' ' << item.passID()
0019           << ' ';
0020     }
0021     std::string stringrep = oss.str();
0022     cms::Digest md5alg(stringrep);
0023     ProcessHistoryID phID(md5alg.digest().toString());
0024     return phID;
0025   }
0026 
0027   ProcessHistoryID ProcessHistory::setProcessHistoryID() {
0028     if (!transient_.phid_.isValid()) {
0029       transient_.phid_ = id();
0030     }
0031     return transient_.phid_;
0032   }
0033 
0034   bool ProcessHistory::getConfigurationForProcess(std::string const& name, ProcessConfiguration& config) const {
0035     for (auto const& item : *this) {
0036       if (item.processName() == name) {
0037         config = item;
0038         return true;
0039       }
0040     }
0041     // Name not found!
0042     return false;
0043   }
0044 
0045   ProcessHistory& ProcessHistory::reduce() {
0046     phid() = ProcessHistoryID();
0047     for (auto& item : data_) {
0048       item.reduce();
0049     }
0050     return *this;
0051   }
0052 
0053   bool isAncestor(ProcessHistory const& a, ProcessHistory const& b) {
0054     if (a.size() >= b.size())
0055       return false;
0056     typedef ProcessHistory::collection_type::const_iterator const_iterator;
0057     for (const_iterator itA = a.data().begin(), itB = b.data().begin(), itAEnd = a.data().end(); itA != itAEnd;
0058          ++itA, ++itB) {
0059       if (*itA != *itB)
0060         return false;
0061     }
0062     return true;
0063   }
0064 
0065   std::ostream& operator<<(std::ostream& ost, ProcessHistory const& ph) {
0066     ost << "Process History = ";
0067     copy_all(ph, std::ostream_iterator<ProcessHistory::value_type>(ost, ";"));
0068     return ost;
0069   }
0070 }  // namespace edm