Go to the documentation of this file.00001 #include "DataFormats/Provenance/interface/ProcessConfiguration.h"
00002 #include "FWCore/Utilities/interface/Digest.h"
00003 #include "FWCore/Utilities/interface/EDMException.h"
00004
00005 #include <ostream>
00006 #include <cassert>
00007 #include <sstream>
00008 #include <cctype>
00009
00010
00011
00012
00013
00014 namespace edm {
00015
00016
00017 ProcessConfiguration::ProcessConfiguration() : processName_(), parameterSetID_(), releaseVersion_(), passID_() {}
00018
00019 ProcessConfiguration::ProcessConfiguration(
00020 std::string const& procName,
00021 ParameterSetID const& pSetID,
00022 ReleaseVersion const& relVersion,
00023 PassID const& pass) :
00024 processName_(procName),
00025 parameterSetID_(pSetID),
00026 releaseVersion_(relVersion),
00027 passID_(pass) { }
00028
00029 ProcessConfiguration::ProcessConfiguration(
00030 std::string const& procName,
00031 ReleaseVersion const& relVersion,
00032 PassID const& pass) :
00033 processName_(procName),
00034 parameterSetID_(),
00035 releaseVersion_(relVersion),
00036 passID_(pass) { isCurrentProcess() = true; }
00037
00038 ParameterSetID const&
00039 ProcessConfiguration::parameterSetID() const {
00040 if (parameterSetID_ == ParameterSetID() && isCurrentProcess()) {
00041 throw edm::Exception(errors::LogicError)
00042 << "Illegal attempt to access the process top level parameter set ID\n"
00043 << "from the ProcessConfiguration before that parameter\n"
00044 << "set has been frozen and registered. The parameter set\n"
00045 << "can be changed during module validation, which occurs\n"
00046 << "concurrently with module construction. The ID of the\n"
00047 << "ProcessConfiguration itself also depends on that parameter\n"
00048 << "set ID. It is illegal to access either before they are frozen.\n";
00049 }
00050 return parameterSetID_;
00051 }
00052
00053 ProcessConfigurationID
00054 ProcessConfiguration::id() const {
00055 if(pcid().isValid()) {
00056 return pcid();
00057 }
00058
00059 std::ostringstream oss;
00060 oss << *this;
00061 std::string stringrep = oss.str();
00062 cms::Digest md5alg(stringrep);
00063 ProcessConfigurationID tmp(md5alg.digest().toString());
00064 pcid().swap(tmp);
00065 return pcid();
00066 }
00067
00068 void
00069 ProcessConfiguration::setParameterSetID(ParameterSetID const& pSetID) {
00070 assert(parameterSetID_ == ParameterSetID());
00071 parameterSetID_ = pSetID;
00072 }
00073
00074 void
00075 ProcessConfiguration::reduce() {
00076
00077
00078 std::string::iterator iter = releaseVersion_.begin();
00079 std::string::iterator iEnd = releaseVersion_.end();
00080 while(iter != iEnd && isdigit(*iter) == 0) ++iter;
00081 while(iter != iEnd && isdigit(*iter) != 0) ++iter;
00082 while(iter != iEnd && isdigit(*iter) == 0) ++iter;
00083 while(iter != iEnd && isdigit(*iter) != 0) ++iter;
00084 if (iter == iEnd) return;
00085 pcid() = ProcessConfigurationID();
00086 releaseVersion_.erase(iter,iEnd);
00087 }
00088
00089 bool operator<(ProcessConfiguration const& a, ProcessConfiguration const& b) {
00090 if (a.processName() < b.processName()) return true;
00091 if (b.processName() < a.processName()) return false;
00092 if (a.parameterSetID() < b.parameterSetID()) return true;
00093 if (b.parameterSetID() < a.parameterSetID()) return false;
00094 if (a.releaseVersion() < b.releaseVersion()) return true;
00095 if (b.releaseVersion() < a.releaseVersion()) return false;
00096 if (a.passID() < b.passID()) return true;
00097 return false;
00098 }
00099
00100 std::ostream&
00101 operator<< (std::ostream& os, ProcessConfiguration const& pc) {
00102 os << pc.processName() << ' '
00103 << pc.parameterSetID() << ' '
00104 << pc.releaseVersion() << ' '
00105 << pc.passID();
00106 return os;
00107 }
00108 }