Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-03-14 23:36:07

0001 #ifndef DataFormats_Provenance_BranchDescription_h
0002 #define DataFormats_Provenance_BranchDescription_h
0003 
0004 /*----------------------------------------------------------------------
0005 
0006 BranchDescription: The full description of a Branch.
0007 This description also applies to every product instance on the branch.
0008 
0009 ----------------------------------------------------------------------*/
0010 #include "DataFormats/Provenance/interface/BranchID.h"
0011 #include "DataFormats/Provenance/interface/BranchType.h"
0012 #include "DataFormats/Provenance/interface/ProvenanceFwd.h"
0013 #include "FWCore/Utilities/interface/TypeID.h"
0014 #include "FWCore/Reflection/interface/TypeWithDict.h"
0015 
0016 #include <iosfwd>
0017 #include <map>
0018 #include <set>
0019 #include <string>
0020 
0021 #if (not defined __INCLUDE_LEVEL__ or __INCLUDE_LEVEL__ > 0) and \
0022     not defined(DataFormats_Provenance_ProductDescription_h)
0023 #error The name BranchDescription is deprecated, please use ProductDescription instead.
0024 #endif
0025 /*
0026   BranchDescription
0027 
0028   definitions:
0029   The event-independent description of an EDProduct.
0030 
0031 */
0032 
0033 namespace edm {
0034   class BranchDescription {
0035   public:
0036     static int const invalidSplitLevel = -1;
0037     static int const invalidBasketSize = 0;
0038     enum MatchMode { Strict = 0, Permissive };
0039 
0040     BranchDescription();
0041 
0042     BranchDescription(BranchType const& branchType,
0043                       std::string const& moduleLabel,
0044                       std::string const& processName,
0045                       std::string const& className,
0046                       std::string const& friendlyClassName,
0047                       std::string const& productInstanceName,
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     //returns true if unscheduled (produced()==true) or using delayed reader (produced()==false)
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 
0102     bool isSwitchAlias() const { return not transient_.switchAliasModuleLabel_.empty(); }
0103     std::string const& switchAliasModuleLabel() const { return transient_.switchAliasModuleLabel_; }
0104     void setSwitchAliasModuleLabel(std::string label) { transient_.switchAliasModuleLabel_ = std::move(label); }
0105     BranchID const& switchAliasForBranchID() const { return transient_.switchAliasForBranchID_; }
0106     void setSwitchAliasForBranch(BranchDescription const& aliasForBranch);
0107 
0108     bool isAnyAlias() const { return isAlias() or isSwitchAlias(); }
0109 
0110     bool isProvenanceSetOnRead() const noexcept { return transient_.isProvenanceSetOnRead_; }
0111     void setIsProvenanceSetOnRead(bool value = true) noexcept { transient_.isProvenanceSetOnRead_ = value; }
0112 
0113     std::set<std::string> const& branchAliases() const { return branchAliases_; }
0114     void insertBranchAlias(std::string const& alias) { branchAliases_.insert(alias); }
0115     std::string const& branchName() const { return transient_.branchName_; }
0116     void clearBranchName() { transient_.branchName_.clear(); }
0117     BranchType const& branchType() const { return branchType_; }
0118     std::string const& wrappedName() const { return transient_.wrappedName_; }
0119     void setWrappedName(std::string const& name) { transient_.wrappedName_ = name; }
0120 
0121     bool isMergeable() const { return transient_.isMergeable_; }
0122     void setIsMergeable(bool v) { transient_.isMergeable_ = v; }
0123 
0124     void updateFriendlyClassName();
0125 
0126     void initializeTransients() { transient_.reset(); }
0127 
0128     struct Transients {
0129       Transients();
0130 
0131       void reset();
0132 
0133       // The branch name, which is currently derivable from the other attributes.
0134       std::string branchName_;
0135 
0136       // The wrapped class name, which is currently derivable from the other attributes.
0137       std::string wrappedName_;
0138 
0139       // For SwitchProducer alias, the label of the aliased-for label; otherwise empty
0140       std::string switchAliasModuleLabel_;
0141 
0142       // Need a separate (transient) BranchID for switch, because
0143       // otherwise originalBranchID() gives wrong answer when reading
0144       // from a file (leading to wrong ProductProvenance to be retrieved)
0145       BranchID switchAliasForBranchID_;
0146 
0147       // A TypeWithDict object for the wrapped object
0148       // This is set if and only if the dropped_ is false
0149       TypeWithDict wrappedType_;
0150 
0151       // A TypeWithDict object for the unwrapped object
0152       // This is set if and only if the dropped_ is false
0153       TypeWithDict unwrappedType_;
0154 
0155       // Was this branch produced in this process rather than in a previous process
0156       bool produced_;
0157 
0158       // Was this branch produced in this current process and by unscheduled production
0159       // This item is set only in the framework, not by FWLite.
0160       bool onDemand_;
0161 
0162       // Was this branch produced in this current process via the transform ability
0163       bool isTransform_;
0164 
0165       // Has the branch been dropped from the product tree in this file
0166       // (or if this is a merged product registry, in the first file).
0167       // This item is set only in the framework, not by FWLite.
0168       bool dropped_;
0169 
0170       // Is the class of the branch marked as transient
0171       // in the data dictionary
0172       bool transient_;
0173 
0174       // if Run or Lumi based, can only get at end transition
0175       bool availableOnlyAtEndTransition_;
0176 
0177       // True if the product definition has a mergeProduct function
0178       // and the branchType is Run or Lumi
0179       bool isMergeable_;
0180 
0181       // True if provenance is set on call from input on read
0182       bool isProvenanceSetOnRead_ = false;
0183     };
0184 
0185   private:
0186     void throwIfInvalid_() const;
0187 
0188     // What tree is the branch in?
0189     BranchType branchType_;
0190 
0191     // A human friendly string that uniquely identifies the EDProducer
0192     // and becomes part of the identity of a product that it produces
0193     std::string moduleLabel_;
0194 
0195     // the physical process that this program was part of (e.g. production)
0196     std::string processName_;
0197 
0198     // An ID uniquely identifying the branch
0199     BranchID branchID_;
0200 
0201     // the full name of the type of product this is
0202     std::string fullClassName_;
0203 
0204     // a readable name of the type of product this is
0205     std::string friendlyClassName_;
0206 
0207     // a user-supplied name to distinguish multiple products of the same type
0208     // that are produced by the same producer
0209     std::string productInstanceName_;
0210 
0211     // The branch ROOT alias(es), which are settable by the user.
0212     std::set<std::string> branchAliases_;
0213 
0214     // If this branch *is* an EDAlias, this field is the BranchID
0215     // of the branch for which this branch is an alias.
0216     // If this branch is not an EDAlias, the normal case, this field is 0.
0217     BranchID aliasForBranchID_;
0218 
0219     Transients transient_;
0220   };
0221 
0222   inline std::ostream& operator<<(std::ostream& os, BranchDescription const& p) {
0223     p.write(os);
0224     return os;
0225   }
0226 
0227   bool operator<(BranchDescription const& a, BranchDescription const& b);
0228 
0229   bool operator==(BranchDescription const& a, BranchDescription const& b);
0230 
0231   bool combinable(BranchDescription const& a, BranchDescription const& b);
0232 
0233   std::string match(BranchDescription const& a, BranchDescription const& b, std::string const& fileName);
0234 }  // namespace edm
0235 #endif