Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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