File indexing completed on 2021-03-29 04:37:54
0001 #ifndef DataFormats_Provenance_BranchDescription_h
0002 #define DataFormats_Provenance_BranchDescription_h
0003
0004
0005
0006
0007
0008
0009
0010 #include "DataFormats/Provenance/interface/BranchID.h"
0011 #include "DataFormats/Provenance/interface/BranchType.h"
0012 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0013 #include "DataFormats/Provenance/interface/ProductID.h"
0014 #include "DataFormats/Provenance/interface/ProvenanceFwd.h"
0015 #include "FWCore/Utilities/interface/TypeID.h"
0016 #include "FWCore/Reflection/interface/TypeWithDict.h"
0017
0018 #include <iosfwd>
0019 #include <map>
0020 #include <set>
0021 #include <string>
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 namespace edm {
0032 class BranchDescription {
0033 public:
0034 static int const invalidSplitLevel = -1;
0035 static int const invalidBasketSize = 0;
0036 enum MatchMode { Strict = 0, Permissive };
0037
0038 BranchDescription();
0039
0040 BranchDescription(BranchType const& branchType,
0041 std::string const& moduleLabel,
0042 std::string const& processName,
0043 std::string const& className,
0044 std::string const& friendlyClassName,
0045 std::string const& productInstanceName,
0046 std::string const& moduleName,
0047 ParameterSetID const& parameterSetID,
0048 TypeWithDict const& theTypeWithDict,
0049 bool produced = true,
0050 bool availableOnlyAtEndTransition = false,
0051 std::set<std::string> const& aliases = std::set<std::string>());
0052
0053 BranchDescription(BranchDescription const& aliasForBranch,
0054 std::string const& moduleLabelAlias,
0055 std::string const& productInstanceAlias);
0056
0057 ~BranchDescription() {}
0058
0059 void init() {
0060 initBranchName();
0061 initFromDictionary();
0062 }
0063
0064 void initBranchName();
0065
0066 void initFromDictionary();
0067
0068 void write(std::ostream& os) const;
0069
0070 void merge(BranchDescription const& other);
0071
0072 std::string const& moduleLabel() const { return moduleLabel_; }
0073 std::string const& processName() const { return processName_; }
0074 BranchID const& branchID() const { return branchID_; }
0075 BranchID const& aliasForBranchID() const { return aliasForBranchID_; }
0076 bool isAlias() const { return aliasForBranchID_.isValid() && produced(); }
0077 BranchID const& originalBranchID() const { return aliasForBranchID_.isValid() ? aliasForBranchID_ : branchID_; }
0078 std::string const& fullClassName() const { return fullClassName_; }
0079 std::string const& className() const { return fullClassName(); }
0080 std::string const& friendlyClassName() const { return friendlyClassName_; }
0081 std::string const& productInstanceName() const { return productInstanceName_; }
0082 bool produced() const { return transient_.produced_; }
0083 void setProduced(bool isProduced) { transient_.produced_ = isProduced; }
0084 bool present() const { return !transient_.dropped_; }
0085 bool dropped() const { return transient_.dropped_; }
0086 void setDropped(bool isDropped) { transient_.dropped_ = isDropped; }
0087
0088 bool onDemand() const { return transient_.onDemand_; }
0089 void setOnDemand(bool isOnDemand) { transient_.onDemand_ = isOnDemand; }
0090 bool availableOnlyAtEndTransition() const { return transient_.availableOnlyAtEndTransition_; }
0091 bool transient() const { return transient_.transient_; }
0092 void setTransient(bool isTransient) { transient_.transient_ = isTransient; }
0093 TypeWithDict const& wrappedType() const { return transient_.wrappedType_; }
0094 void setWrappedType(TypeWithDict const& type) { transient_.wrappedType_ = type; }
0095 TypeWithDict const& unwrappedType() const { return transient_.unwrappedType_; }
0096 void setUnwrappedType(TypeWithDict const& type) { transient_.unwrappedType_ = type; }
0097 TypeID wrappedTypeID() const { return TypeID(transient_.wrappedType_.typeInfo()); }
0098 TypeID unwrappedTypeID() const { return TypeID(transient_.unwrappedType_.typeInfo()); }
0099 int splitLevel() const { return transient_.splitLevel_; }
0100 void setSplitLevel(int level) { transient_.splitLevel_ = level; }
0101 int basketSize() const { return transient_.basketSize_; }
0102 void setBasketSize(int size) { transient_.basketSize_ = size; }
0103
0104 bool isSwitchAlias() const { return not transient_.switchAliasModuleLabel_.empty(); }
0105 std::string const& switchAliasModuleLabel() const { return transient_.switchAliasModuleLabel_; }
0106 void setSwitchAliasModuleLabel(std::string label) { transient_.switchAliasModuleLabel_ = std::move(label); }
0107 BranchID const& switchAliasForBranchID() const { return transient_.switchAliasForBranchID_; }
0108 void setSwitchAliasForBranch(BranchDescription const& aliasForBranch);
0109
0110 bool isAnyAlias() const { return isAlias() or isSwitchAlias(); }
0111
0112 bool isProvenanceSetOnRead() const noexcept { return transient_.isProvenanceSetOnRead_; }
0113 void setIsProvenanceSetOnRead(bool value = true) noexcept { transient_.isProvenanceSetOnRead_ = value; }
0114
0115 ParameterSetID const& parameterSetID() const { return transient_.parameterSetID_; }
0116 std::string const& moduleName() const { return transient_.moduleName_; }
0117
0118 std::set<std::string> const& branchAliases() const { return branchAliases_; }
0119 void insertBranchAlias(std::string const& alias) { branchAliases_.insert(alias); }
0120 std::string const& branchName() const { return transient_.branchName_; }
0121 void clearBranchName() { transient_.branchName_.clear(); }
0122 BranchType const& branchType() const { return branchType_; }
0123 std::string const& wrappedName() const { return transient_.wrappedName_; }
0124 void setWrappedName(std::string const& name) { transient_.wrappedName_ = name; }
0125
0126 bool isMergeable() const { return transient_.isMergeable_; }
0127 void setIsMergeable(bool v) { transient_.isMergeable_ = v; }
0128
0129 void updateFriendlyClassName();
0130
0131 void initializeTransients() { transient_.reset(); }
0132
0133 struct Transients {
0134 Transients();
0135
0136 void reset();
0137
0138
0139
0140 ParameterSetID parameterSetID_;
0141
0142
0143
0144 std::string moduleName_;
0145
0146
0147 std::string branchName_;
0148
0149
0150 std::string wrappedName_;
0151
0152
0153 std::string switchAliasModuleLabel_;
0154
0155
0156
0157
0158 BranchID switchAliasForBranchID_;
0159
0160
0161 TypeWithDict wrappedType_;
0162
0163
0164 TypeWithDict unwrappedType_;
0165
0166
0167
0168 int splitLevel_;
0169
0170
0171
0172 int basketSize_;
0173
0174
0175 bool produced_;
0176
0177
0178
0179 bool onDemand_;
0180
0181
0182
0183
0184 bool dropped_;
0185
0186
0187
0188 bool transient_;
0189
0190
0191 bool availableOnlyAtEndTransition_;
0192
0193
0194
0195 bool isMergeable_;
0196
0197
0198 bool isProvenanceSetOnRead_ = false;
0199 };
0200
0201 private:
0202 void throwIfInvalid_() const;
0203
0204
0205 BranchType branchType_;
0206
0207
0208
0209 std::string moduleLabel_;
0210
0211
0212 std::string processName_;
0213
0214
0215 BranchID branchID_;
0216
0217
0218 std::string fullClassName_;
0219
0220
0221 std::string friendlyClassName_;
0222
0223
0224
0225 std::string productInstanceName_;
0226
0227
0228 std::set<std::string> branchAliases_;
0229
0230
0231
0232
0233 BranchID aliasForBranchID_;
0234
0235 Transients transient_;
0236 };
0237
0238 inline std::ostream& operator<<(std::ostream& os, BranchDescription const& p) {
0239 p.write(os);
0240 return os;
0241 }
0242
0243 bool operator<(BranchDescription const& a, BranchDescription const& b);
0244
0245 bool operator==(BranchDescription const& a, BranchDescription const& b);
0246
0247 bool combinable(BranchDescription const& a, BranchDescription const& b);
0248
0249 std::string match(BranchDescription const& a, BranchDescription const& b, std::string const& fileName);
0250 }
0251 #endif