Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-02-27 07:19:50

0001 #include "DataFormats/Provenance/interface/ProcessConfiguration.h"
0002 #include "FWCore/Utilities/interface/Digest.h"
0003 #include "FWCore/Utilities/interface/EDMException.h"
0004 
0005 #include <ostream>
0006 #include <cassert>
0007 #include <sstream>
0008 #include <cctype>
0009 
0010 /*----------------------------------------------------------------------
0011 
0012 ----------------------------------------------------------------------*/
0013 
0014 namespace edm {
0015 
0016   ProcessConfiguration::ProcessConfiguration() = default;
0017 
0018   ProcessConfiguration::ProcessConfiguration(std::string const& procName,
0019                                              ParameterSetID const& pSetID,
0020                                              ReleaseVersion const& relVersion,
0021                                              HardwareResourcesDescription const& hwDescription)
0022       : processName_(procName),
0023         parameterSetID_(pSetID),
0024         releaseVersion_(relVersion),
0025         passID_(hwDescription.serialize()) {}
0026 
0027   ProcessConfiguration::ProcessConfiguration(std::string const& procName,
0028                                              ReleaseVersion const& relVersion,
0029                                              HardwareResourcesDescription const& hwDescription)
0030       : processName_(procName), parameterSetID_(), releaseVersion_(relVersion), passID_(hwDescription.serialize()) {
0031     setCurrentProcess();
0032   }
0033 
0034   ParameterSetID const& ProcessConfiguration::parameterSetID() const {
0035     if (parameterSetID_ == ParameterSetID() && isCurrentProcess()) {
0036       throw edm::Exception(errors::LogicError) << "Illegal attempt to access the process top level parameter set ID\n"
0037                                                << "from the ProcessConfiguration before that parameter\n"
0038                                                << "set has been frozen and registered.  The parameter set\n"
0039                                                << "can be changed during module validation, which occurs\n"
0040                                                << "concurrently with module construction.  The ID of the\n"
0041                                                << "ProcessConfiguration itself also depends on that parameter\n"
0042                                                << "set ID.  It is illegal to access either before they are frozen.\n";
0043     }
0044     return parameterSetID_;
0045   }
0046 
0047   ProcessConfigurationID ProcessConfiguration::id() const {
0048     if (transient_.pcid_.isValid()) {
0049       return transient_.pcid_;
0050     }
0051     // This implementation is ripe for optimization.
0052     std::ostringstream oss;
0053     oss << *this;
0054     std::string stringrep = oss.str();
0055     cms::Digest md5alg(stringrep);
0056     ProcessConfigurationID pcid(md5alg.digest().toString());
0057     return pcid;
0058   }
0059 
0060   void ProcessConfiguration::setParameterSetID(ParameterSetID const& pSetID) {
0061     assert(parameterSetID_ == ParameterSetID());
0062     parameterSetID_ = pSetID;
0063   }
0064 
0065   ProcessConfigurationID ProcessConfiguration::setProcessConfigurationID() {
0066     if (!transient_.pcid_.isValid()) {
0067       transient_.pcid_ = id();
0068     }
0069     return transient_.pcid_;
0070   }
0071 
0072   void ProcessConfiguration::reduce() {
0073     // Skip to the part of the release version just after
0074     // the first two numbers and erase the rest of it.
0075     std::string::iterator iter = releaseVersion_.begin();
0076     std::string::iterator iEnd = releaseVersion_.end();
0077     while (iter != iEnd && isdigit(*iter) == 0)
0078       ++iter;
0079     while (iter != iEnd && isdigit(*iter) != 0)
0080       ++iter;
0081     while (iter != iEnd && isdigit(*iter) == 0)
0082       ++iter;
0083     while (iter != iEnd && isdigit(*iter) != 0)
0084       ++iter;
0085     if (iter == iEnd)
0086       return;
0087     transient_.pcid_ = ProcessConfigurationID();
0088     releaseVersion_.erase(iter, iEnd);
0089     passID_ = edm::HardwareResourcesDescription().serialize();
0090   }
0091 
0092   bool operator<(ProcessConfiguration const& a, ProcessConfiguration const& b) {
0093     if (a.processName() < b.processName())
0094       return true;
0095     if (b.processName() < a.processName())
0096       return false;
0097     if (a.parameterSetID() < b.parameterSetID())
0098       return true;
0099     if (b.parameterSetID() < a.parameterSetID())
0100       return false;
0101     if (a.releaseVersion() < b.releaseVersion())
0102       return true;
0103     if (b.releaseVersion() < a.releaseVersion())
0104       return false;
0105     if (a.hardwareResourcesDescriptionSerialized() < b.hardwareResourcesDescriptionSerialized())
0106       return true;
0107     return false;
0108   }
0109 
0110   std::ostream& operator<<(std::ostream& os, ProcessConfiguration const& pc) {
0111     os << pc.processName() << ' ' << pc.parameterSetID() << ' ' << pc.releaseVersion() << ' '
0112        << pc.hardwareResourcesDescription();
0113     return os;
0114   }
0115 }  // namespace edm