Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:58

0001 #include "FWCore/ParameterSet/interface/ParameterSetEntry.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "FWCore/Utilities/interface/EDMException.h"
0004 #include "FWCore/Utilities/interface/Digest.h"
0005 
0006 #include <cassert>
0007 #include <sstream>
0008 #include <iostream>
0009 namespace edm {
0010 
0011   ParameterSetEntry::ParameterSetEntry() : isTracked_(false), thePSet_(nullptr), theID_() {}
0012 
0013   ParameterSetEntry::ParameterSetEntry(ParameterSet const& pset, bool isTracked)
0014       : isTracked_(isTracked), thePSet_(new ParameterSet(pset)), theID_() {
0015     if (pset.isRegistered()) {
0016       theID_ = pset.id();
0017     }
0018   }
0019 
0020   ParameterSetEntry::ParameterSetEntry(ParameterSetID const& id, bool isTracked)
0021       : isTracked_(isTracked), thePSet_(), theID_(id) {}
0022 
0023   ParameterSetEntry::ParameterSetEntry(std::string const& rep) : isTracked_(rep[0] == '+'), thePSet_(), theID_() {
0024     assert(rep[0] == '+' || rep[0] == '-');
0025     assert(rep[2] == '(');
0026     assert(rep[rep.size() - 1] == ')');
0027     ParameterSetID newID(std::string(rep.begin() + 3, rep.end() - 1));
0028     theID_.swap(newID);
0029   }
0030 
0031   void ParameterSetEntry::toString(std::string& result) const {
0032     result += isTracked() ? "+Q(" : "-Q(";
0033     if (!theID_.isValid()) {
0034       throw edm::Exception(edm::errors::LogicError) << "ParameterSet::toString() called prematurely\n"
0035                                                     << "before ParameterSet::registerIt() has been called\n"
0036                                                     << "for all nested parameter sets\n";
0037     }
0038     theID_.toString(result);
0039     result += ')';
0040   }
0041 
0042   void ParameterSetEntry::toDigest(cms::Digest& digest) const {
0043     digest.append(isTracked() ? "+Q(" : "-Q(", 3);
0044     if (!theID_.isValid()) {
0045       throw edm::Exception(edm::errors::LogicError) << "ParameterSet::toString() called prematurely\n"
0046                                                     << "before ParameterSet::registerIt() has been called\n"
0047                                                     << "for all nested parameter sets\n";
0048     }
0049     theID_.toDigest(digest);
0050     digest.append(")", 1);
0051   }
0052 
0053   std::string ParameterSetEntry::toString() const {
0054     std::string result;
0055     toString(result);
0056     return result;
0057   }
0058 
0059   ParameterSet const& ParameterSetEntry::pset() const {
0060     fillPSet();
0061     return *thePSet_;
0062   }
0063 
0064   ParameterSet& ParameterSetEntry::psetForUpdate() {
0065     fillPSet();
0066     return *thePSet_;
0067   }
0068 
0069   void ParameterSetEntry::fillPSet() const {
0070     if (nullptr == thePSet_.load()) {
0071       auto tmp = std::make_unique<ParameterSet>(getParameterSet(theID_));
0072       ParameterSet* expected = nullptr;
0073       if (thePSet_.compare_exchange_strong(expected, tmp.get())) {
0074         // thePSet_ was equal to nullptr and now is equal to tmp.get()
0075         tmp.release();
0076       }
0077     }
0078   }
0079 
0080   void ParameterSetEntry::updateID() {
0081     assert(pset().isRegistered());
0082     theID_ = pset().id();
0083   }
0084 
0085   std::string ParameterSetEntry::dump(unsigned int indent) const {
0086     std::ostringstream os;
0087     const char* trackiness = (isTracked() ? "tracked" : "untracked");
0088     os << "PSet " << trackiness << " = (" << pset().dump(indent) << ")";
0089     return os.str();
0090   }
0091 
0092   std::ostream& operator<<(std::ostream& os, ParameterSetEntry const& psetEntry) {
0093     os << psetEntry.dump();
0094     return os;
0095   }
0096 }  // namespace edm