Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:21

0001 #include "FWCore/Utilities/interface/InputTag.h"
0002 #include "FWCore/Utilities/interface/Parse.h"
0003 #include "FWCore/Utilities/interface/EDMException.h"
0004 
0005 namespace edm {
0006 
0007   const std::string InputTag::kSkipCurrentProcess("@skipCurrentProcess");
0008   const std::string InputTag::kCurrentProcess("@currentProcess");
0009   static std::string const separator(":");
0010 
0011   InputTag::InputTag()
0012       : label_(),
0013         instance_(),
0014         process_(),
0015         typeID_(),
0016         productRegistry_(nullptr),
0017         index_(ProductResolverIndexInvalid),
0018         branchType_(NumBranchTypes),
0019         skipCurrentProcess_(false) {}
0020 
0021   InputTag::InputTag(std::string const& label, std::string const& instance, std::string const& processName)
0022       : label_(label),
0023         instance_(instance),
0024         process_(processName),
0025         typeID_(),
0026         productRegistry_(nullptr),
0027         index_(ProductResolverIndexInvalid),
0028         branchType_(NumBranchTypes),
0029         skipCurrentProcess_(calcSkipCurrentProcess()) {}
0030 
0031   InputTag::InputTag(char const* label, char const* instance, char const* processName)
0032       : label_(label),
0033         instance_(instance),
0034         process_(processName),
0035         typeID_(),
0036         productRegistry_(nullptr),
0037         index_(ProductResolverIndexInvalid),
0038         branchType_(NumBranchTypes),
0039         skipCurrentProcess_(calcSkipCurrentProcess()) {}
0040 
0041   InputTag::InputTag(std::string const& s)
0042       : label_(),
0043         instance_(),
0044         process_(),
0045         typeID_(),
0046         productRegistry_(nullptr),
0047         index_(ProductResolverIndexInvalid),
0048         branchType_(NumBranchTypes),
0049         skipCurrentProcess_(false) {
0050     // string is delimited by colons
0051     std::vector<std::string> tokens = tokenize(s, separator);
0052     size_t nwords = tokens.size();
0053     if (nwords > 3) {
0054       throw edm::Exception(errors::Configuration, "InputTag") << "Input tag " << s << " has " << nwords << " tokens";
0055     }
0056     if (nwords > 0)
0057       label_ = tokens[0];
0058     if (nwords > 1)
0059       instance_ = tokens[1];
0060     if (nwords > 2)
0061       process_ = tokens[2];
0062     skipCurrentProcess_ = calcSkipCurrentProcess();
0063   }
0064 
0065   InputTag::~InputTag() {}
0066 
0067   InputTag::InputTag(InputTag const& other)
0068       : label_(other.label()),
0069         instance_(other.instance()),
0070         process_(other.process()),
0071         typeID_(),
0072         productRegistry_(nullptr),
0073         index_(ProductResolverIndexInvalid),
0074         branchType_(NumBranchTypes),
0075         skipCurrentProcess_(other.willSkipCurrentProcess()) {
0076     ProductResolverIndex otherIndex = other.index_.load();
0077     if (otherIndex < ProductResolverIndexInitializing) {
0078       branchType_ = other.branchType_;
0079       typeID_ = other.typeID_;
0080       productRegistry_ = other.productRegistry_;
0081       index_.store(otherIndex);
0082     }
0083   }
0084 
0085   InputTag::InputTag(InputTag&& other)
0086       : label_(std::move(other.label_)),
0087         instance_(std::move(other.instance_)),
0088         process_(std::move(other.process_)),
0089         typeID_(),
0090         productRegistry_(nullptr),
0091         index_(ProductResolverIndexInvalid),
0092         branchType_(NumBranchTypes),
0093         skipCurrentProcess_(other.willSkipCurrentProcess()) {
0094     ProductResolverIndex otherIndex = other.index_.load();
0095     if (otherIndex < ProductResolverIndexInitializing) {
0096       branchType_ = other.branchType_;
0097       typeID_ = other.typeID_;
0098       productRegistry_ = other.productRegistry_;
0099       index_.store(otherIndex);
0100     }
0101   }
0102 
0103   InputTag& InputTag::operator=(InputTag const& other) {
0104     if (this != &other) {
0105       label_ = other.label_;
0106       instance_ = other.instance_;
0107       process_ = other.process_;
0108       skipCurrentProcess_ = other.skipCurrentProcess_;
0109 
0110       ProductResolverIndex otherIndex = other.index_.load();
0111       if (otherIndex < ProductResolverIndexInitializing) {
0112         branchType_ = other.branchType_;
0113         typeID_ = other.typeID_;
0114         productRegistry_ = other.productRegistry_;
0115         index_.store(otherIndex);
0116       } else {
0117         branchType_ = NumBranchTypes;
0118         typeID_ = TypeID();
0119         productRegistry_ = nullptr;
0120         index_.store(ProductResolverIndexInvalid);
0121       }
0122     }
0123     return *this;
0124   }
0125 
0126   InputTag& InputTag::operator=(InputTag&& other) {
0127     if (this != &other) {
0128       label_ = std::move(other.label_);
0129       instance_ = std::move(other.instance_);
0130       process_ = std::move(other.process_);
0131       skipCurrentProcess_ = other.skipCurrentProcess_;
0132 
0133       ProductResolverIndex otherIndex = other.index_.load();
0134       if (otherIndex < ProductResolverIndexInitializing) {
0135         branchType_ = other.branchType_;
0136         typeID_ = other.typeID_;
0137         productRegistry_ = other.productRegistry_;
0138         index_.store(otherIndex);
0139       } else {
0140         branchType_ = NumBranchTypes;
0141         typeID_ = TypeID();
0142         productRegistry_ = nullptr;
0143         index_.store(ProductResolverIndexInvalid);
0144       }
0145     }
0146     return *this;
0147   }
0148 
0149   bool InputTag::calcSkipCurrentProcess() const {
0150     char const* p1 = kSkipCurrentProcess.c_str();
0151     char const* p2 = process_.c_str();
0152     while (*p1 && (*p1 == *p2)) {
0153       ++p1;
0154       ++p2;
0155     }
0156     return *p1 == *p2;
0157   }
0158 
0159   std::string InputTag::encode() const {
0160     //NOTE: since the encoding gets used to form the configuration hash I did not want
0161     // to change it so that not specifying a process would cause two colons to appear in the
0162     // encoding and thus not being backwards compatible
0163     std::string result = label_;
0164     if (!instance_.empty() || !process_.empty()) {
0165       result += separator + instance_;
0166     }
0167     if (!process_.empty()) {
0168       result += separator + process_;
0169     }
0170     return result;
0171   }
0172 
0173   bool InputTag::operator==(InputTag const& tag) const {
0174     return (label_ == tag.label_) && (instance_ == tag.instance_) && (process_ == tag.process_);
0175   }
0176 
0177   ProductResolverIndex InputTag::indexFor(TypeID const& typeID,
0178                                           BranchType branchType,
0179                                           void const* productRegistry) const {
0180     ProductResolverIndex index = index_.load();
0181 
0182     if (index < ProductResolverIndexInitializing && typeID_ == typeID && branchType_ == branchType &&
0183         productRegistry_ == productRegistry) {
0184       return index;
0185     }
0186     return ProductResolverIndexInvalid;
0187   }
0188 
0189   void InputTag::tryToCacheIndex(ProductResolverIndex index,
0190                                  TypeID const& typeID,
0191                                  BranchType branchType,
0192                                  void const* productRegistry) const {
0193     unsigned int invalidValue = static_cast<unsigned int>(ProductResolverIndexInvalid);
0194     if (index_.compare_exchange_strong(invalidValue, static_cast<unsigned int>(ProductResolverIndexInitializing))) {
0195       typeID_ = typeID;
0196       branchType_ = branchType;
0197       productRegistry_ = productRegistry;
0198       index_.store(index);
0199     }
0200   }
0201 
0202   std::ostream& operator<<(std::ostream& ost, InputTag const& tag) {
0203     static std::string const process(", process = ");
0204     ost << "InputTag:  label = " << tag.label() << ", instance = " << tag.instance()
0205         << (tag.process().empty() ? std::string() : (process + tag.process()));
0206     return ost;
0207   }
0208 }  // namespace edm