Back to home page

Project CMSSW displayed by LXR

 
 

    


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 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/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   BranchDescription
0025 
0026   definitions:
0027   The event-independent description of an EDProduct.
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     //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     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       // The parameter set id of the producer.
0141       // This is set if and only if produced_ is true.
0142       ParameterSetID parameterSetID_;
0143 
0144       // The module name of the producer.
0145       // This is set if and only if produced_ is true.
0146       std::string moduleName_;
0147 
0148       // The branch name, which is currently derivable from the other attributes.
0149       std::string branchName_;
0150 
0151       // The wrapped class name, which is currently derivable from the other attributes.
0152       std::string wrappedName_;
0153 
0154       // For SwitchProducer alias, the label of the aliased-for label; otherwise empty
0155       std::string switchAliasModuleLabel_;
0156 
0157       // Need a separate (transient) BranchID for switch, because
0158       // otherwise originalBranchID() gives wrong answer when reading
0159       // from a file (leading to wrong ProductProvenance to be retrieved)
0160       BranchID switchAliasForBranchID_;
0161 
0162       // A TypeWithDict object for the wrapped object
0163       // This is set if and only if the dropped_ is false
0164       TypeWithDict wrappedType_;
0165 
0166       // A TypeWithDict object for the unwrapped object
0167       // This is set if and only if the dropped_ is false
0168       TypeWithDict unwrappedType_;
0169 
0170       // The split level of the branch, as marked
0171       // in the data dictionary.
0172       int splitLevel_;
0173 
0174       // The basket size of the branch, as marked
0175       // in the data dictionary.
0176       int basketSize_;
0177 
0178       // Was this branch produced in this process rather than in a previous process
0179       bool produced_;
0180 
0181       // Was this branch produced in this current process and by unscheduled production
0182       // This item is set only in the framework, not by FWLite.
0183       bool onDemand_;
0184 
0185       // Was this branch produced in this current process via the transform ability
0186       bool isTransform_;
0187 
0188       // Has the branch been dropped from the product tree in this file
0189       // (or if this is a merged product registry, in the first file).
0190       // This item is set only in the framework, not by FWLite.
0191       bool dropped_;
0192 
0193       // Is the class of the branch marked as transient
0194       // in the data dictionary
0195       bool transient_;
0196 
0197       // if Run or Lumi based, can only get at end transition
0198       bool availableOnlyAtEndTransition_;
0199 
0200       // True if the product definition has a mergeProduct function
0201       // and the branchType is Run or Lumi
0202       bool isMergeable_;
0203 
0204       // True if provenance is set on call from input on read
0205       bool isProvenanceSetOnRead_ = false;
0206     };
0207 
0208   private:
0209     void throwIfInvalid_() const;
0210 
0211     // What tree is the branch in?
0212     BranchType branchType_;
0213 
0214     // A human friendly string that uniquely identifies the EDProducer
0215     // and becomes part of the identity of a product that it produces
0216     std::string moduleLabel_;
0217 
0218     // the physical process that this program was part of (e.g. production)
0219     std::string processName_;
0220 
0221     // An ID uniquely identifying the branch
0222     BranchID branchID_;
0223 
0224     // the full name of the type of product this is
0225     std::string fullClassName_;
0226 
0227     // a readable name of the type of product this is
0228     std::string friendlyClassName_;
0229 
0230     // a user-supplied name to distinguish multiple products of the same type
0231     // that are produced by the same producer
0232     std::string productInstanceName_;
0233 
0234     // The branch ROOT alias(es), which are settable by the user.
0235     std::set<std::string> branchAliases_;
0236 
0237     // If this branch *is* an EDAlias, this field is the BranchID
0238     // of the branch for which this branch is an alias.
0239     // If this branch is not an EDAlias, the normal case, this field is 0.
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 }  // namespace edm
0258 #endif