File indexing completed on 2024-04-06 12:05:01
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 isTransform() const { return transient_.isTransform_; }
0085 void setIsTransform(bool isTransform) { transient_.isTransform_ = isTransform; }
0086 bool present() const { return !transient_.dropped_; }
0087 bool dropped() const { return transient_.dropped_; }
0088 void setDropped(bool isDropped) { transient_.dropped_ = isDropped; }
0089
0090 bool onDemand() const { return transient_.onDemand_; }
0091 void setOnDemand(bool isOnDemand) { transient_.onDemand_ = isOnDemand; }
0092 bool availableOnlyAtEndTransition() const { return transient_.availableOnlyAtEndTransition_; }
0093 bool transient() const { return transient_.transient_; }
0094 void setTransient(bool isTransient) { transient_.transient_ = isTransient; }
0095 TypeWithDict const& wrappedType() const { return transient_.wrappedType_; }
0096 void setWrappedType(TypeWithDict const& type) { transient_.wrappedType_ = type; }
0097 TypeWithDict const& unwrappedType() const { return transient_.unwrappedType_; }
0098 void setUnwrappedType(TypeWithDict const& type) { transient_.unwrappedType_ = type; }
0099 TypeID wrappedTypeID() const { return TypeID(transient_.wrappedType_.typeInfo()); }
0100 TypeID unwrappedTypeID() const { return TypeID(transient_.unwrappedType_.typeInfo()); }
0101 int splitLevel() const { return transient_.splitLevel_; }
0102 void setSplitLevel(int level) { transient_.splitLevel_ = level; }
0103 int basketSize() const { return transient_.basketSize_; }
0104 void setBasketSize(int size) { transient_.basketSize_ = size; }
0105
0106 bool isSwitchAlias() const { return not transient_.switchAliasModuleLabel_.empty(); }
0107 std::string const& switchAliasModuleLabel() const { return transient_.switchAliasModuleLabel_; }
0108 void setSwitchAliasModuleLabel(std::string label) { transient_.switchAliasModuleLabel_ = std::move(label); }
0109 BranchID const& switchAliasForBranchID() const { return transient_.switchAliasForBranchID_; }
0110 void setSwitchAliasForBranch(BranchDescription const& aliasForBranch);
0111
0112 bool isAnyAlias() const { return isAlias() or isSwitchAlias(); }
0113
0114 bool isProvenanceSetOnRead() const noexcept { return transient_.isProvenanceSetOnRead_; }
0115 void setIsProvenanceSetOnRead(bool value = true) noexcept { transient_.isProvenanceSetOnRead_ = value; }
0116
0117 ParameterSetID const& parameterSetID() const { return transient_.parameterSetID_; }
0118 std::string const& moduleName() const { return transient_.moduleName_; }
0119
0120 std::set<std::string> const& branchAliases() const { return branchAliases_; }
0121 void insertBranchAlias(std::string const& alias) { branchAliases_.insert(alias); }
0122 std::string const& branchName() const { return transient_.branchName_; }
0123 void clearBranchName() { transient_.branchName_.clear(); }
0124 BranchType const& branchType() const { return branchType_; }
0125 std::string const& wrappedName() const { return transient_.wrappedName_; }
0126 void setWrappedName(std::string const& name) { transient_.wrappedName_ = name; }
0127
0128 bool isMergeable() const { return transient_.isMergeable_; }
0129 void setIsMergeable(bool v) { transient_.isMergeable_ = v; }
0130
0131 void updateFriendlyClassName();
0132
0133 void initializeTransients() { transient_.reset(); }
0134
0135 struct Transients {
0136 Transients();
0137
0138 void reset();
0139
0140
0141
0142 ParameterSetID parameterSetID_;
0143
0144
0145
0146 std::string moduleName_;
0147
0148
0149 std::string branchName_;
0150
0151
0152 std::string wrappedName_;
0153
0154
0155 std::string switchAliasModuleLabel_;
0156
0157
0158
0159
0160 BranchID switchAliasForBranchID_;
0161
0162
0163
0164 TypeWithDict wrappedType_;
0165
0166
0167
0168 TypeWithDict unwrappedType_;
0169
0170
0171
0172 int splitLevel_;
0173
0174
0175
0176 int basketSize_;
0177
0178
0179 bool produced_;
0180
0181
0182
0183 bool onDemand_;
0184
0185
0186 bool isTransform_;
0187
0188
0189
0190
0191 bool dropped_;
0192
0193
0194
0195 bool transient_;
0196
0197
0198 bool availableOnlyAtEndTransition_;
0199
0200
0201
0202 bool isMergeable_;
0203
0204
0205 bool isProvenanceSetOnRead_ = false;
0206 };
0207
0208 private:
0209 void throwIfInvalid_() const;
0210
0211
0212 BranchType branchType_;
0213
0214
0215
0216 std::string moduleLabel_;
0217
0218
0219 std::string processName_;
0220
0221
0222 BranchID branchID_;
0223
0224
0225 std::string fullClassName_;
0226
0227
0228 std::string friendlyClassName_;
0229
0230
0231
0232 std::string productInstanceName_;
0233
0234
0235 std::set<std::string> branchAliases_;
0236
0237
0238
0239
0240 BranchID aliasForBranchID_;
0241
0242 Transients transient_;
0243 };
0244
0245 inline std::ostream& operator<<(std::ostream& os, BranchDescription const& p) {
0246 p.write(os);
0247 return os;
0248 }
0249
0250 bool operator<(BranchDescription const& a, BranchDescription const& b);
0251
0252 bool operator==(BranchDescription const& a, BranchDescription const& b);
0253
0254 bool combinable(BranchDescription const& a, BranchDescription const& b);
0255
0256 std::string match(BranchDescription const& a, BranchDescription const& b, std::string const& fileName);
0257 }
0258 #endif