Back to home page

Project CMSSW displayed by LXR

 
 

    


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